Search in sources :

Example 61 with ModelingExercise

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();
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 62 with ModelingExercise

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);
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 63 with ModelingExercise

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);
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 64 with ModelingExercise

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());
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with ModelingExercise

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());
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) SearchResultPageDTO(de.tum.in.www1.artemis.web.rest.dto.SearchResultPageDTO) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) InvalidExamExerciseDatesArgumentProvider(de.tum.in.www1.artemis.util.InvalidExamExerciseDatesArgumentProvider) Function(java.util.function.Function) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelFactory(de.tum.in.www1.artemis.util.ModelFactory) ModelingExerciseUtilService(de.tum.in.www1.artemis.util.ModelingExerciseUtilService) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult) Mockito.verify(org.mockito.Mockito.verify) InvalidExamExerciseDateConfiguration(de.tum.in.www1.artemis.util.InvalidExamExerciseDatesArgumentProvider.InvalidExamExerciseDateConfiguration) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Assertions(org.junit.jupiter.api.Assertions) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) de.tum.in.www1.artemis.domain.enumeration(de.tum.in.www1.artemis.domain.enumeration) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise)

Aggregations

ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)196 WithMockUser (org.springframework.security.test.context.support.WithMockUser)132 Test (org.junit.jupiter.api.Test)126 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)96 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)72 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)28 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)26 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)20 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)16 BeforeEach (org.junit.jupiter.api.BeforeEach)16 Course (de.tum.in.www1.artemis.domain.Course)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 ZonedDateTime (java.time.ZonedDateTime)12 Exam (de.tum.in.www1.artemis.domain.exam.Exam)10 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)10 TeamAssignmentPayload (de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload)9 JsonParser.parseString (com.google.gson.JsonParser.parseString)8 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)8 ModelCluster (de.tum.in.www1.artemis.domain.modeling.ModelCluster)8