From cacd780f50ab3d43d989cf59804ca3e3b0ff1a3d Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 11 Sep 2019 13:30:16 +0200 Subject: [PATCH] fixes tests and coverage --- pom.xml | 17 -------- .../sebserver/gbl/model/exam/Indicator.java | 8 ++-- .../model/session/ClientConnectionData.java | 2 +- .../session/ClientConnectionTable.java | 11 ++++- .../servicelayer/session/ClientIndicator.java | 2 - .../session/impl/AbstractClientIndicator.java | 6 --- .../session/impl/ClientIndicatorFactory.java | 3 ++ .../integration/UseCasesIntegrationTest.java | 43 ++++++++++++++++++- 8 files changed, 60 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index 124f7ea6..a15b017c 100644 --- a/pom.xml +++ b/pom.xml @@ -174,25 +174,8 @@ report - - post-unit-test - test - - report - - - - target/jacoco.exec - - target/jacoco-ut - - - - - ch/ethz/seb/sebserver/gui/content/**/* ch/ethz/seb/sebserver/gui/form/**/* diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java index 64c9a3da..c0b2c8cf 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java @@ -32,15 +32,17 @@ public final class Indicator implements Entity { public static final String FILTER_ATTR_EXAM_ID = "examId"; public enum IndicatorType { - LAST_PING(Names.LAST_PING), - ERROR_COUNT(Names.ERROR_COUNT) + LAST_PING(Names.LAST_PING, true), + ERROR_COUNT(Names.ERROR_COUNT, true) ; public final String name; + public boolean integerValue; - private IndicatorType(final String name) { + private IndicatorType(final String name, final boolean integerValue) { this.name = name; + this.integerValue = integerValue; } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/ClientConnectionData.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/ClientConnectionData.java index 3f044511..7af93920 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/ClientConnectionData.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/ClientConnectionData.java @@ -69,7 +69,7 @@ public class ClientConnectionData { while (i1.hasNext()) { final IndicatorValue iv1 = i1.next(); final IndicatorValue iv2 = i2.next(); - if (iv1.getType() != iv2.getType() || iv1.getValue() != iv2.getValue()) { + if (iv1.getType() != iv2.getType() || Math.abs(iv1.getValue() - iv2.getValue()) > 0.1) { return false; } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java index 14990f24..0e2201b9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java @@ -245,6 +245,14 @@ public final class ClientConnectionTable { (e1, e2) -> e1, LinkedHashMap::new)); } + private static String getDisplayValue(final IndicatorValue indicatorValue) { + if (indicatorValue.getType().integerValue) { + return String.valueOf((int) indicatorValue.getValue()); + } else { + return String.valueOf(indicatorValue.getValue()); + } + } + private final class UpdatableTableItem implements Comparable { final Long connectionId; @@ -313,7 +321,8 @@ public final class ClientConnectionTable { indicatorData.index, indicatorData.defaultColor); } else { - tableItem.setText(indicatorData.index, String.valueOf(indicatorValue.getValue())); + + tableItem.setText(indicatorData.index, getDisplayValue(indicatorValue)); tableItem.setBackground( indicatorData.index, indicatorData.thresholdColor[this.thresholdColorIndices[i]].color); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ClientIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ClientIndicator.java index b4cda4ee..df1db875 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ClientIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ClientIndicator.java @@ -24,8 +24,6 @@ public interface ClientIndicator extends IndicatorValue { void init(Indicator indicatorDefinition, Long connectionId, boolean cachingEnabled); - String name(); - Long examId(); Long connectionId(); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AbstractClientIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AbstractClientIndicator.java index 3b451c50..87fba65b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AbstractClientIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AbstractClientIndicator.java @@ -18,7 +18,6 @@ public abstract class AbstractClientIndicator implements ClientIndicator { protected Long examId; protected Long connectionId; - protected String name; protected boolean cachingEnabled; protected double currentValue = Double.NaN; @@ -44,11 +43,6 @@ public abstract class AbstractClientIndicator implements ClientIndicator { return this.connectionId; } - @Override - public String name() { - return this.name; - } - @Override public double getValue() { if (Double.isNaN(this.currentValue) || !this.cachingEnabled) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ClientIndicatorFactory.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ClientIndicatorFactory.java index 369a2f6b..d21df775 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ClientIndicatorFactory.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ClientIndicatorFactory.java @@ -79,6 +79,9 @@ public class ClientIndicatorFactory { e); } } + } catch (final RuntimeException e) { + log.error("Failed to create ClientIndicator for ClientConnection: {}", clientConnection); + throw e; } catch (final Exception e) { log.error("Failed to create ClientIndicator for ClientConnection: {}", clientConnection); } 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 6f33b0fc..7c333024 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 @@ -966,8 +966,6 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { // - save configuration in history // - change some attribute // - process an undo - // - table value add, delete, modify - // - export public void testUsecase10() throws IOException { final RestServiceImpl restService = createRestServiceForUser( "examAdmin2", @@ -1159,4 +1157,45 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest { assertEquals("2", currentValue.value); } + @Test + @Order(11) + // ************************************* + // Use Case 11: Login as examAdmin2 and create a new SEB Exam Configuration + // - table value add, delete, modify + // - export + public void testUsecase11() throws IOException { + final RestServiceImpl restService = createRestServiceForUser( + "examAdmin2", + "examAdmin2", + 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()); + + // get configuration page + final Result> pageResponse = restService + .getBuilder(GetExamConfigNodePage.class) + .call(); + + assertNotNull(pageResponse); + assertFalse(pageResponse.hasError()); + final Page page = pageResponse.get(); + assertFalse(page.content.isEmpty()); + + final ConfigurationNode configurationNode = page.content.get(0); + assertEquals("New Exam Config", configurationNode.name); + } + }