Search in sources :

Example 26 with StudentExam

use of de.tum.in.www1.artemis.domain.exam.StudentExam in project Artemis by ls1intum.

the class ExamIntegrationTest method testGenerateStudentExams.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testGenerateStudentExams() throws Exception {
    Exam exam = database.setupExamWithExerciseGroupsExercisesRegisteredStudents(course1);
    // invoke generate student exams
    List<StudentExam> studentExams = request.postListWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/generate-student-exams", Optional.empty(), StudentExam.class, HttpStatus.OK);
    assertThat(studentExams).hasSize(exam.getRegisteredUsers().size());
    for (StudentExam studentExam : studentExams) {
        assertThat(studentExam.getWorkingTime()).as("Working time is set correctly").isEqualTo(120 * 60);
    }
    for (var studentExam : studentExams) {
        assertThat(studentExam.getExercises()).hasSize(exam.getNumberOfExercisesInExam());
        assertThat(studentExam.getExam()).isEqualTo(exam);
    // TODO: check exercise configuration, each mandatory exercise group has to appear, one optional exercise should appear
    }
    // Make sure delete also works if so many objects have been created before
    request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK);
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 27 with StudentExam

use of de.tum.in.www1.artemis.domain.exam.StudentExam in project Artemis by ls1intum.

the class ExamIntegrationTest method testGetStudentExamForStart.

@Test
@WithMockUser(username = "student1", roles = "USER")
public void testGetStudentExamForStart() throws Exception {
    Exam exam = database.addActiveExamWithRegisteredUser(course1, users.get(0));
    StudentExam response = request.get("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/start", HttpStatus.OK, StudentExam.class);
    assertThat(response.getExam()).isEqualTo(exam);
    verify(examAccessService, times(1)).getExamInCourseElseThrow(course1.getId(), exam.getId());
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 28 with StudentExam

use of de.tum.in.www1.artemis.domain.exam.StudentExam in project Artemis by ls1intum.

the class ExamIntegrationTest method testDeleteStudentWithParticipationsAndSubmissions.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testDeleteStudentWithParticipationsAndSubmissions() throws Exception {
    // Create an exam with registered students
    Exam exam = database.setupExamWithExerciseGroupsExercisesRegisteredStudents(course1);
    var student1 = database.getUserByLogin("student1");
    // Create individual student exams
    List<StudentExam> generatedStudentExams = request.postListWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/generate-student-exams", Optional.empty(), StudentExam.class, HttpStatus.OK);
    // Get the student exam of student1
    Optional<StudentExam> optionalStudent1Exam = generatedStudentExams.stream().filter(studentExam -> studentExam.getUser().equals(student1)).findFirst();
    assertThat(optionalStudent1Exam.get()).isNotNull();
    var studentExam1 = optionalStudent1Exam.get();
    // Start the exam to create participations
    request.postWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams/start-exercises", Optional.empty(), Integer.class, HttpStatus.OK);
    List<StudentParticipation> participationsStudent1 = studentParticipationRepository.findByStudentIdAndIndividualExercisesWithEagerSubmissionsResultIgnoreTestRuns(student1.getId(), studentExam1.getExercises());
    assertThat(participationsStudent1).hasSize(studentExam1.getExercises().size());
    // explicitly set the user again to prevent issues in the following server call due to the use of SecurityUtils.setAuthorizationObject();
    database.changeUser("instructor1");
    // Remove student1 from the exam and his participations
    var params = new LinkedMultiValueMap<String, String>();
    params.add("withParticipationsAndSubmission", "true");
    request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/students/student1", HttpStatus.OK, params);
    // Get the exam with all registered users
    params = new LinkedMultiValueMap<>();
    params.add("withStudents", "true");
    Exam storedExam = request.get("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK, Exam.class, params);
    // Ensure that student1 was removed from the exam
    assertThat(storedExam.getRegisteredUsers()).doesNotContain(student1);
    assertThat(storedExam.getRegisteredUsers()).hasSize(3);
    // Ensure that the student exam of student1 was deleted
    List<StudentExam> studentExams = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
    assertThat(studentExams).hasSameSizeAs(storedExam.getRegisteredUsers()).doesNotContain(studentExam1);
    // Ensure that the participations of student1 were deleted
    participationsStudent1 = studentParticipationRepository.findByStudentIdAndIndividualExercisesWithEagerSubmissionsResultIgnoreTestRuns(student1.getId(), studentExam1.getExercises());
    assertThat(participationsStudent1).isEmpty();
    // Make sure delete also works if so many objects have been created before
    request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) PasswordService(de.tum.in.www1.artemis.service.user.PasswordService) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) Participation(de.tum.in.www1.artemis.domain.participation.Participation) Autowired(org.springframework.beans.factory.annotation.Autowired) TextAssessmentKnowledgeService(de.tum.in.www1.artemis.service.TextAssessmentKnowledgeService) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) ExamService(de.tum.in.www1.artemis.service.exam.ExamService) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ModelFactory(de.tum.in.www1.artemis.util.ModelFactory) Path(java.nio.file.Path) IncludedInOverallScore(de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore) Exam(de.tum.in.www1.artemis.domain.exam.Exam) DiagramType(de.tum.in.www1.artemis.domain.enumeration.DiagramType) ExamDateService(de.tum.in.www1.artemis.service.exam.ExamDateService) StudentDTO(de.tum.in.www1.artemis.service.dto.StudentDTO) Awaitility.await(org.awaitility.Awaitility.await) QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) Files(java.nio.file.Files) ExamRegistrationService(de.tum.in.www1.artemis.service.exam.ExamRegistrationService) AssessmentType(de.tum.in.www1.artemis.domain.enumeration.AssessmentType) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) HttpStatus(org.springframework.http.HttpStatus) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) WithMockUser(org.springframework.security.test.context.support.WithMockUser) de.tum.in.www1.artemis.web.rest.dto(de.tum.in.www1.artemis.web.rest.dto) LdapUserDto(de.tum.in.www1.artemis.service.ldap.LdapUserDto) ZonedDateTime.now(java.time.ZonedDateTime.now) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ZipFileTestUtilService(de.tum.in.www1.artemis.util.ZipFileTestUtilService) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 29 with StudentExam

use of de.tum.in.www1.artemis.domain.exam.StudentExam in project Artemis by ls1intum.

the class ExamIntegrationTest method testRemovingAllStudents.

@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testRemovingAllStudents() throws Exception {
    Exam exam = database.setupExamWithExerciseGroupsExercisesRegisteredStudents(course1);
    // Generate student exams
    List<StudentExam> studentExams = request.postListWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/generate-student-exams", Optional.empty(), StudentExam.class, HttpStatus.OK);
    assertThat(studentExams).hasSize(4);
    assertThat(exam.getRegisteredUsers()).hasSize(4);
    // /courses/{courseId}/exams/{examId}/student-exams/start-exercises
    Integer numberOfGeneratedParticipations = request.postWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams/start-exercises", Optional.empty(), Integer.class, HttpStatus.OK);
    assertThat(numberOfGeneratedParticipations).isEqualTo(16);
    // Fetch student exams
    List<StudentExam> studentExamsDB = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
    assertThat(studentExamsDB).hasSize(4);
    List<StudentParticipation> participationList = new ArrayList<>();
    Exercise[] exercises = examRepository.findAllExercisesByExamId(exam.getId()).toArray(new Exercise[0]);
    for (Exercise value : exercises) {
        participationList.addAll(studentParticipationRepository.findByExerciseId(value.getId()));
    }
    assertThat(participationList).hasSize(16);
    // TODO there should be some participation but no submissions unfortunately
    // remove all students
    request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/students", HttpStatus.OK);
    // Get the exam with all registered users
    var params = new LinkedMultiValueMap<String, String>();
    params.add("withStudents", "true");
    Exam storedExam = request.get("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK, Exam.class, params);
    assertThat(storedExam.getRegisteredUsers()).isEmpty();
    // Fetch student exams
    studentExamsDB = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
    assertThat(studentExamsDB).isEmpty();
    // Fetch participations
    exercises = examRepository.findAllExercisesByExamId(exam.getId()).toArray(new Exercise[0]);
    participationList = new ArrayList<>();
    for (Exercise exercise : exercises) {
        participationList.addAll(studentParticipationRepository.findByExerciseId(exercise.getId()));
    }
    assertThat(participationList).hasSize(16);
}
Also used : QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 30 with StudentExam

use of de.tum.in.www1.artemis.domain.exam.StudentExam in project Artemis by ls1intum.

the class ExamQuizServiceTest method evaluateQuiz.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void evaluateQuiz() throws Exception {
    for (int i = 0; i < numberOfParticipants; i++) {
        exam.addRegisteredUser(users.get(i));
    }
    exam = examRepository.save(exam);
    exerciseGroup.setExam(exam);
    exerciseGroup = exerciseGroupRepository.save(exerciseGroup);
    exam.setExerciseGroups(List.of(exerciseGroup));
    quizExercise.setExerciseGroup(exerciseGroup);
    quizExercise = quizExerciseService.save(quizExercise);
    exerciseGroup.setExercises(Set.of(quizExercise));
    assertThat(studentExamRepository.generateStudentExams(exam)).hasSize(numberOfParticipants);
    assertThat(studentExamRepository.findByExamId(exam.getId())).hasSize(numberOfParticipants);
    assertThat(studentExamService.startExercises(exam.getId())).isEqualTo(numberOfParticipants);
    for (int i = 0; i < numberOfParticipants; i++) {
        database.changeUser("student" + (i + 1));
        QuizSubmission quizSubmission = database.generateSubmissionForThreeQuestions(quizExercise, i + 1, true, ZonedDateTime.now());
        request.put("/api/exercises/" + quizExercise.getId() + "/submissions/exam", quizSubmission, HttpStatus.OK);
    }
    database.changeUser("instructor1");
    // All exams should be over before evaluation
    for (StudentExam studentExam : studentExamRepository.findByExamId(exam.getId())) {
        studentExam.setWorkingTime(0);
        studentExamRepository.save(studentExam);
    }
    Integer numberOfEvaluatedExercises = request.postWithResponseBody("/api/courses/" + course.getId() + "/exams/" + exam.getId() + "/student-exams/evaluate-quiz-exercises", Optional.empty(), Integer.class, HttpStatus.OK);
    assertThat(numberOfEvaluatedExercises).isEqualTo(1);
    checkStatistics(quizExercise);
    studentExamRepository.deleteAll();
    // Make sure delete also works if so many objects have been created before
    request.delete("/api/courses/" + course.getId() + "/exams/" + exam.getId(), HttpStatus.OK);
    userRepository.deleteAll();
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Aggregations

StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)69 WithMockUser (org.springframework.security.test.context.support.WithMockUser)44 Test (org.junit.jupiter.api.Test)42 Exam (de.tum.in.www1.artemis.domain.exam.Exam)37 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)22 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)20 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)18 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)18 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)14 ZonedDateTime (java.time.ZonedDateTime)14 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)12 Participation (de.tum.in.www1.artemis.domain.participation.Participation)12 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)12 java.util (java.util)12 Collectors (java.util.stream.Collectors)12 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)12 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)10 AssessmentType (de.tum.in.www1.artemis.domain.enumeration.AssessmentType)10 de.tum.in.www1.artemis.web.rest.dto (de.tum.in.www1.artemis.web.rest.dto)10