From c7c6bf1a422c23d00594d53ebbc5cba09add3d05 Mon Sep 17 00:00:00 2001 From: anhefti Date: Fri, 8 Feb 2019 12:19:15 +0100 Subject: [PATCH] more tests --- .../gbl/api/SEBServerRestEndpoints.java | 2 ++ .../servicelayer/lms/LmsBindingConfig.java | 19 ------------ .../weblayer/api/EntityController.java | 16 ++++++---- .../api/admin/InstitutionAPITest.java | 30 +++++++++++++++++++ 4 files changed, 42 insertions(+), 25 deletions(-) delete mode 100644 src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/LmsBindingConfig.java diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/SEBServerRestEndpoints.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/SEBServerRestEndpoints.java index 6e6403fa..4a5c42ae 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/SEBServerRestEndpoints.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/SEBServerRestEndpoints.java @@ -24,4 +24,6 @@ public class SEBServerRestEndpoints { public static final String NAMES_ENDPOINT_SUFFIX = "/names"; + public static final String LIST_ENDPOINT_SUFFIX = "/list"; + } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/LmsBindingConfig.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/LmsBindingConfig.java deleted file mode 100644 index 4aa58e54..00000000 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/LmsBindingConfig.java +++ /dev/null @@ -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 { - -} diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/EntityController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/EntityController.java index 236b0522..63bc72f7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/EntityController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/EntityController.java @@ -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 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 this.authorizationGrantService.checkGrantOnEntity( entity, PrivilegeType.WRITE)) diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/InstitutionAPITest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/InstitutionAPITest.java index 3abe84f9..cb47c8eb 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/InstitutionAPITest.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/InstitutionAPITest.java @@ -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 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>() { + }); + + assertNotNull(institutions); + assertTrue(institutions.size() == 3); + } + + @Test + public void getNames() throws Exception { + final Collection institutions = new RestAPITestHelper() + .withAccessToken(getSebAdminAccess()) + .withPath(SEBServerRestEndpoints.ENDPOINT_INSTITUTION) + .withPath(SEBServerRestEndpoints.NAMES_ENDPOINT_SUFFIX) + .withExpectedStatus(HttpStatus.OK) + .getAsObject(new TypeReference>() { + }); + + assertNotNull(institutions); + assertTrue(institutions.size() == 3); + } + static void assertContainsInstitution(final String name, final Collection institutions) { assert institutions != null; assert institutions.stream()