Search in sources :

Example 76 with StudentExam

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;
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam)

Example 77 with 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));
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Aggregations

StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)69 WithMockUser (org.springframework.security.test.context.support.WithMockUser)44 Test (org.junit.jupiter.api.Test)42 Exam (de.tum.in.www1.artemis.domain.exam.Exam)37 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)22 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)20 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)18 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)18 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)14 ZonedDateTime (java.time.ZonedDateTime)14 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)12 Participation (de.tum.in.www1.artemis.domain.participation.Participation)12 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)12 java.util (java.util)12 Collectors (java.util.stream.Collectors)12 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)12 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)10 AssessmentType (de.tum.in.www1.artemis.domain.enumeration.AssessmentType)10 de.tum.in.www1.artemis.web.rest.dto (de.tum.in.www1.artemis.web.rest.dto)10