use of de.tum.in.www1.artemis.domain.exam.Exam 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().size()).isEqualTo(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().size()).isEqualTo(0);
// Fetch student exams
studentExamsDB = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
assertThat(studentExamsDB).hasSize(0);
// 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);
}
use of de.tum.in.www1.artemis.domain.exam.Exam 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);
}
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 conflict when course is null.
Exam examB = ModelFactory.generateExam(course1);
examB.setCourse(null);
request.post("/api/courses/" + course1.getId() + "/exams", examB, HttpStatus.CONFLICT);
// Test for conflict when course deviates from course specified in route.
Exam examC = ModelFactory.generateExam(course1);
request.post("/api/courses/" + course2.getId() + "/exams", examC, HttpStatus.CONFLICT);
// Test invalid dates
List<Exam> examsWithInvalidDate = createExamsWithInvalidDates(course1);
for (var exam : examsWithInvalidDate) {
request.post("/api/courses/" + course1.getId() + "/exams", exam, HttpStatus.CONFLICT);
}
// 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());
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project Artemis by ls1intum.
the class ExamIntegrationTest method testGetExamForExamDashboard_NotTAOfCourse_forbidden.
@Test
@WithMockUser(username = "tutor6", roles = "TA")
public void testGetExamForExamDashboard_NotTAOfCourse_forbidden() throws Exception {
User user = userRepo.findOneByLogin("student1").get();
Course course = database.createCourseWithExamAndExerciseGroupAndExercises(user);
Exam exam = course.getExams().iterator().next();
exam.setEndDate(now().plusWeeks(1));
examRepository.save(exam);
request.get("/api/courses/" + course.getId() + "/exams/" + course.getExams().iterator().next().getId() + "/exam-for-assessment-dashboard", HttpStatus.FORBIDDEN, Course.class);
}
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).hasSize(storedExam.getRegisteredUsers().size());
assertThat(studentExams).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