fixed tests

This commit is contained in:
anhefti 2020-12-10 21:01:30 +01:00
parent 4c002b4ac2
commit 34c8e2e33c
7 changed files with 35 additions and 29 deletions

View file

@ -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)

View file

@ -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<LmsSetup> 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<LmsSetupTestResult> 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<APIMessage> result, final Composite parent) {

View file

@ -69,24 +69,23 @@ public class MonitoringExamSearchPopup {
final PageActionBuilder actionBuilder = this.pageService
.pageActionBuilder(pageContext.clearEntityKeys());
final EntityTable<ClientConnection> 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(

View file

@ -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

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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());