Search in sources :

Example 96 with Exam

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);
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) Exam(de.tum.in.www1.artemis.domain.exam.Exam) Test(org.junit.jupiter.api.Test)

Example 97 with 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);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Feedback(de.tum.in.www1.artemis.domain.Feedback) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) Course(de.tum.in.www1.artemis.domain.Course) Autowired(org.springframework.beans.factory.annotation.Autowired) EnumSource(org.junit.jupiter.params.provider.EnumSource) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) ModelFactory(de.tum.in.www1.artemis.util.ModelFactory) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Exam(de.tum.in.www1.artemis.domain.exam.Exam) ExamRepository(de.tum.in.www1.artemis.repository.ExamRepository) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) AssessmentType(de.tum.in.www1.artemis.domain.enumeration.AssessmentType) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) ProgrammingExerciseRepository(de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository) Result(de.tum.in.www1.artemis.domain.Result) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ProgrammingExerciseStudentParticipationRepository(de.tum.in.www1.artemis.repository.ProgrammingExerciseStudentParticipationRepository) WithMockUser(org.springframework.security.test.context.support.WithMockUser) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) FeedbackType(de.tum.in.www1.artemis.domain.enumeration.FeedbackType) Feedback(de.tum.in.www1.artemis.domain.Feedback) Exam(de.tum.in.www1.artemis.domain.exam.Exam) Result(de.tum.in.www1.artemis.domain.Result) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 98 with Exam

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));
}
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) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 99 with Exam

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);
}
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) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 100 with Exam

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());
}
Also used : Exercise(de.tum.in.www1.artemis.domain.Exercise) Post(de.tum.in.www1.artemis.domain.metis.Post) Exam(de.tum.in.www1.artemis.domain.exam.Exam) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest) 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