Search in sources :

Example 66 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.

the class ProgrammingExerciseScheduleServiceTest method verifyLockStudentRepositoryOperation.

private void verifyLockStudentRepositoryOperation(boolean wasCalled, Iterable<StudentParticipation> studentParticipations, long timeoutInMs) {
    int callCount = wasCalled ? 1 : 0;
    for (StudentParticipation studentParticipation : studentParticipations) {
        ProgrammingExerciseStudentParticipation programmingExerciseStudentParticipation = (ProgrammingExerciseStudentParticipation) studentParticipation;
        verify(versionControlService, timeout(timeoutInMs).times(callCount)).setRepositoryPermissionsToReadOnly(programmingExerciseStudentParticipation.getVcsRepositoryUrl(), programmingExercise.getProjectKey(), programmingExerciseStudentParticipation.getStudents());
    }
}
Also used : ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Example 67 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.

the class TextExerciseUtilService method createSampleTextExerciseWithSubmissions.

public TextExercise createSampleTextExerciseWithSubmissions(Course course, List<TextBlock> textBlocks, int submissionCount, int submissionSize) {
    if (textBlocks.size() != submissionCount * submissionSize) {
        throw new IllegalArgumentException("number of textBlocks must be eqaul to submissionCount * submissionSize");
    }
    TextExercise textExercise = new TextExercise();
    textExercise.setCourse(course);
    textExercise.setTitle("Title");
    textExercise.setShortName("Shortname");
    textExercise.setAssessmentType(AssessmentType.SEMI_AUTOMATIC);
    textExercise = textExerciseRepository.save(textExercise);
    // submissions.length must be equal to studentParticipations.length;
    for (int i = 0; i < submissionCount; i++) {
        TextSubmission submission = new TextSubmission();
        StudentParticipation studentParticipation = new StudentParticipation();
        studentParticipation.setExercise(textExercise);
        studentParticipation = participationRepository.save(studentParticipation);
        submission.setParticipation(studentParticipation);
        submission.setLanguage(Language.ENGLISH);
        submission.setText("Test123");
        submission.setBlocks(new HashSet<>(textBlocks.subList(i * submissionSize, (i + 1) * submissionSize)));
        submission.setSubmitted(true);
        submission.setSubmissionDate(ZonedDateTime.now());
        textBlocks.subList(i * submissionSize, (i + 1) * submissionSize).forEach(textBlock -> textBlock.setSubmission(submission));
        studentParticipation.addSubmission(submission);
        textSubmissionRepository.save(submission);
    }
    return textExercise;
}
Also used : StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Example 68 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.

the class CourseServiceTest method testGetActiveStudents_UTCConversion.

@Test
public void testGetActiveStudents_UTCConversion() {
    ZonedDateTime date = ZonedDateTime.of(2022, 1, 2, 0, 0, 0, 0, ZonedDateTime.now().getZone());
    SecurityUtils.setAuthorizationObject();
    var course = database.addEmptyCourse();
    var exercise = ModelFactory.generateTextExercise(date, date, date, course);
    course.addExercises(exercise);
    exercise = exerciseRepo.save(exercise);
    var users = database.addUsers(2, 0, 0, 0);
    var student1 = users.get(0);
    var participation1 = new StudentParticipation();
    participation1.setParticipant(student1);
    participation1.exercise(exercise);
    studentParticipationRepo.save(participation1);
    var submission1 = new TextSubmission();
    submission1.text("text of text submission1");
    submission1.setLanguage(Language.ENGLISH);
    submission1.setSubmitted(true);
    submission1.setParticipation(participation1);
    submission1.setSubmissionDate(date.plusDays(1).plusMinutes(59).plusSeconds(59).plusNanos(59));
    submissionRepository.save(submission1);
    var exerciseList = new HashSet<Long>();
    exerciseList.add(exercise.getId());
    var activeStudents = courseService.getActiveStudents(exerciseList, 0, 4, ZonedDateTime.of(2022, 1, 25, 0, 0, 0, 0, ZoneId.systemDefault()));
    assertThat(activeStudents).hasSize(4).containsExactly(1, 0, 0, 0);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) TextSubmission(de.tum.in.www1.artemis.domain.TextSubmission) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 69 with StudentParticipation

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

Example 70 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation 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();
}
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

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)219 Test (org.junit.jupiter.api.Test)118 WithMockUser (org.springframework.security.test.context.support.WithMockUser)112 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)60 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)50 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)48 ZonedDateTime (java.time.ZonedDateTime)44 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)42 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)40 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)36 Exam (de.tum.in.www1.artemis.domain.exam.Exam)30 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)30 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)28 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)28 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)26 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)24 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)24 Participation (de.tum.in.www1.artemis.domain.participation.Participation)24 Collectors (java.util.stream.Collectors)24