Search in sources :

Example 66 with ModelingExercise

use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project ArTEMiS by ls1intum.

the class ModelingExerciseIntegrationTest method importModelingExerciseFromExamToCourse.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void importModelingExerciseFromExamToCourse() throws Exception {
    ExerciseGroup exerciseGroup1 = database.addExerciseGroupWithExamAndCourse(true);
    ModelingExercise modelingExercise = ModelFactory.generateModelingExerciseForExam(DiagramType.ClassDiagram, exerciseGroup1);
    Course course1 = database.addEmptyCourse();
    modelingExerciseRepository.save(modelingExercise);
    modelingExercise.setCourse(course1);
    modelingExercise.setExerciseGroup(null);
    request.postWithResponseBody("/api/modeling-exercises/import/" + modelingExercise.getId(), modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
}
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 67 with ModelingExercise

use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project ArTEMiS by ls1intum.

the class ModelingExerciseIntegrationTest method createModelingExercise_setValidExampleSolutionPublicationDate.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void createModelingExercise_setValidExampleSolutionPublicationDate() throws Exception {
    final var baseTime = ZonedDateTime.now();
    final Course course = database.addCourseWithOneModelingExercise();
    ModelingExercise modelingExercise = modelingExerciseRepository.findByCourseIdWithCategories(course.getId()).get(0);
    modelingExercise.setId(null);
    modelingExercise.setAssessmentDueDate(null);
    modelingExercise.setIncludedInOverallScore(IncludedInOverallScore.INCLUDED_COMPLETELY);
    modelingExercise.setReleaseDate(baseTime.plusHours(1));
    modelingExercise.setDueDate(baseTime.plusHours(2));
    var exampleSolutionPublicationDate = baseTime.plusHours(3);
    modelingExercise.setExampleSolutionPublicationDate(exampleSolutionPublicationDate);
    var result = request.postWithResponseBody("/api/modeling-exercises/", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    assertThat(result.getExampleSolutionPublicationDate()).isEqualTo(exampleSolutionPublicationDate);
    modelingExercise.setIncludedInOverallScore(IncludedInOverallScore.NOT_INCLUDED);
    modelingExercise.setReleaseDate(baseTime.plusHours(1));
    modelingExercise.setDueDate(baseTime.plusHours(3));
    exampleSolutionPublicationDate = baseTime.plusHours(2);
    modelingExercise.setExampleSolutionPublicationDate(exampleSolutionPublicationDate);
    result = request.postWithResponseBody("/api/modeling-exercises/", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    assertThat(result.getExampleSolutionPublicationDate()).isEqualTo(exampleSolutionPublicationDate);
}
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 68 with ModelingExercise

use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project ArTEMiS by ls1intum.

the class ModelingExerciseIntegrationTest method testCreateModelingExercise_instructorNotInCourse.

@Test
@WithMockUser(username = "instructor2", roles = "INSTRUCTOR")
public void testCreateModelingExercise_instructorNotInCourse() throws Exception {
    ModelingExercise modelingExercise = modelingExerciseUtilService.createModelingExercise(classExercise.getCourseViaExerciseGroupOrCourseMember().getId());
    request.post("/api/modeling-exercises", modelingExercise, HttpStatus.FORBIDDEN);
}
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 69 with ModelingExercise

use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project ArTEMiS by ls1intum.

the class SubmissionExportIntegrationTest method initTestCase.

@BeforeEach
public void initTestCase() {
    List<User> users = database.addUsers(3, 1, 0, 1);
    users.remove(database.getUserByLogin("admin"));
    Course course1 = database.addCourseWithModelingAndTextAndFileUploadExercise();
    course1.getExercises().forEach(exercise -> {
        database.createAndSaveParticipationForExercise(exercise, "student1");
        database.createAndSaveParticipationForExercise(exercise, "student2");
        database.createAndSaveParticipationForExercise(exercise, "student3");
        if (exercise instanceof ModelingExercise) {
            modelingExercise = (ModelingExercise) exercise;
            try {
                modelingSubmission1 = database.addModelingSubmissionFromResources(modelingExercise, "test-data/model-submission/model.54727.json", "student1");
                modelingSubmission2 = database.addModelingSubmissionFromResources(modelingExercise, "test-data/model-submission/model.54742.json", "student2");
                modelingSubmission3 = database.addModelingSubmissionFromResources(modelingExercise, "test-data/model-submission/model.54745.json", "student3");
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (exercise instanceof TextExercise) {
            textExercise = (TextExercise) exercise;
            textSubmission1 = database.saveTextSubmission(textExercise, ModelFactory.generateTextSubmission("example text", Language.ENGLISH, true), "student1");
            textSubmission2 = database.saveTextSubmission(textExercise, ModelFactory.generateTextSubmission("some other text", Language.ENGLISH, true), "student2");
            textSubmission3 = database.saveTextSubmission(textExercise, ModelFactory.generateTextSubmission("a third text", Language.ENGLISH, true), "student3");
        } else if (exercise instanceof FileUploadExercise) {
            fileUploadExercise = (FileUploadExercise) exercise;
            fileUploadSubmission1 = database.addFileUploadSubmission(fileUploadExercise, ModelFactory.generateFileUploadSubmissionWithFile(true, "test1.pdf"), "student1");
            fileUploadSubmission2 = database.addFileUploadSubmission(fileUploadExercise, ModelFactory.generateFileUploadSubmissionWithFile(true, "test2.pdf"), "student2");
            fileUploadSubmission3 = database.addFileUploadSubmission(fileUploadExercise, ModelFactory.generateFileUploadSubmissionWithFile(true, "test3.pdf"), "student3");
            try {
                saveEmptySubmissionFile(fileUploadExercise, fileUploadSubmission1);
                saveEmptySubmissionFile(fileUploadExercise, fileUploadSubmission2);
                saveEmptySubmissionFile(fileUploadExercise, fileUploadSubmission3);
            } catch (IOException e) {
                fail("Could not create submission files", e);
            }
        }
    });
    baseExportOptions = new SubmissionExportOptionsDTO();
    baseExportOptions.setExportAllParticipants(true);
    baseExportOptions.setFilterLateSubmissions(false);
}
Also used : SubmissionExportOptionsDTO(de.tum.in.www1.artemis.web.rest.dto.SubmissionExportOptionsDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) IOException(java.io.IOException) IOException(java.io.IOException) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 70 with ModelingExercise

use of de.tum.in.www1.artemis.domain.modeling.ModelingExercise in project ArTEMiS by ls1intum.

the class TeamIntegrationTest method getCourseWithExercisesAndParticipationsForTeam_AsTutor.

@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void getCourseWithExercisesAndParticipationsForTeam_AsTutor() throws Exception {
    List<Course> courses = database.createCoursesWithExercisesAndLectures(false);
    Course course = courses.get(0);
    ProgrammingExercise programmingExercise = (ProgrammingExercise) course.getExercises().stream().filter(exercise -> exercise instanceof ProgrammingExercise).findAny().orElseThrow();
    TextExercise textExercise = (TextExercise) course.getExercises().stream().filter(exercise -> exercise instanceof TextExercise).findAny().orElseThrow();
    ModelingExercise modelingExercise = (ModelingExercise) course.getExercises().stream().filter(exercise -> exercise instanceof ModelingExercise).findAny().orElseThrow();
    // make exercises team-based
    Stream.of(programmingExercise, textExercise, modelingExercise).forEach(exercise -> {
        exercise.setMode(ExerciseMode.TEAM);
        exerciseRepo.save(exercise);
    });
    String shortNamePrefix1 = "team";
    String shortNamePrefix2 = "otherTeam";
    Team team1a = database.addTeamsForExercise(programmingExercise, shortNamePrefix1, "team1astudent", 1, tutor).get(0);
    Team team1b = database.addTeamsForExercise(textExercise, shortNamePrefix1, "team1bstudent", 1, tutor).get(0);
    Team team1c = database.addTeamsForExercise(modelingExercise, shortNamePrefix1, "team1cstudent", 1, tutor).get(0);
    Team team2a = database.addTeamsForExercise(programmingExercise, shortNamePrefix2, "team2astudent", 1, null).get(0);
    Team team2b = database.addTeamsForExercise(textExercise, shortNamePrefix2, "team2bstudent", 1, null).get(0);
    assertThat(Stream.of(team1a, team1b, team1c).map(Team::getShortName).distinct()).as("Teams 1 need the same short name for this test").hasSize(1);
    assertThat(Stream.of(team2a, team2b).map(Team::getShortName).distinct()).as("Teams 2 need the same short name for this test").hasSize(1);
    assertThat(Stream.of(team1a, team1b, team1c, team2a, team2b).map(Team::getShortName).distinct()).as("Teams 1 and Teams 2 need different short names").hasSize(2);
    database.addTeamParticipationForExercise(programmingExercise, team1a.getId());
    database.addTeamParticipationForExercise(textExercise, team1b.getId());
    database.addTeamParticipationForExercise(programmingExercise, team2a.getId());
    database.addTeamParticipationForExercise(textExercise, team2b.getId());
    Course course1 = request.get(resourceUrlCourseWithExercisesAndParticipationsForTeam(course, team1a), HttpStatus.OK, Course.class);
    assertThat(course1.getExercises()).as("All exercises of team 1 in course were returned").hasSize(3);
    assertThat(course1.getExercises().stream().map(Exercise::getTeams).collect(Collectors.toSet())).as("All team instances of team 1 in course were returned").hasSize(3);
    assertThat(course1.getExercises().stream().flatMap(exercise -> exercise.getStudentParticipations().stream()).collect(Collectors.toSet())).as("All participations of team 1 in course were returned").hasSize(2);
    Course course2 = request.get(resourceUrlCourseWithExercisesAndParticipationsForTeam(course, team2a), HttpStatus.OK, Course.class);
    assertThat(course2.getExercises()).as("All exercises of team 2 in course were returned").hasSize(2);
    StudentParticipation studentParticipation = course2.getExercises().iterator().next().getStudentParticipations().iterator().next();
    assertThat(studentParticipation.getSubmissionCount()).as("Participation includes submission count").isNotNull();
    // Submission and Result should be present for Team of which the user is the Team Owner
    final String submissionText = "Hello World";
    TextSubmission submission = ModelFactory.generateTextSubmission(submissionText, Language.ENGLISH, true);
    database.saveTextSubmissionWithResultAndAssessor(textExercise, submission, team1b.getId(), tutor.getLogin());
    Course course3 = request.get(resourceUrlCourseWithExercisesAndParticipationsForTeam(course, team1a), HttpStatus.OK, Course.class);
    StudentParticipation participation = course3.getExercises().stream().filter(exercise -> exercise.equals(textExercise)).findAny().orElseThrow().getStudentParticipations().iterator().next();
    assertThat(participation.getSubmissions()).as("Latest submission is present").hasSize(1);
    assertThat(((TextSubmission) participation.getSubmissions().iterator().next()).getText()).as("Latest submission is present").isEqualTo(submissionText);
    assertThat(participation.getResults()).as("Latest result is present").hasSize(1);
    // Submission and Result should not be present for a Team of which the user is not (!) the Team Owner
    submission = ModelFactory.generateTextSubmission(submissionText, Language.ENGLISH, true);
    database.saveTextSubmissionWithResultAndAssessor(textExercise, submission, team2b.getId(), "tutor2");
    Course course4 = request.get(resourceUrlCourseWithExercisesAndParticipationsForTeam(course, team2a), HttpStatus.OK, Course.class);
    participation = course4.getExercises().stream().filter(exercise -> exercise.equals(textExercise)).findAny().orElseThrow().getStudentParticipations().iterator().next();
    assertThat(participation.getSubmissions()).as("Latest submission is not present").isEmpty();
    assertThat(participation.getResults()).as("Latest result is not present").isEmpty();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) Language(de.tum.in.www1.artemis.domain.enumeration.Language) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) ExerciseMode(de.tum.in.www1.artemis.domain.enumeration.ExerciseMode) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) HttpStatus(org.springframework.http.HttpStatus) AfterEach(org.junit.jupiter.api.AfterEach) Stream(java.util.stream.Stream) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) WithMockUser(org.springframework.security.test.context.support.WithMockUser) TeamSearchUserDTO(de.tum.in.www1.artemis.service.dto.TeamSearchUserDTO) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ModelFactory(de.tum.in.www1.artemis.util.ModelFactory) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

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