Search in sources :

Example 16 with TextExercise

use of de.tum.in.www1.artemis.domain.TextExercise in project Artemis by ls1intum.

the class DatabaseUtilService method createCourseWithTestModelingAndFileUploadExercisesAndSubmissions.

public Course createCourseWithTestModelingAndFileUploadExercisesAndSubmissions() throws Exception {
    Course course = addCourseWithModelingAndTextAndFileUploadExercise();
    course.setEndDate(ZonedDateTime.now().minusMinutes(5));
    course = courseRepo.save(course);
    var fileUploadExercise = findFileUploadExerciseWithTitle(course.getExercises(), "FileUpload");
    createFileUploadSubmissionWithFile(fileUploadExercise, "uploaded-file.png");
    var textExercise = findTextExerciseWithTitle(course.getExercises(), "Text");
    var textSubmission = ModelFactory.generateTextSubmission("example text", Language.ENGLISH, true);
    saveTextSubmission(textExercise, textSubmission, "student1");
    var modelingExercise = findModelingExerciseWithTitle(course.getExercises(), "Modeling");
    createAndSaveParticipationForExercise(modelingExercise, "student1");
    String emptyActivityModel = FileUtils.loadFileFromResources("test-data/model-submission/empty-activity-diagram.json");
    ModelingSubmission submission = ModelFactory.generateModelingSubmission(emptyActivityModel, true);
    addSubmission(modelingExercise, submission, "student1");
    return course;
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) JsonParser.parseString(com.google.gson.JsonParser.parseString)

Example 17 with TextExercise

use of de.tum.in.www1.artemis.domain.TextExercise in project Artemis by ls1intum.

the class DatabaseUtilService method createCourseWithExamAndExercises.

public Course createCourseWithExamAndExercises() throws IOException {
    Course course = courseRepo.save(addEmptyCourse());
    // Create a file upload exercise with a dummy submission file
    var exerciseGroup1 = exerciseGroupRepository.save(new ExerciseGroup());
    var fileUploadExercise = ModelFactory.generateFileUploadExerciseForExam(".png", exerciseGroup1);
    fileUploadExercise = exerciseRepo.save(fileUploadExercise);
    createFileUploadSubmissionWithFile(fileUploadExercise, "uploaded-file.png");
    exerciseGroup1.addExercise(fileUploadExercise);
    exerciseGroup1 = exerciseGroupRepository.save(exerciseGroup1);
    // Create a text exercise with a dummy submission file
    var exerciseGroup2 = exerciseGroupRepository.save(new ExerciseGroup());
    var textExercise = ModelFactory.generateTextExerciseForExam(exerciseGroup2);
    textExercise = exerciseRepo.save(textExercise);
    var textSubmission = ModelFactory.generateTextSubmission("example text", Language.ENGLISH, true);
    saveTextSubmission(textExercise, textSubmission, "student1");
    exerciseGroup2.addExercise(textExercise);
    exerciseGroup2 = exerciseGroupRepository.save(exerciseGroup2);
    // Create a modeling exercise with a dummy submission file
    var exerciseGroup3 = exerciseGroupRepository.save(new ExerciseGroup());
    var modelingExercise = ModelFactory.generateModelingExerciseForExam(DiagramType.ClassDiagram, exerciseGroup2);
    modelingExercise = exerciseRepo.save(modelingExercise);
    String emptyActivityModel = FileUtils.loadFileFromResources("test-data/model-submission/empty-activity-diagram.json");
    var modelingSubmission = ModelFactory.generateModelingSubmission(emptyActivityModel, true);
    addSubmission(modelingExercise, modelingSubmission, "student1");
    exerciseGroup3.addExercise(modelingExercise);
    exerciseGroupRepository.save(exerciseGroup3);
    Exam exam = addExam(course);
    exam.setEndDate(ZonedDateTime.now().minusMinutes(5));
    exam.addExerciseGroup(exerciseGroup1);
    exam.addExerciseGroup(exerciseGroup2);
    examRepository.save(exam);
    return course;
}
Also used : JsonParser.parseString(com.google.gson.JsonParser.parseString) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam)

Example 18 with TextExercise

use of de.tum.in.www1.artemis.domain.TextExercise in project Artemis by ls1intum.

the class DatabaseUtilService method addExerciseGroupsAndExercisesToExam.

public Exam addExerciseGroupsAndExercisesToExam(Exam exam, boolean withProgrammingExercise) {
    // text
    ModelFactory.generateExerciseGroup(true, exam);
    // quiz
    ModelFactory.generateExerciseGroup(true, exam);
    // file upload
    ModelFactory.generateExerciseGroup(true, exam);
    // modeling
    ModelFactory.generateExerciseGroup(true, exam);
    // bonus text
    ModelFactory.generateExerciseGroup(true, exam);
    // not included text
    ModelFactory.generateExerciseGroup(true, exam);
    exam.setNumberOfExercisesInExam(6);
    exam.setMaxPoints(24);
    exam = examRepository.save(exam);
    // NOTE: we have to reassign, otherwise we get problems, because the objects have changed
    var exerciseGroup0 = exam.getExerciseGroups().get(0);
    var exerciseGroup1 = exam.getExerciseGroups().get(1);
    var exerciseGroup2 = exam.getExerciseGroups().get(2);
    var exerciseGroup3 = exam.getExerciseGroups().get(3);
    var exerciseGroup4 = exam.getExerciseGroups().get(4);
    var exerciseGroup5 = exam.getExerciseGroups().get(5);
    TextExercise textExercise1 = ModelFactory.generateTextExerciseForExam(exerciseGroup0);
    TextExercise textExercise2 = ModelFactory.generateTextExerciseForExam(exerciseGroup0);
    textExercise1.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
    textExercise2.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
    exerciseGroup0.setExercises(Set.of(textExercise1, textExercise2));
    exerciseRepo.save(textExercise1);
    exerciseRepo.save(textExercise2);
    QuizExercise quizExercise1 = createQuizForExam(exerciseGroup1);
    QuizExercise quizExercise2 = createQuizForExam(exerciseGroup1);
    exerciseGroup1.setExercises(Set.of(quizExercise1, quizExercise2));
    exerciseRepo.save(quizExercise1);
    exerciseRepo.save(quizExercise2);
    FileUploadExercise fileUploadExercise1 = ModelFactory.generateFileUploadExerciseForExam("pdf", exerciseGroup2);
    FileUploadExercise fileUploadExercise2 = ModelFactory.generateFileUploadExerciseForExam("pdf", exerciseGroup2);
    exerciseGroup2.setExercises(Set.of(fileUploadExercise1, fileUploadExercise2));
    exerciseRepo.save(fileUploadExercise1);
    exerciseRepo.save(fileUploadExercise2);
    ModelingExercise modelingExercise1 = ModelFactory.generateModelingExerciseForExam(DiagramType.ClassDiagram, exerciseGroup3);
    ModelingExercise modelingExercise2 = ModelFactory.generateModelingExerciseForExam(DiagramType.ClassDiagram, exerciseGroup3);
    modelingExercise1.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
    modelingExercise2.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
    exerciseGroup3.setExercises(Set.of(modelingExercise1, modelingExercise2));
    exerciseRepo.save(modelingExercise1);
    exerciseRepo.save(modelingExercise2);
    TextExercise bonusTextExercise = ModelFactory.generateTextExerciseForExam(exerciseGroup4);
    bonusTextExercise.setIncludedInOverallScore(IncludedInOverallScore.INCLUDED_AS_BONUS);
    bonusTextExercise.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
    exerciseGroup4.setExercises(Set.of(bonusTextExercise));
    exerciseRepo.save(bonusTextExercise);
    TextExercise notIncludedTextExercise = ModelFactory.generateTextExerciseForExam(exerciseGroup5);
    notIncludedTextExercise.setIncludedInOverallScore(IncludedInOverallScore.NOT_INCLUDED);
    notIncludedTextExercise.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
    exerciseGroup5.setExercises(Set.of(notIncludedTextExercise));
    exerciseRepo.save(notIncludedTextExercise);
    if (withProgrammingExercise) {
        // programming
        ModelFactory.generateExerciseGroup(true, exam);
        exam.setNumberOfExercisesInExam(7);
        exam.setMaxPoints(29);
        exam = examRepository.save(exam);
        var exerciseGroup6 = exam.getExerciseGroups().get(6);
        // Programming exercises need a proper setup for 'prepare exam start' to work
        ProgrammingExercise programmingExercise1 = ModelFactory.generateProgrammingExerciseForExam(exerciseGroup6);
        exerciseRepo.save(programmingExercise1);
        addTemplateParticipationForProgrammingExercise(programmingExercise1);
        addSolutionParticipationForProgrammingExercise(programmingExercise1);
        exerciseGroup6.setExercises(Set.of(programmingExercise1));
    }
    return exam;
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise)

Example 19 with TextExercise

use of de.tum.in.www1.artemis.domain.TextExercise in project Artemis by ls1intum.

the class DatabaseUtilService method createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAndResults.

public Course createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAndResults(boolean hasAssessmentDueDatePassed) {
    Course course = ModelFactory.generateCourse(null, pastTimestamp, futureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
    ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, DiagramType.ClassDiagram, course);
    TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, course);
    FileUploadExercise fileUploadExercise = ModelFactory.generateFileUploadExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, "png", course);
    ProgrammingExercise programmingExercise = ModelFactory.generateProgrammingExercise(pastTimestamp, futureTimestamp, course);
    QuizExercise quizExercise = ModelFactory.generateQuizExercise(pastTimestamp, futureTimestamp, course);
    // Set assessment due dates
    if (hasAssessmentDueDatePassed) {
        modelingExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
        textExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
        fileUploadExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
        programmingExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
        quizExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
    } else {
        modelingExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
        textExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
        fileUploadExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
        programmingExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
        quizExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
    }
    // Add exercises to course
    course.addExercises(modelingExercise);
    course.addExercises(textExercise);
    course.addExercises(fileUploadExercise);
    course.addExercises(programmingExercise);
    course.addExercises(quizExercise);
    // Save course and exercises to database
    Course courseSaved = courseRepo.save(course);
    modelingExercise = exerciseRepo.save(modelingExercise);
    textExercise = exerciseRepo.save(textExercise);
    fileUploadExercise = exerciseRepo.save(fileUploadExercise);
    programmingExercise = exerciseRepo.save(programmingExercise);
    quizExercise = exerciseRepo.save(quizExercise);
    // Get user and setup participations
    User user = (userRepo.findOneByLogin("student1")).get();
    StudentParticipation participationModeling = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, modelingExercise, user);
    StudentParticipation participationText = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, textExercise, user);
    StudentParticipation participationFileUpload = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, fileUploadExercise, user);
    StudentParticipation participationQuiz = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, quizExercise, user);
    StudentParticipation participationProgramming = ModelFactory.generateStudentParticipation(InitializationState.INITIALIZED, programmingExercise, user);
    // Save participations
    participationModeling = studentParticipationRepo.save(participationModeling);
    participationText = studentParticipationRepo.save(participationText);
    participationFileUpload = studentParticipationRepo.save(participationFileUpload);
    participationQuiz = studentParticipationRepo.save(participationQuiz);
    participationProgramming = studentParticipationRepo.save(participationProgramming);
    // Setup results
    Result resultModeling = ModelFactory.generateResult(true, 10D);
    resultModeling.setAssessmentType(AssessmentType.MANUAL);
    resultModeling.setCompletionDate(ZonedDateTime.now());
    Result resultText = ModelFactory.generateResult(true, 12D);
    resultText.setAssessmentType(AssessmentType.MANUAL);
    resultText.setCompletionDate(ZonedDateTime.now());
    Result resultFileUpload = ModelFactory.generateResult(true, 0D);
    resultFileUpload.setAssessmentType(AssessmentType.MANUAL);
    resultFileUpload.setCompletionDate(ZonedDateTime.now());
    Result resultQuiz = ModelFactory.generateResult(true, 0D);
    resultQuiz.setAssessmentType(AssessmentType.AUTOMATIC);
    resultQuiz.setCompletionDate(ZonedDateTime.now());
    Result resultProgramming = ModelFactory.generateResult(true, 20D);
    resultProgramming.setAssessmentType(AssessmentType.AUTOMATIC);
    resultProgramming.setCompletionDate(ZonedDateTime.now());
    // Connect participations to results and vice versa
    resultModeling.setParticipation(participationModeling);
    resultText.setParticipation(participationText);
    resultFileUpload.setParticipation(participationFileUpload);
    resultQuiz.setParticipation(participationQuiz);
    resultProgramming.setParticipation(participationProgramming);
    participationModeling.addResult(resultModeling);
    participationText.addResult(resultText);
    participationFileUpload.addResult(resultFileUpload);
    participationQuiz.addResult(resultQuiz);
    participationProgramming.addResult(resultProgramming);
    // Save results and participations
    resultModeling = resultRepo.save(resultModeling);
    resultText = resultRepo.save(resultText);
    resultFileUpload = resultRepo.save(resultFileUpload);
    resultQuiz = resultRepo.save(resultQuiz);
    resultProgramming = resultRepo.save(resultProgramming);
    participationModeling = studentParticipationRepo.save(participationModeling);
    participationText = studentParticipationRepo.save(participationText);
    participationFileUpload = studentParticipationRepo.save(participationFileUpload);
    participationQuiz = studentParticipationRepo.save(participationQuiz);
    participationProgramming = studentParticipationRepo.save(participationProgramming);
    // Connect exercises with participations
    modelingExercise.addParticipation(participationModeling);
    textExercise.addParticipation(participationText);
    fileUploadExercise.addParticipation(participationFileUpload);
    quizExercise.addParticipation(participationQuiz);
    programmingExercise.addParticipation(participationProgramming);
    // Setup submissions and connect with participations
    ModelingSubmission modelingSubmission = ModelFactory.generateModelingSubmission("model1", true);
    TextSubmission textSubmission = ModelFactory.generateTextSubmission("text of text submission", Language.ENGLISH, true);
    FileUploadSubmission fileUploadSubmission = ModelFactory.generateFileUploadSubmission(true);
    QuizSubmission quizSubmission = ModelFactory.generateQuizSubmission(true);
    ProgrammingSubmission programmingSubmission = ModelFactory.generateProgrammingSubmission(true);
    // Save submissions
    modelingSubmission = submissionRepository.save(modelingSubmission);
    textSubmission = submissionRepository.save(textSubmission);
    fileUploadSubmission = submissionRepository.save(fileUploadSubmission);
    quizSubmission = submissionRepository.save(quizSubmission);
    programmingSubmission = submissionRepository.save(programmingSubmission);
    modelingSubmission.setParticipation(participationModeling);
    modelingSubmission.addResult(resultModeling);
    textSubmission.setParticipation(participationText);
    textSubmission.addResult(resultText);
    fileUploadSubmission.setParticipation(participationFileUpload);
    fileUploadSubmission.addResult(resultFileUpload);
    quizSubmission.setParticipation(participationQuiz);
    quizSubmission.addResult(resultQuiz);
    programmingSubmission.setParticipation(participationProgramming);
    programmingSubmission.addResult(resultProgramming);
    // Save submissions
    modelingSubmission = submissionRepository.save(modelingSubmission);
    textSubmission = submissionRepository.save(textSubmission);
    fileUploadSubmission = submissionRepository.save(fileUploadSubmission);
    quizSubmission = submissionRepository.save(quizSubmission);
    programmingSubmission = submissionRepository.save(programmingSubmission);
    // Save exercises
    exerciseRepo.save(modelingExercise);
    exerciseRepo.save(textExercise);
    exerciseRepo.save(fileUploadExercise);
    exerciseRepo.save(programmingExercise);
    exerciseRepo.save(quizExercise);
    // Connect participations with submissions
    participationModeling.setSubmissions(Set.of(modelingSubmission));
    participationText.setSubmissions(Set.of(textSubmission));
    participationFileUpload.setSubmissions(Set.of(fileUploadSubmission));
    participationQuiz.setSubmissions(Set.of(quizSubmission));
    participationProgramming.setSubmissions(Set.of(programmingSubmission));
    // Save participations
    studentParticipationRepo.save(participationModeling);
    studentParticipationRepo.save(participationText);
    studentParticipationRepo.save(participationFileUpload);
    studentParticipationRepo.save(participationQuiz);
    studentParticipationRepo.save(participationProgramming);
    return courseSaved;
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)

Example 20 with TextExercise

use of de.tum.in.www1.artemis.domain.TextExercise in project Artemis by ls1intum.

the class DatabaseUtilService method addCourseInOtherInstructionGroupAndExercise.

/**
 * @param title The title reflect the genre of exercise that will be added to the course
 */
public void addCourseInOtherInstructionGroupAndExercise(String title) {
    Course course = ModelFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "other-instructors");
    if ("Programming".equals(title)) {
        course = courseRepo.save(course);
        var programmingExercise = (ProgrammingExercise) new ProgrammingExercise().course(course);
        populateProgrammingExercise(programmingExercise, "TSTEXC", "Programming", false);
        programmingExercise.setPresentationScoreEnabled(course.getPresentationScore() != 0);
        programmingExercise = programmingExerciseRepository.save(programmingExercise);
        course.addExercises(programmingExercise);
        programmingExercise = addSolutionParticipationForProgrammingExercise(programmingExercise);
        programmingExercise = addTemplateParticipationForProgrammingExercise(programmingExercise);
        assertThat(programmingExercise.getPresentationScoreEnabled()).as("presentation score is enabled").isTrue();
    } else if ("Text".equals(title)) {
        TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, course);
        textExercise.setTitle("Text");
        course.addExercises(textExercise);
        courseRepo.save(course);
        exerciseRepo.save(textExercise);
    } else if ("ClassDiagram".equals(title)) {
        ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, DiagramType.ClassDiagram, course);
        modelingExercise.setTitle("ClassDiagram");
        course.addExercises(modelingExercise);
        courseRepo.save(course);
        exerciseRepo.save(modelingExercise);
    }
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise)

Aggregations

WithMockUser (org.springframework.security.test.context.support.WithMockUser)109 Test (org.junit.jupiter.api.Test)105 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)58 TextExercise (de.tum.in.www1.artemis.domain.TextExercise)51 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)50 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)44 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)41 Course (de.tum.in.www1.artemis.domain.Course)31 Exam (de.tum.in.www1.artemis.domain.exam.Exam)30 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)30 BeforeEach (org.junit.jupiter.api.BeforeEach)26 TextSubmissionElement (de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement)25 PlagiarismComparison (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison)23 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)22 PlagiarismSubmission (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission)22 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)22 Participation (de.tum.in.www1.artemis.domain.participation.Participation)16 TextAssessmentDTO (de.tum.in.www1.artemis.web.rest.dto.TextAssessmentDTO)16 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14