From 34c8e2e33c89aa7443bc6e6ed47b84c8509f44fb Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 10 Dec 2020 21:01:30 +0100 Subject: [PATCH] fixed tests --- .../model/institution/LmsSetupTestResult.java | 5 --- .../seb/sebserver/gui/content/ExamForm.java | 13 ++++++-- .../content/MonitoringExamSearchPopup.java | 31 +++++++++---------- .../lms/impl/LmsAPIServiceImpl.java | 4 +-- .../indicator/AbstractClientIndicator.java | 5 ++- .../AbstractLogLevelCountIndicator.java | 2 +- .../indicator/AbstractLogNumberIndicator.java | 4 +-- 7 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/LmsSetupTestResult.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/LmsSetupTestResult.java index 2af204d7..fe631d8b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/LmsSetupTestResult.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/institution/LmsSetupTestResult.java @@ -27,7 +27,6 @@ public final class LmsSetupTestResult { public static final String ATTR_MISSING_ATTRIBUTE = "missingLMSSetupAttribute"; public enum ErrorType { - FEATURE_NOT_AVAILABLE, MISSING_ATTRIBUTE, TOKEN_REQUEST, QUIZ_ACCESS_API_REQUEST, @@ -119,10 +118,6 @@ public final class LmsSetupTestResult { return new LmsSetupTestResult(new Error(ErrorType.QUIZ_RESTRICTION_API_REQUEST, message)); } - public static LmsSetupTestResult ofQuizRestrictionNotAvailable() { - return new LmsSetupTestResult(new Error(ErrorType.FEATURE_NOT_AVAILABLE, "Restriction Feature Not Available")); - } - public final static class Error { @JsonProperty(ATTR_ERROR_TYPE) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java index 44e231ae..53aaf559 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java @@ -36,6 +36,8 @@ import ch.ethz.seb.sebserver.gbl.model.exam.Exam; import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamStatus; import ch.ethz.seb.sebserver.gbl.model.exam.ProctoringSettings; import ch.ethz.seb.sebserver.gbl.model.exam.QuizData; +import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup; +import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.Features; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetupTestResult; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetupTestResult.ErrorType; import ch.ethz.seb.sebserver.gbl.model.user.UserRole; @@ -464,6 +466,14 @@ public class ExamForm implements TemplateComposer { } private boolean testSEBRestrictionAPI(final Exam exam) { + final Result lmsSetupCall = this.restService.getBuilder(GetLmsSetup.class) + .withURIVariable(API.PARAM_MODEL_ID, String.valueOf(exam.lmsSetupId)) + .call(); + + if (!lmsSetupCall.hasError() && !lmsSetupCall.get().lmsType.features.contains(Features.SEB_RESTRICTION)) { + return false; + } + // Call the testing endpoint with the specified data to test final Result result = this.restService.getBuilder(TestLmsSetup.class) .withURIVariable(API.PARAM_MODEL_ID, String.valueOf(exam.lmsSetupId)) @@ -474,8 +484,7 @@ public class ExamForm implements TemplateComposer { } final LmsSetupTestResult lmsSetupTestResult = result.get(); - return !lmsSetupTestResult.hasError(ErrorType.QUIZ_RESTRICTION_API_REQUEST) - && !lmsSetupTestResult.hasError(ErrorType.FEATURE_NOT_AVAILABLE); + return !lmsSetupTestResult.hasError(ErrorType.QUIZ_RESTRICTION_API_REQUEST); } private void showConsistencyChecks(final Collection result, final Composite parent) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/MonitoringExamSearchPopup.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/MonitoringExamSearchPopup.java index 173e50ef..311be579 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/MonitoringExamSearchPopup.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/MonitoringExamSearchPopup.java @@ -69,24 +69,23 @@ public class MonitoringExamSearchPopup { final PageActionBuilder actionBuilder = this.pageService .pageActionBuilder(pageContext.clearEntityKeys()); - final EntityTable table = - this.pageService.entityTableBuilder(restService.getRestCall(GetClientConnectionPage.class)) - .withEmptyMessage(EMPTY_LIST_TEXT_KEY) - .withPaging(10) - .withStaticFilter(ClientConnection.FILTER_ATTR_EXAM_ID, examKey.modelId) + this.pageService.entityTableBuilder(restService.getRestCall(GetClientConnectionPage.class)) + .withEmptyMessage(EMPTY_LIST_TEXT_KEY) + .withPaging(10) + .withStaticFilter(ClientConnection.FILTER_ATTR_EXAM_ID, examKey.modelId) - .withColumn(new ColumnDefinition<>( - Domain.CLIENT_CONNECTION.ATTR_EXAM_USER_SESSION_ID, - TABLE_COLUMN_NAME, - ClientConnection::getUserSessionId) - .withFilter(this.nameFilter)) - .withDefaultAction(t -> actionBuilder - .newAction(ActionDefinition.MONITOR_EXAM_CLIENT_CONNECTION) - .withParentEntityKey(examKey) - .withExec(action -> showClientConnection(action, dialog, t)) - .create()) + .withColumn(new ColumnDefinition<>( + Domain.CLIENT_CONNECTION.ATTR_EXAM_USER_SESSION_ID, + TABLE_COLUMN_NAME, + ClientConnection::getUserSessionId) + .withFilter(this.nameFilter)) + .withDefaultAction(t -> actionBuilder + .newAction(ActionDefinition.MONITOR_EXAM_CLIENT_CONNECTION) + .withParentEntityKey(examKey) + .withExec(action -> showClientConnection(action, dialog, t)) + .create()) - .compose(pageContext); + .compose(pageContext); } private PageAction showClientConnection( diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java index 9455cb13..8607f46f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/lms/impl/LmsAPIServiceImpl.java @@ -120,9 +120,9 @@ public class LmsAPIServiceImpl implements LmsAPIService { if (template.lmsSetup().getLmsType().features.contains(LmsSetup.Features.SEB_RESTRICTION)) { return template.testCourseRestrictionAPI(); - } else { - return LmsSetupTestResult.ofQuizRestrictionNotAvailable(); } + + return LmsSetupTestResult.ofOkay(); } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractClientIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractClientIndicator.java index 34c647ce..e3d3ca86 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractClientIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractClientIndicator.java @@ -21,6 +21,7 @@ public abstract class AbstractClientIndicator implements ClientIndicator { protected Long connectionId; protected boolean cachingEnabled; + protected boolean valueInitializes = false; protected double currentValue = Double.NaN; @Override @@ -52,12 +53,14 @@ public abstract class AbstractClientIndicator implements ClientIndicator { public void reset() { this.currentValue = Double.NaN; + this.valueInitializes = false; } @Override public double getValue() { - if (Double.isNaN(this.currentValue) || !this.cachingEnabled) { + if (!this.valueInitializes || !this.cachingEnabled) { this.currentValue = computeValueAt(DateTime.now(DateTimeZone.UTC).getMillis()); + this.valueInitializes = true; } return this.currentValue; diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogLevelCountIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogLevelCountIndicator.java index 5c968b37..ca033f9c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogLevelCountIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogLevelCountIndicator.java @@ -61,7 +61,7 @@ public abstract class AbstractLogLevelCountIndicator extends AbstractLogIndicato return errors.doubleValue(); } catch (final Exception e) { log.error("Failed to get indicator count from persistent storage: ", e); - return 0; + return super.currentValue; } } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogNumberIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogNumberIndicator.java index 55eb5f68..0ac7844e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogNumberIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogNumberIndicator.java @@ -65,14 +65,14 @@ public abstract class AbstractLogNumberIndicator extends AbstractLogIndicator { .execute(); if (execute == null || execute.isEmpty()) { - return 0; + return super.currentValue; } final BigDecimal numericValue = execute.get(execute.size() - 1).getNumericValue(); if (numericValue != null) { return numericValue.doubleValue(); } else { - return 0; + return super.currentValue; } } catch (final Exception e) { log.error("Failed to get indicator number from persistent storage: {}", e.getMessage());