more tests

This commit is contained in:
anhefti 2020-06-22 16:27:22 +02:00
parent 7e73f08bea
commit f689eb8ecb
2 changed files with 46 additions and 5 deletions

View file

@ -126,7 +126,7 @@ public final class LmsSetupTestResult {
public final String message; public final String message;
@JsonCreator @JsonCreator
protected Error( public Error(
@JsonProperty(ATTR_ERROR_TYPE) final ErrorType errorType, @JsonProperty(ATTR_ERROR_TYPE) final ErrorType errorType,
@JsonProperty(ATTR_ERROR_MESSAGE) final String message) { @JsonProperty(ATTR_ERROR_MESSAGE) final String message) {

View file

@ -18,21 +18,62 @@ import org.junit.Test;
import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.ObjectWriter;
import ch.ethz.seb.sebserver.gbl.api.APIMessage;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.api.JSONMapper; import ch.ethz.seb.sebserver.gbl.api.JSONMapper;
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup;
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType;
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.PasswordChange;
import ch.ethz.seb.sebserver.gbl.model.user.UserActivityLog;
import ch.ethz.seb.sebserver.gbl.model.user.UserInfo; import ch.ethz.seb.sebserver.gbl.model.user.UserInfo;
import ch.ethz.seb.sebserver.gbl.model.user.UserLogActivityType;
import ch.ethz.seb.sebserver.gbl.model.user.UserMod;
import ch.ethz.seb.sebserver.gbl.model.user.UserRole; import ch.ethz.seb.sebserver.gbl.model.user.UserRole;
public class ModelObjectJSONGenerator { public class ModelObjectJSONGenerator {
@Test @Test
public void generateJSON() throws Exception { public void generateJSON() throws Exception {
final Object domainObject = new UserInfo("uuid", 1L, DateTime.now(), "name", "surname", "username", "email", final JSONMapper mapper = new JSONMapper();
final ObjectWriter writerWithDefaultPrettyPrinter = mapper.writerWithDefaultPrettyPrinter();
Object domainObject = new UserInfo("uuid", 1L, DateTime.now(), "name", "surname", "username", "email",
true, Locale.ENGLISH, DateTimeZone.UTC, true, Locale.ENGLISH, DateTimeZone.UTC,
new HashSet<>(Arrays.asList(UserRole.EXAM_ADMIN.name(), UserRole.EXAM_SUPPORTER.name()))); new HashSet<>(Arrays.asList(UserRole.EXAM_ADMIN.name(), UserRole.EXAM_SUPPORTER.name())));
final JSONMapper mapper = new JSONMapper(); System.out.println(domainObject.getClass().getSimpleName() + ":");
final ObjectWriter writerWithDefaultPrettyPrinter = mapper.writerWithDefaultPrettyPrinter(); System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));
System.out.print(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));
domainObject = new UserMod(
"UUID", 1L, "NAME", "SURNAME", "USERNAME", "newPassword", "confirmNewPassword", "EMAIL",
Locale.ENGLISH, DateTimeZone.UTC,
new HashSet<>(Arrays.asList(UserRole.EXAM_ADMIN.name(), UserRole.EXAM_SUPPORTER.name())));
System.out.println(domainObject.getClass().getSimpleName() + ":");
System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));
domainObject = new PasswordChange("userUUID", "password", "newPassword", "confirmNewPassword");
System.out.println(domainObject.getClass().getSimpleName() + ":");
System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));
domainObject = new UserActivityLog(
3L, "userUUID", "username", 123L, UserLogActivityType.EXPORT,
EntityType.USER, "5", "message");
System.out.println(domainObject.getClass().getSimpleName() + ":");
System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));
domainObject = new LmsSetup(
1L, 1L, "name", LmsType.OPEN_EDX, "lmsApiAccountName", "lmsApiAccountPassword",
"lmsApiUrl", "lmsApiToken", "proxyHost", 8085, "proxyAuthUsername", "proxyAuthSecret", true);
System.out.println(domainObject.getClass().getSimpleName() + ":");
System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));
domainObject = new LmsSetupTestResult(
Arrays.asList(new LmsSetupTestResult.Error(ErrorType.QUIZ_ACCESS_API_REQUEST, "No Access")),
Arrays.asList(APIMessage.ErrorMessage.UNEXPECTED.of()));
System.out.println(domainObject.getClass().getSimpleName() + ":");
System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));
} }