diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/AdministrationAPIIntegrationTester.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/AdministrationAPIIntegrationTester.java index 8aa78542..dc971516 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/AdministrationAPIIntegrationTester.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/AdministrationAPIIntegrationTester.java @@ -125,7 +125,10 @@ public abstract class AdministrationAPIIntegrationTester { } public RestAPITestHelper withPath(final String path) { - this.path = this.path + path; + if (path == null) { + return this; + } + this.path += (path.startsWith("/")) ? path : "/" + path; return this; } diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/EntityAPITests.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/EntityAPITests.java new file mode 100644 index 00000000..e598d9df --- /dev/null +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/EntityAPITests.java @@ -0,0 +1,28 @@ +/* + * 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.integration.api.admin; + +import org.junit.Test; +import org.springframework.test.context.jdbc.Sql; + +@Sql(scripts = { "classpath:schema-test.sql", "classpath:data-test.sql" }) +public class EntityAPITests extends AdministrationAPIIntegrationTester { + + // TODO test to create two Institutions with the same name (should not be possible) + @Test + public void createInstitutionsWithSameName() { + + } + + // TOOD test get for ids with several equal ids --> should get only one instance per id + @Test + public void getInstitutionForIdsWithEqualIds() { + + } +} diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/LmsSetupAPITest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/LmsSetupAPITest.java index 3a1c3291..821c8d0e 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/LmsSetupAPITest.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/admin/LmsSetupAPITest.java @@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.webservice.integration.api.admin; import static org.junit.Assert.*; +import java.util.Collection; import java.util.List; import org.junit.Test; @@ -22,6 +23,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.Domain; +import ch.ethz.seb.sebserver.gbl.model.EntityName; import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType; @@ -31,9 +33,7 @@ public class LmsSetupAPITest extends AdministrationAPIIntegrationTester { @Test public void testCreateModifyActivateDelete() throws Exception { - // Institutional admin 1 create a LMSSetup - - // create new institution with seb-admin + // create new LmsSetup with seb-admin LmsSetup lmsSetup = new RestAPITestHelper() .withAccessToken(getAdminInstitution1Access()) .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) @@ -196,4 +196,134 @@ public class LmsSetupAPITest extends AdministrationAPIIntegrationTester { assertEquals("[lmsSetup, lmsType, notNull]", String.valueOf(errors.get(0).attributes)); } + @Test + public void getForIds() throws Exception { + // create some new LmsSetup with seb-admin + final LmsSetup lmsSetup1 = new RestAPITestHelper() + .withAccessToken(getAdminInstitution1Access()) + .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) + .withMethod(HttpMethod.POST) + .withAttribute("name", "new LmsSetup 1") + .withAttribute(Domain.LMS_SETUP.ATTR_LMS_TYPE, LmsType.MOCKUP.name()) + .withAttribute("active", "false") + .withExpectedStatus(HttpStatus.OK) + .getAsObject(new TypeReference() { + }); + final LmsSetup lmsSetup2 = new RestAPITestHelper() + .withAccessToken(getAdminInstitution1Access()) + .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) + .withMethod(HttpMethod.POST) + .withAttribute("name", "new LmsSetup 2") + .withAttribute(Domain.LMS_SETUP.ATTR_LMS_TYPE, LmsType.MOCKUP.name()) + .withAttribute("active", "false") + .withExpectedStatus(HttpStatus.OK) + .getAsObject(new TypeReference() { + }); + + final Collection lmsSetups = new RestAPITestHelper() + .withAccessToken(getSebAdminAccess()) + .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) + .withPath(SEBServerRestEndpoints.LIST_ENDPOINT_SUFFIX) + .withAttribute("ids", lmsSetup1.id + "," + lmsSetup2.id) + .withExpectedStatus(HttpStatus.OK) + .getAsObject(new TypeReference>() { + }); + + assertNotNull(lmsSetups); + assertTrue(lmsSetups.size() == 2); + } + + @Test + public void getNames() throws Exception { + // create some new LmsSetup with seb-admin + new RestAPITestHelper() + .withAccessToken(getAdminInstitution1Access()) + .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) + .withMethod(HttpMethod.POST) + .withAttribute("name", "new LmsSetup 1") + .withAttribute(Domain.LMS_SETUP.ATTR_LMS_TYPE, LmsType.MOCKUP.name()) + .withAttribute("active", "false") + .withExpectedStatus(HttpStatus.OK) + .getAsObject(new TypeReference() { + }); + new RestAPITestHelper() + .withAccessToken(getAdminInstitution1Access()) + .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) + .withMethod(HttpMethod.POST) + .withAttribute("name", "new LmsSetup 2") + .withAttribute(Domain.LMS_SETUP.ATTR_LMS_TYPE, LmsType.MOCKUP.name()) + .withAttribute("active", "false") + .withExpectedStatus(HttpStatus.OK) + .getAsObject(new TypeReference() { + }); + + final Collection lmsSetupNames = new RestAPITestHelper() + .withAccessToken(getSebAdminAccess()) + .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) + .withPath(SEBServerRestEndpoints.NAMES_ENDPOINT_SUFFIX) + .withExpectedStatus(HttpStatus.OK) + .getAsObject(new TypeReference>() { + }); + + assertNotNull(lmsSetupNames); + assertTrue(lmsSetupNames.size() == 2); + } + + @Test + public void getById() throws Exception { + final Long id1 = new RestAPITestHelper() + .withAccessToken(getSebAdminAccess()) + .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) + .withMethod(HttpMethod.POST) + .withAttribute("name", "new LmsSetup 1") + .withAttribute(Domain.LMS_SETUP.ATTR_LMS_TYPE, LmsType.MOCKUP.name()) + .withAttribute("active", "false") + .withExpectedStatus(HttpStatus.OK) + .getAsObject(new TypeReference() { + }).id; + + final Long id2 = new RestAPITestHelper() + .withAccessToken(getSebAdminAccess()) + .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) + .withMethod(HttpMethod.POST) + .withAttribute("name", "new LmsSetup 2") + .withAttribute(Domain.LMS_SETUP.ATTR_INSTITUTION_ID, "2") + .withAttribute(Domain.LMS_SETUP.ATTR_LMS_TYPE, LmsType.MOCKUP.name()) + .withAttribute("active", "false") + .withExpectedStatus(HttpStatus.OK) + .getAsObject(new TypeReference() { + }).id; + + LmsSetup lmsSetup = new RestAPITestHelper() + .withAccessToken(getSebAdminAccess()) + .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) + .withPath(String.valueOf(id1)) + .withExpectedStatus(HttpStatus.OK) + .getAsObject(new TypeReference() { + }); + + assertNotNull(lmsSetup); + assertTrue(lmsSetup.id.longValue() == id1.longValue()); + + // a seb-admin is also able to get an institution that is not the one he self belongs to + lmsSetup = new RestAPITestHelper() + .withAccessToken(getSebAdminAccess()) + .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) + .withPath(String.valueOf(id2)) + .withExpectedStatus(HttpStatus.OK) + .getAsObject(new TypeReference() { + }); + + assertNotNull(lmsSetup); + assertTrue(lmsSetup.id.longValue() == id2.longValue()); + + // but a institutional-admin is not able to get an institution that is not the one he self belongs to + new RestAPITestHelper() + .withAccessToken(getAdminInstitution1Access()) + .withPath(SEBServerRestEndpoints.ENDPOINT_LMS_SETUP) + .withPath(String.valueOf(id2)) + .withExpectedStatus(HttpStatus.FORBIDDEN) + .getAsString(); + } + }