Skip to content

Commit

Permalink
fixed architecture tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonEntholzer committed Jan 3, 2025
1 parent 0997b6a commit 4cea0f9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
import de.tum.cit.aet.artemis.communication.domain.Post;
import de.tum.cit.aet.artemis.communication.domain.conversation.Channel;
import de.tum.cit.aet.artemis.communication.domain.notification.Notification;
import de.tum.cit.aet.artemis.communication.repository.NotificationRepository;
import de.tum.cit.aet.artemis.communication.repository.NotificationSettingRepository;
import de.tum.cit.aet.artemis.communication.service.notifications.GroupNotificationScheduleService;
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.core.domain.User;
import de.tum.cit.aet.artemis.core.test_repository.NotificationTestRepository;
import de.tum.cit.aet.artemis.core.test_repository.UserTestRepository;
import de.tum.cit.aet.artemis.core.user.util.UserUtilService;
import de.tum.cit.aet.artemis.core.util.CourseUtilService;
Expand All @@ -76,7 +76,7 @@ class GroupNotificationServiceTest extends AbstractSpringIntegrationIndependentT
private static final String TEST_PREFIX = "groupnotificationservice";

@Autowired
private NotificationRepository notificationRepository;
private NotificationTestRepository notificationTestRepository;

@Autowired
private NotificationSettingRepository notificationSettingRepository;
Expand Down Expand Up @@ -231,12 +231,12 @@ void setUp() {
userUtilService.changeUser(TEST_PREFIX + "instructor1");

// store the current notification count to let tests work even if notifications are created in other tests
notificationCountBeforeTest = notificationRepository.findAll().size();
notificationCountBeforeTest = notificationTestRepository.findAll().size();
}

@AfterEach
void tearDown() {
notificationRepository.deleteAllInBatch();
notificationTestRepository.deleteAllInBatch();
}

/**
Expand All @@ -262,10 +262,10 @@ private Notification verifyRepositoryCallWithCorrectNotificationAndReturnNotific
*/
private Notification verifyRepositoryCallWithCorrectNotificationAndReturnNotificationAtIndex(int numberOfGroupsAndCalls, String expectedNotificationTitle, int index) {
await().untilAsserted(
() -> assertThat(notificationRepository.findAll()).as("The number of created notifications should be the same as the number of notified groups/authorities")
() -> assertThat(notificationTestRepository.findAll()).as("The number of created notifications should be the same as the number of notified groups/authorities")
.hasSize(numberOfGroupsAndCalls + notificationCountBeforeTest));

List<Notification> capturedNotifications = notificationRepository.findAll();
List<Notification> capturedNotifications = notificationTestRepository.findAll();
Notification lastCapturedNotification = capturedNotifications.get(capturedNotifications.size() - 1);
assertThat(lastCapturedNotification.getTitle()).as("The title of the captured notification should be equal to the expected one").isEqualTo(expectedNotificationTitle);

Expand Down Expand Up @@ -440,10 +440,10 @@ private void verifyPush(Notification notification, Set<User> users, Object notif
*/
@Test
void testNotifyStudentGroupAboutAttachmentChange_futureReleaseDate() {
var countBefore = notificationRepository.count();
var countBefore = notificationTestRepository.count();
attachment.setReleaseDate(FUTURE_TIME);
groupNotificationService.notifyStudentGroupAboutAttachmentChange(attachment, NOTIFICATION_TEXT);
var countAfter = notificationRepository.count();
var countAfter = notificationTestRepository.count();
assertThat(countAfter).as("No notification should be created/saved").isEqualTo(countBefore);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
import de.tum.cit.aet.artemis.communication.domain.notification.NotificationConstants;
import de.tum.cit.aet.artemis.communication.domain.notification.SingleUserNotification;
import de.tum.cit.aet.artemis.communication.notification.util.NotificationFactory;
import de.tum.cit.aet.artemis.communication.repository.NotificationRepository;
import de.tum.cit.aet.artemis.communication.repository.NotificationSettingRepository;
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.core.domain.User;
import de.tum.cit.aet.artemis.core.test_repository.NotificationTestRepository;
import de.tum.cit.aet.artemis.shared.base.AbstractSpringIntegrationIndependentTest;
import de.tum.cit.aet.artemis.text.util.TextExerciseUtilService;

class NotificationResourceIntegrationTest extends AbstractSpringIntegrationIndependentTest {

@Autowired
private NotificationRepository notificationRepository;
private NotificationTestRepository notificationTestRepository;

@Autowired
private NotificationSettingRepository notificationSettingRepository;
Expand All @@ -49,7 +49,7 @@ void initTestCase() {
userUtilService.addUsers(TEST_PREFIX, 2, 1, 1, 1);
course1 = textExerciseUtilService.addCourseWithOneReleasedTextExercise();
course2 = textExerciseUtilService.addCourseWithOneReleasedTextExercise();
notificationRepository.deleteAll();
notificationTestRepository.deleteAll();

User student1 = userUtilService.getUserByLogin(TEST_PREFIX + "student1");
student1.setLastNotificationRead(ZonedDateTime.now().minusDays(1));
Expand All @@ -58,17 +58,17 @@ void initTestCase() {

@AfterEach
void tearDown() {
notificationRepository.deleteAll();
notificationTestRepository.deleteAll();
}

@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void testGetNotifications_recipientEvaluation() throws Exception {
User recipient = userTestRepository.getUser();
SingleUserNotification notification1 = NotificationFactory.generateSingleUserNotification(ZonedDateTime.now(), recipient);
notificationRepository.save(notification1);
notificationTestRepository.save(notification1);
SingleUserNotification notification2 = NotificationFactory.generateSingleUserNotification(ZonedDateTime.now(), userUtilService.getUserByLogin(TEST_PREFIX + "student2"));
notificationRepository.save(notification2);
notificationTestRepository.save(notification2);

List<Notification> notifications = request.getList("/api/notifications", HttpStatus.OK, Notification.class);
assertThat(notifications).as("Notification with recipient equal to current user is returned").contains(notification1);
Expand All @@ -81,11 +81,11 @@ void testGetNotifications_courseEvaluation() throws Exception {
// student1 is member of `testgroup` and `tumuser` per default
// the studentGroupName of course1 is `tumuser` per default
GroupNotification notification1 = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.STUDENT);
notificationRepository.save(notification1);
notificationTestRepository.save(notification1);
course2.setStudentGroupName("some-group");
courseRepository.save(course2);
GroupNotification notification2 = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course2, GroupNotificationType.STUDENT);
notificationRepository.save(notification2);
notificationTestRepository.save(notification2);

List<Notification> notifications = request.getList("/api/notifications", HttpStatus.OK, Notification.class);
assertThat(notifications).as("Notification with course the current user belongs to is returned").contains(notification1);
Expand All @@ -96,13 +96,13 @@ void testGetNotifications_courseEvaluation() throws Exception {
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void testGetNotifications_groupNotificationTypeEvaluation_asStudent() throws Exception {
GroupNotification notificationStudent = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.STUDENT);
notificationRepository.save(notificationStudent);
notificationTestRepository.save(notificationStudent);
GroupNotification notificationTutor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.TA);
notificationRepository.save(notificationTutor);
notificationTestRepository.save(notificationTutor);
GroupNotification notificationEditor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.EDITOR);
notificationRepository.save(notificationEditor);
notificationTestRepository.save(notificationEditor);
GroupNotification notificationInstructor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.INSTRUCTOR);
notificationRepository.save(notificationInstructor);
notificationTestRepository.save(notificationInstructor);

List<Notification> notifications = request.getList("/api/notifications", HttpStatus.OK, Notification.class);
assertThat(notifications).as("Notification with type student is returned").contains(notificationStudent);
Expand All @@ -115,13 +115,13 @@ void testGetNotifications_groupNotificationTypeEvaluation_asStudent() throws Exc
@WithMockUser(username = TEST_PREFIX + "tutor1", roles = "TA")
void testGetNotifications_groupNotificationTypeEvaluation_asTutor() throws Exception {
GroupNotification notificationStudent = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.STUDENT);
notificationRepository.save(notificationStudent);
notificationTestRepository.save(notificationStudent);
GroupNotification notificationTutor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.TA);
notificationRepository.save(notificationTutor);
notificationTestRepository.save(notificationTutor);
GroupNotification notificationEditor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.EDITOR);
notificationRepository.save(notificationEditor);
notificationTestRepository.save(notificationEditor);
GroupNotification notificationInstructor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.INSTRUCTOR);
notificationRepository.save(notificationInstructor);
notificationTestRepository.save(notificationInstructor);

List<Notification> notifications = request.getList("/api/notifications", HttpStatus.OK, Notification.class);
assertThat(notifications).as("Notification with type student is not returned").doesNotContain(notificationStudent);
Expand All @@ -134,13 +134,13 @@ void testGetNotifications_groupNotificationTypeEvaluation_asTutor() throws Excep
@WithMockUser(username = TEST_PREFIX + "editor1", roles = "EDITOR")
void testGetNotifications_groupNotificationTypeEvaluation_asEditor() throws Exception {
GroupNotification notificationStudent = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.STUDENT);
notificationRepository.save(notificationStudent);
notificationTestRepository.save(notificationStudent);
GroupNotification notificationTutor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.TA);
notificationRepository.save(notificationTutor);
notificationTestRepository.save(notificationTutor);
GroupNotification notificationEditor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.EDITOR);
notificationRepository.save(notificationEditor);
notificationTestRepository.save(notificationEditor);
GroupNotification notificationInstructor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.INSTRUCTOR);
notificationRepository.save(notificationInstructor);
notificationTestRepository.save(notificationInstructor);

List<Notification> notifications = request.getList("/api/notifications", HttpStatus.OK, Notification.class);
assertThat(notifications).as("Notification with type student is not returned").doesNotContain(notificationStudent);
Expand All @@ -153,13 +153,13 @@ void testGetNotifications_groupNotificationTypeEvaluation_asEditor() throws Exce
@WithMockUser(username = TEST_PREFIX + "instructor1", roles = "INSTRUCTOR")
void testGetNotifications_groupNotificationTypeEvaluation_asInstructor() throws Exception {
GroupNotification notificationStudent = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.STUDENT);
notificationRepository.save(notificationStudent);
notificationTestRepository.save(notificationStudent);
GroupNotification notificationTutor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.TA);
notificationRepository.save(notificationTutor);
notificationTestRepository.save(notificationTutor);
GroupNotification notificationEditor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.EDITOR);
notificationRepository.save(notificationEditor);
notificationTestRepository.save(notificationEditor);
GroupNotification notificationInstructor = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.INSTRUCTOR);
notificationRepository.save(notificationInstructor);
notificationTestRepository.save(notificationInstructor);

List<Notification> notifications = request.getList("/api/notifications", HttpStatus.OK, Notification.class);
assertThat(notifications).as("Notification with type student is not returned").doesNotContain(notificationStudent);
Expand All @@ -184,11 +184,11 @@ void testGetAllNotificationsForCurrentUserFilteredBySettings() throws Exception

GroupNotification allowedNotification = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.STUDENT);
allowedNotification.setTitle(NotificationConstants.findCorrespondingNotificationTitle(allowedType));
notificationRepository.save(allowedNotification);
notificationTestRepository.save(allowedNotification);

GroupNotification blockedNotification = NotificationFactory.generateGroupNotification(ZonedDateTime.now(), course1, GroupNotificationType.STUDENT);
blockedNotification.setTitle(NotificationConstants.findCorrespondingNotificationTitle(blockedType));
notificationRepository.save(blockedNotification);
notificationTestRepository.save(blockedNotification);

List<Notification> notifications = request.getList("/api/notifications", HttpStatus.OK, Notification.class);

Expand All @@ -207,10 +207,10 @@ void testGetAllNotificationsForCurrentUser_hideUntilDeactivated() throws Excepti
userTestRepository.save(student1);

GroupNotification futureNotification = NotificationFactory.generateGroupNotification(timeNow.plusHours(1), course1, GroupNotificationType.STUDENT);
notificationRepository.save(futureNotification);
notificationTestRepository.save(futureNotification);

GroupNotification pastNotification = NotificationFactory.generateGroupNotification(timeNow.minusHours(1), course1, GroupNotificationType.STUDENT);
notificationRepository.save(pastNotification);
notificationTestRepository.save(pastNotification);

List<Notification> notifications = request.getList("/api/notifications", HttpStatus.OK, Notification.class);

Expand All @@ -228,10 +228,10 @@ void testGetAllNotificationsForCurrentUser_hideUntilActivated() throws Exception
userTestRepository.save(student1);

GroupNotification futureNotification = NotificationFactory.generateGroupNotification(timeNow.plusHours(1), course1, GroupNotificationType.STUDENT);
notificationRepository.save(futureNotification);
notificationTestRepository.save(futureNotification);

GroupNotification pastNotification = NotificationFactory.generateGroupNotification(timeNow.minusHours(1), course1, GroupNotificationType.STUDENT);
notificationRepository.save(pastNotification);
notificationTestRepository.save(pastNotification);

List<Notification> notifications = request.getList("/api/notifications", HttpStatus.OK, Notification.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import de.tum.cit.aet.artemis.assessment.domain.Result;
import de.tum.cit.aet.artemis.assessment.test_repository.ResultTestRepository;
import de.tum.cit.aet.artemis.communication.domain.NotificationSetting;
import de.tum.cit.aet.artemis.communication.repository.NotificationRepository;
import de.tum.cit.aet.artemis.communication.repository.NotificationSettingRepository;
import de.tum.cit.aet.artemis.core.domain.Course;
import de.tum.cit.aet.artemis.core.domain.User;
import de.tum.cit.aet.artemis.core.service.messaging.InstanceMessageReceiveService;
import de.tum.cit.aet.artemis.core.test_repository.NotificationTestRepository;
import de.tum.cit.aet.artemis.core.user.util.UserUtilService;
import de.tum.cit.aet.artemis.core.util.CourseUtilService;
import de.tum.cit.aet.artemis.exercise.domain.Exercise;
Expand All @@ -43,7 +43,7 @@ class NotificationScheduleServiceTest extends AbstractSpringIntegrationLocalCILo
private InstanceMessageReceiveService instanceMessageReceiveService;

@Autowired
private NotificationRepository notificationRepository;
private NotificationTestRepository notificationTestRepository;

@Autowired
private NotificationSettingRepository notificationSettingRepository;
Expand Down Expand Up @@ -80,7 +80,7 @@ void init() {
exercise.setMaxPoints(5.0);
exerciseRepository.saveAndFlush(exercise);

sizeBefore = notificationRepository.count();
sizeBefore = notificationTestRepository.count();
}

@Test
Expand All @@ -91,7 +91,7 @@ void shouldCreateNotificationAndEmailAtReleaseDate() {
exerciseRepository.saveAndFlush(exercise);

instanceMessageReceiveService.processScheduleExerciseReleasedNotification(exercise.getId());
await().until(() -> notificationRepository.count() > sizeBefore);
await().until(() -> notificationTestRepository.count() > sizeBefore);
verify(groupNotificationService, timeout(TIMEOUT_MS)).notifyAllGroupsAboutReleasedExercise(exercise);
verify(mailService, timeout(TIMEOUT_MS).atLeastOnce()).sendNotification(any(), anySet(), any());
}
Expand All @@ -114,7 +114,7 @@ void shouldCreateNotificationAndEmailAtAssessmentDueDate() {
exerciseRepository.saveAndFlush(exercise);
instanceMessageReceiveService.processScheduleAssessedExerciseSubmittedNotification(exercise.getId());

await().until(() -> notificationRepository.count() > sizeBefore);
await().until(() -> notificationTestRepository.count() > sizeBefore);
verify(singleUserNotificationService, timeout(TIMEOUT_MS)).notifyUsersAboutAssessedExerciseSubmission(exercise);
verify(javaMailSender, timeout(TIMEOUT_MS)).send(any(MimeMessage.class));
}
Expand Down
Loading

0 comments on commit 4cea0f9

Please sign in to comment.