use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class ExamIntegrationTest method testCreateTestExam_asInstructor_badReuestWithWorkingTimeGreatherThanWorkingWindow.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testCreateTestExam_asInstructor_badReuestWithWorkingTimeGreatherThanWorkingWindow() throws Exception {
// Test for bad request, where workingTime is greater than difference between StartDate and EndDate
Exam examC = ModelFactory.generateTestExam(course1);
examC.setWorkingTime(5000);
request.post("/api/courses/" + course1.getId() + "/exams", examC, HttpStatus.BAD_REQUEST);
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class ExamIntegrationTest method testAllPreAuthorize.
private void testAllPreAuthorize() throws Exception {
Exam exam = ModelFactory.generateExam(course1);
request.post("/api/courses/" + course1.getId() + "/exams", exam, HttpStatus.FORBIDDEN);
request.put("/api/courses/" + course1.getId() + "/exams", exam, HttpStatus.FORBIDDEN);
request.get("/api/courses/" + course1.getId() + "/exams/" + exam1.getId(), HttpStatus.FORBIDDEN, Exam.class);
request.delete("/api/courses/" + course1.getId() + "/exams/" + exam1.getId(), HttpStatus.FORBIDDEN);
request.delete("/api/courses/" + course1.getId() + "/exams/" + exam1.getId() + "/reset", HttpStatus.FORBIDDEN);
request.post("/api/courses/" + course1.getId() + "/exams/" + exam1.getId() + "/students/student1", null, HttpStatus.FORBIDDEN);
request.post("/api/courses/" + course1.getId() + "/exams/" + exam1.getId() + "/students", Collections.singletonList(new StudentDTO()), HttpStatus.FORBIDDEN);
request.delete("/api/courses/" + course1.getId() + "/exams/" + exam1.getId() + "/students/student1", HttpStatus.FORBIDDEN);
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class ExamIntegrationTest method testDeleteStudentWithParticipationsAndSubmissions.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testDeleteStudentWithParticipationsAndSubmissions() throws Exception {
// Create an exam with registered students
Exam exam = database.setupExamWithExerciseGroupsExercisesRegisteredStudents(course1);
var student1 = database.getUserByLogin("student1");
// 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);
// Get the student exam of student1
Optional<StudentExam> optionalStudent1Exam = generatedStudentExams.stream().filter(studentExam -> studentExam.getUser().equals(student1)).findFirst();
assertThat(optionalStudent1Exam.get()).isNotNull();
var studentExam1 = optionalStudent1Exam.get();
// 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);
List<StudentParticipation> participationsStudent1 = studentParticipationRepository.findByStudentIdAndIndividualExercisesWithEagerSubmissionsResultIgnoreTestRuns(student1.getId(), studentExam1.getExercises());
assertThat(participationsStudent1).hasSize(studentExam1.getExercises().size());
// explicitly set the user again to prevent issues in the following server call due to the use of SecurityUtils.setAuthorizationObject();
database.changeUser("instructor1");
// Remove student1 from the exam and his participations
var params = new LinkedMultiValueMap<String, String>();
params.add("withParticipationsAndSubmission", "true");
request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/students/student1", HttpStatus.OK, params);
// Get the exam with all registered users
params = new LinkedMultiValueMap<>();
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);
// Ensure that the student exam of student1 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(studentExam1);
// Ensure that the participations of student1 were deleted
participationsStudent1 = studentParticipationRepository.findByStudentIdAndIndividualExercisesWithEagerSubmissionsResultIgnoreTestRuns(student1.getId(), studentExam1.getExercises());
assertThat(participationsStudent1).isEmpty();
// 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 testGenerateMissingStudentExams.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testGenerateMissingStudentExams() 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(exam.getRegisteredUsers().size());
// Register two new students
var student5 = database.getUserByLogin("student5");
var student6 = database.getUserByLogin("student6");
exam.getRegisteredUsers().addAll(Set.of(student5, student6));
examRepository.save(exam);
// Generate individual exams for the two missing students
List<StudentExam> missingStudentExams = request.postListWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/generate-missing-student-exams", Optional.empty(), StudentExam.class, HttpStatus.OK);
assertThat(missingStudentExams).hasSize(2);
// Fetch student exams
List<StudentExam> studentExamsDB = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
assertThat(studentExamsDB).hasSize(exam.getRegisteredUsers().size());
// Another request should not create any exams
missingStudentExams = request.postListWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/generate-missing-student-exams", Optional.empty(), StudentExam.class, HttpStatus.OK);
assertThat(missingStudentExams).isEmpty();
studentExamsDB = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
assertThat(studentExamsDB).hasSize(exam.getRegisteredUsers().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);
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class ExamIntegrationTest method testGenerateStudentExamsTemplateCombine.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testGenerateStudentExamsTemplateCombine() throws Exception {
Exam examWithProgramming = database.addExerciseGroupsAndExercisesToExam(exam1, true);
doNothing().when(gitService).combineAllCommitsOfRepositoryIntoOne(any());
// invoke generate student exams
request.postListWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + examWithProgramming.getId() + "/generate-student-exams", Optional.empty(), StudentExam.class, HttpStatus.OK);
verify(gitService, times(1)).combineAllCommitsOfRepositoryIntoOne(any());
}
Aggregations