From 71635c85f6cb0f20dc3d8d6474635f1eee4c7840 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 10 Sep 2019 10:26:07 +0200 Subject: [PATCH] more tests and find-bug fixes --- findbugs-excludes.xml | 4 + ...InstitutionalAuthenticationEntryPoint.java | 40 ++++---- .../seb/sebserver/gui/RAPConfiguration.java | 3 + .../integration/UseCasesIntegrationTest.java | 94 +++++++++++++++++++ 4 files changed, 118 insertions(+), 23 deletions(-) diff --git a/findbugs-excludes.xml b/findbugs-excludes.xml index 13ddcdd9..e27b9224 100644 --- a/findbugs-excludes.xml +++ b/findbugs-excludes.xml @@ -27,6 +27,10 @@ + + + + diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/InstitutionalAuthenticationEntryPoint.java b/src/main/java/ch/ethz/seb/sebserver/gui/InstitutionalAuthenticationEntryPoint.java index e3b018f0..0a1584c1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/InstitutionalAuthenticationEntryPoint.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/InstitutionalAuthenticationEntryPoint.java @@ -9,8 +9,6 @@ package ch.ethz.seb.sebserver.gui; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; @@ -18,9 +16,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; -import org.eclipse.rap.rwt.RWT; -import org.eclipse.rap.rwt.client.WebClient; -import org.eclipse.rap.rwt.internal.application.ApplicationContextImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -36,7 +31,6 @@ import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import ch.ethz.seb.sebserver.gbl.api.API; -import ch.ethz.seb.sebserver.gui.RAPConfiguration.RAPSpringEntryPointFactory; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.WebserviceURIService; @Lazy @@ -146,24 +140,24 @@ final class InstitutionalAuthenticationEntryPoint implements AuthenticationEntry /** TODO this seems not to work as expected. Different Theme is only possible in RAP on different * entry-points and since entry-points are statically defined within the RAPConficuration * there is no possibility to apply them dynamically within an institution so far. - * + * * @param institutionalEndpoint * @return */ - private boolean initInstitutionalBasedThemeEntryPoint(final String institutionalEndpoint) { - try { - final ApplicationContextImpl appContext = (ApplicationContextImpl) RWT.getApplicationContext(); - final Map properties = new HashMap<>(); - properties.put(WebClient.THEME_ID, "sms"); - appContext.getEntryPointManager().register( - institutionalEndpoint, - new RAPSpringEntryPointFactory(), - properties); - - return true; - } catch (final Exception e) { - log.warn("Failed to dynamically set entry point for institution: {}", institutionalEndpoint, e); - return false; - } - } +// private boolean initInstitutionalBasedThemeEntryPoint(final String institutionalEndpoint) { +// try { +// final ApplicationContextImpl appContext = (ApplicationContextImpl) RWT.getApplicationContext(); +// final Map properties = new HashMap<>(); +// properties.put(WebClient.THEME_ID, "sms"); +// appContext.getEntryPointManager().register( +// institutionalEndpoint, +// new RAPSpringEntryPointFactory(), +// properties); +// +// return true; +// } catch (final Exception e) { +// log.warn("Failed to dynamically set entry point for institution: {}", institutionalEndpoint, e); +// return false; +// } +// } } \ No newline at end of file diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java b/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java index 5dcdc60e..9273d58a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java @@ -151,6 +151,9 @@ public class RAPConfiguration implements ApplicationConfiguration { return WebApplicationContextUtils .getRequiredWebApplicationContext(servletContext); + } catch (final RuntimeException e) { + log.error("Failed to initialize Spring-Context on HttpSession: " + httpSession); + throw e; } catch (final Exception e) { log.error("Failed to initialize Spring-Context on HttpSession: " + httpSession); throw new RuntimeException("Failed to initialize Spring-Context on HttpSession: " + httpSession); 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 d709dab1..5ad89efa 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 @@ -10,6 +10,8 @@ package ch.ethz.seb.sebserver.gui.integration; import static org.junit.Assert.*; +import java.util.Collection; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; @@ -28,6 +30,9 @@ import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport; import ch.ethz.seb.sebserver.gbl.model.Page; import ch.ethz.seb.sebserver.gbl.model.exam.Exam; import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamType; +import ch.ethz.seb.sebserver.gbl.model.exam.Indicator; +import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.IndicatorType; +import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold; 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; @@ -40,8 +45,13 @@ import ch.ethz.seb.sebserver.gbl.util.Utils; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCallError; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestServiceImpl; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExam; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExamNames; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExamPage; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetIndicator; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetIndicatorPage; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.NewIndicator; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.SaveExam; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.SaveIndicator; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.ActivateInstitution; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.GetInstitution; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.GetInstitutionNames; @@ -663,4 +673,88 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { assertFalse(savedExam.supporter.isEmpty()); } + @Test + @Order(7) + // ************************************* + // Use Case 7: Login as examAdmin2 + // - Get imported exam + // - add new indicator for exam + // - save exam with new indicator and test + // - create some thresholds for the new indicator + public void testUsecase7() { + final RestServiceImpl restService = createRestServiceForUser( + "examAdmin2", + "examAdmin2", + new GetExam(), + new GetExamNames(), + new NewIndicator(), + new SaveIndicator(), + new GetIndicator(), + new GetIndicatorPage()); + + final Result> examNamesResult = restService + .getBuilder(GetExamNames.class) + .call(); + + assertNotNull(examNamesResult); + assertFalse(examNamesResult.hasError()); + final List exams = examNamesResult.get(); + assertFalse(exams.isEmpty()); + final EntityName examName = exams.get(0); + assertEquals("Demo Quiz 1", examName.name); + + final Result examResult = restService + .getBuilder(GetExam.class) + .withURIVariable(API.PARAM_MODEL_ID, examName.modelId) + .call(); + + assertNotNull(examResult); + assertFalse(examResult.hasError()); + final Exam exam = examResult.get(); + + final Result newIndicatorResult = restService + .getBuilder(NewIndicator.class) + .withFormParam(Domain.INDICATOR.ATTR_EXAM_ID, exam.getModelId()) + .withFormParam(Domain.INDICATOR.ATTR_NAME, "Ping") + .withFormParam(Domain.INDICATOR.ATTR_TYPE, IndicatorType.LAST_PING.name) + .withFormParam(Domain.INDICATOR.ATTR_COLOR, "000001") + .call(); + + assertNotNull(newIndicatorResult); + assertFalse(newIndicatorResult.hasError()); + final Indicator newIndicator = newIndicatorResult.get(); + + assertEquals("Ping", newIndicator.name); + assertEquals("000001", newIndicator.defaultColor); + + final Indicator indicatorToSave = new Indicator( + newIndicator.id, newIndicator.examId, newIndicator.name, newIndicator.type, newIndicator.defaultColor, + Utils.immutableCollectionOf( + new Indicator.Threshold(2000d, "000011"), + new Indicator.Threshold(5000d, "001111"))); + + final Result savedIndicatorResult = restService + .getBuilder(SaveIndicator.class) + .withBody(indicatorToSave) + .call(); + + assertNotNull(savedIndicatorResult); + assertFalse(savedIndicatorResult.hasError()); + final Indicator savedIndicator = savedIndicatorResult.get(); + + assertEquals("Ping", savedIndicator.name); + assertEquals("000001", savedIndicator.defaultColor); + final Collection thresholds = savedIndicator.getThresholds(); + assertFalse(thresholds.isEmpty()); + assertTrue(thresholds.size() == 2); + final Iterator iterator = thresholds.iterator(); + final Threshold t1 = iterator.next(); + final Threshold t2 = iterator.next(); + + assertTrue(2000d - t1.value < .0001); + assertEquals("000011", t1.color); + assertTrue(5000d - t2.value < .0001); + assertEquals("001111", t2.color); + } + }