add more tests

This commit is contained in:
anhefti 2020-02-27 12:18:44 +01:00
parent 49abd4e5b0
commit e250f340d8
4 changed files with 1194 additions and 1108 deletions

View file

@ -1,110 +1,110 @@
/* /*
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET) * Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
* *
* This Source Code Form is subject to the terms of the Mozilla Public * This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
package ch.ethz.seb.sebserver.gbl.model.sebconfig; package ch.ethz.seb.sebserver.gbl.model.sebconfig;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import ch.ethz.seb.sebserver.gbl.api.EntityType; import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.Domain.CONFIGURATION_NODE; import ch.ethz.seb.sebserver.gbl.model.Domain.CONFIGURATION_NODE;
import ch.ethz.seb.sebserver.gbl.model.Entity; import ch.ethz.seb.sebserver.gbl.model.Entity;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode.ConfigurationType; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode.ConfigurationType;
public final class ConfigCreationInfo implements Entity { public final class ConfigCreationInfo implements Entity {
public static final String ATTR_COPY_WITH_HISTORY = "with-history"; public static final String ATTR_COPY_WITH_HISTORY = "with-history";
@NotNull @NotNull
@JsonProperty(CONFIGURATION_NODE.ATTR_ID) @JsonProperty(CONFIGURATION_NODE.ATTR_ID)
public final Long configurationNodeId; public final Long configurationNodeId;
@NotNull(message = "configurationNode:name:notNull") @NotNull(message = "configurationNode:name:notNull")
@Size(min = 3, max = 255, message = "configurationNode:name:size:{min}:{max}:${validatedValue}") @Size(min = 3, max = 255, message = "configurationNode:name:size:{min}:{max}:${validatedValue}")
@JsonProperty(CONFIGURATION_NODE.ATTR_NAME) @JsonProperty(CONFIGURATION_NODE.ATTR_NAME)
public final String name; public final String name;
@Size(max = 4000, message = "configurationNode:description:size:{min}:{max}:${validatedValue}") @Size(max = 4000, message = "configurationNode:description:size:{min}:{max}:${validatedValue}")
@JsonProperty(CONFIGURATION_NODE.ATTR_DESCRIPTION) @JsonProperty(CONFIGURATION_NODE.ATTR_DESCRIPTION)
public final String description; public final String description;
@JsonProperty(ATTR_COPY_WITH_HISTORY) @JsonProperty(ATTR_COPY_WITH_HISTORY)
public final Boolean withHistory; public final Boolean withHistory;
@JsonProperty(CONFIGURATION_NODE.ATTR_TYPE) @JsonProperty(CONFIGURATION_NODE.ATTR_TYPE)
public final ConfigurationType configurationType; public final ConfigurationType configurationType;
protected ConfigCreationInfo( public ConfigCreationInfo(
@JsonProperty(CONFIGURATION_NODE.ATTR_ID) final Long configurationNodeId, @JsonProperty(CONFIGURATION_NODE.ATTR_ID) final Long configurationNodeId,
@JsonProperty(CONFIGURATION_NODE.ATTR_NAME) final String name, @JsonProperty(CONFIGURATION_NODE.ATTR_NAME) final String name,
@JsonProperty(CONFIGURATION_NODE.ATTR_DESCRIPTION) final String description, @JsonProperty(CONFIGURATION_NODE.ATTR_DESCRIPTION) final String description,
@JsonProperty(ATTR_COPY_WITH_HISTORY) final Boolean withHistory, @JsonProperty(ATTR_COPY_WITH_HISTORY) final Boolean withHistory,
@JsonProperty(CONFIGURATION_NODE.ATTR_TYPE) final ConfigurationType configurationType) { @JsonProperty(CONFIGURATION_NODE.ATTR_TYPE) final ConfigurationType configurationType) {
this.configurationNodeId = configurationNodeId; this.configurationNodeId = configurationNodeId;
this.name = name; this.name = name;
this.description = description; this.description = description;
this.withHistory = withHistory; this.withHistory = withHistory;
this.configurationType = (configurationType != null) this.configurationType = (configurationType != null)
? configurationType ? configurationType
: ConfigurationType.EXAM_CONFIG; : ConfigurationType.EXAM_CONFIG;
} }
public Long getConfigurationNodeId() { public Long getConfigurationNodeId() {
return this.configurationNodeId; return this.configurationNodeId;
} }
@Override @Override
public String getName() { public String getName() {
return this.name; return this.name;
} }
public String getDescription() { public String getDescription() {
return this.description; return this.description;
} }
public Boolean getWithHistory() { public Boolean getWithHistory() {
return this.withHistory; return this.withHistory;
} }
public ConfigurationType getConfigurationType() { public ConfigurationType getConfigurationType() {
return this.configurationType; return this.configurationType;
} }
@Override @Override
public String getModelId() { public String getModelId() {
return (this.configurationNodeId != null) return (this.configurationNodeId != null)
? String.valueOf(this.configurationNodeId) ? String.valueOf(this.configurationNodeId)
: null; : null;
} }
@Override @Override
public EntityType entityType() { public EntityType entityType() {
return EntityType.CONFIGURATION_NODE; return EntityType.CONFIGURATION_NODE;
} }
@Override @Override
public String toString() { public String toString() {
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
builder.append("ConfigCopyInfo [configurationNodeId="); builder.append("ConfigCopyInfo [configurationNodeId=");
builder.append(this.configurationNodeId); builder.append(this.configurationNodeId);
builder.append(", name="); builder.append(", name=");
builder.append(this.name); builder.append(this.name);
builder.append(", description="); builder.append(", description=");
builder.append(this.description); builder.append(this.description);
builder.append(", withHistory="); builder.append(", withHistory=");
builder.append(this.withHistory); builder.append(this.withHistory);
builder.append(", configurationType="); builder.append(", configurationType=");
builder.append(this.configurationType); builder.append(this.configurationType);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }

View file

@ -263,7 +263,7 @@ public class ExamAPI_V1_Controller {
@RequestParam(required = false) final MultiValueMap<String, String> formParams, @RequestParam(required = false) final MultiValueMap<String, String> formParams,
final Principal principal, final Principal principal,
final HttpServletRequest request, final HttpServletRequest request,
final HttpServletResponse response) throws IOException { final HttpServletResponse response) {
return CompletableFuture.runAsync( return CompletableFuture.runAsync(
() -> streamExamConfig(connectionToken, formParams, principal, response), () -> streamExamConfig(connectionToken, formParams, principal, response),

View file

@ -23,6 +23,8 @@ import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigCreationInfo;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.*;
import org.apache.commons.codec.Charsets; import org.apache.commons.codec.Charsets;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.BooleanUtils;
@ -103,29 +105,6 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.GetClientConfigPage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.GetClientConfigPage;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.NewClientConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.NewClientConfig;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.SaveClientConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.SaveClientConfig;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.ExportPlainXML;
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.GetConfigurationTableValues;
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;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetOrientationPage;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetOrientations;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetViewList;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetViewPage;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetViews;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.ImportExamConfigOnExistingConfig;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.ImportNewExamConfig;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.NewExamConfig;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.SaveExamConfig;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.SaveExamConfigHistory;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.SaveExamConfigTableValues;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.SaveExamConfigValue;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.SebExamConfigUndo;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.ActivateUserAccount; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.ActivateUserAccount;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.ChangePassword; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.ChangePassword;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserAccount; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserAccount;
@ -1342,6 +1321,9 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest {
"examAdmin2", "examAdmin2",
"examAdmin2", "examAdmin2",
new GetConfigAttributes(), new GetConfigAttributes(),
new GetConfigurationValues(),
new GetConfigurationValuePage(),
new GetConfigurationTableValues(),
new GetExamConfigNodePage(), new GetExamConfigNodePage(),
new SaveExamConfigHistory(), new SaveExamConfigHistory(),
new ExportExamConfig(), new ExportExamConfig(),
@ -1407,6 +1389,64 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest {
assertNotNull(importedConfig); assertNotNull(importedConfig);
// Check imported value
final Configuration fallow_up = restService.getBuilder(GetFollowupConfiguration.class)
.withURIVariable(API.PARAM_MODEL_ID, String.valueOf(importedConfig.configurationNodeId))
.call()
.getOrThrow();
assertNotNull(fallow_up);
List<ConfigurationValue> values = restService.getBuilder(GetConfigurationValues.class)
.withQueryParam(
ConfigurationValue.FILTER_ATTR_CONFIGURATION_ID,
String.valueOf(fallow_up.id))
.call()
.getOrThrow();
assertNotNull(values);
attributes
.stream()
.filter(attr -> "URLFilterEnable".equals(attr.name))
.findFirst()
.ifPresentOrElse(
attr -> {
values.stream()
.filter(cv -> cv.attributeId.equals(attr.id))
.findFirst()
.ifPresentOrElse(
val -> assertEquals(Constants.TRUE_STRING, val.value),
() -> fail("Expect to find one value")
);
},
() -> fail("Expect to find one attribute")
);
attributes
.stream()
.filter(attr -> "URLFilterRules".equals(attr.name))
.findFirst()
.ifPresentOrElse(
parent -> {
attributes.stream()
.filter(attr -> parent.id.equals(attr.parentId) && "URLFilterRules.expression".equals(attr.name))
.findFirst()
.ifPresentOrElse(
tAttr -> {
values.stream()
.filter(tVal -> tVal.attributeId.equals(tAttr.id) && tVal.listIndex == 0)
.findFirst()
.ifPresentOrElse(
firstTVal -> assertEquals("jrtjrtzj", firstTVal.value),
() -> fail("Expect to find one value")
);
},
() -> fail("Expect to find one attribute")
);
},
() -> fail("Expect to find one attribute")
);
// import with the same name should cause an exception // import with the same name should cause an exception
try { try {
restService restService
@ -1488,6 +1528,7 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest {
// ************************************* // *************************************
// Use Case 15: Login as examAdmin2 and get views and orientations // Use Case 15: Login as examAdmin2 and get views and orientations
// - test Views API // - test Views API
// - create configuration template form existing configuration
public void testUsecase15() throws IOException { public void testUsecase15() throws IOException {
final RestServiceImpl restService = createRestServiceForUser( final RestServiceImpl restService = createRestServiceForUser(
"examAdmin2", "examAdmin2",
@ -1495,7 +1536,11 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest {
new GetViews(), new GetViews(),
new GetViewPage(), new GetViewPage(),
new GetOrientationPage(), new GetOrientationPage(),
new GetOrientations()); new GetOrientations(),
new CopyConfiguration(),
new GetTemplateAttributePage(),
new GetExamConfigNodePage(),
new GetTemplateAttribute());
final List<View> views = restService final List<View> views = restService
.getBuilder(GetViews.class) .getBuilder(GetViews.class)
@ -1503,12 +1548,53 @@ public class UseCasesIntegrationTest extends GuiIntegrationTest {
.getOrThrow(); .getOrThrow();
assertNotNull(views); assertNotNull(views);
assertTrue(views.size() == 11); assertEquals(11, views.size());
views.forEach(v -> assertEquals(v.templateId, ConfigurationNode.DEFAULT_TEMPLATE_ID));
final List<Orientation> orientations = restService final List<Orientation> orientations = restService
.getBuilder(GetOrientations.class) .getBuilder(GetOrientations.class)
.call() .call()
.getOrThrow(); .getOrThrow();
orientations.forEach(o -> assertEquals(o.templateId, ConfigurationNode.DEFAULT_TEMPLATE_ID));
// get configuration page and first config from the page to copy as template
final Result<Page<ConfigurationNode>> pageResponse = restService
.getBuilder(GetExamConfigNodePage.class)
.call();
assertNotNull(pageResponse);
assertFalse(pageResponse.hasError());
final Page<ConfigurationNode> page = pageResponse.get();
assertFalse(page.content.isEmpty());
final ConfigurationNode configurationNode = page.content.get(0);
assertEquals("New Exam Config", configurationNode.name);
ConfigCreationInfo copyInfo = new ConfigCreationInfo(
configurationNode.id,
"Config Template",
"Test Config Template creation",
false,
ConfigurationType.TEMPLATE
);
ConfigurationNode template = restService
.getBuilder(CopyConfiguration.class)
.withBody(copyInfo)
.call()
.getOrThrow();
assertNotNull(template);
// get template page and check new template is available
Page<ConfigurationNode> templates = restService
.getBuilder(GetExamConfigNodePage.class)
.withQueryParam(ConfigurationNode.FILTER_ATTR_TYPE, ConfigurationType.TEMPLATE.name())
.call()
.getOrThrow();
assertNotNull(templates);
assertFalse(templates.isEmpty());
ConfigurationNode newTemplate = templates.content.get(0);
assertNotNull(newTemplate);
assertEquals("Config Template", newTemplate.name);
assertNotNull(orientations); assertNotNull(orientations);
} }

File diff suppressed because it is too large Load diff