Skip to content

Commit

Permalink
Use competencyProgressApi in spy-verification (in non-atlas tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
ole-ve committed Oct 15, 2024
1 parent bf2dd86 commit 755f3be
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.tum.cit.aet.artemis.fileupload;

import static de.tum.cit.aet.artemis.core.util.TestResourceUtils.HalfSecond;
import static java.time.ZonedDateTime.now;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -332,7 +331,7 @@ void testDeleteFileUploadExerciseWithCompetency() throws Exception {
fileUploadExercise = fileUploadExerciseRepository.save(fileUploadExercise);
request.delete("/api/file-upload-exercises/" + fileUploadExercise.getId(), HttpStatus.OK);

verify(competencyProgressService).updateProgressByCompetencyAsync(eq(competency));
verify(competencyProgressApi).updateProgressByCompetencyAsync(eq(competency));
}

@Test
Expand Down Expand Up @@ -391,7 +390,7 @@ void updateFileUploadExercise_asInstructor() throws Exception {
assertThat(receivedFileUploadExercise.getCourseViaExerciseGroupOrCourseMember().getId()).as("courseId was not updated").isEqualTo(course.getId());
verify(examLiveEventsService, never()).createAndSendProblemStatementUpdateEvent(any(), any(), any());
verify(groupNotificationScheduleService, times(1)).checkAndCreateAppropriateNotificationsWhenUpdatingExercise(any(), any(), any());
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(fileUploadExercise), eq(Optional.of(fileUploadExercise)));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(fileUploadExercise), eq(Optional.of(fileUploadExercise)));
}

@Test
Expand Down Expand Up @@ -691,7 +690,7 @@ void testImportFileUploadExerciseFromCourseToCourseAsEditorSuccess() throws Exce
Channel channelFromDB = channelRepository.findChannelByExerciseId(importedFileUploadExercise.getId());
assertThat(channelFromDB).isNotNull();
assertThat(channelFromDB.getName()).isEqualTo(uniqueChannelName);
verify(competencyProgressService).updateProgressByLearningObjectAsync(eq(importedFileUploadExercise));
verify(competencyProgressApi).updateProgressByLearningObjectAsync(eq(importedFileUploadExercise));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ void createAttachmentUnit_asInstructor_shouldCreateAttachmentUnit() throws Excep
await().untilAsserted(() -> assertThat(slideRepository.findAllByAttachmentUnitId(persistedAttachmentUnit.getId())).hasSize(SLIDE_COUNT));
assertThat(updatedAttachmentUnit.getAttachment()).isEqualTo(persistedAttachment);
assertThat(updatedAttachmentUnit.getAttachment().getName()).isEqualTo("LoremIpsum");
verify(competencyProgressService).updateProgressByLearningObjectAsync(eq(updatedAttachmentUnit));
verify(competencyProgressApi).updateProgressByLearningObjectAsync(eq(updatedAttachmentUnit));
}

@Test
Expand Down Expand Up @@ -276,7 +276,7 @@ void updateAttachmentUnit_asInstructor_shouldUpdateAttachmentUnit() throws Excep
attachment = attachmentRepository.findById(attachment.getId()).orElseThrow();
assertThat(attachmentUnit2.getAttachment()).isEqualTo(attachment);
assertThat(attachment.getAttachmentUnit()).isEqualTo(attachmentUnit2);
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(attachmentUnit), eq(Optional.of(attachmentUnit)));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(attachmentUnit), eq(Optional.of(attachmentUnit)));
}

@Test
Expand Down Expand Up @@ -352,6 +352,6 @@ void deleteAttachmentUnit_withAttachment_shouldDeleteAttachment() throws Excepti
assertThat(slideRepository.findAllByAttachmentUnitId(persistedAttachmentUnit.getId())).hasSize(0);
request.delete("/api/lectures/" + lecture1.getId() + "/lecture-units/" + persistedAttachmentUnit.getId(), HttpStatus.OK);
request.get("/api/lectures/" + lecture1.getId() + "/attachment-units/" + persistedAttachmentUnit.getId(), HttpStatus.NOT_FOUND, AttachmentUnit.class);
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(persistedAttachmentUnit), eq(Optional.empty()));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(persistedAttachmentUnit), eq(Optional.empty()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void deleteExerciseUnit_exerciseConnectedWithExerciseUnit_shouldNOTDeleteExercis
request.get("/api/exercises/" + exercise.getId(), HttpStatus.OK, Exercise.class);
}

verify(competencyProgressService, never()).updateProgressForUpdatedLearningObjectAsync(any(), any());
verify(competencyProgressApi, never()).updateProgressForUpdatedLearningObjectAsync(any(), any());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void deleteLecture_lectureExists_shouldDeleteLecture() throws Exception {
assertThat(lectureOptional).isEmpty();

// ExerciseUnits do not have competencies, their exercises do
verify(competencyProgressService, timeout(1000).times(lecture1.getLectureUnits().size() - 1)).updateProgressForUpdatedLearningObjectAsync(any(), eq(Optional.empty()));
verify(competencyProgressApi, timeout(1000).times(lecture1.getLectureUnits().size() - 1)).updateProgressForUpdatedLearningObjectAsync(any(), eq(Optional.empty()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void createOnlineUnit_asInstructor_shouldCreateOnlineUnit() throws Exception {
onlineUnit.setSource("https://www.youtube.com/embed/8iU8LPEa4o0");
var persistedOnlineUnit = request.postWithResponseBody("/api/lectures/" + this.lecture1.getId() + "/online-units", onlineUnit, OnlineUnit.class, HttpStatus.CREATED);
assertThat(persistedOnlineUnit.getId()).isNotNull();
verify(competencyProgressService).updateProgressByLearningObjectAsync(eq(persistedOnlineUnit));
verify(competencyProgressApi).updateProgressByLearningObjectAsync(eq(persistedOnlineUnit));
}

@Test
Expand Down Expand Up @@ -147,7 +147,7 @@ void updateOnlineUnit_asInstructor_shouldUpdateOnlineUnit() throws Exception {
this.onlineUnit.setDescription("Changed");
this.onlineUnit = request.putWithResponseBody("/api/lectures/" + lecture1.getId() + "/online-units", this.onlineUnit, OnlineUnit.class, HttpStatus.OK);
assertThat(this.onlineUnit.getDescription()).isEqualTo("Changed");
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(onlineUnit), eq(Optional.of(onlineUnit)));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(onlineUnit), eq(Optional.of(onlineUnit)));
}

@Test
Expand Down Expand Up @@ -264,7 +264,7 @@ void deleteOnlineUnit_correctId_shouldDeleteOnlineUnit() throws Exception {
assertThat(this.onlineUnit.getId()).isNotNull();
request.delete("/api/lectures/" + lecture1.getId() + "/lecture-units/" + this.onlineUnit.getId(), HttpStatus.OK);
request.get("/api/lectures/" + lecture1.getId() + "/online-units/" + this.onlineUnit.getId(), HttpStatus.NOT_FOUND, OnlineUnit.class);
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(onlineUnit), eq(Optional.empty()));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(onlineUnit), eq(Optional.empty()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void createTextUnit_asEditor_shouldCreateTextUnitUnit() throws Exception {
var persistedTextUnit = request.postWithResponseBody("/api/lectures/" + this.lecture.getId() + "/text-units", textUnit, TextUnit.class, HttpStatus.CREATED);
assertThat(persistedTextUnit.getId()).isNotNull();
assertThat(persistedTextUnit.getName()).isEqualTo("LoremIpsum");
verify(competencyProgressService).updateProgressByLearningObjectAsync(eq(persistedTextUnit));
verify(competencyProgressApi).updateProgressByLearningObjectAsync(eq(persistedTextUnit));
}

@Test
Expand All @@ -112,7 +112,7 @@ void updateTextUnit_asEditor_shouldUpdateTextUnit() throws Exception {
textUnitFromRequest.setContent("Changed");
TextUnit updatedTextUnit = request.putWithResponseBody("/api/lectures/" + lecture.getId() + "/text-units", textUnitFromRequest, TextUnit.class, HttpStatus.OK);
assertThat(updatedTextUnit.getContent()).isEqualTo("Changed");
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(textUnit), eq(Optional.of(textUnit)));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(textUnit), eq(Optional.of(textUnit)));
}

@Test
Expand Down Expand Up @@ -161,7 +161,7 @@ void deleteTextUnit_correctId_shouldDeleteTextUnit() throws Exception {
assertThat(this.textUnit.getId()).isNotNull();
request.delete("/api/lectures/" + lecture.getId() + "/lecture-units/" + this.textUnit.getId(), HttpStatus.OK);
request.get("/api/lectures/" + lecture.getId() + "/text-units/" + this.textUnit.getId(), HttpStatus.NOT_FOUND, TextUnit.class);
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(textUnit), eq(Optional.empty()));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(textUnit), eq(Optional.empty()));
}

private void persistTextUnitWithLecture() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void createVideoUnit_asInstructor_shouldCreateVideoUnit() throws Exception {
videoUnit.setCompetencies(Set.of(competency));
var persistedVideoUnit = request.postWithResponseBody("/api/lectures/" + this.lecture1.getId() + "/video-units", videoUnit, VideoUnit.class, HttpStatus.CREATED);
assertThat(persistedVideoUnit.getId()).isNotNull();
verify(competencyProgressService).updateProgressByLearningObjectAsync(eq(persistedVideoUnit));
verify(competencyProgressApi).updateProgressByLearningObjectAsync(eq(persistedVideoUnit));
}

@Test
Expand Down Expand Up @@ -124,7 +124,7 @@ void updateVideoUnit_asInstructor_shouldUpdateVideoUnit() throws Exception {
this.videoUnit.setDescription("Changed");
this.videoUnit = request.putWithResponseBody("/api/lectures/" + lecture1.getId() + "/video-units", this.videoUnit, VideoUnit.class, HttpStatus.OK);
assertThat(this.videoUnit.getDescription()).isEqualTo("Changed");
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(videoUnit), eq(Optional.of(videoUnit)));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(videoUnit), eq(Optional.of(videoUnit)));
}

@Test
Expand Down Expand Up @@ -204,7 +204,7 @@ void deleteVideoUnit_correctId_shouldDeleteVideoUnit() throws Exception {
assertThat(this.videoUnit.getId()).isNotNull();
request.delete("/api/lectures/" + lecture1.getId() + "/lecture-units/" + this.videoUnit.getId(), HttpStatus.OK);
request.get("/api/lectures/" + lecture1.getId() + "/video-units/" + this.videoUnit.getId(), HttpStatus.NOT_FOUND, VideoUnit.class);
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(videoUnit), eq(Optional.empty()));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(videoUnit), eq(Optional.empty()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ void testUpdateModelingExercise_asInstructor() throws Exception {
assertThat(returnedModelingExercise.getGradingCriteria()).hasSameSizeAs(gradingCriteria);
verify(groupNotificationService).notifyStudentAndEditorAndInstructorGroupAboutExerciseUpdate(returnedModelingExercise, notificationText);
verify(examLiveEventsService, never()).createAndSendProblemStatementUpdateEvent(eq(returnedModelingExercise), eq(notificationText), any());
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(createdModelingExercise),
eq(Optional.of(createdModelingExercise)));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(createdModelingExercise), eq(Optional.of(createdModelingExercise)));
}

@Test
Expand Down Expand Up @@ -412,7 +411,7 @@ void testDeleteModelingExerciseWithCompetency() throws Exception {

request.delete("/api/modeling-exercises/" + classExercise.getId(), HttpStatus.OK);

verify(competencyProgressService).updateProgressByCompetencyAsync(eq(competency));
verify(competencyProgressApi).updateProgressByCompetencyAsync(eq(competency));
}

@Test
Expand Down Expand Up @@ -482,7 +481,7 @@ void importModelingExerciseFromCourseToCourse() throws Exception {
Channel channelFromDB = channelRepository.findChannelByExerciseId(importedExercise.getId());
assertThat(channelFromDB).isNotNull();
assertThat(channelFromDB.getName()).isEqualTo(uniqueChannelName);
verify(competencyProgressService).updateProgressByLearningObjectAsync(eq(importedExercise));
verify(competencyProgressApi).updateProgressByLearningObjectAsync(eq(importedExercise));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void testCreateProgrammingExercise() throws Exception {
localVCLocalCITestService.testLatestSubmission(createdExercise.getTemplateParticipation().getId(), null, 0, false);
localVCLocalCITestService.testLatestSubmission(createdExercise.getSolutionParticipation().getId(), null, 13, false);

verify(competencyProgressService).updateProgressByLearningObjectAsync(eq(createdExercise));
verify(competencyProgressApi).updateProgressByLearningObjectAsync(eq(createdExercise));
}

@Test
Expand All @@ -223,7 +223,7 @@ void testUpdateProgrammingExercise() throws Exception {
ProgrammingExercise updatedExercise = request.putWithResponseBody("/api/programming-exercises", programmingExercise, ProgrammingExercise.class, HttpStatus.OK);

assertThat(updatedExercise.getReleaseDate()).isEqualTo(programmingExercise.getReleaseDate());
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(programmingExercise), eq(Optional.of(programmingExercise)));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(programmingExercise), eq(Optional.of(programmingExercise)));
}

@Test
Expand Down Expand Up @@ -256,7 +256,7 @@ void testDeleteProgrammingExercise() throws Exception {
assertThat(solutionRepositoryUri.getLocalRepositoryPath(localVCBasePath)).doesNotExist();
LocalVCRepositoryUri testsRepositoryUri = new LocalVCRepositoryUri(programmingExercise.getTestRepositoryUri());
assertThat(testsRepositoryUri.getLocalRepositoryPath(localVCBasePath)).doesNotExist();
verify(competencyProgressService).updateProgressByCompetencyAsync(eq(competency));
verify(competencyProgressApi).updateProgressByCompetencyAsync(eq(competency));
}

@Test
Expand Down Expand Up @@ -306,7 +306,7 @@ void testImportProgrammingExercise() throws Exception {
.orElseThrow();
localVCLocalCITestService.testLatestSubmission(templateParticipation.getId(), null, 0, false);
localVCLocalCITestService.testLatestSubmission(solutionParticipation.getId(), null, 13, false);
verify(competencyProgressService).updateProgressByLearningObjectAsync(eq(importedExercise));
verify(competencyProgressApi).updateProgressByLearningObjectAsync(eq(importedExercise));
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import de.tum.cit.aet.artemis.assessment.service.ParticipantScoreScheduleService;
import de.tum.cit.aet.artemis.assessment.test_repository.ResultTestRepository;
import de.tum.cit.aet.artemis.atlas.api.CompetencyProgressApi;
import de.tum.cit.aet.artemis.atlas.service.competency.CompetencyProgressService;
import de.tum.cit.aet.artemis.communication.service.WebsocketMessagingService;
import de.tum.cit.aet.artemis.communication.service.notifications.ConversationNotificationService;
Expand Down Expand Up @@ -170,6 +171,9 @@ public abstract class AbstractArtemisIntegrationTest implements MockDelegate {
@SpyBean
protected CompetencyProgressService competencyProgressService;

@SpyBean
protected CompetencyProgressApi competencyProgressApi;

@Autowired
protected RequestUtilService request;

Expand Down Expand Up @@ -223,7 +227,8 @@ void stopRunningTasks() {
protected void resetSpyBeans() {
Mockito.reset(gitService, groupNotificationService, conversationNotificationService, tutorialGroupNotificationService, singleUserNotificationService,
websocketMessagingService, examAccessService, mailService, instanceMessageSendService, programmingExerciseScheduleService, programmingExerciseParticipationService,
uriService, scheduleService, participantScoreScheduleService, javaMailSender, programmingTriggerService, zipFileService, competencyProgressService);
uriService, scheduleService, participantScoreScheduleService, javaMailSender, programmingTriggerService, zipFileService, competencyProgressService,
competencyProgressApi);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void testDeleteTextExerciseWithCompetency() throws Exception {

request.delete("/api/text-exercises/" + textExercise.getId(), HttpStatus.OK);

verify(competencyProgressService).updateProgressByCompetencyAsync(eq(competency));
verify(competencyProgressApi).updateProgressByCompetencyAsync(eq(competency));
}

@Test
Expand Down Expand Up @@ -429,7 +429,7 @@ void updateTextExercise() throws Exception {
assertThat(updatedTextExercise.getCourseViaExerciseGroupOrCourseMember().getId()).as("courseId was not updated").isEqualTo(course.getId());
verify(examLiveEventsService, never()).createAndSendProblemStatementUpdateEvent(any(), any(), any());
verify(groupNotificationScheduleService, times(1)).checkAndCreateAppropriateNotificationsWhenUpdatingExercise(any(), any(), any());
verify(competencyProgressService, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(textExercise), eq(Optional.of(textExercise)));
verify(competencyProgressApi, timeout(1000).times(1)).updateProgressForUpdatedLearningObjectAsync(eq(textExercise), eq(Optional.of(textExercise)));
}

@Test
Expand Down Expand Up @@ -592,7 +592,7 @@ void importTextExerciseFromCourseToCourse() throws Exception {
var newTextExercise = request.postWithResponseBody("/api/text-exercises/import/" + textExercise.getId(), textExercise, TextExercise.class, HttpStatus.CREATED);
Channel channel = channelRepository.findChannelByExerciseId(newTextExercise.getId());
assertThat(channel).isNotNull();
verify(competencyProgressService).updateProgressByLearningObjectAsync(eq(newTextExercise));
verify(competencyProgressApi).updateProgressByLearningObjectAsync(eq(newTextExercise));
}

@Test
Expand Down

0 comments on commit 755f3be

Please sign in to comment.