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);
}
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);
}
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());
}
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);
}
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);
}
Aggregations