Search in sources :

Example 86 with ModelingExercise

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

the class ExampleSubmissionIntegrationTest method importExampleSubmissionWithModelingSubmission_exerciseIdNotMatched.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void importExampleSubmissionWithModelingSubmission_exerciseIdNotMatched() throws Exception {
    Submission submission = ModelFactory.generateModelingSubmission(validModel, true);
    submission = database.addModelingSubmission(modelingExercise, (ModelingSubmission) submission, "student1");
    Exercise modelingExerciseToBeConflicted = new ModelingExercise();
    modelingExerciseToBeConflicted.setCourse(course);
    Exercise exercise = exerciseRepository.save(modelingExerciseToBeConflicted);
    importExampleSubmission(exercise.getId(), submission.getId(), HttpStatus.BAD_REQUEST);
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 87 with ModelingExercise

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

the class AssessmentKnowledgeIntegrationTest method testKeepModelAssessmentKnowledgeWhenExerciseIsDeletedIfOtherExercisesUseIt.

/**
 * Tests that ModelAssessmentKnowledge is not removed from the DB even after deleting
 * the parent exercise if there are other exercises using it
 *
 * @throws Exception might be thrown from Network Call to Artemis API
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testKeepModelAssessmentKnowledgeWhenExerciseIsDeletedIfOtherExercisesUseIt() throws Exception {
    final Course course = database.addCourseWithOneReleasedModelExerciseWithKnowledge();
    ModelingExercise modelingExercise = modelingExerciseRepository.findByCourseIdWithCategories(course.getId()).get(0);
    request.postWithResponseBody("/api/modeling-exercises/import/" + modelingExercise.getId(), modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    int exerciseCount = modelingExerciseRepository.findAll().size();
    int modelAssessmentKnowledgeCount = modelAssessmentKnowledgeRepository.findAll().size();
    request.delete("/api/modeling-exercises/" + modelingExercise.getId(), HttpStatus.OK);
    assertThat(modelingExerciseRepository.findAll()).hasSize(exerciseCount - 1);
    assertThat(modelAssessmentKnowledgeRepository.findAll()).hasSize(modelAssessmentKnowledgeCount);
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) Course(de.tum.in.www1.artemis.domain.Course) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 88 with ModelingExercise

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

the class AssessmentKnowledgeIntegrationTest method testSetModelAssessmentKnowledgeToModelElements.

/**
 * Tests that a ModelAssessmentKnowledge is correctly set to model elements
 * based on the ModelAssessmentKnowledge of the respective exercise
 *
 * @throws Exception might be thrown from Network Call to Artemis API
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testSetModelAssessmentKnowledgeToModelElements() throws Exception {
    ModelingSubmission submission1 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.json"), true);
    submission1.setId(1L);
    ModelingSubmission submission2 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.cpy.json"), true);
    submission2.setId(2L);
    ModelingSubmission submission3 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.cpy.json"), true);
    submission3.setId(3L);
    ModelingSubmission submission4 = ModelFactory.generateModelingSubmission(FileUtils.loadFileFromResources("test-data/model-submission/model.54727.cpy.json"), true);
    submission4.setId(4L);
    Course course = database.addEmptyCourse();
    ModelingExercise exercise1 = modelingExerciseUtilService.createModelingExercise(course.getId());
    ModelingExercise exercise2 = modelingExerciseUtilService.createModelingExercise(course.getId());
    modelAssessmentKnowledgeService = new ModelAssessmentKnowledgeService(modelAssessmentKnowledgeRepository, modelingExerciseRepository);
    exercise1.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
    exercise2.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
    ModelClusterFactory modelClusterFactory = new ModelClusterFactory();
    List<ModelCluster> modelClusters1 = modelClusterFactory.buildClusters(List.of(submission1, submission2), exercise1);
    List<ModelCluster> modelClusters2 = modelClusterFactory.buildClusters(List.of(submission3, submission4), exercise2);
    ModelCluster modelCluster = modelClusters1.get(0);
    for (ModelElement element : modelCluster.getModelElements()) {
        assertThat(element.getKnowledge().getId()).isEqualTo(exercise1.getKnowledge().getId());
    }
    modelCluster = modelClusters2.get(0);
    for (ModelElement element : modelCluster.getModelElements()) {
        assertThat(element.getKnowledge().getId()).isEqualTo(exercise2.getKnowledge().getId());
    }
    assertThat(exercise1.getKnowledge().getId()).isNotEqualTo(exercise2.getKnowledge().getId());
}
Also used : ModelClusterFactory(de.tum.in.www1.artemis.service.compass.controller.ModelClusterFactory) ModelElement(de.tum.in.www1.artemis.domain.modeling.ModelElement) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ModelAssessmentKnowledgeService(de.tum.in.www1.artemis.service.ModelAssessmentKnowledgeService) ModelCluster(de.tum.in.www1.artemis.domain.modeling.ModelCluster) Course(de.tum.in.www1.artemis.domain.Course) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 89 with ModelingExercise

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

the class AssessmentKnowledgeIntegrationTest method testCreateModelAssessmentKnowledgeIfExerciseIsCreatedFromScratch.

/**
 * Tests that a new ModelAssessmentKnowledge is created when we create an exercise from scratch
 *
 * @throws Exception might be thrown from Network Call to Artemis API
 */
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testCreateModelAssessmentKnowledgeIfExerciseIsCreatedFromScratch() throws Exception {
    Course course = database.addEmptyCourse();
    ModelingExercise modelingExercise = modelingExerciseUtilService.createModelingExercise(course.getId());
    int count = modelAssessmentKnowledgeRepository.findAll().size();
    request.postWithResponseBody("/api/modeling-exercises", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
    assertThat(modelAssessmentKnowledgeRepository.findAll()).hasSize(count + 1);
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) Course(de.tum.in.www1.artemis.domain.Course) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 90 with ModelingExercise

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

the class ParticipationTeamWebsocketService method updateSubmission.

/**
 * Updates a modeling or text submission
 *
 * @param participationId id of participation
 * @param submission      updated modeling text submission
 * @param principal       principal of user who wants to update the submission
 * @param topicPath       path of websocket destination topic where to send the new submission
 */
private void updateSubmission(@DestinationVariable Long participationId, @Payload Submission submission, Principal principal, String topicPath) {
    // Without this, custom jpa repository methods don't work in websocket channel.
    SecurityUtils.setAuthorizationObject();
    final StudentParticipation participation = studentParticipationRepository.findByIdElseThrow(participationId);
    // user must belong to the team who owns the participation in order to update a submission
    if (!participation.isOwnedBy(principal.getName())) {
        return;
    }
    final User user = userRepository.getUserWithGroupsAndAuthorities(principal.getName());
    final Exercise exercise = exerciseRepository.findByIdElseThrow(participation.getExercise().getId());
    if (submission instanceof ModelingSubmission && exercise instanceof ModelingExercise) {
        submission = modelingSubmissionService.save((ModelingSubmission) submission, (ModelingExercise) exercise, principal.getName());
        modelingSubmissionService.hideDetails(submission, user);
    } else if (submission instanceof TextSubmission && exercise instanceof TextExercise) {
        submission = textSubmissionService.handleTextSubmission((TextSubmission) submission, (TextExercise) exercise, principal);
        textSubmissionService.hideDetails(submission, user);
    } else {
        throw new IllegalArgumentException("Submission type '" + submission.getType() + "' not allowed.");
    }
    // update the last action date for the user and send out list of team members
    updateValue(lastActionTracker, participationId, principal.getName());
    sendOnlineTeamStudents(participationId);
    SubmissionSyncPayload payload = new SubmissionSyncPayload(submission, user);
    messagingTemplate.convertAndSend(getDestination(participationId, topicPath), payload);
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) SubmissionSyncPayload(de.tum.in.www1.artemis.web.websocket.dto.SubmissionSyncPayload) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Aggregations

ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)196 WithMockUser (org.springframework.security.test.context.support.WithMockUser)132 Test (org.junit.jupiter.api.Test)126 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)96 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)72 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)28 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)26 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)20 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)16 BeforeEach (org.junit.jupiter.api.BeforeEach)16 Course (de.tum.in.www1.artemis.domain.Course)14 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)14 ZonedDateTime (java.time.ZonedDateTime)12 Exam (de.tum.in.www1.artemis.domain.exam.Exam)10 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)10 TeamAssignmentPayload (de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload)9 JsonParser.parseString (com.google.gson.JsonParser.parseString)8 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)8 ModelCluster (de.tum.in.www1.artemis.domain.modeling.ModelCluster)8