use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class ExerciseTest method getExamViaExerciseGroupOrCourseMember_withExamExercise.
@Test
public void getExamViaExerciseGroupOrCourseMember_withExamExercise() {
Exercise examExercise = mock(Exercise.class, CALLS_REAL_METHODS);
when(examExercise.isExamExercise()).thenReturn(true);
when(examExercise.getExerciseGroup()).thenReturn(exerciseGroup);
when(exerciseGroup.getExam()).thenReturn(exam);
Exam result = examExercise.getExamViaExerciseGroupOrCourseMember();
assertThat(result).isEqualTo(exam);
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class ResultServiceTest method testGetFeedbacksForResultAsStudent_shouldFilterInExamsAfterPublish.
@Test
@WithMockUser(username = "student1", roles = "STUDENT")
public void testGetFeedbacksForResultAsStudent_shouldFilterInExamsAfterPublish() {
Exam exam = examStudentParticipation.getExercise().getExamViaExerciseGroupOrCourseMember();
exam.setPublishResultsDate(ZonedDateTime.now().minusDays(2));
examRepository.save(exam);
Result result = database.addResultToParticipation(null, null, examStudentParticipation);
result = database.addVariousVisibilityFeedbackToResults(result);
List<Feedback> expectedFeedbacks = result.getFeedbacks().stream().filter(feedback -> !feedback.isInvisible()).collect(Collectors.toList());
assertThat(resultService.getFeedbacksForResult(result)).isEqualTo(expectedFeedbacks);
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class StudentExamAccessServiceTest method testUserIsRegisteredForExam.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testUserIsRegisteredForExam() {
Exam examNotRegistered = database.addExam(course1, users.get(1), ZonedDateTime.now().minusHours(4), ZonedDateTime.now().minusHours(1), ZonedDateTime.now().plusHours(1));
assertThrows(AccessForbiddenException.class, () -> studentExamAccessService.checkCourseAndExamAccessElseThrow(course1.getId(), examNotRegistered.getId(), users.get(0), false));
assertThrows(AccessForbiddenException.class, () -> studentExamAccessService.checkStudentExamAccessElseThrow(course1.getId(), examNotRegistered.getId(), studentExam1.getId(), false));
assertThrows(AccessForbiddenException.class, () -> studentExamAccessService.checkStudentExamAccessElseThrow(course1.getId(), examNotRegistered.getId(), studentExam1.getId(), users.get(0), false));
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class StudentExamAccessServiceTest method testExamIsLive.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testExamIsLive() {
// Exam is not visible.
Exam examNotStarted = database.addExam(course1, users.get(0), ZonedDateTime.now().plusHours(1), ZonedDateTime.now().plusHours(2), ZonedDateTime.now().plusHours(3));
assertThrows(AccessForbiddenException.class, () -> studentExamAccessService.checkCourseAndExamAccessElseThrow(course1.getId(), examNotStarted.getId(), users.get(0), false));
assertThrows(AccessForbiddenException.class, () -> studentExamAccessService.checkStudentExamAccessElseThrow(course1.getId(), examNotStarted.getId(), studentExam1.getId(), false));
assertThrows(AccessForbiddenException.class, () -> studentExamAccessService.checkStudentExamAccessElseThrow(course1.getId(), examNotStarted.getId(), studentExam1.getId(), users.get(0), false));
// Exam has ended. After exam has ended, it should still be retrievable by the students to see their participation
Exam examEnded = database.addExam(course1, users.get(0), ZonedDateTime.now().minusHours(4), ZonedDateTime.now().minusHours(3), ZonedDateTime.now().minusHours(1));
StudentExam studentExamEnded = database.addStudentExam(examEnded);
studentExamEnded.setUser(users.get(0));
studentExamRepository.save(studentExamEnded);
// does not throw
studentExamAccessService.checkCourseAndExamAccessElseThrow(course1.getId(), examEnded.getId(), users.get(0), false);
// does not throw
studentExamAccessService.checkStudentExamAccessElseThrow(course1.getId(), examEnded.getId(), studentExamEnded.getId(), false);
// does not throw
studentExamAccessService.checkStudentExamAccessElseThrow(course1.getId(), examEnded.getId(), studentExamEnded.getId(), users.get(0), false);
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class PostIntegrationTest method testCreateExamExercisePost_badRequest.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCreateExamExercisePost_badRequest() throws Exception {
Exam exam = database.setupSimpleExamWithExerciseGroupExercise(course);
Post postToSave = createPostWithoutContext();
Exercise examExercise = exam.getExerciseGroups().get(0).getExercises().stream().findFirst().orElseThrow();
postToSave.setExercise(examExercise);
request.postWithResponseBody("/api/courses/" + courseId + "/posts", postToSave, Post.class, HttpStatus.BAD_REQUEST);
assertThat(existingExercisePosts).hasSameSizeAs(postRepository.findPostsByExerciseId(exerciseId, false, false, false, null));
verify(groupNotificationService, times(0)).notifyAllGroupsAboutNewPostForExercise(any(), any());
}
Aggregations