Search in sources :

Example 31 with Exam

use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.

the class ExamIntegrationTest method testGetExamTitle.

private void testGetExamTitle() throws Exception {
    Course course = database.createCourse();
    Exam exam = ModelFactory.generateExam(course);
    exam.setTitle("Test Exam");
    exam = examRepository.save(exam);
    course.addExam(exam);
    courseRepo.save(course);
    final var title = request.get("/api/exams/" + exam.getId() + "/title", HttpStatus.OK, String.class);
    assertThat(title).isEqualTo(exam.getTitle());
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam)

Example 32 with Exam

use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.

the class ExamIntegrationTest method testArchiveExamBeforeEndDate_badRequest.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testArchiveExamBeforeEndDate_badRequest() throws Exception {
    Course course = database.addEmptyCourse();
    course.setEndDate(ZonedDateTime.now().plusMinutes(5));
    course = courseRepo.save(course);
    Exam exam = database.addExam(course);
    exam = examRepository.save(exam);
    request.put("/api/courses/" + course.getId() + "/exams/" + exam.getId() + "/archive", null, HttpStatus.BAD_REQUEST);
}
Also used : 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 33 with Exam

use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.

the class ExamIntegrationTest method createExamsWithInvalidDates.

private List<Exam> createExamsWithInvalidDates(Course course) {
    // Test for bad request, visible date not set
    Exam examA = ModelFactory.generateExam(course);
    examA.setVisibleDate(null);
    // Test for bad request, start date not set
    Exam examB = ModelFactory.generateExam(course);
    examB.setStartDate(null);
    // Test for bad request, end date not set
    Exam examC = ModelFactory.generateExam(course);
    examC.setEndDate(null);
    // Test for bad request, start date not after visible date
    Exam examD = ModelFactory.generateExam(course);
    examD.setStartDate(examD.getVisibleDate());
    // Test for bad request, end date not after start date
    Exam examE = ModelFactory.generateExam(course);
    examE.setEndDate(examE.getStartDate());
    // Test for bad request, when visibleDate equals the startDate
    Exam examF = ModelFactory.generateExam(course);
    examF.setVisibleDate(examF.getStartDate());
    return List.of(examA, examB, examC, examD, examE, examF);
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam)

Example 34 with Exam

use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.

the class ExamIntegrationTest method testCreateExam_asInstructor.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testCreateExam_asInstructor() throws Exception {
    // Test for bad request when exam id is already set.
    Exam examA = ModelFactory.generateExam(course1);
    examA.setId(55L);
    request.post("/api/courses/" + course1.getId() + "/exams", examA, HttpStatus.BAD_REQUEST);
    // Test for bad request when course is null.
    Exam examB = ModelFactory.generateExam(course1);
    examB.setCourse(null);
    request.post("/api/courses/" + course1.getId() + "/exams", examB, HttpStatus.BAD_REQUEST);
    // Test for bad request when course deviates from course specified in route.
    Exam examC = ModelFactory.generateExam(course1);
    request.post("/api/courses/" + course2.getId() + "/exams", examC, HttpStatus.BAD_REQUEST);
    // Test invalid dates
    List<Exam> examsWithInvalidDate = createExamsWithInvalidDates(course1);
    for (var exam : examsWithInvalidDate) {
        request.post("/api/courses/" + course1.getId() + "/exams", exam, HttpStatus.BAD_REQUEST);
    }
    // Test for conflict when user tries to create an exam with exercise groups.
    Exam examD = ModelFactory.generateExam(course1);
    examD.addExerciseGroup(ModelFactory.generateExerciseGroup(true, exam1));
    request.post("/api/courses/" + course1.getId() + "/exams", examD, HttpStatus.CONFLICT);
    // Test examAccessService.
    Exam examE = ModelFactory.generateExam(course1);
    request.post("/api/courses/" + course1.getId() + "/exams", examE, HttpStatus.CREATED);
    verify(examAccessService, times(1)).checkCourseAccessForInstructorElseThrow(course1.getId());
}
Also used : 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 35 with Exam

use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.

the class ExamIntegrationTest method testDeleteStudent.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testDeleteStudent() throws Exception {
    // Create an exam with registered students
    Exam exam = database.setupExamWithExerciseGroupsExercisesRegisteredStudents(course1);
    var student1 = database.getUserByLogin("student1");
    var student2 = database.getUserByLogin("student2");
    // Remove student1 from the exam
    request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/students/student1", 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);
    // Ensure that student1 was removed from the exam
    assertThat(storedExam.getRegisteredUsers()).doesNotContain(student1);
    assertThat(storedExam.getRegisteredUsers()).hasSize(3);
    // 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);
    assertThat(generatedStudentExams).hasSize(storedExam.getRegisteredUsers().size());
    // 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);
    // Get the student exam of student2
    Optional<StudentExam> optionalStudent1Exam = generatedStudentExams.stream().filter(studentExam -> studentExam.getUser().equals(student2)).findFirst();
    assertThat(optionalStudent1Exam.get()).isNotNull();
    var studentExam2 = optionalStudent1Exam.get();
    // explicitly set the user again to prevent issues in the following server call due to the use of SecurityUtils.setAuthorizationObject();
    database.changeUser("instructor1");
    // Remove student2 from the exam
    request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/students/student2", HttpStatus.OK);
    // Get the exam with all registered users
    params = new LinkedMultiValueMap<>();
    params.add("withStudents", "true");
    storedExam = request.get("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK, Exam.class, params);
    // Ensure that student2 was removed from the exam
    assertThat(storedExam.getRegisteredUsers()).doesNotContain(student2);
    assertThat(storedExam.getRegisteredUsers()).hasSize(2);
    // Ensure that the student exam of student2 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(studentExam2);
    // Ensure that the participations were not deleted
    List<StudentParticipation> participationsStudent2 = studentParticipationRepository.findByStudentIdAndIndividualExercisesWithEagerSubmissionsResultIgnoreTestRuns(student2.getId(), studentExam2.getExercises());
    assertThat(participationsStudent2).hasSize(studentExam2.getExercises().size());
    // 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)

Aggregations

Exam (de.tum.in.www1.artemis.domain.exam.Exam)228 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)180 WithMockUser (org.springframework.security.test.context.support.WithMockUser)164 Test (org.junit.jupiter.api.Test)158 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)92 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)75 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)52 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)48 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)46 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)46 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)42 ZonedDateTime (java.time.ZonedDateTime)40 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)38 Course (de.tum.in.www1.artemis.domain.Course)36 GradingScale (de.tum.in.www1.artemis.domain.GradingScale)34 BeforeEach (org.junit.jupiter.api.BeforeEach)30 User (de.tum.in.www1.artemis.domain.User)27 Collectors (java.util.stream.Collectors)26 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)24 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)24