From a0f5d95037f1dbaafef286f1b7c8240ce723485e Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 11 Sep 2019 12:25:09 +0200 Subject: [PATCH] testing code coverage --- pmd-rulesets.xml | 5 +- pom.xml | 14 +- .../impl/ExamConfigurationServiceImpl.java | 2 +- .../WebserviceResourceConfiguration.java | 2 +- .../integration/UseCasesIntegrationTest.java | 178 +++++++++++++++++- 5 files changed, 186 insertions(+), 15 deletions(-) diff --git a/pmd-rulesets.xml b/pmd-rulesets.xml index a05b9b64..efb5d8a5 100644 --- a/pmd-rulesets.xml +++ b/pmd-rulesets.xml @@ -12,6 +12,9 @@ .*/batis/mapper/*.java .*/batis/model/*.java - + + + + diff --git a/pom.xml b/pom.xml index 9457ed1e..52c47fd4 100644 --- a/pom.xml +++ b/pom.xml @@ -173,6 +173,14 @@ report + + + ch/ethz/seb/sebserver/gui/content/**/* + ch/ethz/seb/sebserver/gui/form/**/* + ch/ethz/seb/sebserver/gui/table/**/* + ch/ethz/seb/sebserver/gui/widget/**/* + + post-unit-test @@ -186,12 +194,6 @@ target/jacoco.exec target/jacoco-ut - - ch/ethz/seb/sebserver/gui/content/**/* - ch/ethz/seb/sebserver/gui/form/**/* - ch/ethz/seb/sebserver/gui/table/**/* - ch/ethz/seb/sebserver/gui/widget/**/* - diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ExamConfigurationServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ExamConfigurationServiceImpl.java index 826c114d..2c020087 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ExamConfigurationServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ExamConfigurationServiceImpl.java @@ -124,7 +124,7 @@ public class ExamConfigurationServiceImpl implements ExamConfigurationService { final String ids = StringUtils.join( viewIds .stream() - .map(id -> String.valueOf(id)) + .map(String::valueOf) .collect(Collectors.toList()), Constants.LIST_SEPARATOR_CHAR); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/WebserviceResourceConfiguration.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/WebserviceResourceConfiguration.java index d9decc4e..8a8e1356 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/WebserviceResourceConfiguration.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/oauth/WebserviceResourceConfiguration.java @@ -63,7 +63,7 @@ public abstract class WebserviceResourceConfiguration extends ResourceServerConf // Switches off the Spring Boot auto configuration @Override @SuppressWarnings("PMD") - public void setConfigurers(final List configurers) { + public final void setConfigurers(final List configurers) { super.setConfigurers(configurers); } 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 4f7498f6..6f33b0fc 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 @@ -21,6 +21,7 @@ import java.util.Locale; import java.util.stream.Collectors; import org.apache.commons.io.IOUtils; +import org.apache.tomcat.util.buf.StringUtils; import org.joda.time.DateTimeZone; import org.junit.Test; import org.junit.jupiter.api.AfterAll; @@ -28,6 +29,7 @@ import org.junit.jupiter.api.BeforeAll; import org.springframework.core.annotation.Order; import org.springframework.test.context.jdbc.Sql; +import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.api.API; import ch.ethz.seb.sebserver.gbl.api.JSONMapper; import ch.ethz.seb.sebserver.gbl.model.Domain; @@ -44,8 +46,11 @@ import ch.ethz.seb.sebserver.gbl.model.exam.QuizData; import ch.ethz.seb.sebserver.gbl.model.institution.Institution; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.Configuration; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue; import ch.ethz.seb.sebserver.gbl.model.sebconfig.SebClientConfig; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.View; import ch.ethz.seb.sebserver.gbl.model.user.PasswordChange; import ch.ethz.seb.sebserver.gbl.model.user.UserInfo; import ch.ethz.seb.sebserver.gbl.model.user.UserRole; @@ -87,7 +92,10 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig. import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.ActivateExamConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.DeactivateExamConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigAttributes; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigurationPage; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigurationValuePage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigurationValues; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigurations; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNode; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNodePage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetFollowupConfiguration; @@ -937,6 +945,18 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { .collect(Collectors.toList()) .toString()); + final String viewIds = StringUtils.join(attributeMapping.getViewIds().stream().map(String::valueOf) + .collect(Collectors.toList()), + Constants.LIST_SEPARATOR_CHAR); + + assertEquals("1,2,3,4,5,6,8,9,10,11", viewIds); + final Result> viewsResponse = restService + .getBuilder(GetViewList.class) + .withQueryParam(API.PARAM_MODEL_ID_LIST, viewIds) + .call(); + + assertNotNull(viewsResponse); + assertFalse(viewsResponse.hasError()); } @Test @@ -955,23 +975,20 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { new NewExamConfig(), new GetExamConfigNode(), new GetExamConfigNodePage(), + new GetConfigurationPage(), + new GetConfigurations(), new SaveExamConfigHistory(), new ExportExamConfig(), new GetFollowupConfiguration(), new SebExamConfigUndo(), new SaveExamConfigValue(), new SaveExamConfigTableValues(), + new GetConfigurationValuePage(), new GetConfigurationValues(), new ActivateExamConfig(), new DeactivateExamConfig(), new GetUserAccountNames()); - final Result newConfigResponse = restService - .getBuilder(NewExamConfig.class) - .withFormParam(Domain.CONFIGURATION_NODE.ATTR_NAME, "New Exam Config") - .withFormParam(Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION, "This is a New Exam Config") - .call(); - // get user id final String userId = restService .getBuilder(GetUserAccountNames.class) @@ -985,12 +1002,161 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { assertNotNull(userId); + // get configuration page + final Result> pageResponse = restService + .getBuilder(GetExamConfigNodePage.class) + .call(); + + // there should be not configuration (for this institution of examAdmin2) now + assertNotNull(pageResponse); + assertFalse(pageResponse.hasError()); + final Page page = pageResponse.get(); + assertTrue(page.content.isEmpty()); + + final Result newConfigResponse = restService + .getBuilder(NewExamConfig.class) + .withFormParam(Domain.CONFIGURATION_NODE.ATTR_NAME, "New Exam Config") + .withFormParam(Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION, "This is a New Exam Config") + .call(); + assertNotNull(newConfigResponse); assertFalse(newConfigResponse.hasError()); final ConfigurationNode newConfig = newConfigResponse.get(); assertEquals("New Exam Config", newConfig.name); assertEquals(Long.valueOf(0), newConfig.templateId); assertEquals(userId, newConfig.owner); + + // get follow-up configuration + Result> configHistoryResponse = restService + .getBuilder(GetConfigurations.class) + .withQueryParam(Configuration.FILTER_ATTR_CONFIGURATION_NODE_ID, newConfig.getModelId()) + .call(); + + assertNotNull(configHistoryResponse); + assertFalse(configHistoryResponse.hasError()); + List configHistory = configHistoryResponse.get(); + assertFalse(configHistory.isEmpty()); + assertTrue(2 == configHistory.size()); + final Configuration initConfig = configHistory.get(0); + Configuration followup = configHistory.get(1); + assertEquals("v0", initConfig.version); + assertFalse(initConfig.followup); + assertNull(followup.version); + assertTrue(followup.followup); + + // get all configuration values + Result> valuesResponse = restService + .getBuilder(GetConfigurationValues.class) + .withQueryParam(ConfigurationValue.FILTER_ATTR_CONFIGURATION_ID, followup.getModelId()) + .call(); + + assertNotNull(valuesResponse); + assertFalse(valuesResponse.hasError()); + List values = valuesResponse.get(); + assertFalse(values.isEmpty()); + + // update a value -- grab first + final ConfigurationValue value = values.get(0); + ConfigurationValue newValue = new ConfigurationValue( + null, value.institutionId, value.configurationId, + value.attributeId, value.listIndex, "2"); + Result newValueResponse = restService + .getBuilder(SaveExamConfigValue.class) + .withBody(newValue) + .call(); + + assertNotNull(newValueResponse); + assertFalse(newValueResponse.hasError()); + ConfigurationValue savedValue = newValueResponse.get(); + assertEquals("2", savedValue.value); + + // save to history + final Result saveHistoryResponse = restService + .getBuilder(SaveExamConfigHistory.class) + .withURIVariable(API.PARAM_MODEL_ID, followup.getModelId()) + .call(); + + assertNotNull(saveHistoryResponse); + assertFalse(saveHistoryResponse.hasError()); + Configuration configuration = saveHistoryResponse.get(); + assertFalse(configuration.followup); + + configHistoryResponse = restService + .getBuilder(GetConfigurations.class) + .withQueryParam(Configuration.FILTER_ATTR_CONFIGURATION_NODE_ID, newConfig.getModelId()) + .call(); + + assertNotNull(configHistoryResponse); + assertFalse(configHistoryResponse.hasError()); + configHistory = configHistoryResponse.get(); + assertFalse(configHistory.isEmpty()); + assertTrue(3 == configHistory.size()); + + configHistoryResponse = restService + .getBuilder(GetConfigurations.class) + .withQueryParam(Configuration.FILTER_ATTR_CONFIGURATION_NODE_ID, newConfig.getModelId()) + .withQueryParam(Configuration.FILTER_ATTR_FOLLOWUP, "true") + .call(); + + assertNotNull(configHistoryResponse); + assertFalse(configHistoryResponse.hasError()); + followup = configHistoryResponse.get().get(0); + assertNotNull(followup); + assertTrue(followup.followup); + + // change value again + newValue = new ConfigurationValue( + null, value.institutionId, followup.id, + value.attributeId, value.listIndex, "3"); + newValueResponse = restService + .getBuilder(SaveExamConfigValue.class) + .withBody(newValue) + .call(); + + assertNotNull(newValueResponse); + assertFalse(newValueResponse.hasError()); + savedValue = newValueResponse.get(); + assertEquals("3", savedValue.value); + + // get current value + valuesResponse = restService + .getBuilder(GetConfigurationValues.class) + .withQueryParam(ConfigurationValue.FILTER_ATTR_CONFIGURATION_ID, followup.getModelId()) + .call(); + + assertNotNull(valuesResponse); + assertFalse(valuesResponse.hasError()); + values = valuesResponse.get(); + assertFalse(values.isEmpty()); + assertNotNull(newValueResponse); + assertFalse(newValueResponse.hasError()); + savedValue = newValueResponse.get(); + assertEquals("3", savedValue.value); + + // undo + final Result undoResponse = restService + .getBuilder(SebExamConfigUndo.class) + .withURIVariable(API.PARAM_MODEL_ID, followup.getModelId()) + .call(); + + assertNotNull(undoResponse); + assertFalse(undoResponse.hasError()); + configuration = undoResponse.get(); + assertTrue(configuration.followup); + + // check value has been reset + valuesResponse = restService + .getBuilder(GetConfigurationValues.class) + .withQueryParam(ConfigurationValue.FILTER_ATTR_CONFIGURATION_ID, configuration.getModelId()) + .call(); + + assertNotNull(valuesResponse); + assertFalse(valuesResponse.hasError()); + values = valuesResponse.get(); + final ConfigurationValue currentValue = + values.stream().filter(v -> v.attributeId == value.attributeId).findFirst().orElse(null); + assertNotNull(currentValue); + assertEquals("2", currentValue.value); } }