more integration tests
This commit is contained in:
parent
f69176cc23
commit
462546a30a
6 changed files with 84 additions and 80 deletions
|
@ -23,7 +23,6 @@ public final class API {
|
||||||
public static final String PARAM_PARENT_MODEL_ID = "parentModelId";
|
public static final String PARAM_PARENT_MODEL_ID = "parentModelId";
|
||||||
public static final String PARAM_ENTITY_TYPE = "entityType";
|
public static final String PARAM_ENTITY_TYPE = "entityType";
|
||||||
public static final String PARAM_BULK_ACTION_TYPE = "bulkActionType";
|
public static final String PARAM_BULK_ACTION_TYPE = "bulkActionType";
|
||||||
public static final String PARAM_LMS_SETUP_ID = "lmsSetupId";
|
|
||||||
|
|
||||||
public static final String INSTITUTION_VAR_PATH_SEGMENT = "/{" + PARAM_INSTITUTION_ID + "}";
|
public static final String INSTITUTION_VAR_PATH_SEGMENT = "/{" + PARAM_INSTITUTION_ID + "}";
|
||||||
public static final String MODEL_ID_VAR_PATH_SEGMENT = "/{" + PARAM_MODEL_ID + "}";
|
public static final String MODEL_ID_VAR_PATH_SEGMENT = "/{" + PARAM_MODEL_ID + "}";
|
||||||
|
|
|
@ -25,7 +25,6 @@ import ch.ethz.seb.sebserver.gbl.model.EntityKey;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.exam.Exam;
|
import ch.ethz.seb.sebserver.gbl.model.exam.Exam;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
|
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
|
import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.user.UserInfo;
|
|
||||||
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
|
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
|
||||||
import ch.ethz.seb.sebserver.gbl.util.Result;
|
import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||||
import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition;
|
import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition;
|
||||||
|
@ -94,7 +93,6 @@ public class ExamForm implements TemplateComposer {
|
||||||
final WidgetFactory widgetFactory = this.pageService.getWidgetFactory();
|
final WidgetFactory widgetFactory = this.pageService.getWidgetFactory();
|
||||||
final I18nSupport i18nSupport = this.resourceService.getI18nSupport();
|
final I18nSupport i18nSupport = this.resourceService.getI18nSupport();
|
||||||
|
|
||||||
final UserInfo user = currentUser.get();
|
|
||||||
final EntityKey entityKey = pageContext.getEntityKey();
|
final EntityKey entityKey = pageContext.getEntityKey();
|
||||||
final EntityKey parentEntityKey = pageContext.getParentEntityKey();
|
final EntityKey parentEntityKey = pageContext.getParentEntityKey();
|
||||||
final boolean readonly = pageContext.isReadonly();
|
final boolean readonly = pageContext.isReadonly();
|
||||||
|
@ -143,9 +141,6 @@ public class ExamForm implements TemplateComposer {
|
||||||
.putStaticValue(
|
.putStaticValue(
|
||||||
Domain.EXAM.ATTR_INSTITUTION_ID,
|
Domain.EXAM.ATTR_INSTITUTION_ID,
|
||||||
String.valueOf(exam.getInstitutionId()))
|
String.valueOf(exam.getInstitutionId()))
|
||||||
.putStaticValue(
|
|
||||||
Domain.EXAM.ATTR_OWNER,
|
|
||||||
user.uuid)
|
|
||||||
.putStaticValueIf(isNotNew,
|
.putStaticValueIf(isNotNew,
|
||||||
Domain.EXAM.ATTR_LMS_SETUP_ID,
|
Domain.EXAM.ATTR_LMS_SETUP_ID,
|
||||||
String.valueOf(exam.lmsSetupId))
|
String.valueOf(exam.lmsSetupId))
|
||||||
|
@ -319,7 +314,7 @@ public class ExamForm implements TemplateComposer {
|
||||||
|
|
||||||
return restService.getBuilder(GetQuizData.class)
|
return restService.getBuilder(GetQuizData.class)
|
||||||
.withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId)
|
.withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId)
|
||||||
.withQueryParam(API.PARAM_LMS_SETUP_ID, parentEntityKey.modelId)
|
.withQueryParam(QuizData.QUIZ_ATTR_LMS_SETUP_ID, parentEntityKey.modelId)
|
||||||
.call()
|
.call()
|
||||||
.map(quizzData -> new Exam(quizzData));
|
.map(quizzData -> new Exam(quizzData));
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import ch.ethz.seb.sebserver.gbl.api.API;
|
||||||
import ch.ethz.seb.sebserver.gbl.api.EntityType;
|
import ch.ethz.seb.sebserver.gbl.api.EntityType;
|
||||||
import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
|
import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
|
||||||
import ch.ethz.seb.sebserver.gbl.authorization.PrivilegeType;
|
import ch.ethz.seb.sebserver.gbl.authorization.PrivilegeType;
|
||||||
|
import ch.ethz.seb.sebserver.gbl.model.Domain.EXAM;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.Page;
|
import ch.ethz.seb.sebserver.gbl.model.Page;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.exam.Exam;
|
import ch.ethz.seb.sebserver.gbl.model.exam.Exam;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
|
import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
|
||||||
|
@ -33,6 +34,7 @@ import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ExamRecordDynamic
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.PaginationService;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.PaginationService;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.PaginationService.SortOrder;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.PaginationService.SortOrder;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.AuthorizationService;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.AuthorizationService;
|
||||||
|
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.SEBServerUser;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.UserService;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.UserService;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionService;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionService;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamDAO;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamDAO;
|
||||||
|
@ -134,81 +136,13 @@ public class ExamAdministrationController extends ActivatableEntityController<Ex
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @RequestMapping(path = "/{examId}/indicator", method = RequestMethod.GET)
|
|
||||||
// public Collection<Indicator> getIndicatorOfExam(@PathVariable final Long examId) {
|
|
||||||
// // check read-only grant on Exam
|
|
||||||
// this.examDAO.byPK(examId)
|
|
||||||
// .map(this.authorization::checkReadonly)
|
|
||||||
// .getOrThrow();
|
|
||||||
//
|
|
||||||
// return this.indicatorDAO.allForExam(examId)
|
|
||||||
// .getOrThrow();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @RequestMapping(path = "/{examId}/indicator/{indicatorId}", method = RequestMethod.DELETE)
|
|
||||||
// public Collection<Indicator> deleteIndicatorOfExam(
|
|
||||||
// @PathVariable final Long examId,
|
|
||||||
// @PathVariable(required = false) final Long indicatorId) {
|
|
||||||
//
|
|
||||||
// // check write grant on Exam
|
|
||||||
// this.examDAO.byPK(examId)
|
|
||||||
// .map(this.authorization::checkWrite)
|
|
||||||
// .getOrThrow();
|
|
||||||
//
|
|
||||||
// final Set<EntityKey> toDelete = (indicatorId != null)
|
|
||||||
// ? this.indicatorDAO.allForExam(examId)
|
|
||||||
// .getOrThrow()
|
|
||||||
// .stream()
|
|
||||||
// .map(ind -> new EntityKey(String.valueOf(ind.id), EntityType.INDICATOR))
|
|
||||||
// .collect(Collectors.toSet())
|
|
||||||
// : Utils.immutableSetOf(new EntityKey(String.valueOf(indicatorId), EntityType.INDICATOR));
|
|
||||||
//
|
|
||||||
// this.indicatorDAO.delete(toDelete);
|
|
||||||
//
|
|
||||||
// return this.indicatorDAO.allForExam(examId)
|
|
||||||
// .getOrThrow();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @RequestMapping(path = "/{examId}/indicator", method = RequestMethod.POST)
|
|
||||||
// public Indicator addNewIndicatorToExam(
|
|
||||||
// @PathVariable final Long examId,
|
|
||||||
// @Valid @RequestBody final Indicator indicator) {
|
|
||||||
//
|
|
||||||
// // check write grant on Exam
|
|
||||||
// this.examDAO.byPK(examId)
|
|
||||||
// .flatMap(this.authorization::checkWrite)
|
|
||||||
// .getOrThrow();
|
|
||||||
//
|
|
||||||
// if (indicator.id != null) {
|
|
||||||
// return this.indicatorDAO.byPK(indicator.id)
|
|
||||||
// .getOrThrow();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return this.indicatorDAO
|
|
||||||
// .createNew(indicator)
|
|
||||||
// .getOrThrow();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @RequestMapping(path = "/{examId}/indicator/{id}", method = RequestMethod.PUT)
|
|
||||||
// public Indicator putIndicatorForExam(
|
|
||||||
// @PathVariable final String id,
|
|
||||||
// @Valid @RequestBody final Indicator indicator) {
|
|
||||||
//
|
|
||||||
// // check modify grant on Exam
|
|
||||||
// this.examDAO.byPK(indicator.examId)
|
|
||||||
// .flatMap(this.authorization::checkModify)
|
|
||||||
// .getOrThrow();
|
|
||||||
//
|
|
||||||
// return this.indicatorDAO
|
|
||||||
// .save(indicator)
|
|
||||||
// .getOrThrow();
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Exam createNew(final POSTMapper postParams) {
|
protected Exam createNew(final POSTMapper postParams) {
|
||||||
|
|
||||||
final Long lmsSetupId = postParams.getLong(QuizData.QUIZ_ATTR_LMS_SETUP_ID);
|
final Long lmsSetupId = postParams.getLong(QuizData.QUIZ_ATTR_LMS_SETUP_ID);
|
||||||
final String quizId = postParams.getString(QuizData.QUIZ_ATTR_ID);
|
final String quizId = postParams.getString(QuizData.QUIZ_ATTR_ID);
|
||||||
|
final SEBServerUser currentUser = this.authorization.getUserService().getCurrentUser();
|
||||||
|
postParams.putIfAbsent(EXAM.ATTR_OWNER, currentUser.uuid());
|
||||||
|
|
||||||
return this.lmsAPIService
|
return this.lmsAPIService
|
||||||
.getLmsAPITemplate(lmsSetupId)
|
.getLmsAPITemplate(lmsSetupId)
|
||||||
|
|
|
@ -34,7 +34,7 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPIService;
|
||||||
@WebServiceProfile
|
@WebServiceProfile
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/${sebserver.webservice.api.admin.endpoint}" + API.QUIZ_DISCOVERY_ENDPOINT)
|
@RequestMapping("/${sebserver.webservice.api.admin.endpoint}" + API.QUIZ_DISCOVERY_ENDPOINT)
|
||||||
public class QuizImportController {
|
public class QuizController {
|
||||||
|
|
||||||
private final int defaultPageSize;
|
private final int defaultPageSize;
|
||||||
private final int maxPageSize;
|
private final int maxPageSize;
|
||||||
|
@ -42,7 +42,7 @@ public class QuizImportController {
|
||||||
private final LmsAPIService lmsAPIService;
|
private final LmsAPIService lmsAPIService;
|
||||||
private final AuthorizationService authorization;
|
private final AuthorizationService authorization;
|
||||||
|
|
||||||
public QuizImportController(
|
public QuizController(
|
||||||
@Value("${sebserver.webservice.api.pagination.defaultPageSize:10}") final int defaultPageSize,
|
@Value("${sebserver.webservice.api.pagination.defaultPageSize:10}") final int defaultPageSize,
|
||||||
@Value("${sebserver.webservice.api.pagination.maxPageSize:500}") final int maxPageSize,
|
@Value("${sebserver.webservice.api.pagination.maxPageSize:500}") final int maxPageSize,
|
||||||
final LmsAPIService lmsAPIService,
|
final LmsAPIService lmsAPIService,
|
||||||
|
@ -109,7 +109,7 @@ public class QuizImportController {
|
||||||
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||||
public QuizData getQuiz(
|
public QuizData getQuiz(
|
||||||
@PathVariable final String modelId,
|
@PathVariable final String modelId,
|
||||||
@RequestParam(name = API.PARAM_LMS_SETUP_ID, required = true) final Long lmsSetupId) {
|
@RequestParam(name = QuizData.QUIZ_ATTR_LMS_SETUP_ID, required = true) final Long lmsSetupId) {
|
||||||
|
|
||||||
return this.lmsAPIService
|
return this.lmsAPIService
|
||||||
.getLmsAPITemplate(lmsSetupId)
|
.getLmsAPITemplate(lmsSetupId)
|
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ch.ethz.seb.sebserver.webservice.integration.api.admin;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.test.context.jdbc.Sql;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
|
||||||
|
import ch.ethz.seb.sebserver.gbl.api.API;
|
||||||
|
import ch.ethz.seb.sebserver.gbl.model.exam.Exam;
|
||||||
|
import ch.ethz.seb.sebserver.gbl.model.exam.QuizData;
|
||||||
|
import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup;
|
||||||
|
|
||||||
|
@Sql(scripts = { "classpath:schema-test.sql", "classpath:data-test.sql" })
|
||||||
|
public class ExamImportTest extends AdministrationAPIIntegrationTester {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImportFromQuizz() throws Exception {
|
||||||
|
// create new active LmsSetup Mock with seb-admin
|
||||||
|
final LmsSetup lmsSetup1 = QuizDataTest.createLmsSetupMockWith(
|
||||||
|
this,
|
||||||
|
getSebAdminAccess(),
|
||||||
|
"new LmsSetup 1",
|
||||||
|
true);
|
||||||
|
|
||||||
|
// import Exam from quiz1
|
||||||
|
final Exam exam = new RestAPITestHelper()
|
||||||
|
.withAccessToken(getSebAdminAccess())
|
||||||
|
.withPath(API.EXAM_ADMINISTRATION_ENDPOINT)
|
||||||
|
.withMethod(HttpMethod.POST)
|
||||||
|
.withAttribute(QuizData.QUIZ_ATTR_LMS_SETUP_ID, lmsSetup1.getModelId())
|
||||||
|
.withAttribute(QuizData.QUIZ_ATTR_ID, "quiz1")
|
||||||
|
.withExpectedStatus(HttpStatus.OK)
|
||||||
|
.getAsObject(new TypeReference<Exam>() {
|
||||||
|
});
|
||||||
|
|
||||||
|
assertNotNull(exam);
|
||||||
|
assertEquals("quiz1", exam.getExternalId());
|
||||||
|
assertEquals(lmsSetup1.id, exam.getLmsSetupId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -113,6 +113,28 @@ public class QuizDataTest extends AdministrationAPIIntegrationTester {
|
||||||
assertTrue(quizzes.content.size() == 5);
|
assertTrue(quizzes.content.size() == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetQuiz() throws Exception {
|
||||||
|
// create new active LmsSetup Mock with seb-admin
|
||||||
|
final LmsSetup lmsSetup = createLmsSetupMockWith(
|
||||||
|
this,
|
||||||
|
getSebAdminAccess(),
|
||||||
|
"new LmsSetup 1",
|
||||||
|
true);
|
||||||
|
|
||||||
|
final QuizData quizData = new RestAPITestHelper()
|
||||||
|
.withAccessToken(getSebAdminAccess())
|
||||||
|
.withPath(API.QUIZ_DISCOVERY_ENDPOINT)
|
||||||
|
.withPath("quiz1")
|
||||||
|
.withAttribute(QuizData.QUIZ_ATTR_LMS_SETUP_ID, lmsSetup.getModelId())
|
||||||
|
.withMethod(HttpMethod.GET)
|
||||||
|
.withExpectedStatus(HttpStatus.OK)
|
||||||
|
.getAsObject(new TypeReference<QuizData>() {
|
||||||
|
});
|
||||||
|
|
||||||
|
assertNotNull(quizData);
|
||||||
|
}
|
||||||
|
|
||||||
public static final LmsSetup createLmsSetupMockWith(
|
public static final LmsSetup createLmsSetupMockWith(
|
||||||
final AdministrationAPIIntegrationTester tester,
|
final AdministrationAPIIntegrationTester tester,
|
||||||
final String token,
|
final String token,
|
||||||
|
|
Loading…
Reference in a new issue