use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project ArTEMiS by ls1intum.
the class ModelingExerciseIntegrationTest method testUpdateModelingExerciseCriteria_asInstructor.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testUpdateModelingExerciseCriteria_asInstructor() throws Exception {
ModelingExercise modelingExercise = modelingExerciseUtilService.createModelingExercise(classExercise.getCourseViaExerciseGroupOrCourseMember().getId());
gradingCriteria = database.addGradingInstructionsToExercise(modelingExercise);
var currentCriteriaSize = modelingExercise.getGradingCriteria().size();
var newCriteria = new GradingCriterion();
newCriteria.setTitle("new");
modelingExercise.addGradingCriteria(newCriteria);
ModelingExercise createdModelingExercise = request.postWithResponseBody("/api/modeling-exercises", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
assertThat(createdModelingExercise.getGradingCriteria()).hasSize(currentCriteriaSize + 1);
modelingExercise.getGradingCriteria().get(1).setTitle("UPDATE");
createdModelingExercise = request.postWithResponseBody("/api/modeling-exercises", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
assertThat(createdModelingExercise.getGradingCriteria().get(1).getTitle()).isEqualTo("UPDATE");
// If the grading criteria are deleted then their instructions should also be deleted
modelingExercise.setGradingCriteria(null);
createdModelingExercise = request.postWithResponseBody("/api/modeling-exercises", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
assertThat(createdModelingExercise.getGradingCriteria()).isEmpty();
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project ArTEMiS by ls1intum.
the class ModelingExerciseIntegrationTest method importModelingExerciseFromCourseToCourse.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void importModelingExerciseFromCourseToCourse() throws Exception {
var now = ZonedDateTime.now();
Course course1 = database.addEmptyCourse();
Course course2 = database.addEmptyCourse();
ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(now.minusDays(1), now.minusHours(2), now.minusHours(1), DiagramType.ClassDiagram, course1);
modelingExerciseRepository.save(modelingExercise);
modelingExercise.setCourse(course2);
request.postWithResponseBody("/api/modeling-exercises/import/" + modelingExercise.getId(), modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project ArTEMiS by ls1intum.
the class ModelingExerciseIntegrationTest method importModelingExerciseFromCourseToCourse_badRequest.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void importModelingExerciseFromCourseToCourse_badRequest() throws Exception {
var now = ZonedDateTime.now();
Course course1 = database.addEmptyCourse();
ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(now.minusDays(1), now.minusHours(2), now.minusHours(1), DiagramType.ClassDiagram, course1);
modelingExerciseRepository.save(modelingExercise);
modelingExercise.setCourse(null);
request.postWithResponseBody("/api/modeling-exercises/import/" + modelingExercise.getId(), modelingExercise, ModelingExercise.class, HttpStatus.BAD_REQUEST);
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project ArTEMiS by ls1intum.
the class ModelingExerciseIntegrationTest method createModelingExerciseForExam.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void createModelingExerciseForExam() throws Exception {
ExerciseGroup exerciseGroup = database.addExerciseGroupWithExamAndCourse(true);
ModelingExercise modelingExercise = ModelFactory.generateModelingExerciseForExam(DiagramType.ClassDiagram, exerciseGroup);
String title = "New Exam Modeling Exercise";
DifficultyLevel difficulty = DifficultyLevel.HARD;
modelingExercise.setTitle(title);
modelingExercise.setDifficulty(difficulty);
ModelingExercise newModelingExercise = request.postWithResponseBody("/api/modeling-exercises/", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
assertThat(newModelingExercise.getTitle()).as("modeling exercise title was correctly set").isEqualTo(title);
assertThat(newModelingExercise.getDifficulty()).as("modeling exercise difficulty was correctly set").isEqualTo(difficulty);
assertThat(newModelingExercise.isCourseExercise()).as("course was not set for exam exercise").isFalse();
assertThat(newModelingExercise.getExerciseGroup()).as("exerciseGroup was set for exam exercise").isNotNull();
assertThat(newModelingExercise.getExerciseGroup().getId()).as("exerciseGroupId was set correctly").isEqualTo(exerciseGroup.getId());
}
use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project ArTEMiS by ls1intum.
the class ModelingExerciseIntegrationTest method testGetModelingExercise_exampleSolutionVisibility.
private void testGetModelingExercise_exampleSolutionVisibility(boolean isStudent, String username) throws Exception {
// Utility function to avoid duplication
Function<Course, ModelingExercise> modelingExerciseGetter = c -> (ModelingExercise) c.getExercises().stream().filter(e -> e.getId().equals(classExercise.getId())).findAny().get();
classExercise.setExampleSolutionModel("<Sample solution model>");
classExercise.setExampleSolutionExplanation("<Sample solution explanation>");
if (isStudent) {
database.createAndSaveParticipationForExercise(classExercise, username);
}
// Test example solution publication date not set.
classExercise.setExampleSolutionPublicationDate(null);
modelingExerciseRepository.save(classExercise);
Course course = request.get("/api/courses/" + classExercise.getCourseViaExerciseGroupOrCourseMember().getId() + "/for-dashboard", HttpStatus.OK, Course.class);
ModelingExercise modelingExercise = modelingExerciseGetter.apply(course);
if (isStudent) {
assertThat(modelingExercise.getExampleSolutionModel()).isNull();
assertThat(modelingExercise.getExampleSolutionExplanation()).isNull();
} else {
assertThat(modelingExercise.getExampleSolutionModel()).isEqualTo(classExercise.getExampleSolutionModel());
assertThat(modelingExercise.getExampleSolutionExplanation()).isEqualTo(classExercise.getExampleSolutionExplanation());
}
// Test example solution publication date in the past.
classExercise.setExampleSolutionPublicationDate(ZonedDateTime.now().minusHours(1));
modelingExerciseRepository.save(classExercise);
course = request.get("/api/courses/" + classExercise.getCourseViaExerciseGroupOrCourseMember().getId() + "/for-dashboard", HttpStatus.OK, Course.class);
modelingExercise = modelingExerciseGetter.apply(course);
assertThat(modelingExercise.getExampleSolutionModel()).isEqualTo(classExercise.getExampleSolutionModel());
assertThat(modelingExercise.getExampleSolutionExplanation()).isEqualTo(classExercise.getExampleSolutionExplanation());
// Test example solution publication date in the future.
classExercise.setExampleSolutionPublicationDate(ZonedDateTime.now().plusHours(1));
modelingExerciseRepository.save(classExercise);
course = request.get("/api/courses/" + classExercise.getCourseViaExerciseGroupOrCourseMember().getId() + "/for-dashboard", HttpStatus.OK, Course.class);
modelingExercise = modelingExerciseGetter.apply(course);
if (isStudent) {
assertThat(modelingExercise.getExampleSolutionModel()).isNull();
assertThat(modelingExercise.getExampleSolutionExplanation()).isNull();
} else {
assertThat(modelingExercise.getExampleSolutionModel()).isEqualTo(classExercise.getExampleSolutionModel());
assertThat(modelingExercise.getExampleSolutionExplanation()).isEqualTo(classExercise.getExampleSolutionExplanation());
}
}
Aggregations