diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/SEBServerMigrationStrategy.java b/src/main/java/ch/ethz/seb/sebserver/webservice/SEBServerMigrationStrategy.java index e90d7fec..a972257d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/SEBServerMigrationStrategy.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/SEBServerMigrationStrategy.java @@ -51,9 +51,14 @@ public class SEBServerMigrationStrategy implements FlywayMigrationStrategy { } public void applyMigration() { + if (this.webserviceInfo.hasProfile("test")) { + SEBServerInit.INIT_LOGGER.info("No migration applies for test profile"); + return; + } + final String webserviceUUID = this.webserviceInfo.getWebserviceUUID(); if (this.migrationApplied) { - log.warn("Migration already applied for this webservice: {}", webserviceUUID); + SEBServerInit.INIT_LOGGER.warn("Migration already applied for this webservice: {}", webserviceUUID); return; } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceInfo.java b/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceInfo.java index f1dbf615..6745b1d0 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceInfo.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/WebserviceInfo.java @@ -10,9 +10,12 @@ package ch.ethz.seb.sebserver.webservice; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; import java.util.UUID; import org.apache.commons.lang3.BooleanUtils; @@ -64,6 +67,7 @@ public class WebserviceInfo { private final long distributedUpdateInterval; private Map lmsExternalAddressAlias; + private final Set activeProfiles; private final WebserviceInfoDAO webserviceInfoDAO; private boolean isMaster = false; @@ -89,6 +93,8 @@ public class WebserviceInfo { Long.class, 3000L); + this.activeProfiles = new HashSet<>(Arrays.asList(environment.getActiveProfiles())); + if (StringUtils.isEmpty(this.webserverName)) { log.warn("NOTE: External server name, property : 'sebserver.webservice.http.external.servername' " + "is not set from configuration. The external server name is set to the server address!"); @@ -151,6 +157,10 @@ public class WebserviceInfo { return this.testProperty; } + public boolean hasProfile(final String profile) { + return this.activeProfiles.contains(profile); + } + public String getHttpScheme() { return this.httpScheme; } diff --git a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java index fe651cd7..a357ebeb 100644 --- a/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/gui/integration/UseCasesIntegrationTest.java @@ -209,6 +209,7 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUs import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserAccountNames; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserDependencies; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.NewUserAccount; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.RegisterNewUser; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.SaveUserAccount; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.SEBClientConfigDAO; @@ -3098,4 +3099,32 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { } + @Test + @Order(24) + // ************************************* + // Use Case 24: Register a new User + public void testUsecase24_RegisterUser() throws Exception { + final RestServiceImpl restService = createRestServiceForUser( + "admin", + "admin", + new RegisterNewUser()); + + final UserInfo newUser = restService.getBuilder(RegisterNewUser.class) + .withFormParam(Domain.USER.ATTR_INSTITUTION_ID, "1") + .withFormParam(Domain.USER.ATTR_NAME, "testSupport1") + .withFormParam(Domain.USER.ATTR_USERNAME, "testSupport1") + .withFormParam(Domain.USER.ATTR_SURNAME, "testSupport1") + .withFormParam(Domain.USER.ATTR_EMAIL, "test@test16.ch") + .withFormParam(PasswordChange.ATTR_NAME_NEW_PASSWORD, "testSupport1") + .withFormParam(PasswordChange.ATTR_NAME_CONFIRM_NEW_PASSWORD, "testSupport1") + .withFormParam(Domain.USER.ATTR_LANGUAGE, Locale.ENGLISH.getLanguage()) + .withFormParam(Domain.USER.ATTR_TIMEZONE, DateTimeZone.UTC.getID()) + .call() + .getOrThrow(); + + assertNotNull(newUser); + assertEquals("testSupport1", newUser.name); + assertEquals("[EXAM_SUPPORTER]", newUser.getRoles().toString()); + } + }