use of de.tum.in.www1.artemis.domain.exam.ExerciseGroup in project ArTEMiS by ls1intum.
the class ExamServiceTest method addNewTextExerciseToExerciseGroup.
private TextExercise addNewTextExerciseToExerciseGroup(ExerciseGroup exerciseGroup, Long id, Double maxPoints, Double maxBonusPoints, IncludedInOverallScore includedInOverallScore) {
TextExercise includedTextExercise = new TextExercise();
includedTextExercise.setId(id);
includedTextExercise.setMaxPoints(maxPoints);
includedTextExercise.setBonusPoints(maxBonusPoints);
includedTextExercise.setIncludedInOverallScore(includedInOverallScore);
includedTextExercise.setExerciseGroup(exerciseGroup);
return includedTextExercise;
}
use of de.tum.in.www1.artemis.domain.exam.ExerciseGroup in project ArTEMiS by ls1intum.
the class ExamServiceTest method validateForStudentExamGeneration_tooManyPointsInMandatoryExercises_shouldThrowException.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void validateForStudentExamGeneration_tooManyPointsInMandatoryExercises_shouldThrowException() {
Exam exam = createExam(1, 1L, 10);
ExerciseGroup exerciseGroup = addExerciseGroupToExam(exam, 1L, true);
TextExercise exercise1 = addNewTextExerciseToExerciseGroup(exerciseGroup, 1L, 20.0, 5.0, IncludedInOverallScore.INCLUDED_COMPLETELY);
TextExercise exercise2 = addNewTextExerciseToExerciseGroup(exerciseGroup, 2L, 20.0, 5.0, IncludedInOverallScore.INCLUDED_COMPLETELY);
exerciseGroup.setExercises(Set.of(exercise1, exercise2));
BadRequestAlertException thrown = assertThrows(BadRequestAlertException.class, () -> examService.validateForStudentExamGeneration(exam), "Expected to throw bad request alert exception, but it didn't");
assertTrue(thrown.getMessage().contains("Check that you set the exam max points correctly! The max points a student can earn in the mandatory exercise groups is too big"));
}
use of de.tum.in.www1.artemis.domain.exam.ExerciseGroup in project ArTEMiS by ls1intum.
the class GroupNotificationServiceTest method setUp.
/**
* Sets up all needed mocks and their wanted behavior.
*/
@BeforeEach
public void setUp() {
course = database.createCourse();
database.addUsers(1, 0, 0, 1);
student = database.getUserByLogin("student1");
instructor = database.getUserByLogin("instructor1");
archiveErrors = new ArrayList<>();
exam = database.addExam(course);
examRepository.save(exam);
lecture = new Lecture();
lecture.setCourse(course);
attachment = new Attachment();
exercise = ModelFactory.generateTextExercise(null, null, null, course);
exerciseRepository.save(exercise);
updatedExercise = ModelFactory.generateTextExercise(null, null, null, course);
exerciseRepository.save(updatedExercise);
ExerciseGroup exerciseGroup = new ExerciseGroup();
exerciseGroup.setExam(exam);
examExercise = new TextExercise();
examExercise.setExerciseGroup(exerciseGroup);
examExercise.setProblemStatement(EXAM_PROBLEM_STATEMENT);
quizExercise = database.createQuiz(course, null, null, QuizMode.SYNCHRONIZED);
exerciseRepository.save(quizExercise);
programmingExercise = new ProgrammingExercise();
programmingExercise.setCourse(course);
post = new Post();
post.setExercise(exercise);
post.setLecture(lecture);
post.setCourse(course);
answerPost = new AnswerPost();
answerPost.setPost(post);
// explicitly change the user to prevent issues in the following server call due to userRepository.getUser() (@WithMockUser is not working here)
database.changeUser("instructor1");
doNothing().when(javaMailSender).send(any(MimeMessage.class));
}
use of de.tum.in.www1.artemis.domain.exam.ExerciseGroup in project ArTEMiS by ls1intum.
the class ExamService method reset.
/**
* Deletes all elements associated with the exam but not the exam itself in order to reset it.
*
* The deleted elements are:
* <ul>
* <li>All StudentExams</li>
* <li>Everything that has been submitted by students to the exercises that are part of the exam,
* but not the exercises themself. See {@link ExerciseDeletionService#reset}</li>
* </ul>
* @param examId the ID of the exam to be reset
*/
public void reset(@NotNull Long examId) {
User user = userRepository.getUser();
Exam exam = examRepository.findOneWithEagerExercisesGroupsAndStudentExams(examId);
log.info("User {} has requested to reset the exam {}", user.getLogin(), exam.getTitle());
AuditEvent auditEvent = new AuditEvent(user.getLogin(), Constants.RESET_EXAM, "exam=" + exam.getTitle());
auditEventRepository.add(auditEvent);
for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
if (exerciseGroup != null) {
for (Exercise exercise : exerciseGroup.getExercises()) {
exerciseDeletionService.reset(exercise);
}
}
}
studentExamRepository.deleteAll(exam.getStudentExams());
}
use of de.tum.in.www1.artemis.domain.exam.ExerciseGroup in project ArTEMiS by ls1intum.
the class ExamService method delete.
/**
* Fetches the exam and eagerly loads all required elements and deletes all elements associated with the
* exam including:
* <ul>
* <li>The Exam</li>
* <li>All ExerciseGroups</li>
* <li>All Exercises including:
* Submissions, Participations, Results, Repositories and build plans, see {@link ExerciseDeletionService#delete}</li>
* <li>All StudentExams</li>
* <li>The exam Grading Scale if such exists</li>
* </ul>
* Note: StudentExams and ExerciseGroups are not explicitly deleted as the delete operation of the exam is cascaded by the database.
*
* @param examId the ID of the exam to be deleted
*/
public void delete(@NotNull long examId) {
User user = userRepository.getUser();
Exam exam = examRepository.findOneWithEagerExercisesGroupsAndStudentExams(examId);
log.info("User {} has requested to delete the exam {}", user.getLogin(), exam.getTitle());
AuditEvent auditEvent = new AuditEvent(user.getLogin(), Constants.DELETE_EXAM, "exam=" + exam.getTitle());
auditEventRepository.add(auditEvent);
for (ExerciseGroup exerciseGroup : exam.getExerciseGroups()) {
if (exerciseGroup != null) {
for (Exercise exercise : exerciseGroup.getExercises()) {
exerciseDeletionService.delete(exercise.getId(), true, true);
}
}
}
deleteGradingScaleOfExam(exam);
examRepository.deleteById(exam.getId());
}
Aggregations