use of de.tum.in.www1.artemis.domain.exam.StudentExam in project ArTEMiS by ls1intum.
the class DatabaseUtilService method addStudentExamWithUser.
public StudentExam addStudentExamWithUser(Exam exam, User user, int additionalWorkingTime) {
StudentExam studentExam = ModelFactory.generateStudentExam(exam);
studentExam.setUser(user);
studentExam.setWorkingTime((int) Duration.between(exam.getStartDate(), exam.getEndDate()).toSeconds() + additionalWorkingTime);
studentExamRepository.save(studentExam);
return studentExam;
}
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));
}
Aggregations