more tests

This commit is contained in:
anhefti 2019-02-08 12:19:15 +01:00
parent 04d438923d
commit c7c6bf1a42
4 changed files with 42 additions and 25 deletions

View file

@ -24,4 +24,6 @@ public class SEBServerRestEndpoints {
public static final String NAMES_ENDPOINT_SUFFIX = "/names";
public static final String LIST_ENDPOINT_SUFFIX = "/list";
}

View file

@ -1,19 +0,0 @@
/*
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package ch.ethz.seb.sebserver.webservice.servicelayer.lms;
import org.springframework.context.annotation.Configuration;
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
@Configuration
@WebServiceProfile
public class LmsBindingConfig {
}

View file

@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
import ch.ethz.seb.sebserver.gbl.api.SEBServerRestEndpoints;
import ch.ethz.seb.sebserver.gbl.model.Domain;
import ch.ethz.seb.sebserver.gbl.model.Entity;
import ch.ethz.seb.sebserver.gbl.model.EntityKey;
@ -120,7 +121,7 @@ public abstract class EntityController<T extends GrantEntity, M extends GrantEnt
// ******************
@RequestMapping(
path = "/names",
path = SEBServerRestEndpoints.NAMES_ENDPOINT_SUFFIX,
method = RequestMethod.GET,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
@ -168,16 +169,19 @@ public abstract class EntityController<T extends GrantEntity, M extends GrantEnt
// ******************
@RequestMapping(
path = "/list",
path = SEBServerRestEndpoints.LIST_ENDPOINT_SUFFIX,
method = RequestMethod.GET,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public Collection<T> getForIds(@RequestParam(name = "ids", required = true) final String ids) {
return Result.tryCatch(() -> {
return Arrays.asList(StringUtils.split(ids, Constants.LIST_SEPARATOR_CHAR))
.stream()
.map(modelId -> new EntityKey(modelId, this.entityDAO.entityType()))
.collect(Collectors.toList());
})
.flatMap(this.entityDAO::loadEntities)
.getOrThrow()
@ -274,17 +278,17 @@ public abstract class EntityController<T extends GrantEntity, M extends GrantEnt
// ******************
@RequestMapping(
path = "/{id}",
path = "/{modelId}",
method = RequestMethod.DELETE,
produces = MediaType.APPLICATION_JSON_VALUE)
public EntityProcessingReport hardDelete(@PathVariable final String id) {
public EntityProcessingReport hardDelete(@PathVariable final String modelId) {
final EntityType entityType = this.entityDAO.entityType();
final BulkAction bulkAction = new BulkAction(
Type.HARD_DELETE,
entityType,
new EntityKey(id, entityType));
new EntityKey(modelId, entityType));
return this.entityDAO.byModelId(id)
return this.entityDAO.byModelId(modelId)
.flatMap(entity -> this.authorizationGrantService.checkGrantOnEntity(
entity,
PrivilegeType.WRITE))

View file

@ -22,6 +22,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import ch.ethz.seb.sebserver.gbl.api.APIMessage;
import ch.ethz.seb.sebserver.gbl.api.SEBServerRestEndpoints;
import ch.ethz.seb.sebserver.gbl.model.EntityName;
import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport;
import ch.ethz.seb.sebserver.gbl.model.Page;
import ch.ethz.seb.sebserver.gbl.model.institution.Institution;
@ -337,6 +338,35 @@ public class InstitutionAPITest extends AdministrationAPIIntegrationTester {
assertEquals("Resource INSTITUTION with ID: 4 not found", error.get(0).details);
}
@Test
public void getForIds() throws Exception {
final Collection<Institution> institutions = new RestAPITestHelper()
.withAccessToken(getSebAdminAccess())
.withPath(SEBServerRestEndpoints.ENDPOINT_INSTITUTION)
.withPath(SEBServerRestEndpoints.LIST_ENDPOINT_SUFFIX)
.withAttribute("ids", "1,2,3")
.withExpectedStatus(HttpStatus.OK)
.getAsObject(new TypeReference<Collection<Institution>>() {
});
assertNotNull(institutions);
assertTrue(institutions.size() == 3);
}
@Test
public void getNames() throws Exception {
final Collection<EntityName> institutions = new RestAPITestHelper()
.withAccessToken(getSebAdminAccess())
.withPath(SEBServerRestEndpoints.ENDPOINT_INSTITUTION)
.withPath(SEBServerRestEndpoints.NAMES_ENDPOINT_SUFFIX)
.withExpectedStatus(HttpStatus.OK)
.getAsObject(new TypeReference<Collection<EntityName>>() {
});
assertNotNull(institutions);
assertTrue(institutions.size() == 3);
}
static void assertContainsInstitution(final String name, final Collection<Institution> institutions) {
assert institutions != null;
assert institutions.stream()