use of de.tum.in.www1.artemis.domain.exam.StudentExam in project ArTEMiS by ls1intum.
the class StudentExamAccessServiceTest method testCurrentUserIsUserOfStudentExam.
@Test
@WithMockUser(username = "student1", roles = "USER")
public void testCurrentUserIsUserOfStudentExam() {
StudentExam studentExamWithOtherUser = database.addStudentExam(exam1);
studentExamWithOtherUser.setUser(users.get(1));
studentExamRepository.save(studentExamWithOtherUser);
assertThrows(AccessForbiddenException.class, () -> studentExamAccessService.checkStudentExamAccessElseThrow(course1.getId(), exam1.getId(), studentExamWithOtherUser.getId(), false));
assertThrows(AccessForbiddenException.class, () -> studentExamAccessService.checkStudentExamAccessElseThrow(course1.getId(), exam1.getId(), studentExamWithOtherUser.getId(), users.get(0), false));
}
use of de.tum.in.www1.artemis.domain.exam.StudentExam 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.StudentExam in project ArTEMiS by ls1intum.
the class ExamQuizServiceTest method evaluateQuizWithNoSubmissions.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void evaluateQuizWithNoSubmissions() 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);
// add participations with no submissions
for (int i = 0; i < numberOfParticipants; i++) {
final var user = database.getUserByLogin("student" + (i + 1));
var participation = new StudentParticipation();
participation.setExercise(quizExercise);
participation.setParticipant(user);
participation.setInitializationDate(ZonedDateTime.now());
participation.setInitializationState(InitializationState.INITIALIZED);
studentParticipationRepository.save(participation);
}
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);
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();
}
use of de.tum.in.www1.artemis.domain.exam.StudentExam in project ArTEMiS by ls1intum.
the class ExamQuizServiceTest method evaluateQuizWithMultipleSubmissions.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void evaluateQuizWithMultipleSubmissions() 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++) {
final var user = database.getUserByLogin("student" + (i + 1));
database.changeUser(user.getLogin());
QuizSubmission quizSubmission = database.generateSubmissionForThreeQuestions(quizExercise, i + 1, true, ZonedDateTime.now());
request.put("/api/exercises/" + quizExercise.getId() + "/submissions/exam", quizSubmission, HttpStatus.OK);
// add another submission manually to trigger multiple submission branch of evaluateQuizSubmission
final var studentParticipation = studentParticipationRepository.findWithEagerLegalSubmissionsByExerciseIdAndStudentLogin(quizExercise.getId(), user.getLogin()).get();
QuizSubmission quizSubmission2 = database.generateSubmissionForThreeQuestions(quizExercise, i + 1, true, ZonedDateTime.now());
quizSubmission2.setParticipation(studentParticipation);
quizSubmissionRepository.save(quizSubmission2);
}
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();
}
use of de.tum.in.www1.artemis.domain.exam.StudentExam 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);
}
Aggregations