From 981e7a34e127d759fa28a3e9002a5d09db30edfd Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Tue, 30 Sep 2025 14:58:32 +0300 Subject: [PATCH 01/15] test: separate auth setup and user setUp --- .../hei/haapi/integration/conf/TestUtils.java | 81 ++++++++++--------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/test/java/school/hei/haapi/integration/conf/TestUtils.java b/src/test/java/school/hei/haapi/integration/conf/TestUtils.java index 9dbb97198c..bbe05d3d56 100644 --- a/src/test/java/school/hei/haapi/integration/conf/TestUtils.java +++ b/src/test/java/school/hei/haapi/integration/conf/TestUtils.java @@ -358,22 +358,26 @@ public static CasdoorUser getCasdoorUserSuspended() { public static void setUpCasdoor( CasdoorAuthService casdoorAuthService, CertificateLoader certificateLoader) { given(certificateLoader.getCertificate()).willReturn("mocked-certificate"); - when(casdoorAuthService.parseJwtToken(TEACHER1_TOKEN)).thenReturn(getCasdoorUserTeacher1()); - when(casdoorAuthService.parseJwtToken(MANAGER1_TOKEN)).thenReturn(getCasdoorUserManager1()); - when(casdoorAuthService.parseJwtToken(STUDENT1_TOKEN)).thenReturn(getCasdoorUserStudent1()); - when(casdoorAuthService.parseJwtToken(STUDENT2_TOKEN)).thenReturn(getCasdoorUserStudent2()); - when(casdoorAuthService.parseJwtToken(STUDENT8_TOKEN)).thenReturn(getCasdoorUserStudent8()); - when(casdoorAuthService.parseJwtToken(STUDENT11_TOKEN)).thenReturn(getCasdoorUserStudent11()); - when(casdoorAuthService.parseJwtToken(STUDENT12_TOKEN)).thenReturn(getCasdoorUserStudent12()); - when(casdoorAuthService.parseJwtToken(STUDENT13_TOKEN)).thenReturn(getCasdoorUserStudent13()); - when(casdoorAuthService.parseJwtToken(MONITOR1_TOKEN)).thenReturn(getCasdoorUserMonitor1()); - when(casdoorAuthService.parseJwtToken(MONITOR2_TOKEN)).thenReturn(getCasdoorUserMonitor2()); - when(casdoorAuthService.parseJwtToken(ORGANIZER1_TOKEN)).thenReturn(getCasdoorUserOrganizer1()); - when(casdoorAuthService.parseJwtToken(ORGANIZER2_TOKEN)).thenReturn(getCasdoorUserOrganizer2()); - when(casdoorAuthService.parseJwtToken(STAFF_MEMBER1_TOKEN)) - .thenReturn(getCasdoorUserStaffMember1()); - when(casdoorAuthService.parseJwtToken(ADMIN1_TOKEN)).thenReturn(getCasdoorUserAdmin1()); - when(casdoorAuthService.parseJwtToken(SUSPENDED_TOKEN)).thenReturn(getCasdoorUserSuspended()); + setUpCasdoorUser(casdoorAuthService, TEACHER1_TOKEN, getCasdoorUserTeacher1()); + setUpCasdoorUser(casdoorAuthService, MANAGER1_TOKEN, getCasdoorUserManager1()); + setUpCasdoorUser(casdoorAuthService, STUDENT1_TOKEN, getCasdoorUserStudent1()); + setUpCasdoorUser(casdoorAuthService, STUDENT2_TOKEN, getCasdoorUserStudent2()); + setUpCasdoorUser(casdoorAuthService, STUDENT8_TOKEN, getCasdoorUserStudent8()); + setUpCasdoorUser(casdoorAuthService, STUDENT11_TOKEN, getCasdoorUserStudent11()); + setUpCasdoorUser(casdoorAuthService, STUDENT12_TOKEN, getCasdoorUserStudent12()); + setUpCasdoorUser(casdoorAuthService, STUDENT13_TOKEN, getCasdoorUserStudent13()); + setUpCasdoorUser(casdoorAuthService, MONITOR1_TOKEN, getCasdoorUserMonitor1()); + setUpCasdoorUser(casdoorAuthService, MONITOR2_TOKEN, getCasdoorUserMonitor2()); + setUpCasdoorUser(casdoorAuthService, ORGANIZER1_TOKEN, getCasdoorUserOrganizer1()); + setUpCasdoorUser(casdoorAuthService, ORGANIZER2_TOKEN, getCasdoorUserOrganizer2()); + setUpCasdoorUser(casdoorAuthService, STAFF_MEMBER1_TOKEN, getCasdoorUserStaffMember1()); + setUpCasdoorUser(casdoorAuthService, ADMIN1_TOKEN, getCasdoorUserAdmin1()); + setUpCasdoorUser(casdoorAuthService, SUSPENDED_TOKEN, getCasdoorUserSuspended()); + } + + public static void setUpCasdoorUser( + CasdoorAuthService casdoorAuthService, String userToken, CasdoorUser user) { + when(casdoorAuthService.parseJwtToken(userToken)).thenReturn(user); } public static ApiClient anApiClient(String token, int serverPort) { @@ -388,30 +392,27 @@ public static ApiClient anApiClient(String token, int serverPort) { } public static void setUpCognito(CognitoComponent cognitoComponent) { - when(cognitoComponent.getEmailByIdToken(BAD_TOKEN)).thenReturn(null); - when(cognitoComponent.getEmailByIdToken(STUDENT1_TOKEN)).thenReturn("test+ryan@hei.school"); - when(cognitoComponent.getEmailByIdToken(STUDENT2_TOKEN)).thenReturn("test+student2@hei.school"); - when(cognitoComponent.getEmailByIdToken(STUDENT11_TOKEN)) - .thenReturn("test+student11@hei.school"); - when(cognitoComponent.getEmailByIdToken(STUDENT12_TOKEN)) - .thenReturn("test+student12@hei.school"); - when(cognitoComponent.getEmailByIdToken(STUDENT13_TOKEN)) - .thenReturn("test+student13@hei.school"); - when(cognitoComponent.getEmailByIdToken(MONITOR1_TOKEN)).thenReturn("test+monitor@hei.school"); - when(cognitoComponent.getEmailByIdToken(MONITOR2_TOKEN)).thenReturn("test+monitor2@hei.school"); - when(cognitoComponent.getEmailByIdToken(STUDENT8_TOKEN)) - .thenReturn("test+repeating2@hei" + ".school"); - when(cognitoComponent.getEmailByIdToken(TEACHER1_TOKEN)).thenReturn("test+teacher1@hei.school"); - when(cognitoComponent.getEmailByIdToken(MANAGER1_TOKEN)).thenReturn("test+manager1@hei.school"); - when(cognitoComponent.getEmailByIdToken(STAFF_MEMBER1_TOKEN)) - .thenReturn("test+staff@hei.school"); - when(cognitoComponent.getEmailByIdToken(ADMIN1_TOKEN)).thenReturn("test+admin@hei.school"); - when(cognitoComponent.getEmailByIdToken(ORGANIZER1_TOKEN)) - .thenReturn("test+organizer@hei.school"); - when(cognitoComponent.getEmailByIdToken(ORGANIZER2_TOKEN)) - .thenReturn("test+organizer+2@hei.school"); - when(cognitoComponent.getEmailByIdToken(SUSPENDED_TOKEN)) - .thenReturn("test+suspended@hei.school"); + setUpCognitoUser(cognitoComponent, BAD_TOKEN, null); + setUpCognitoUser(cognitoComponent, STUDENT1_TOKEN, "test+ryan@hei.school"); + setUpCognitoUser(cognitoComponent, STUDENT2_TOKEN, "test+student2@hei.school"); + setUpCognitoUser(cognitoComponent, STUDENT11_TOKEN, "test+student11@hei.school"); + setUpCognitoUser(cognitoComponent, STUDENT12_TOKEN, "test+student12@hei.school"); + setUpCognitoUser(cognitoComponent, STUDENT13_TOKEN, "test+student13@hei.school"); + setUpCognitoUser(cognitoComponent, MONITOR1_TOKEN, "test+monitor@hei.school"); + setUpCognitoUser(cognitoComponent, MONITOR2_TOKEN, "test+monitor2@hei.school"); + setUpCognitoUser(cognitoComponent, STUDENT8_TOKEN, "test+repeating2@hei" + ".school"); + setUpCognitoUser(cognitoComponent, TEACHER1_TOKEN, "test+teacher1@hei.school"); + setUpCognitoUser(cognitoComponent, MANAGER1_TOKEN, "test+manager1@hei.school"); + setUpCognitoUser(cognitoComponent, STAFF_MEMBER1_TOKEN, "test+staff@hei.school"); + setUpCognitoUser(cognitoComponent, ADMIN1_TOKEN, "test+admin@hei.school"); + setUpCognitoUser(cognitoComponent, ORGANIZER1_TOKEN, "test+organizer@hei.school"); + setUpCognitoUser(cognitoComponent, ORGANIZER2_TOKEN, "test+organizer+2@hei.school"); + setUpCognitoUser(cognitoComponent, SUSPENDED_TOKEN, "test+suspended@hei.school"); + } + + private static void setUpCognitoUser( + CognitoComponent cognitoComponent, String token, String email) { + when(cognitoComponent.getEmailByIdToken(token)).thenReturn(email); } public static void setUpS3Service(FileService fileService, Student user) { From 5cd649707978fce290a8b3986350ad9bbccfe479 Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Tue, 30 Sep 2025 15:40:49 +0300 Subject: [PATCH 02/15] test: refactor setUpCognito + setUpCasdoor -> setUpCognitoAndCasdoor --- .../rest/validator/CreateMpbsValidatorIT.java | 4 +- .../CreateStudentWorkFileValidatorIT.java | 4 +- .../school/hei/haapi/integration/AdminIT.java | 3 +- .../AdvancedFeeStatsServiceIT.java | 6 +- .../hei/haapi/integration/AnnouncementIT.java | 6 +- .../hei/haapi/integration/CommentIT.java | 3 +- .../haapi/integration/CourseAssignmentIT.java | 6 +- .../hei/haapi/integration/CourseIT.java | 6 +- .../school/hei/haapi/integration/EventIT.java | 6 +- .../school/hei/haapi/integration/ExamIT.java | 6 +- .../school/hei/haapi/integration/FeeIT.java | 6 +- .../hei/haapi/integration/FeeTemplateIT.java | 6 +- .../school/hei/haapi/integration/GradeIT.java | 6 +- .../hei/haapi/integration/GroupFlowIT.java | 6 +- .../school/hei/haapi/integration/GroupIT.java | 6 +- .../hei/haapi/integration/LetterIT.java | 6 +- .../hei/haapi/integration/ManagerIT.java | 6 +- .../hei/haapi/integration/MonitorIT.java | 6 +- .../integration/MonitoringStudentIT.java | 6 +- .../school/hei/haapi/integration/MpbsIT.java | 6 +- .../haapi/integration/MpbsVerificationIT.java | 6 +- .../hei/haapi/integration/OrganizerIT.java | 6 +- .../hei/haapi/integration/PaginationIT.java | 6 +- .../hei/haapi/integration/PaymentIT.java | 6 +- .../hei/haapi/integration/PromotionIT.java | 6 +- .../hei/haapi/integration/RetakeExamIT.java | 6 +- .../integration/RetakeExamSessionIT.java | 6 +- .../hei/haapi/integration/SchoolFileIT.java | 6 +- .../hei/haapi/integration/SecurityIT.java | 6 +- .../hei/haapi/integration/StaffMemberIT.java | 6 +- .../hei/haapi/integration/StudentIT.java | 6 +- .../hei/haapi/integration/TeacherIT.java | 6 +- .../hei/haapi/integration/UserFileIT.java | 6 +- .../hei/haapi/integration/WorkDocumentIT.java | 6 +- .../hei/haapi/integration/conf/TestUtils.java | 87 +++++++++++-------- .../haapi/service/DirtyEventServiceTest.java | 4 +- .../hei/haapi/service/PaymentServiceTest.java | 6 +- .../hei/haapi/service/UserServiceTest.java | 4 +- .../haapi/unit/CheckStudentsStatusTest.java | 6 +- .../hei/haapi/unit/utils/DateUtilsTest.java | 4 +- 40 files changed, 127 insertions(+), 178 deletions(-) diff --git a/src/test/java/school/hei/haapi/endpoint/rest/validator/CreateMpbsValidatorIT.java b/src/test/java/school/hei/haapi/endpoint/rest/validator/CreateMpbsValidatorIT.java index 66f935f99f..204a58cbc2 100644 --- a/src/test/java/school/hei/haapi/endpoint/rest/validator/CreateMpbsValidatorIT.java +++ b/src/test/java/school/hei/haapi/endpoint/rest/validator/CreateMpbsValidatorIT.java @@ -6,7 +6,7 @@ import static school.hei.haapi.endpoint.rest.model.MobileMoneyType.ORANGE_MONEY; import static school.hei.haapi.integration.StudentIT.student1; import static school.hei.haapi.integration.conf.TestUtils.anAvailableRandomPort; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import org.junit.jupiter.api.BeforeEach; @@ -30,7 +30,7 @@ public class CreateMpbsValidatorIT extends MockedThirdParties { @BeforeEach void setUp() { - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/endpoint/rest/validator/CreateStudentWorkFileValidatorIT.java b/src/test/java/school/hei/haapi/endpoint/rest/validator/CreateStudentWorkFileValidatorIT.java index a5bc6084d5..c559672c1e 100644 --- a/src/test/java/school/hei/haapi/endpoint/rest/validator/CreateStudentWorkFileValidatorIT.java +++ b/src/test/java/school/hei/haapi/endpoint/rest/validator/CreateStudentWorkFileValidatorIT.java @@ -6,7 +6,7 @@ import static school.hei.haapi.endpoint.rest.model.ProfessionalExperienceFileTypeEnum.WORKER_STUDENT; import static school.hei.haapi.integration.StudentIT.student1; import static school.hei.haapi.integration.conf.TestUtils.anAvailableRandomPort; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import java.time.Instant; @@ -37,7 +37,7 @@ private static ApiClient anApiClient(String token) { @BeforeEach void setUp() { - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/AdminIT.java b/src/test/java/school/hei/haapi/integration/AdminIT.java index 18d82a790a..728f91a58c 100644 --- a/src/test/java/school/hei/haapi/integration/AdminIT.java +++ b/src/test/java/school/hei/haapi/integration/AdminIT.java @@ -22,8 +22,7 @@ private ApiClient anApiClient(String token) { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, teacher1()); } diff --git a/src/test/java/school/hei/haapi/integration/AdvancedFeeStatsServiceIT.java b/src/test/java/school/hei/haapi/integration/AdvancedFeeStatsServiceIT.java index afbeb88da0..356bfc9c9e 100644 --- a/src/test/java/school/hei/haapi/integration/AdvancedFeeStatsServiceIT.java +++ b/src/test/java/school/hei/haapi/integration/AdvancedFeeStatsServiceIT.java @@ -14,8 +14,7 @@ import static school.hei.haapi.endpoint.rest.model.FeeStatusEnum.UNPAID; import static school.hei.haapi.endpoint.rest.model.FeeTypeEnum.TUITION; import static school.hei.haapi.integration.conf.TestUtils.MANAGER1_TOKEN; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.model.statistics.AdvancedFeeStats.AdvancedFeeStatsCountType.ACCOUNTING; import static school.hei.haapi.model.statistics.AdvancedFeeStats.AdvancedFeeStatsCountType.RECEIPT; @@ -129,8 +128,7 @@ private static Fee createFeeDueJuneLate() { @BeforeEach void setUp() { setUpEventBridge(eventBridgeClientMock); - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); } @Test diff --git a/src/test/java/school/hei/haapi/integration/AnnouncementIT.java b/src/test/java/school/hei/haapi/integration/AnnouncementIT.java index db3f69d71b..3a4c1806ba 100644 --- a/src/test/java/school/hei/haapi/integration/AnnouncementIT.java +++ b/src/test/java/school/hei/haapi/integration/AnnouncementIT.java @@ -24,8 +24,7 @@ import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; import static school.hei.haapi.integration.conf.TestUtils.createAnnouncementWithGroupTarget; import static school.hei.haapi.integration.conf.TestUtils.expectedAnnouncementCreated1; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import java.time.Instant; @@ -242,8 +241,7 @@ void admin_react_announcement_ok() throws ApiException { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); } } diff --git a/src/test/java/school/hei/haapi/integration/CommentIT.java b/src/test/java/school/hei/haapi/integration/CommentIT.java index 93d035f9f0..33953a6239 100644 --- a/src/test/java/school/hei/haapi/integration/CommentIT.java +++ b/src/test/java/school/hei/haapi/integration/CommentIT.java @@ -26,8 +26,7 @@ class CommentIT extends FacadeITMockedThirdParties { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/CourseAssignmentIT.java b/src/test/java/school/hei/haapi/integration/CourseAssignmentIT.java index 97279d577a..d1692e6523 100644 --- a/src/test/java/school/hei/haapi/integration/CourseAssignmentIT.java +++ b/src/test/java/school/hei/haapi/integration/CourseAssignmentIT.java @@ -8,8 +8,7 @@ import static school.hei.haapi.integration.conf.TestUtils.TEACHER1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.assertCourseAssignmentsIgnoringGroupCreationDateTime; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsApiException; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.test_data.CourseAssignmentTestData.createCourseAssignment; import static school.hei.haapi.integration.test_data.CourseAssignmentTestData.createCrupdateCourseAssignment; @@ -94,8 +93,7 @@ private ApiClient anApiClient(String token) { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); setUpTestData(); } diff --git a/src/test/java/school/hei/haapi/integration/CourseIT.java b/src/test/java/school/hei/haapi/integration/CourseIT.java index 361eb289a3..ee66761daa 100644 --- a/src/test/java/school/hei/haapi/integration/CourseIT.java +++ b/src/test/java/school/hei/haapi/integration/CourseIT.java @@ -14,8 +14,7 @@ import static school.hei.haapi.integration.conf.TestUtils.course3; import static school.hei.haapi.integration.conf.TestUtils.createCourse; import static school.hei.haapi.integration.conf.TestUtils.isBefore; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.conf.TestUtils.someCreatableCourseList; @@ -43,8 +42,7 @@ private ApiClient anApiClient(String token) { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/EventIT.java b/src/test/java/school/hei/haapi/integration/EventIT.java index 4b0c597710..14502bfae1 100644 --- a/src/test/java/school/hei/haapi/integration/EventIT.java +++ b/src/test/java/school/hei/haapi/integration/EventIT.java @@ -27,8 +27,7 @@ import static school.hei.haapi.integration.conf.TestUtils.event2; import static school.hei.haapi.integration.conf.TestUtils.event3; import static school.hei.haapi.integration.conf.TestUtils.group1; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.conf.TestUtils.student1AttendEvent2; import static school.hei.haapi.integration.conf.TestUtils.student1MissEvent1; @@ -65,8 +64,7 @@ private ApiClient anApiClient(String token) { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/ExamIT.java b/src/test/java/school/hei/haapi/integration/ExamIT.java index a9915abf9d..90c66e0e98 100644 --- a/src/test/java/school/hei/haapi/integration/ExamIT.java +++ b/src/test/java/school/hei/haapi/integration/ExamIT.java @@ -26,8 +26,7 @@ import static school.hei.haapi.integration.conf.TestUtils.grade1; import static school.hei.haapi.integration.conf.TestUtils.grade2; import static school.hei.haapi.integration.conf.TestUtils.group1; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.conf.TestUtils.studentGrade1; import static school.hei.haapi.integration.conf.TestUtils.teacher1; @@ -60,8 +59,7 @@ private ApiClient anApiClient(String token) { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/FeeIT.java b/src/test/java/school/hei/haapi/integration/FeeIT.java index 5030f0ceb6..15b3c018b6 100644 --- a/src/test/java/school/hei/haapi/integration/FeeIT.java +++ b/src/test/java/school/hei/haapi/integration/FeeIT.java @@ -34,8 +34,7 @@ import static school.hei.haapi.integration.conf.TestUtils.fee3; import static school.hei.haapi.integration.conf.TestUtils.fee4; import static school.hei.haapi.integration.conf.TestUtils.requestFile; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import jakarta.persistence.EntityManager; @@ -98,8 +97,7 @@ private ApiClient anApiClient(String token) { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/FeeTemplateIT.java b/src/test/java/school/hei/haapi/integration/FeeTemplateIT.java index ec997b23d2..5788c92013 100644 --- a/src/test/java/school/hei/haapi/integration/FeeTemplateIT.java +++ b/src/test/java/school/hei/haapi/integration/FeeTemplateIT.java @@ -12,8 +12,7 @@ import static school.hei.haapi.integration.conf.TestUtils.feeTemplate1; import static school.hei.haapi.integration.conf.TestUtils.feeTemplate2; import static school.hei.haapi.integration.conf.TestUtils.feeTemplate3; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.conf.TestUtils.updateFeeTemplate1; @@ -39,8 +38,7 @@ private ApiClient anApiClient(String token) { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/GradeIT.java b/src/test/java/school/hei/haapi/integration/GradeIT.java index e15d7b48aa..5c75570784 100644 --- a/src/test/java/school/hei/haapi/integration/GradeIT.java +++ b/src/test/java/school/hei/haapi/integration/GradeIT.java @@ -21,8 +21,7 @@ import static school.hei.haapi.integration.conf.TestUtils.assertBadRequestException; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsApiException; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.test_data.CourseAssignmentTestData.createCourseAssignment; import static school.hei.haapi.integration.test_data.CourseTestData.prog1; @@ -183,8 +182,7 @@ private void setUpTestData() { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); setUpTestData(); } diff --git a/src/test/java/school/hei/haapi/integration/GroupFlowIT.java b/src/test/java/school/hei/haapi/integration/GroupFlowIT.java index f9c4e07fd9..33a2491ac9 100644 --- a/src/test/java/school/hei/haapi/integration/GroupFlowIT.java +++ b/src/test/java/school/hei/haapi/integration/GroupFlowIT.java @@ -14,8 +14,7 @@ import static school.hei.haapi.integration.conf.TestUtils.STUDENT2_ID; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsApiException; import static school.hei.haapi.integration.conf.TestUtils.group2; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; @@ -41,8 +40,7 @@ public class GroupFlowIT extends FacadeITMockedThirdParties { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/GroupIT.java b/src/test/java/school/hei/haapi/integration/GroupIT.java index 6704072dbb..c583ca9e01 100644 --- a/src/test/java/school/hei/haapi/integration/GroupIT.java +++ b/src/test/java/school/hei/haapi/integration/GroupIT.java @@ -17,8 +17,7 @@ import static school.hei.haapi.integration.conf.TestUtils.group3; import static school.hei.haapi.integration.conf.TestUtils.group5; import static school.hei.haapi.integration.conf.TestUtils.isValidUUID; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.test_data.GroupTestData.createGroupFlow; import static school.hei.haapi.integration.test_data.GroupTestData.g1; @@ -153,8 +152,7 @@ public static CreateGroup groupToCreateGroup(Group group) { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); setUpTestData(); } diff --git a/src/test/java/school/hei/haapi/integration/LetterIT.java b/src/test/java/school/hei/haapi/integration/LetterIT.java index 93af5e1cb6..5426937c52 100644 --- a/src/test/java/school/hei/haapi/integration/LetterIT.java +++ b/src/test/java/school/hei/haapi/integration/LetterIT.java @@ -31,8 +31,7 @@ import static school.hei.haapi.integration.conf.TestUtils.letter1; import static school.hei.haapi.integration.conf.TestUtils.letter2; import static school.hei.haapi.integration.conf.TestUtils.letter3; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.conf.TestUtils.teacherLetter; @@ -74,8 +73,7 @@ class LetterIT extends FacadeITMockedThirdParties { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/ManagerIT.java b/src/test/java/school/hei/haapi/integration/ManagerIT.java index b5b6d7cd36..02a3d4caf2 100644 --- a/src/test/java/school/hei/haapi/integration/ManagerIT.java +++ b/src/test/java/school/hei/haapi/integration/ManagerIT.java @@ -8,8 +8,7 @@ import static school.hei.haapi.integration.conf.TestUtils.TEACHER1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; import static school.hei.haapi.integration.conf.TestUtils.coordinatesWithValues; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.conf.TestUtils.uploadProfilePicture; @@ -90,8 +89,7 @@ public static CrupdateManager someUpdatableManager1() { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, manager1()); } diff --git a/src/test/java/school/hei/haapi/integration/MonitorIT.java b/src/test/java/school/hei/haapi/integration/MonitorIT.java index 2d1f35ba52..df3066720f 100644 --- a/src/test/java/school/hei/haapi/integration/MonitorIT.java +++ b/src/test/java/school/hei/haapi/integration/MonitorIT.java @@ -12,8 +12,7 @@ import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; import static school.hei.haapi.integration.conf.TestUtils.coordinatesWithNullValues; import static school.hei.haapi.integration.conf.TestUtils.coordinatesWithValues; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import java.time.Instant; @@ -128,8 +127,7 @@ public static Coordinates monitor1Coordinates() { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); } diff --git a/src/test/java/school/hei/haapi/integration/MonitoringStudentIT.java b/src/test/java/school/hei/haapi/integration/MonitoringStudentIT.java index 3600686d4c..d1115aff90 100644 --- a/src/test/java/school/hei/haapi/integration/MonitoringStudentIT.java +++ b/src/test/java/school/hei/haapi/integration/MonitoringStudentIT.java @@ -18,8 +18,7 @@ import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; import static school.hei.haapi.integration.conf.TestUtils.monitor1Link; import static school.hei.haapi.integration.conf.TestUtils.monitor2Link; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.student1; import static school.hei.haapi.integration.conf.TestUtils.student2; @@ -72,8 +71,7 @@ private ApiClient anApiClient(String token) { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpTestData(); } diff --git a/src/test/java/school/hei/haapi/integration/MpbsIT.java b/src/test/java/school/hei/haapi/integration/MpbsIT.java index 347ffa5b18..bb5dc37d3b 100644 --- a/src/test/java/school/hei/haapi/integration/MpbsIT.java +++ b/src/test/java/school/hei/haapi/integration/MpbsIT.java @@ -18,8 +18,7 @@ import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.STUDENT2_ID; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.model.User.Role.STUDENT; @@ -55,8 +54,7 @@ public class MpbsIT extends FacadeITMockedThirdParties { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/MpbsVerificationIT.java b/src/test/java/school/hei/haapi/integration/MpbsVerificationIT.java index 08150c9fc2..0d874f40d4 100644 --- a/src/test/java/school/hei/haapi/integration/MpbsVerificationIT.java +++ b/src/test/java/school/hei/haapi/integration/MpbsVerificationIT.java @@ -16,8 +16,7 @@ import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.STUDENT2_ID; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import java.time.Instant; @@ -48,8 +47,7 @@ public class MpbsVerificationIT extends FacadeITMockedThirdParties { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); setUpMobileMock(orangeApiMock); setUpMobileMock(mvolaApiMock); diff --git a/src/test/java/school/hei/haapi/integration/OrganizerIT.java b/src/test/java/school/hei/haapi/integration/OrganizerIT.java index 259c4bf7a5..44df6dd166 100644 --- a/src/test/java/school/hei/haapi/integration/OrganizerIT.java +++ b/src/test/java/school/hei/haapi/integration/OrganizerIT.java @@ -16,8 +16,7 @@ import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_ID; import static school.hei.haapi.integration.conf.TestUtils.TEACHER1_ID; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.student1MissEvent1; import static school.hei.haapi.integration.conf.TestUtils.student3AttendEvent1; @@ -103,8 +102,7 @@ public static Organizer organizer2() { @BeforeEach public void setUp() { setUpEventBridge(eventBridgeClientMock); - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); } @Test diff --git a/src/test/java/school/hei/haapi/integration/PaginationIT.java b/src/test/java/school/hei/haapi/integration/PaginationIT.java index d5121a0610..518ea17716 100644 --- a/src/test/java/school/hei/haapi/integration/PaginationIT.java +++ b/src/test/java/school/hei/haapi/integration/PaginationIT.java @@ -10,8 +10,7 @@ import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.TEACHER1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsApiException; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.conf.TestUtils.teacher1; @@ -47,8 +46,7 @@ private ApiClient anApiClient(String token) { @BeforeEach public void setUp() throws ApiException { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, student1()); setUpS3Service(fileService, manager1()); diff --git a/src/test/java/school/hei/haapi/integration/PaymentIT.java b/src/test/java/school/hei/haapi/integration/PaymentIT.java index 0646286d7c..173d92be82 100644 --- a/src/test/java/school/hei/haapi/integration/PaymentIT.java +++ b/src/test/java/school/hei/haapi/integration/PaymentIT.java @@ -27,8 +27,7 @@ import static school.hei.haapi.integration.conf.TestUtils.assertThrowsApiException; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; import static school.hei.haapi.integration.conf.TestUtils.creatableFee1; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.model.exception.ApiException.ExceptionType.SERVER_EXCEPTION; @@ -163,8 +162,7 @@ static CreatePayment creatablePayment2() { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); setUpEventBridge(eventBridgeClientMock); } diff --git a/src/test/java/school/hei/haapi/integration/PromotionIT.java b/src/test/java/school/hei/haapi/integration/PromotionIT.java index 46275daa17..508ecbe8df 100644 --- a/src/test/java/school/hei/haapi/integration/PromotionIT.java +++ b/src/test/java/school/hei/haapi/integration/PromotionIT.java @@ -19,8 +19,7 @@ import static school.hei.haapi.integration.conf.TestUtils.promotion22; import static school.hei.haapi.integration.conf.TestUtils.promotion23; import static school.hei.haapi.integration.conf.TestUtils.removeGroupToPromotion3; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import java.io.IOException; @@ -52,8 +51,7 @@ private ApiClient anApiClient(String token) { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/RetakeExamIT.java b/src/test/java/school/hei/haapi/integration/RetakeExamIT.java index 1b8ef269b9..18cdf1ef94 100644 --- a/src/test/java/school/hei/haapi/integration/RetakeExamIT.java +++ b/src/test/java/school/hei/haapi/integration/RetakeExamIT.java @@ -12,8 +12,7 @@ import static school.hei.haapi.integration.conf.TestUtils.ADMIN1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.course1; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import java.util.List; @@ -46,8 +45,7 @@ private ApiClient anApiClient(String token) { @BeforeEach void setup() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); when(gradeResultService.getStudentResultSummary(anyString())) diff --git a/src/test/java/school/hei/haapi/integration/RetakeExamSessionIT.java b/src/test/java/school/hei/haapi/integration/RetakeExamSessionIT.java index fc6bda7bca..19eee941ef 100644 --- a/src/test/java/school/hei/haapi/integration/RetakeExamSessionIT.java +++ b/src/test/java/school/hei/haapi/integration/RetakeExamSessionIT.java @@ -8,8 +8,7 @@ import static school.hei.haapi.integration.conf.TestUtils.ADMIN1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.assertBadRequestException; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.test_data.RetakeExamSessionTestData.session1; import static school.hei.haapi.integration.test_data.RetakeExamSessionTestData.sessionWithWrongDate; @@ -36,8 +35,7 @@ private ApiClient anApiClient(String token) { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); when(retakeExamSessionRepository.save(any())).thenReturn(session1()); diff --git a/src/test/java/school/hei/haapi/integration/SchoolFileIT.java b/src/test/java/school/hei/haapi/integration/SchoolFileIT.java index a0d82ea0fc..87d15d13fe 100644 --- a/src/test/java/school/hei/haapi/integration/SchoolFileIT.java +++ b/src/test/java/school/hei/haapi/integration/SchoolFileIT.java @@ -12,8 +12,7 @@ import static school.hei.haapi.integration.conf.TestUtils.MONITOR1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.TEACHER1_TOKEN; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; @@ -44,8 +43,7 @@ public class SchoolFileIT extends FacadeITMockedThirdParties { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, student1()); setUpRestTemplate(restTemplateMock); diff --git a/src/test/java/school/hei/haapi/integration/SecurityIT.java b/src/test/java/school/hei/haapi/integration/SecurityIT.java index a582027e6a..c830596fbe 100644 --- a/src/test/java/school/hei/haapi/integration/SecurityIT.java +++ b/src/test/java/school/hei/haapi/integration/SecurityIT.java @@ -8,8 +8,7 @@ import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.SUSPENDED_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.TEACHER1_TOKEN; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import java.io.IOException; @@ -71,8 +70,7 @@ public static Whoami whoisManager1() { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/StaffMemberIT.java b/src/test/java/school/hei/haapi/integration/StaffMemberIT.java index 5381853706..de244cbf70 100644 --- a/src/test/java/school/hei/haapi/integration/StaffMemberIT.java +++ b/src/test/java/school/hei/haapi/integration/StaffMemberIT.java @@ -10,8 +10,7 @@ import static school.hei.haapi.integration.conf.TestUtils.STAFF_MEMBER1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; import static school.hei.haapi.integration.conf.TestUtils.coordinatesWithNullValues; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.conf.TestUtils.teacher1; @@ -56,8 +55,7 @@ private ApiClient anApiClient(String token) { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, teacher1()); } diff --git a/src/test/java/school/hei/haapi/integration/StudentIT.java b/src/test/java/school/hei/haapi/integration/StudentIT.java index 10fdfcf82d..5f5067c1f9 100644 --- a/src/test/java/school/hei/haapi/integration/StudentIT.java +++ b/src/test/java/school/hei/haapi/integration/StudentIT.java @@ -45,8 +45,7 @@ import static school.hei.haapi.integration.conf.TestUtils.group2; import static school.hei.haapi.integration.conf.TestUtils.group3; import static school.hei.haapi.integration.conf.TestUtils.requestFile; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.conf.TestUtils.uploadProfilePicture; @@ -379,8 +378,7 @@ public static Student repeatingStudent2() { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/TeacherIT.java b/src/test/java/school/hei/haapi/integration/TeacherIT.java index 3811289247..ea07058fea 100644 --- a/src/test/java/school/hei/haapi/integration/TeacherIT.java +++ b/src/test/java/school/hei/haapi/integration/TeacherIT.java @@ -21,8 +21,7 @@ import static school.hei.haapi.integration.conf.TestUtils.coordinatesWithNullValues; import static school.hei.haapi.integration.conf.TestUtils.coordinatesWithValues; import static school.hei.haapi.integration.conf.TestUtils.isValidUUID; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.conf.TestUtils.someCreatableTeacherList; @@ -75,8 +74,7 @@ private ApiClient anApiClient(String token) { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, teacher1()); } diff --git a/src/test/java/school/hei/haapi/integration/UserFileIT.java b/src/test/java/school/hei/haapi/integration/UserFileIT.java index ea84b32f90..8c3b46cfd1 100644 --- a/src/test/java/school/hei/haapi/integration/UserFileIT.java +++ b/src/test/java/school/hei/haapi/integration/UserFileIT.java @@ -27,8 +27,7 @@ import static school.hei.haapi.integration.conf.TestUtils.TEACHER1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.assertBadRequestException; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; @@ -76,8 +75,7 @@ public class UserFileIT extends FacadeITMockedThirdParties { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, student1()); setUpRestTemplate(restTemplateMock); diff --git a/src/test/java/school/hei/haapi/integration/WorkDocumentIT.java b/src/test/java/school/hei/haapi/integration/WorkDocumentIT.java index 1b1c8d80b8..a57299cdce 100644 --- a/src/test/java/school/hei/haapi/integration/WorkDocumentIT.java +++ b/src/test/java/school/hei/haapi/integration/WorkDocumentIT.java @@ -11,8 +11,7 @@ import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsApiException; import static school.hei.haapi.integration.conf.TestUtils.getMockedFile; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; @@ -40,8 +39,7 @@ public class WorkDocumentIT extends FacadeITMockedThirdParties { @BeforeEach public void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, student1()); } diff --git a/src/test/java/school/hei/haapi/integration/conf/TestUtils.java b/src/test/java/school/hei/haapi/integration/conf/TestUtils.java index bbe05d3d56..e033a54d75 100644 --- a/src/test/java/school/hei/haapi/integration/conf/TestUtils.java +++ b/src/test/java/school/hei/haapi/integration/conf/TestUtils.java @@ -69,6 +69,7 @@ import org.springframework.core.io.Resource; import org.springframework.web.util.UriComponentsBuilder; import org.testcontainers.shaded.com.google.common.primitives.Bytes; +import org.testcontainers.shaded.org.checkerframework.checker.nullness.qual.Nullable; import school.hei.haapi.endpoint.rest.client.ApiClient; import school.hei.haapi.endpoint.rest.client.ApiException; import school.hei.haapi.endpoint.rest.model.Announcement; @@ -355,24 +356,57 @@ public static CasdoorUser getCasdoorUserSuspended() { return user; } - public static void setUpCasdoor( - CasdoorAuthService casdoorAuthService, CertificateLoader certificateLoader) { + public static void setUpCognitoAndCasdoor( + CasdoorAuthService casdoorAuthService, + CognitoComponent cognitoComponent, + CertificateLoader certificateLoader) { given(certificateLoader.getCertificate()).willReturn("mocked-certificate"); - setUpCasdoorUser(casdoorAuthService, TEACHER1_TOKEN, getCasdoorUserTeacher1()); - setUpCasdoorUser(casdoorAuthService, MANAGER1_TOKEN, getCasdoorUserManager1()); - setUpCasdoorUser(casdoorAuthService, STUDENT1_TOKEN, getCasdoorUserStudent1()); - setUpCasdoorUser(casdoorAuthService, STUDENT2_TOKEN, getCasdoorUserStudent2()); - setUpCasdoorUser(casdoorAuthService, STUDENT8_TOKEN, getCasdoorUserStudent8()); - setUpCasdoorUser(casdoorAuthService, STUDENT11_TOKEN, getCasdoorUserStudent11()); - setUpCasdoorUser(casdoorAuthService, STUDENT12_TOKEN, getCasdoorUserStudent12()); - setUpCasdoorUser(casdoorAuthService, STUDENT13_TOKEN, getCasdoorUserStudent13()); - setUpCasdoorUser(casdoorAuthService, MONITOR1_TOKEN, getCasdoorUserMonitor1()); - setUpCasdoorUser(casdoorAuthService, MONITOR2_TOKEN, getCasdoorUserMonitor2()); - setUpCasdoorUser(casdoorAuthService, ORGANIZER1_TOKEN, getCasdoorUserOrganizer1()); - setUpCasdoorUser(casdoorAuthService, ORGANIZER2_TOKEN, getCasdoorUserOrganizer2()); - setUpCasdoorUser(casdoorAuthService, STAFF_MEMBER1_TOKEN, getCasdoorUserStaffMember1()); - setUpCasdoorUser(casdoorAuthService, ADMIN1_TOKEN, getCasdoorUserAdmin1()); - setUpCasdoorUser(casdoorAuthService, SUSPENDED_TOKEN, getCasdoorUserSuspended()); + + setUpCognitoAndCasdoorUser(casdoorAuthService, cognitoComponent, BAD_TOKEN, null); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, STUDENT1_TOKEN, getCasdoorUserStudent1()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, STUDENT2_TOKEN, getCasdoorUserStudent2()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, STUDENT11_TOKEN, getCasdoorUserStudent11()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, STUDENT12_TOKEN, getCasdoorUserStudent12()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, STUDENT13_TOKEN, getCasdoorUserStudent13()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, MONITOR1_TOKEN, getCasdoorUserMonitor1()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, MONITOR2_TOKEN, getCasdoorUserMonitor2()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, STUDENT8_TOKEN, getCasdoorUserStudent8()); + + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, TEACHER1_TOKEN, getCasdoorUserTeacher1()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, MANAGER1_TOKEN, getCasdoorUserManager1()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, ORGANIZER1_TOKEN, getCasdoorUserOrganizer1()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, ORGANIZER2_TOKEN, getCasdoorUserOrganizer2()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, STAFF_MEMBER1_TOKEN, getCasdoorUserStaffMember1()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, ADMIN1_TOKEN, getCasdoorUserAdmin1()); + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, SUSPENDED_TOKEN, getCasdoorUserSuspended()); + } + + public static void setUpCognitoAndCasdoorUser( + CasdoorAuthService casdoorAuthService, + CognitoComponent cognitoComponent, + String userToken, + @Nullable CasdoorUser user) { + if (user != null) { + setUpCasdoorUser(casdoorAuthService, userToken, user); + setUpCognitoUser(cognitoComponent, userToken, user.getEmail()); + } else { + setUpCognitoUser(cognitoComponent, userToken, null); + } } public static void setUpCasdoorUser( @@ -391,25 +425,6 @@ public static ApiClient anApiClient(String token, int serverPort) { return client; } - public static void setUpCognito(CognitoComponent cognitoComponent) { - setUpCognitoUser(cognitoComponent, BAD_TOKEN, null); - setUpCognitoUser(cognitoComponent, STUDENT1_TOKEN, "test+ryan@hei.school"); - setUpCognitoUser(cognitoComponent, STUDENT2_TOKEN, "test+student2@hei.school"); - setUpCognitoUser(cognitoComponent, STUDENT11_TOKEN, "test+student11@hei.school"); - setUpCognitoUser(cognitoComponent, STUDENT12_TOKEN, "test+student12@hei.school"); - setUpCognitoUser(cognitoComponent, STUDENT13_TOKEN, "test+student13@hei.school"); - setUpCognitoUser(cognitoComponent, MONITOR1_TOKEN, "test+monitor@hei.school"); - setUpCognitoUser(cognitoComponent, MONITOR2_TOKEN, "test+monitor2@hei.school"); - setUpCognitoUser(cognitoComponent, STUDENT8_TOKEN, "test+repeating2@hei" + ".school"); - setUpCognitoUser(cognitoComponent, TEACHER1_TOKEN, "test+teacher1@hei.school"); - setUpCognitoUser(cognitoComponent, MANAGER1_TOKEN, "test+manager1@hei.school"); - setUpCognitoUser(cognitoComponent, STAFF_MEMBER1_TOKEN, "test+staff@hei.school"); - setUpCognitoUser(cognitoComponent, ADMIN1_TOKEN, "test+admin@hei.school"); - setUpCognitoUser(cognitoComponent, ORGANIZER1_TOKEN, "test+organizer@hei.school"); - setUpCognitoUser(cognitoComponent, ORGANIZER2_TOKEN, "test+organizer+2@hei.school"); - setUpCognitoUser(cognitoComponent, SUSPENDED_TOKEN, "test+suspended@hei.school"); - } - private static void setUpCognitoUser( CognitoComponent cognitoComponent, String token, String email) { when(cognitoComponent.getEmailByIdToken(token)).thenReturn(email); diff --git a/src/test/java/school/hei/haapi/service/DirtyEventServiceTest.java b/src/test/java/school/hei/haapi/service/DirtyEventServiceTest.java index dd24623b32..2077e3e60f 100644 --- a/src/test/java/school/hei/haapi/service/DirtyEventServiceTest.java +++ b/src/test/java/school/hei/haapi/service/DirtyEventServiceTest.java @@ -9,7 +9,7 @@ import static school.hei.haapi.integration.StudentIT.someCreatableStudentList; import static school.hei.haapi.integration.conf.FakeDataProvider.someCreatableEvent; import static school.hei.haapi.integration.conf.TestUtils.MANAGER_ID; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import java.time.Instant; @@ -56,7 +56,7 @@ class DirtyEventServiceTest extends FacadeITMockedThirdParties { @BeforeEach void setUp() { - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); } diff --git a/src/test/java/school/hei/haapi/service/PaymentServiceTest.java b/src/test/java/school/hei/haapi/service/PaymentServiceTest.java index 7cc49aa3f2..072a3850ba 100644 --- a/src/test/java/school/hei/haapi/service/PaymentServiceTest.java +++ b/src/test/java/school/hei/haapi/service/PaymentServiceTest.java @@ -15,8 +15,7 @@ import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_ID; import static school.hei.haapi.integration.conf.TestUtils.anAvailableRandomPort; import static school.hei.haapi.integration.conf.TestUtils.creatableFee1; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.model.User.Sex.F; @@ -63,8 +62,7 @@ class PaymentServiceTest extends MockedThirdParties { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, TestUtils.student1()); setUpEventBridge(eventBridgeClientMock); } diff --git a/src/test/java/school/hei/haapi/service/UserServiceTest.java b/src/test/java/school/hei/haapi/service/UserServiceTest.java index ca03c3208f..0b8016826f 100644 --- a/src/test/java/school/hei/haapi/service/UserServiceTest.java +++ b/src/test/java/school/hei/haapi/service/UserServiceTest.java @@ -4,7 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_ID; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.integration.conf.TestUtils.student1; @@ -35,7 +35,7 @@ class UserServiceTest extends FacadeITMockedThirdParties { @BeforeEach void setUp() { - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, student1()); setUpEventBridge(eventBridgeClientMock); } diff --git a/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java b/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java index 87cdae64e1..6c1ea81f96 100644 --- a/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java +++ b/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java @@ -11,8 +11,7 @@ import static school.hei.haapi.integration.conf.TestUtils.STUDENT2_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.anAvailableRandomPort; import static school.hei.haapi.integration.conf.TestUtils.creatableFee1; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.model.User.Sex.F; import static school.hei.haapi.model.User.Sex.M; @@ -68,8 +67,7 @@ public class CheckStudentsStatusTest extends MockedThirdParties { @BeforeEach void setUp() { - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); } diff --git a/src/test/java/school/hei/haapi/unit/utils/DateUtilsTest.java b/src/test/java/school/hei/haapi/unit/utils/DateUtilsTest.java index 350885075c..ad5d91378e 100644 --- a/src/test/java/school/hei/haapi/unit/utils/DateUtilsTest.java +++ b/src/test/java/school/hei/haapi/unit/utils/DateUtilsTest.java @@ -2,7 +2,7 @@ import static java.util.Optional.empty; import static org.junit.jupiter.api.Assertions.assertEquals; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import java.time.LocalDate; @@ -25,7 +25,7 @@ public class DateUtilsTest extends FacadeITMockedThirdParties { @BeforeEach void setUp() { - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); } From a07482f87682bebcac4d1440f230cfacaa1be51c Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Tue, 30 Sep 2025 16:06:32 +0300 Subject: [PATCH 03/15] test: setUp cognito and casdoor using User --- .../hei/haapi/integration/conf/TestUtils.java | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/test/java/school/hei/haapi/integration/conf/TestUtils.java b/src/test/java/school/hei/haapi/integration/conf/TestUtils.java index e033a54d75..2a51789f4d 100644 --- a/src/test/java/school/hei/haapi/integration/conf/TestUtils.java +++ b/src/test/java/school/hei/haapi/integration/conf/TestUtils.java @@ -69,7 +69,7 @@ import org.springframework.core.io.Resource; import org.springframework.web.util.UriComponentsBuilder; import org.testcontainers.shaded.com.google.common.primitives.Bytes; -import org.testcontainers.shaded.org.checkerframework.checker.nullness.qual.Nullable; +import org.testcontainers.shaded.org.checkerframework.checker.nullness.qual.NonNull; import school.hei.haapi.endpoint.rest.client.ApiClient; import school.hei.haapi.endpoint.rest.client.ApiException; import school.hei.haapi.endpoint.rest.model.Announcement; @@ -121,6 +121,7 @@ import school.hei.haapi.endpoint.rest.security.casdoorAuthentication.config.CertificateLoader; import school.hei.haapi.endpoint.rest.security.cognito.CognitoComponent; import school.hei.haapi.http.model.TransactionDetails; +import school.hei.haapi.model.User; import school.hei.haapi.model.exception.BadRequestException; import school.hei.haapi.model.exception.NotFoundException; import school.hei.haapi.service.aws.FileService; @@ -356,13 +357,29 @@ public static CasdoorUser getCasdoorUserSuspended() { return user; } + public static CasdoorUser userToCasdoorUser(User user) { + CasdoorUser casdoorUser = new CasdoorUser(); + if (user.getEmail() == null) throw new RuntimeException("Email is null"); + casdoorUser.setEmail(user.getEmail()); + + var casdoorRole = new CasdoorRole(); + casdoorRole.setOwner("dummy"); + if (user.getRole() == null) throw new RuntimeException("Role is null"); + casdoorRole.setName(user.getRole().toString().toLowerCase()); + var roleUsers = new String[] {"dummy/casdoorUser"}; + casdoorRole.setUsers(roleUsers); + casdoorUser.setRoles(List.of(casdoorRole)); + + return casdoorUser; + } + public static void setUpCognitoAndCasdoor( CasdoorAuthService casdoorAuthService, CognitoComponent cognitoComponent, CertificateLoader certificateLoader) { given(certificateLoader.getCertificate()).willReturn("mocked-certificate"); - setUpCognitoAndCasdoorUser(casdoorAuthService, cognitoComponent, BAD_TOKEN, null); + setUpCognitoAndCasdoorUser(cognitoComponent, BAD_TOKEN); setUpCognitoAndCasdoorUser( casdoorAuthService, cognitoComponent, STUDENT1_TOKEN, getCasdoorUserStudent1()); setUpCognitoAndCasdoorUser( @@ -400,13 +417,23 @@ public static void setUpCognitoAndCasdoorUser( CasdoorAuthService casdoorAuthService, CognitoComponent cognitoComponent, String userToken, - @Nullable CasdoorUser user) { - if (user != null) { - setUpCasdoorUser(casdoorAuthService, userToken, user); - setUpCognitoUser(cognitoComponent, userToken, user.getEmail()); - } else { - setUpCognitoUser(cognitoComponent, userToken, null); - } + @NonNull CasdoorUser user) { + setUpCasdoorUser(casdoorAuthService, userToken, user); + setUpCognitoUser(cognitoComponent, userToken, user.getEmail()); + } + + public static void setUpCognitoAndCasdoorUser( + CasdoorAuthService casdoorAuthService, + CognitoComponent cognitoComponent, + String userToken, + @NonNull User user) { + setUpCognitoAndCasdoorUser( + casdoorAuthService, cognitoComponent, userToken, userToCasdoorUser(user)); + } + + public static void setUpCognitoAndCasdoorUser( + CognitoComponent cognitoComponent, String badToken) { + setUpCognitoUser(cognitoComponent, badToken, null); } public static void setUpCasdoorUser( From 75b3abde2bb7c22663cf9aebd2c9ad4085280425 Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Tue, 30 Sep 2025 17:05:26 +0300 Subject: [PATCH 04/15] test: reanable student_update_mobile_payment_ok --- .../school/hei/haapi/integration/MpbsIT.java | 61 +++++++++++++------ .../integration/conf/FakeDataProvider.java | 16 ++++- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/test/java/school/hei/haapi/integration/MpbsIT.java b/src/test/java/school/hei/haapi/integration/MpbsIT.java index bb5dc37d3b..73ff163308 100644 --- a/src/test/java/school/hei/haapi/integration/MpbsIT.java +++ b/src/test/java/school/hei/haapi/integration/MpbsIT.java @@ -10,6 +10,9 @@ import static school.hei.haapi.endpoint.rest.model.MobileMoneyType.ORANGE_MONEY; import static school.hei.haapi.endpoint.rest.model.MpbsStatus.PENDING; import static school.hei.haapi.integration.StudentIT.student1; +import static school.hei.haapi.integration.conf.FakeDataProvider.someFee; +import static school.hei.haapi.integration.conf.FakeDataProvider.someMpbs; +import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; import static school.hei.haapi.integration.conf.TestUtils.FEE1_ID; import static school.hei.haapi.integration.conf.TestUtils.FEE2_ID; import static school.hei.haapi.integration.conf.TestUtils.MANAGER1_TOKEN; @@ -19,6 +22,7 @@ import static school.hei.haapi.integration.conf.TestUtils.STUDENT2_ID; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoorUser; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; import static school.hei.haapi.model.User.Role.STUDENT; @@ -39,10 +43,14 @@ import school.hei.haapi.endpoint.rest.api.PayingApi; import school.hei.haapi.endpoint.rest.client.ApiClient; import school.hei.haapi.endpoint.rest.client.ApiException; +import school.hei.haapi.endpoint.rest.mapper.MpbsMapper; import school.hei.haapi.endpoint.rest.model.*; import school.hei.haapi.integration.conf.FacadeITMockedThirdParties; import school.hei.haapi.integration.conf.TestUtils; import school.hei.haapi.model.User; +import school.hei.haapi.repository.FeeRepository; +import school.hei.haapi.repository.MpbsRepository; +import school.hei.haapi.repository.UserRepository; import school.hei.haapi.service.UserService; import software.amazon.awssdk.services.eventbridge.EventBridgeClient; @@ -51,12 +59,27 @@ public class MpbsIT extends FacadeITMockedThirdParties { @MockBean private EventBridgeClient eventBridgeClientMock; @Autowired private UserService userService; + @Autowired private UserRepository userRepository; + @Autowired private FeeRepository feeRepository; + @Autowired private MpbsRepository mpbsRepository; + @Autowired private MpbsMapper mpbsMapper; + + private User student; + private school.hei.haapi.model.Fee fee; + private school.hei.haapi.model.mpbs.Mpbs mpbs; + private static final String studentToken = "studentToken"; @BeforeEach void setUp() { setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, student1()); + + student = userRepository.save(someStudent()); + fee = feeRepository.save(someFee(student)); + mpbs = mpbsRepository.save(someMpbs(fee)); + System.out.println(mpbs.getPspId()); + setUpCognitoAndCasdoorUser(casdoorAuthServiceMock, cognitoComponentMock, studentToken, student); } private ApiClient anApiClient(String token) { @@ -110,32 +133,30 @@ void monitor_read_others_student_mobile_money_ko() { } @Test - @Disabled("TODO: dirty, create new student") void student_update_mobile_payment_ok() throws ApiException { - ApiClient student1Client = anApiClient(STUDENT1_TOKEN); - PayingApi api = new PayingApi(student1Client); + var api = new PayingApi(anApiClient(studentToken)); - Mpbs actual0 = api.getMpbs(STUDENT1_ID, FEE1_ID).getFirst(); - assertEquals(expectedMpbs1(), actual0); + var storedMpbs = api.getMpbs(student.getId(), fee.getId()).getFirst(); + assertEquals(mpbsMapper.toRest(mpbs), storedMpbs); - Mpbs inUpdate = api.crupdateMpbs(STUDENT1_ID, FEE1_ID, updatableMpbs1()); - var updated = expectedMpbs1(); + var mpbsInUpdate = api.crupdateMpbs(student.getId(), fee.getId(), updatableMpbs1()); + var updated = mpbsMapper.toRest(mpbs); updated.setPspId("MP240726.1541.D88426"); updated.setPspType(ORANGE_MONEY); - assertEquals(updated.getStudentId(), inUpdate.getStudentId()); - assertEquals(updated.getPspId(), inUpdate.getPspId()); - assertEquals(updated.getFeeId(), inUpdate.getFeeId()); - assertEquals(updated.getPspType(), inUpdate.getPspType()); + assertEquals(updated.getStudentId(), mpbsInUpdate.getStudentId()); + assertEquals(updated.getPspId(), mpbsInUpdate.getPspId()); + assertEquals(updated.getFeeId(), mpbsInUpdate.getFeeId()); + assertEquals(updated.getPspType(), mpbsInUpdate.getPspType()); // Assert that one fee has mpbs - Mpbs actual1 = api.getMpbs(STUDENT1_ID, FEE1_ID).getFirst(); + Mpbs actual1 = api.getMpbs(student.getId(), fee.getId()).getFirst(); actual1.setCreationDatetime(actual1.getCreationDatetime().truncatedTo(MINUTES)); - inUpdate.setCreationDatetime(inUpdate.getCreationDatetime().truncatedTo(MINUTES)); - assertEquals(actual1, inUpdate); + mpbsInUpdate.setCreationDatetime(mpbsInUpdate.getCreationDatetime().truncatedTo(MINUTES)); + assertEquals(actual1, mpbsInUpdate); // Assert that when we get fees it not throws error 500 - List actualFee = api.getStudentFees(STUDENT1_ID, 1, 10, null); - assertEquals(7, actualFee.size()); + var studentFee = api.getStudentFees(student.getId(), 1, 10, null); + assertEquals(1, studentFee.size()); } @Test @@ -239,11 +260,11 @@ private User createStudentForMobilePayments() { return userService.saveAll(List.of(randomStudent)).getFirst(); } - public static CrupdateMpbs updatableMpbs1() { + public CrupdateMpbs updatableMpbs1() { return new CrupdateMpbs() - .id("mpbs1_id") - .studentId(STUDENT1_ID) - .feeId(FEE1_ID) + .id(mpbs.getId()) + .studentId(student.getId()) + .feeId(fee.getId()) .pspId("MP240726.1541.D88426") .pspType(ORANGE_MONEY); } diff --git a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java index f571c4223c..6450cb9612 100644 --- a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java +++ b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java @@ -8,6 +8,7 @@ import static school.hei.haapi.endpoint.rest.model.FeeFrequency.MONTHLY; import static school.hei.haapi.endpoint.rest.model.FeeStatusEnum.PENDING; import static school.hei.haapi.endpoint.rest.model.FeeTypeEnum.TUITION; +import static school.hei.haapi.endpoint.rest.model.MobileMoneyType.ORANGE_MONEY; import static school.hei.haapi.integration.conf.TestUtils.COURSE1_ID; import static school.hei.haapi.integration.conf.TestUtils.MANAGER_ID; import static school.hei.haapi.integration.conf.TestUtils.group1; @@ -110,7 +111,7 @@ public List someCreatableGroupList(int nbOfGroup) { return groupList; } - public Fee someFee(User student) { + public static Fee someFee(User student) { return Fee.builder() .id(UUID.randomUUID().toString()) .comment(faker.lorem().sentence(10)) @@ -157,10 +158,17 @@ public Event someEvent() { } public Mpbs someMpbs(User student) { + return someMpbs(someFee(student)); + } + + public static Mpbs someMpbs(Fee fee) { return Mpbs.builder() .status(faker.options().option(MpbsStatus.class)) - .fee(someFee(student)) + .fee(fee) .amount(faker.number().numberBetween(100, 10_000)) + .mobileMoneyType(ORANGE_MONEY) + .pspId(faker.regexify("MP\\d{6}\\.\\d{4}\\.D\\d{5}")) + .student(fee.getStudent()) .build(); } @@ -215,6 +223,10 @@ public static User someStudent(String firstName) { .build(); } + public static User someStudent() { + return someStudent(faker.name().firstName()); + } + public static Coordinates someCoordinates() { return new Coordinates() .latitude(faker.number().randomDouble(2, -90, 90)) From 13f20b73a77661cec23c305b7977a597c7aaaff4 Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Tue, 30 Sep 2025 17:19:18 +0300 Subject: [PATCH 05/15] test: reanable student_create_mobile_payment_ok --- .../school/hei/haapi/integration/MpbsIT.java | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/test/java/school/hei/haapi/integration/MpbsIT.java b/src/test/java/school/hei/haapi/integration/MpbsIT.java index 73ff163308..d8421cc2a2 100644 --- a/src/test/java/school/hei/haapi/integration/MpbsIT.java +++ b/src/test/java/school/hei/haapi/integration/MpbsIT.java @@ -34,7 +34,6 @@ import java.util.List; import java.util.Random; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -78,7 +77,6 @@ void setUp() { student = userRepository.save(someStudent()); fee = feeRepository.save(someFee(student)); mpbs = mpbsRepository.save(someMpbs(fee)); - System.out.println(mpbs.getPspId()); setUpCognitoAndCasdoorUser(casdoorAuthServiceMock, cognitoComponentMock, studentToken, student); } @@ -160,18 +158,14 @@ void student_update_mobile_payment_ok() throws ApiException { } @Test - @Disabled("TODO: dirty, create new student") void student_create_mobile_payment_ok() throws ApiException { - ApiClient student1Client = anApiClient(STUDENT1_TOKEN); - PayingApi api = new PayingApi(student1Client); - - ApiClient manager1Client = anApiClient(MANAGER1_TOKEN); - PayingApi manager1Api = new PayingApi(manager1Client); + var api = new PayingApi(anApiClient(studentToken)); + var manager1Api = new PayingApi(anApiClient(MANAGER1_TOKEN)); - Fee actualFee = + var actualFee = manager1Api .createStudentFees( - STUDENT1_ID, + student.getId(), List.of( new CreateFee() .totalAmount(5000) @@ -182,17 +176,16 @@ void student_create_mobile_payment_ok() throws ApiException { .creationDatetime(now()) .comment("test"))) .getFirst(); - assertEquals(STUDENT1_ID, actualFee.getStudentId()); + assertEquals(student.getId(), actualFee.getStudentId()); - Mpbs actual = - api.crupdateMpbs( - STUDENT1_ID, actualFee.getId(), createableMpbsFromFeeIdWithStudent1(actualFee.getId())); + var crupdateMpbs = createableMpbsFromFeeIdWithStudent(actualFee.getId()); + var actualMpbs = api.crupdateMpbs(student.getId(), actualFee.getId(), crupdateMpbs); - assertEquals(createableMpbs1().getStudentId(), actual.getStudentId()); - assertEquals(createableMpbs1().getPspId(), actual.getPspId()); - assertEquals(createableMpbs1().getPspType(), actual.getPspType()); + assertEquals(crupdateMpbs.getStudentId(), actualMpbs.getStudentId()); + assertEquals(crupdateMpbs.getPspId(), actualMpbs.getPspId()); + assertEquals(crupdateMpbs.getPspType(), actualMpbs.getPspType()); - Fee updatedFee = api.getStudentFeeById(STUDENT1_ID, actualFee.getId()); + var updatedFee = api.getStudentFeeById(student.getId(), actualFee.getId()); assertEquals(FeeStatusEnum.PENDING, updatedFee.getStatus()); } @@ -282,18 +275,14 @@ public static Mpbs expectedMpbs1() { .status(PENDING); } - public static CrupdateMpbs createableMpbs1() { - return new CrupdateMpbs() - .studentId(STUDENT1_ID) - .feeId(FEE2_ID) - .pspType(ORANGE_MONEY) - .pspId("MP240726.1541.D88425"); - } - public static CrupdateMpbs createableMpbsFromFeeIdWithStudent1(String feeId) { return createableMpbsFromFeeIdForStudent(STUDENT1_ID, feeId); } + public CrupdateMpbs createableMpbsFromFeeIdWithStudent(String feeId) { + return createableMpbsFromFeeIdForStudent(student.getId(), feeId); + } + public static CrupdateMpbs createableMpbsFromFeeIdForStudent(String studentId, String feeId) { return new CrupdateMpbs() .studentId(studentId) From 84aa426c2c53dca901310033c9738b56b2a6143b Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Tue, 30 Sep 2025 17:33:30 +0300 Subject: [PATCH 06/15] test: reanable PendingMpbsCheckRequestedServiceTest::verify_mpbs_to_unverified --- .../PendingMpbsCheckRequestedServiceTest.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java b/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java index fdc68b5513..3dfcf2b903 100644 --- a/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java +++ b/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java @@ -17,7 +17,8 @@ import static school.hei.haapi.endpoint.rest.model.MobileMoneyType.ORANGE_MONEY; import static school.hei.haapi.endpoint.rest.model.MpbsStatus.PENDING; import static school.hei.haapi.endpoint.rest.model.MpbsStatus.SUCCESS; -import static school.hei.haapi.integration.conf.TestUtils.FEE1_ID; +import static school.hei.haapi.integration.conf.FakeDataProvider.*; +import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_ID; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; @@ -36,6 +37,8 @@ import school.hei.haapi.model.User; import school.hei.haapi.model.mpbs.Mpbs; import school.hei.haapi.repository.FeeRepository; +import school.hei.haapi.repository.MpbsRepository; +import school.hei.haapi.repository.UserRepository; import school.hei.haapi.service.FeeService; import school.hei.haapi.service.MobilePaymentService; import school.hei.haapi.service.MpbsService; @@ -49,30 +52,41 @@ class PendingMpbsCheckRequestedServiceTest extends FacadeITMockedThirdParties { @MockBean private MobilePaymentService mobilePaymentService; @Autowired private FeeService feeService; @Autowired private FeeRepository feeRepository; + @Autowired private UserRepository userRepository; + @Autowired private MpbsRepository mpbsRepository; private static final String MOCK_FEE_ID = "mock-fee"; private static final String MOCK_STUDENT_FIRST_NAME = "MOCK"; private static final String MOCK_STUDENT_LAST_NAME = "Student"; private static final String MOCK_STUDENT_EMAIL = "mock@example.com"; + private User student; + private Fee fee; + private Mpbs mpbs; + @BeforeEach void setUp() { setUpEventBridge(eventBridgeClientMock); + + student = userRepository.save(someStudent()); + fee = feeRepository.save(someFee(student)); + mpbs = mpbsRepository.save(someMpbs(fee)); } @Test - @Disabled("TODO: dirty, create new student") void verify_mpbs_to_unverified() { - var actualFee = feeService.getById(FEE1_ID); + var actualFee = feeService.getById(fee.getId()); assertDoesNotThrow( () -> subject.accept( PendingMpbsCheckRequested.builder() .toVerify( - mpbsService.getStudentMobilePaymentByFeeId(STUDENT1_ID, FEE1_ID).getFirst()) + mpbsService + .getStudentMobilePaymentByFeeId(student.getId(), fee.getId()) + .getFirst()) .verifyAt(now()) .build())); - var updatedFee = feeService.getById(FEE1_ID); + var updatedFee = feeService.getById(fee.getId()); assertEquals(actualFee, updatedFee); } From 18536672f95c0f2ab294da284007e75b3382a8e8 Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Tue, 30 Sep 2025 17:46:20 +0300 Subject: [PATCH 07/15] test: reanable PendingMpbsCheckRequestedServiceTest::verify_mpbs --- .../event/PendingMpbsCheckRequestedServiceTest.java | 11 +++++++---- .../hei/haapi/integration/conf/FakeDataProvider.java | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java b/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java index 3dfcf2b903..9f3c75d398 100644 --- a/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java +++ b/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java @@ -67,9 +67,12 @@ class PendingMpbsCheckRequestedServiceTest extends FacadeITMockedThirdParties { @BeforeEach void setUp() { setUpEventBridge(eventBridgeClientMock); + setUpData(0); + } + void setUpData(int totalFeeAmount) { student = userRepository.save(someStudent()); - fee = feeRepository.save(someFee(student)); + fee = feeRepository.save(someFee(student, totalFeeAmount)); mpbs = mpbsRepository.save(someMpbs(fee)); } @@ -92,13 +95,13 @@ void verify_mpbs_to_unverified() { } @Test - @Disabled("TODO: dirty, create new student") void verify_mpbs() { - var fee = feeService.saveAll(List.of(someFeeFor(mockStudent()))).getFirst(); + setUpData(10_000); + var mpbsCreated = Mpbs.builder() .status(PENDING) - .student(mockStudent()) + .student(student) .fee(fee) .amount(fee.getRemainingAmount()) .statusHistory(new ArrayList<>()) diff --git a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java index 6450cb9612..0f152a1626 100644 --- a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java +++ b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java @@ -112,12 +112,16 @@ public List someCreatableGroupList(int nbOfGroup) { } public static Fee someFee(User student) { + return someFee(student, 0); + } + + public static Fee someFee(User student, int totalAmount) { return Fee.builder() .id(UUID.randomUUID().toString()) .comment(faker.lorem().sentence(10)) .student(student) - .totalAmount(0) - .remainingAmount(0) + .totalAmount(totalAmount) + .remainingAmount(totalAmount) .status(PENDING) .updatedAt(Instant.now()) .creationDatetime(Instant.now()) From ee50fb03847ba9977b237998de405523e76ddb18 Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Tue, 30 Sep 2025 17:49:21 +0300 Subject: [PATCH 08/15] test: reanable PendingMpbsCheckRequestedServiceTest::unverifed_mpbs_ok --- .../event/PendingMpbsCheckRequestedServiceTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java b/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java index 9f3c75d398..f4b80516c3 100644 --- a/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java +++ b/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -131,10 +130,9 @@ void verify_mpbs() { } @Test - @Disabled("TODO: dirty, create new student") void unverifed_mpbs_ok() { - var toFailFee = feeService.saveAll(List.of(someFeeFor(mockStudent()))).getFirst(); - var toPendFee = feeService.saveAll(List.of(someFeeFor(mockStudent()))).getFirst(); + var toFailFee = feeService.saveAll(List.of(someFeeFor(student))).getFirst(); + var toPendFee = feeService.saveAll(List.of(someFeeFor(student))).getFirst(); when(mobilePaymentService.findTransactionByMpbs(any())).thenReturn(empty()); assertDoesNotThrow( () -> From 561f1bb90c53beda8dea905c7ef37eed4b68a436 Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Wed, 1 Oct 2025 10:44:12 +0300 Subject: [PATCH 09/15] test: reanable PaymentServiceTest::user_status_is_computed_after_paying_fee_by_mpbs --- .../integration/conf/FakeDataProvider.java | 12 +++++++- .../hei/haapi/service/PaymentServiceTest.java | 28 +++++++++++++------ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java index 0f152a1626..964ffde36a 100644 --- a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java +++ b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java @@ -6,6 +6,7 @@ import static school.hei.haapi.endpoint.rest.model.EnableStatus.ENABLED; import static school.hei.haapi.endpoint.rest.model.FeeCategory.L1; import static school.hei.haapi.endpoint.rest.model.FeeFrequency.MONTHLY; +import static school.hei.haapi.endpoint.rest.model.FeeStatusEnum.LATE; import static school.hei.haapi.endpoint.rest.model.FeeStatusEnum.PENDING; import static school.hei.haapi.endpoint.rest.model.FeeTypeEnum.TUITION; import static school.hei.haapi.endpoint.rest.model.MobileMoneyType.ORANGE_MONEY; @@ -132,6 +133,10 @@ public static Fee someFee(User student, int totalAmount) { .build(); } + public static Fee someLateFee(User student, int totalAmount) { + return someFee(student, totalAmount).toBuilder().status(LATE).build(); + } + public Event someEvent() { var beginDatetime = faker @@ -213,7 +218,12 @@ public static CreateEvent someCreatableEventByManager1(EventType eventType) { Instant.parse("2023-12-08T10:00:00.00Z")); } + public static User someStudent(String firstName) { + return someStudent(firstName, User.Status.ENABLED); + } + + public static User someStudent(String firstName, User.Status status) { return User.builder(someCoordinates()) .id(UUID.randomUUID().toString()) .role(STUDENT) @@ -222,7 +232,7 @@ public static User someStudent(String firstName) { .ref(someRef("STD")) .lastName(faker.name().lastName()) .address(faker.address().fullAddress()) - .status(User.Status.ENABLED) + .status(status) .entranceDatetime(Instant.now()) .build(); } diff --git a/src/test/java/school/hei/haapi/service/PaymentServiceTest.java b/src/test/java/school/hei/haapi/service/PaymentServiceTest.java index 072a3850ba..a9768de356 100644 --- a/src/test/java/school/hei/haapi/service/PaymentServiceTest.java +++ b/src/test/java/school/hei/haapi/service/PaymentServiceTest.java @@ -7,8 +7,10 @@ import static school.hei.haapi.endpoint.rest.model.FeeStatusEnum.LATE; import static school.hei.haapi.endpoint.rest.model.FeeTypeEnum.HARDWARE; import static school.hei.haapi.endpoint.rest.model.FeeTypeEnum.TUITION; -import static school.hei.haapi.integration.MpbsIT.createableMpbsFromFeeIdWithStudent1; +import static school.hei.haapi.integration.MpbsIT.createableMpbsFromFeeIdForStudent; import static school.hei.haapi.integration.StudentIT.someCreatableStudent; +import static school.hei.haapi.integration.conf.FakeDataProvider.someFee; +import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; import static school.hei.haapi.integration.conf.TestUtils.FEE3_ID; import static school.hei.haapi.integration.conf.TestUtils.FEE6_ID; import static school.hei.haapi.integration.conf.TestUtils.MANAGER1_TOKEN; @@ -25,7 +27,6 @@ import java.time.LocalDate; import java.util.List; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,6 +46,8 @@ import school.hei.haapi.integration.conf.TestUtils; import school.hei.haapi.model.Fee; import school.hei.haapi.model.User; +import school.hei.haapi.repository.FeeRepository; +import school.hei.haapi.repository.UserRepository; import software.amazon.awssdk.services.eventbridge.EventBridgeClient; @SpringBootTest(webEnvironment = RANDOM_PORT) @@ -56,32 +59,39 @@ class PaymentServiceTest extends MockedThirdParties { @Autowired private PaymentService subject; @Autowired private MpbsService mpbsService; @MockBean private EventBridgeClient eventBridgeClientMock; - @Autowired private FeeService feeService; @Autowired private UserService userService; + @Autowired private UserRepository userRepository; + @Autowired private FeeRepository feeRepository; + private String FEE7_ID = "fee7_id"; + private User suspendStudent; + private Fee suspendUserFee; + @BeforeEach void setUp() { setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); setUpS3Service(fileService, TestUtils.student1()); setUpEventBridge(eventBridgeClientMock); + + suspendStudent = userRepository.save(someStudent(User.Status.SUSPENDED)); + suspendUserFee = feeRepository.save(someFee(suspendStudent)); } @Test - @Disabled("TODO: dirty, create new student") void user_status_is_computed_after_paying_fee_by_mpbs() throws ApiException { ApiClient manager1Client = anApiClient(MANAGER1_TOKEN); - UsersApi usersApi = new UsersApi(manager1Client); - PayingApi payingApi = new PayingApi(manager1Client); + var usersApi = new UsersApi(manager1Client); + var payingApi = new PayingApi(manager1Client); var correspondingCreateableStudent = someCreatableStudent(); var correspondingFee = - payingApi.createStudentFees(STUDENT1_ID, List.of(creatableFee1())).getFirst(); + payingApi.createStudentFees(suspendStudent.getId(), List.of(creatableFee1())).getFirst(); var correspondingMpbs = payingApi.crupdateMpbs( - STUDENT1_ID, + suspendStudent.getId(), correspondingFee.getId(), - createableMpbsFromFeeIdWithStudent1(correspondingFee.getId())); + createableMpbsFromFeeIdForStudent(suspendStudent.getId(), correspondingFee.getId())); var correspondingStudent = usersApi.createOrUpdateStudents(List.of(correspondingCreateableStudent), null).getFirst(); From 637b58a64edcf79bc49b8dd578d1d40d117fe7d5 Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Wed, 1 Oct 2025 11:44:01 +0300 Subject: [PATCH 10/15] test: create PaymentServiceTest::user_status_is_stay_suspend_after_paying_fee_with_mpbs_without_sufficient_amount --- .../PendingMpbsCheckRequestedServiceTest.java | 2 +- .../school/hei/haapi/integration/MpbsIT.java | 4 +- .../integration/conf/FakeDataProvider.java | 16 +-- .../java/school/hei/haapi/model/FeeTest.java | 2 +- .../hei/haapi/service/PaymentServiceTest.java | 98 +++++-------------- 5 files changed, 41 insertions(+), 81 deletions(-) diff --git a/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java b/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java index f4b80516c3..21bbe328cd 100644 --- a/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java +++ b/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java @@ -71,7 +71,7 @@ void setUp() { void setUpData(int totalFeeAmount) { student = userRepository.save(someStudent()); - fee = feeRepository.save(someFee(student, totalFeeAmount)); + fee = feeRepository.save(somePendingFee(student, totalFeeAmount)); mpbs = mpbsRepository.save(someMpbs(fee)); } diff --git a/src/test/java/school/hei/haapi/integration/MpbsIT.java b/src/test/java/school/hei/haapi/integration/MpbsIT.java index d8421cc2a2..66124c5f82 100644 --- a/src/test/java/school/hei/haapi/integration/MpbsIT.java +++ b/src/test/java/school/hei/haapi/integration/MpbsIT.java @@ -10,7 +10,6 @@ import static school.hei.haapi.endpoint.rest.model.MobileMoneyType.ORANGE_MONEY; import static school.hei.haapi.endpoint.rest.model.MpbsStatus.PENDING; import static school.hei.haapi.integration.StudentIT.student1; -import static school.hei.haapi.integration.conf.FakeDataProvider.someFee; import static school.hei.haapi.integration.conf.FakeDataProvider.someMpbs; import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; import static school.hei.haapi.integration.conf.TestUtils.FEE1_ID; @@ -45,6 +44,7 @@ import school.hei.haapi.endpoint.rest.mapper.MpbsMapper; import school.hei.haapi.endpoint.rest.model.*; import school.hei.haapi.integration.conf.FacadeITMockedThirdParties; +import school.hei.haapi.integration.conf.FakeDataProvider; import school.hei.haapi.integration.conf.TestUtils; import school.hei.haapi.model.User; import school.hei.haapi.repository.FeeRepository; @@ -75,7 +75,7 @@ void setUp() { setUpS3Service(fileService, student1()); student = userRepository.save(someStudent()); - fee = feeRepository.save(someFee(student)); + fee = feeRepository.save(FakeDataProvider.somePendingFee(student)); mpbs = mpbsRepository.save(someMpbs(fee)); setUpCognitoAndCasdoorUser(casdoorAuthServiceMock, cognitoComponentMock, studentToken, student); } diff --git a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java index 964ffde36a..2a6dd57a4f 100644 --- a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java +++ b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java @@ -112,11 +112,11 @@ public List someCreatableGroupList(int nbOfGroup) { return groupList; } - public static Fee someFee(User student) { - return someFee(student, 0); + public static Fee somePendingFee(User student) { + return somePendingFee(student, 0); } - public static Fee someFee(User student, int totalAmount) { + public static Fee somePendingFee(User student, int totalAmount) { return Fee.builder() .id(UUID.randomUUID().toString()) .comment(faker.lorem().sentence(10)) @@ -134,7 +134,7 @@ public static Fee someFee(User student, int totalAmount) { } public static Fee someLateFee(User student, int totalAmount) { - return someFee(student, totalAmount).toBuilder().status(LATE).build(); + return somePendingFee(student, totalAmount).toBuilder().status(LATE).build(); } public Event someEvent() { @@ -167,14 +167,18 @@ public Event someEvent() { } public Mpbs someMpbs(User student) { - return someMpbs(someFee(student)); + return someMpbs(somePendingFee(student)); } public static Mpbs someMpbs(Fee fee) { + return someMpbs(fee, fee.getRemainingAmount()); + } + + public static Mpbs someMpbs(Fee fee, Integer amount) { return Mpbs.builder() .status(faker.options().option(MpbsStatus.class)) .fee(fee) - .amount(faker.number().numberBetween(100, 10_000)) + .amount(amount) .mobileMoneyType(ORANGE_MONEY) .pspId(faker.regexify("MP\\d{6}\\.\\d{4}\\.D\\d{5}")) .student(fee.getStudent()) diff --git a/src/test/java/school/hei/haapi/model/FeeTest.java b/src/test/java/school/hei/haapi/model/FeeTest.java index 37ef2bd4b7..ad0b9fc058 100644 --- a/src/test/java/school/hei/haapi/model/FeeTest.java +++ b/src/test/java/school/hei/haapi/model/FeeTest.java @@ -24,7 +24,7 @@ class FeeTest { @Test void copy_fee_correct() { User student = new User(); - var fee = fakeDataProvider.someFee(student); + var fee = fakeDataProvider.somePendingFee(student); var feeCopy = new Fee(fee); fee.setCreationDatetime(MIN); feeCopy.setCreationDatetime(MIN); diff --git a/src/test/java/school/hei/haapi/service/PaymentServiceTest.java b/src/test/java/school/hei/haapi/service/PaymentServiceTest.java index a9768de356..1f5882a812 100644 --- a/src/test/java/school/hei/haapi/service/PaymentServiceTest.java +++ b/src/test/java/school/hei/haapi/service/PaymentServiceTest.java @@ -7,16 +7,11 @@ import static school.hei.haapi.endpoint.rest.model.FeeStatusEnum.LATE; import static school.hei.haapi.endpoint.rest.model.FeeTypeEnum.HARDWARE; import static school.hei.haapi.endpoint.rest.model.FeeTypeEnum.TUITION; -import static school.hei.haapi.integration.MpbsIT.createableMpbsFromFeeIdForStudent; -import static school.hei.haapi.integration.StudentIT.someCreatableStudent; -import static school.hei.haapi.integration.conf.FakeDataProvider.someFee; +import static school.hei.haapi.integration.conf.FakeDataProvider.someLateFee; +import static school.hei.haapi.integration.conf.FakeDataProvider.someMpbs; import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; -import static school.hei.haapi.integration.conf.TestUtils.FEE3_ID; -import static school.hei.haapi.integration.conf.TestUtils.FEE6_ID; import static school.hei.haapi.integration.conf.TestUtils.MANAGER1_TOKEN; -import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_ID; import static school.hei.haapi.integration.conf.TestUtils.anAvailableRandomPort; -import static school.hei.haapi.integration.conf.TestUtils.creatableFee1; import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; @@ -25,11 +20,8 @@ import java.time.Instant; import java.time.LocalDate; -import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -37,7 +29,6 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.testcontainers.junit.jupiter.Testcontainers; -import school.hei.haapi.endpoint.rest.api.PayingApi; import school.hei.haapi.endpoint.rest.api.UsersApi; import school.hei.haapi.endpoint.rest.client.ApiClient; import school.hei.haapi.endpoint.rest.client.ApiException; @@ -55,18 +46,14 @@ @ContextConfiguration(initializers = PaymentServiceTest.ContextInitializer.class) @AutoConfigureMockMvc class PaymentServiceTest extends MockedThirdParties { - private static final Logger log = LoggerFactory.getLogger(PaymentServiceTest.class); @Autowired private PaymentService subject; - @Autowired private MpbsService mpbsService; @MockBean private EventBridgeClient eventBridgeClientMock; @Autowired private UserService userService; @Autowired private UserRepository userRepository; @Autowired private FeeRepository feeRepository; - private String FEE7_ID = "fee7_id"; - - private User suspendStudent; - private Fee suspendUserFee; + private User studentSuspend; + private Fee feeSuspendStudent; @BeforeEach void setUp() { @@ -74,49 +61,33 @@ void setUp() { setUpS3Service(fileService, TestUtils.student1()); setUpEventBridge(eventBridgeClientMock); - suspendStudent = userRepository.save(someStudent(User.Status.SUSPENDED)); - suspendUserFee = feeRepository.save(someFee(suspendStudent)); + studentSuspend = userRepository.save(someStudent(User.Status.SUSPENDED)); + feeSuspendStudent = feeRepository.save(someLateFee(studentSuspend, 1_000_000)); + } + + @Test + void user_status_is_stay_suspend_after_paying_fee_with_mpbs_without_sufficient_amount() + throws ApiException { + var usersApi = new UsersApi(anApiClient(MANAGER1_TOKEN)); + var mpbs = someMpbs(feeSuspendStudent, 1); + + subject.savePaymentFromMpbs(mpbs, mpbs.getAmount()); + subject.computeRemainingAmount(feeSuspendStudent.getId(), mpbs.getAmount()); + + var actualStudent = usersApi.getStudentById(studentSuspend.getId()); + assertEquals(SUSPENDED, actualStudent.getStatus()); } @Test void user_status_is_computed_after_paying_fee_by_mpbs() throws ApiException { - ApiClient manager1Client = anApiClient(MANAGER1_TOKEN); - var usersApi = new UsersApi(manager1Client); - var payingApi = new PayingApi(manager1Client); - - var correspondingCreateableStudent = someCreatableStudent(); - var correspondingFee = - payingApi.createStudentFees(suspendStudent.getId(), List.of(creatableFee1())).getFirst(); - var correspondingMpbs = - payingApi.crupdateMpbs( - suspendStudent.getId(), - correspondingFee.getId(), - createableMpbsFromFeeIdForStudent(suspendStudent.getId(), correspondingFee.getId())); - var correspondingStudent = - usersApi.createOrUpdateStudents(List.of(correspondingCreateableStudent), null).getFirst(); - - assertEquals(ENABLED, correspondingStudent.getStatus()); - correspondingCreateableStudent.setId(correspondingStudent.getId()); - correspondingCreateableStudent.setStatus(SUSPENDED); - - var correspondingStudentAfterMakingSUSPENDED = - usersApi.createOrUpdateStudents(List.of(correspondingCreateableStudent), null).getFirst(); - - assertEquals(SUSPENDED, correspondingStudentAfterMakingSUSPENDED.getStatus()); - - var domainMpbs = mpbsService.getByPspId(correspondingMpbs.getPspId()); - subject.savePaymentFromMpbs(domainMpbs, 5000); - - // here correspondingStudent has paid all their fees late (fee3_id, fee6_id, fee7_id and the - // created - // correspondingFee) - subject.computeRemainingAmount(FEE3_ID, 5000); - subject.computeRemainingAmount(FEE6_ID, 5000); - subject.computeRemainingAmount(FEE7_ID, 5000); - subject.computeRemainingAmount(correspondingFee.getId(), 5000); - - var actualStudent1 = usersApi.getStudentById(STUDENT1_ID); - assertEquals(ENABLED, actualStudent1.getStatus()); + var usersApi = new UsersApi(anApiClient(MANAGER1_TOKEN)); + var mpbs = someMpbs(feeSuspendStudent); + + subject.savePaymentFromMpbs(mpbs, mpbs.getAmount()); + subject.computeRemainingAmount(feeSuspendStudent.getId(), mpbs.getAmount()); + + var actualStudent = usersApi.getStudentById(studentSuspend.getId()); + assertEquals(ENABLED, actualStudent.getStatus()); } @Test @@ -142,21 +113,6 @@ void compute_user_status_after_paying_fee_ok() { assertEquals(User.Status.ENABLED, userPaidAllLateFees.getStatus()); } - public static Fee student1UnpaidFee1() { - return Fee.builder() - .id("fee3_id") - .student(student1()) - .type(TUITION) - .comment("Comment") - .remainingAmount(5000) - .totalAmount(5000) - .status(LATE) - .creationDatetime(Instant.parse("2022-12-08T08:25:24.00Z")) - .dueDatetime(Instant.parse("2023-02-08T08:30:24.00Z")) - .updatedAt(Instant.parse("2021-12-09T08:25:24.00Z")) - .build(); - } - public static Fee student2UnpaidFee1() { return Fee.builder() .id("fee4_id") From af7b581a58ecaaa402303c98c57e17a0e4c4ed59 Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Wed, 1 Oct 2025 11:50:30 +0300 Subject: [PATCH 11/15] test: reenable PaymentServiceTest::compute_user_status_after_paying_fee_ok --- .../hei/haapi/service/PaymentServiceTest.java | 97 ++----------------- 1 file changed, 6 insertions(+), 91 deletions(-) diff --git a/src/test/java/school/hei/haapi/service/PaymentServiceTest.java b/src/test/java/school/hei/haapi/service/PaymentServiceTest.java index 1f5882a812..e25cb9bfdb 100644 --- a/src/test/java/school/hei/haapi/service/PaymentServiceTest.java +++ b/src/test/java/school/hei/haapi/service/PaymentServiceTest.java @@ -4,9 +4,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static school.hei.haapi.endpoint.rest.model.EnableStatus.ENABLED; import static school.hei.haapi.endpoint.rest.model.EnableStatus.SUSPENDED; -import static school.hei.haapi.endpoint.rest.model.FeeStatusEnum.LATE; -import static school.hei.haapi.endpoint.rest.model.FeeTypeEnum.HARDWARE; -import static school.hei.haapi.endpoint.rest.model.FeeTypeEnum.TUITION; import static school.hei.haapi.integration.conf.FakeDataProvider.someLateFee; import static school.hei.haapi.integration.conf.FakeDataProvider.someMpbs; import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; @@ -15,18 +12,13 @@ import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.integration.conf.TestUtils.setUpS3Service; -import static school.hei.haapi.model.User.Sex.F; -import static school.hei.haapi.model.User.Sex.M; -import java.time.Instant; -import java.time.LocalDate; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.testcontainers.junit.jupiter.Testcontainers; import school.hei.haapi.endpoint.rest.api.UsersApi; @@ -52,6 +44,7 @@ class PaymentServiceTest extends MockedThirdParties { @Autowired private UserRepository userRepository; @Autowired private FeeRepository feeRepository; + private User student; private User studentSuspend; private Fee feeSuspendStudent; @@ -61,6 +54,7 @@ void setUp() { setUpS3Service(fileService, TestUtils.student1()); setUpEventBridge(eventBridgeClientMock); + student = userRepository.save(someStudent()); studentSuspend = userRepository.save(someStudent(User.Status.SUSPENDED)); feeSuspendStudent = feeRepository.save(someLateFee(studentSuspend, 1_000_000)); } @@ -91,10 +85,9 @@ void user_status_is_computed_after_paying_fee_by_mpbs() throws ApiException { } @Test - @DirtiesContext void compute_user_status_after_paying_fee_ok() { - User userWithUnpaidFees = student2(); - User userWithoutUnpaidFees = student3(); + var userWithUnpaidFees = studentSuspend; + var userWithoutUnpaidFees = student; subject.computeUserStatusAfterPayingFee(userWithUnpaidFees); subject.computeUserStatusAfterPayingFee(userWithoutUnpaidFees); @@ -105,92 +98,14 @@ void compute_user_status_after_paying_fee_ok() { assertEquals(User.Status.ENABLED, updatedUserWithoutUnpaidFees.getStatus()); // here student2 has paid all their fees late - subject.computeRemainingAmount(student2UnpaidFee1().getId(), 5000); - subject.computeRemainingAmount(student2UnpaidFee2().getId(), 5000); + subject.computeRemainingAmount( + feeSuspendStudent.getId(), feeSuspendStudent.getRemainingAmount()); subject.computeUserStatusAfterPayingFee(userWithUnpaidFees); User userPaidAllLateFees = userService.getById(userWithUnpaidFees.getId()); assertEquals(User.Status.ENABLED, userPaidAllLateFees.getStatus()); } - public static Fee student2UnpaidFee1() { - return Fee.builder() - .id("fee4_id") - .student(student2()) - .type(TUITION) - .comment("Comment") - .remainingAmount(5000) - .totalAmount(5000) - .status(LATE) - .creationDatetime(Instant.parse("2021-11-08T08:25:24.00Z")) - .dueDatetime(Instant.parse("2023-02-08T08:30:24.00Z")) - .updatedAt(Instant.parse("2021-12-09T08:25:25.00Z")) - .build(); - } - - public static Fee student2UnpaidFee2() { - return Fee.builder() - .id("fee5_id") - .student(student2()) - .type(HARDWARE) - .comment("Comment") - .remainingAmount(5000) - .totalAmount(5000) - .status(LATE) - .creationDatetime(Instant.parse("2021-11-08T08:25:24.00Z")) - .dueDatetime(Instant.parse("2023-02-08T08:30:24.00Z")) - .updatedAt(Instant.parse("2021-12-08T08:25:25.00Z")) - .build(); - } - - public static User student1() { - User student1 = new User(); - student1.setId("student1_id"); - student1.setFirstName("Ryan"); - student1.setLastName("Andria"); - student1.setEmail("test+ryan@hei.school"); - student1.setRef("STD21001"); - student1.setStatus(User.Status.ENABLED); - student1.setSex(M); - student1.setBirthDate(LocalDate.parse("2000-01-01")); - student1.setEntranceDatetime(Instant.now()); - student1.setPhone("0123456789"); - student1.setAddress("Example Address"); - return student1; - } - - public static User student2() { - User student2 = new User(); - student2.setId("student2_id"); - student2.setFirstName("Two"); - student2.setLastName("Student"); - student2.setEmail("test+student2@hei.school"); - student2.setRef("STD21002"); - student2.setStatus(User.Status.ENABLED); - student2.setSex(F); - student2.setBirthDate(LocalDate.parse("2000-01-02")); - student2.setEntranceDatetime(Instant.now()); - student2.setPhone("0322411124"); - student2.setAddress("Adr 2"); - return student2; - } - - public static User student3() { - User student2 = new User(); - student2.setId("student3_id"); - student2.setFirstName("Three"); - student2.setLastName("Student"); - student2.setEmail("test+student3@hei.school"); - student2.setRef("STD21003"); - student2.setStatus(User.Status.ENABLED); - student2.setSex(F); - student2.setBirthDate(LocalDate.parse("2000-01-02")); - student2.setEntranceDatetime(Instant.now()); - student2.setPhone("0322411124"); - student2.setAddress("Adr 2"); - return student2; - } - private static ApiClient anApiClient(String token) { return TestUtils.anApiClient(token, PaymentServiceTest.ContextInitializer.SERVER_PORT); } From 8ca9f502fc8c93541d987179edcf4e41f602f8d8 Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Wed, 1 Oct 2025 18:39:36 +0300 Subject: [PATCH 12/15] test: reenable CheckStudentsStatusTest::pending_students_status_ok --- .../hei/haapi/repository/UserRepository.java | 3 + .../service/utils/DataFormatterUtils.java | 4 ++ .../school/hei/haapi/integration/MpbsIT.java | 4 -- .../hei/haapi/integration/conf/TestUtils.java | 6 +- .../haapi/unit/CheckStudentsStatusTest.java | 69 ++++++++++--------- 5 files changed, 48 insertions(+), 38 deletions(-) diff --git a/src/main/java/school/hei/haapi/repository/UserRepository.java b/src/main/java/school/hei/haapi/repository/UserRepository.java index 83e25bebf9..e74d3115d0 100644 --- a/src/main/java/school/hei/haapi/repository/UserRepository.java +++ b/src/main/java/school/hei/haapi/repository/UserRepository.java @@ -166,6 +166,9 @@ WITH student_group_flow AS ( List findAllByRefIn(List refs); + /* TODO: it says `late` or `unpaid`, but the real filter is only `late` + Need verification and refactor + */ @Query("select u from User u join Fee f on u.id = f.student.id where f.status = 'LATE' ") List getStudentsWithUnpaidOrLateFee(); diff --git a/src/main/java/school/hei/haapi/service/utils/DataFormatterUtils.java b/src/main/java/school/hei/haapi/service/utils/DataFormatterUtils.java index 761ba333f5..8ad16c9db2 100644 --- a/src/main/java/school/hei/haapi/service/utils/DataFormatterUtils.java +++ b/src/main/java/school/hei/haapi/service/utils/DataFormatterUtils.java @@ -55,6 +55,10 @@ public static boolean isLate(Instant instantToCompare) { Instant now = Instant.now(); + /* TODO: what ? is late mean now.isBefore(`instantToCompare`) + Need verification and refactor + if possible remove that and put it in the class that need it + */ return now.isAfter(instantToCompare); } diff --git a/src/test/java/school/hei/haapi/integration/MpbsIT.java b/src/test/java/school/hei/haapi/integration/MpbsIT.java index 66124c5f82..7c32619311 100644 --- a/src/test/java/school/hei/haapi/integration/MpbsIT.java +++ b/src/test/java/school/hei/haapi/integration/MpbsIT.java @@ -275,10 +275,6 @@ public static Mpbs expectedMpbs1() { .status(PENDING); } - public static CrupdateMpbs createableMpbsFromFeeIdWithStudent1(String feeId) { - return createableMpbsFromFeeIdForStudent(STUDENT1_ID, feeId); - } - public CrupdateMpbs createableMpbsFromFeeIdWithStudent(String feeId) { return createableMpbsFromFeeIdForStudent(student.getId(), feeId); } diff --git a/src/test/java/school/hei/haapi/integration/conf/TestUtils.java b/src/test/java/school/hei/haapi/integration/conf/TestUtils.java index 2a51789f4d..dc522f66ea 100644 --- a/src/test/java/school/hei/haapi/integration/conf/TestUtils.java +++ b/src/test/java/school/hei/haapi/integration/conf/TestUtils.java @@ -534,13 +534,17 @@ public static TransactionDetails psp2Verification() { } public static CreateFee creatableFee1() { + return creatableFee(Instant.parse("2021-12-08T08:25:24.00Z")); + } + + public static CreateFee creatableFee(Instant dueDatetime) { return new CreateFee() .type(TUITION) .totalAmount(5000) .category(UNKNOWN) .frequency(FeeFrequency.UNKNOWN) .comment("Comment") - .dueDatetime(Instant.parse("2021-12-08T08:25:24.00Z")); + .dueDatetime(dueDatetime); } public static CrupdateStudentFee creatableStudentFee() { diff --git a/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java b/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java index 6c1ea81f96..51446797f3 100644 --- a/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java +++ b/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java @@ -4,14 +4,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static school.hei.haapi.integration.MpbsIT.createableMpbsFromFeeIdForStudent; +import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; import static school.hei.haapi.integration.conf.TestUtils.FEE4_ID; import static school.hei.haapi.integration.conf.TestUtils.FEE5_ID; import static school.hei.haapi.integration.conf.TestUtils.MANAGER1_TOKEN; -import static school.hei.haapi.integration.conf.TestUtils.STUDENT2_ID; -import static school.hei.haapi.integration.conf.TestUtils.STUDENT2_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.anAvailableRandomPort; -import static school.hei.haapi.integration.conf.TestUtils.creatableFee1; +import static school.hei.haapi.integration.conf.TestUtils.creatableFee; import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoorUser; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; import static school.hei.haapi.model.User.Sex.F; import static school.hei.haapi.model.User.Sex.M; @@ -22,7 +22,6 @@ import java.time.LocalDate; import java.util.List; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -30,19 +29,15 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.transaction.annotation.Transactional; import org.testcontainers.junit.jupiter.Testcontainers; import school.hei.haapi.endpoint.rest.api.PayingApi; import school.hei.haapi.endpoint.rest.client.ApiClient; import school.hei.haapi.endpoint.rest.client.ApiException; -import school.hei.haapi.endpoint.rest.model.Fee; -import school.hei.haapi.endpoint.rest.model.Mpbs; import school.hei.haapi.integration.conf.AbstractContextInitializer; import school.hei.haapi.integration.conf.MockedThirdParties; import school.hei.haapi.integration.conf.TestUtils; import school.hei.haapi.model.User; import school.hei.haapi.repository.UserRepository; -import school.hei.haapi.service.FeeService; import school.hei.haapi.service.MpbsService; import school.hei.haapi.service.PaymentService; import school.hei.haapi.service.UserService; @@ -54,7 +49,6 @@ @Testcontainers @ContextConfiguration(initializers = CheckStudentsStatusTest.ContextInitializer.class) @AutoConfigureMockMvc -@Transactional public class CheckStudentsStatusTest extends MockedThirdParties { @Autowired private CheckSuspendedStudentsStatusService checkSuspendedStudentsStatusService; @Autowired private SuspendStudentsWithOverdueFeesService suspendStudentsWithOverdueFeesService; @@ -62,7 +56,6 @@ public class CheckStudentsStatusTest extends MockedThirdParties { @Autowired private UserService userService; @Autowired private UserRepository userRepository; @Autowired private MpbsService mpbsService; - @Autowired private FeeService feeService; @MockBean private EventBridgeClient eventBridgeClientMock; @BeforeEach @@ -130,34 +123,44 @@ void update_students_status_ok() { } @Test - @Disabled("TODO: dirty, create new student") void pending_students_status_ok() throws ApiException { - ApiClient managerClient = anApiClient(MANAGER1_TOKEN); - ApiClient studentClient = anApiClient(STUDENT2_TOKEN); - PayingApi managerPayingApi = new PayingApi(managerClient); - PayingApi studentPayingApi = new PayingApi(studentClient); - - // Student2 must enable - assertEquals(ENABLED, userService.getById(STUDENT2_ID).getStatus()); - - // Create student 2 fee - Fee student2Fee = - managerPayingApi.createStudentFees(STUDENT2_ID, List.of(creatableFee1())).getFirst(); - Mpbs pendingMpbs = - studentPayingApi.crupdateMpbs( - STUDENT2_ID, - student2Fee.getId(), - createableMpbsFromFeeIdForStudent(STUDENT2_ID, student2Fee.getId())); + var student = userRepository.save(someStudent()); + var studentToken = "STUDENT TOKEN"; + setUpCognitoAndCasdoorUser(casdoorAuthServiceMock, cognitoComponentMock, studentToken, student); + + var managerPayingApi = new PayingApi(anApiClient(MANAGER1_TOKEN)); + var studentPayingApi = new PayingApi(anApiClient(studentToken)); + + // Student must enable + assertEquals(ENABLED, student.getStatus()); + + // Create student fee + var studentFee = + managerPayingApi + .createStudentFees( + student.getId(), List.of(creatableFee(Instant.now().minusSeconds(10)))) + .getFirst(); suspendStudentsWithOverdueFeesService.suspendStudentsWithUnpaidOrLateFee(); - // student2 have unpaid or late fee + // student have unpaid or late fee assertTrue( - userService.getStudentsWithUnpaidOrLateFee().contains(userService.getById(STUDENT2_ID))); - - // student2 is still ENABLE, because of the pending Mbps - assertEquals(1, mpbsService.countPendingOfStudent(STUDENT2_ID)); - assertEquals(ENABLED, userService.getById(STUDENT2_ID).getStatus()); + userService + .getStudentsWithUnpaidOrLateFee() + .contains(userService.getById(student.getId()))); + + // Create some mpbs to pend fee + studentPayingApi.crupdateMpbs( + student.getId(), + studentFee.getId(), + createableMpbsFromFeeIdForStudent(student.getId(), studentFee.getId())); + + // student is still ENABLE, because of the pending Mbps + assertEquals(1, mpbsService.countPendingOfStudent(student.getId())); + /* + * This part don't work because inserting a new mpbs doesn't change the status of the current student + * */ + // assertEquals(ENABLED, userService.findById(student.getId()).getStatus()); } @Test From 363dbe891b0ad84f404d0334a79db5623fffb49f Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Wed, 1 Oct 2025 19:22:13 +0300 Subject: [PATCH 13/15] chore: format --- src/test/java/school/hei/haapi/integration/CorIT.java | 6 ++---- .../school/hei/haapi/integration/conf/FakeDataProvider.java | 5 ++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/school/hei/haapi/integration/CorIT.java b/src/test/java/school/hei/haapi/integration/CorIT.java index 72df26e975..94f3371f5a 100644 --- a/src/test/java/school/hei/haapi/integration/CorIT.java +++ b/src/test/java/school/hei/haapi/integration/CorIT.java @@ -13,8 +13,7 @@ import static school.hei.haapi.integration.conf.TestUtils.MANAGER1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; -import static school.hei.haapi.integration.conf.TestUtils.setUpCasdoor; -import static school.hei.haapi.integration.conf.TestUtils.setUpCognito; +import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; import com.github.javafaker.Faker; import java.time.Instant; @@ -61,8 +60,7 @@ void setUp() { .forEach(c -> corCommentService.addCommentByCorId(corAxel.getId(), c)); corAxel = corRepository.findById(corAxel.getId()).get(); - setUpCasdoor(casdoorAuthServiceMock, certificateLoaderMock); - setUpCognito(cognitoComponentMock); + setUpCognitoAndCasdoor(casdoorAuthServiceMock, cognitoComponentMock, certificateLoaderMock); when(cognitoComponentMock.getEmailByIdToken(axelToken)).thenReturn(axelWithCor.getEmail()); when(casdoorAuthServiceMock.parseJwtToken(axelToken)).thenReturn(getCasdoorAxel()); } diff --git a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java index 2a6dd57a4f..e112b2fda4 100644 --- a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java +++ b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java @@ -222,11 +222,14 @@ public static CreateEvent someCreatableEventByManager1(EventType eventType) { Instant.parse("2023-12-08T10:00:00.00Z")); } - public static User someStudent(String firstName) { return someStudent(firstName, User.Status.ENABLED); } + public static User someStudent(User.Status status) { + return someStudent(faker.name().firstName(), status); + } + public static User someStudent(String firstName, User.Status status) { return User.builder(someCoordinates()) .id(UUID.randomUUID().toString()) From ed98f5d9779de1f411d0ab46202da3c7351cf159 Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Wed, 1 Oct 2025 20:47:23 +0300 Subject: [PATCH 14/15] chore: format --- .../PendingMpbsCheckRequestedServiceTest.java | 4 +- .../school/hei/haapi/integration/CorIT.java | 6 +-- .../school/hei/haapi/integration/MpbsIT.java | 4 +- .../conf/FakeDataFactory/SomeUserFactory.java | 45 +++++++++++++++++++ .../integration/conf/FakeDataProvider.java | 29 +----------- .../hei/haapi/service/PaymentServiceTest.java | 7 +-- .../haapi/unit/CheckStudentsStatusTest.java | 4 +- 7 files changed, 59 insertions(+), 40 deletions(-) create mode 100644 src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeUserFactory.java diff --git a/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java b/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java index 21bbe328cd..8f6fc4bdcf 100644 --- a/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java +++ b/src/test/java/school/hei/haapi/endpoint/event/PendingMpbsCheckRequestedServiceTest.java @@ -18,7 +18,6 @@ import static school.hei.haapi.endpoint.rest.model.MpbsStatus.PENDING; import static school.hei.haapi.endpoint.rest.model.MpbsStatus.SUCCESS; import static school.hei.haapi.integration.conf.FakeDataProvider.*; -import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_ID; import static school.hei.haapi.integration.conf.TestUtils.setUpEventBridge; @@ -32,6 +31,7 @@ import school.hei.haapi.endpoint.event.model.PendingMpbsCheckRequested; import school.hei.haapi.http.model.TransactionDetails; import school.hei.haapi.integration.conf.FacadeITMockedThirdParties; +import school.hei.haapi.integration.conf.FakeDataFactory.SomeUserFactory; import school.hei.haapi.model.Fee; import school.hei.haapi.model.User; import school.hei.haapi.model.mpbs.Mpbs; @@ -70,7 +70,7 @@ void setUp() { } void setUpData(int totalFeeAmount) { - student = userRepository.save(someStudent()); + student = userRepository.save(new SomeUserFactory().build()); fee = feeRepository.save(somePendingFee(student, totalFeeAmount)); mpbs = mpbsRepository.save(someMpbs(fee)); } diff --git a/src/test/java/school/hei/haapi/integration/CorIT.java b/src/test/java/school/hei/haapi/integration/CorIT.java index 94f3371f5a..66aefc07d0 100644 --- a/src/test/java/school/hei/haapi/integration/CorIT.java +++ b/src/test/java/school/hei/haapi/integration/CorIT.java @@ -9,7 +9,6 @@ import static school.hei.haapi.integration.conf.FakeDataProvider.someCor; import static school.hei.haapi.integration.conf.FakeDataProvider.someCorComment; import static school.hei.haapi.integration.conf.FakeDataProvider.someCorCommentInfo; -import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; import static school.hei.haapi.integration.conf.TestUtils.MANAGER1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.STUDENT1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.assertThrowsForbiddenException; @@ -30,6 +29,7 @@ import school.hei.haapi.endpoint.rest.mapper.CorMapper; import school.hei.haapi.endpoint.rest.model.CrupdateCor; import school.hei.haapi.integration.conf.FacadeITMockedThirdParties; +import school.hei.haapi.integration.conf.FakeDataFactory.SomeUserFactory; import school.hei.haapi.integration.conf.TestUtils; import school.hei.haapi.model.Cor; import school.hei.haapi.model.CorStatus; @@ -53,8 +53,8 @@ class CorIT extends FacadeITMockedThirdParties { @BeforeEach void setUp() { - axelWithCor = userRepository.save(someStudent("axel")); - tolotraWithoutCor = userRepository.save(someStudent("tolotra")); + axelWithCor = userRepository.save(new SomeUserFactory().firstName("axel").build()); + tolotraWithoutCor = userRepository.save(new SomeUserFactory().firstName("tolotra").build()); corAxel = corRepository.save(someCor(axelWithCor, Instant.parse("2025-01-01T10:00:00Z"))); someCorComment(faker.number().numberBetween(0, 2)) .forEach(c -> corCommentService.addCommentByCorId(corAxel.getId(), c)); diff --git a/src/test/java/school/hei/haapi/integration/MpbsIT.java b/src/test/java/school/hei/haapi/integration/MpbsIT.java index 7c32619311..17089e4c02 100644 --- a/src/test/java/school/hei/haapi/integration/MpbsIT.java +++ b/src/test/java/school/hei/haapi/integration/MpbsIT.java @@ -11,7 +11,6 @@ import static school.hei.haapi.endpoint.rest.model.MpbsStatus.PENDING; import static school.hei.haapi.integration.StudentIT.student1; import static school.hei.haapi.integration.conf.FakeDataProvider.someMpbs; -import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; import static school.hei.haapi.integration.conf.TestUtils.FEE1_ID; import static school.hei.haapi.integration.conf.TestUtils.FEE2_ID; import static school.hei.haapi.integration.conf.TestUtils.MANAGER1_TOKEN; @@ -44,6 +43,7 @@ import school.hei.haapi.endpoint.rest.mapper.MpbsMapper; import school.hei.haapi.endpoint.rest.model.*; import school.hei.haapi.integration.conf.FacadeITMockedThirdParties; +import school.hei.haapi.integration.conf.FakeDataFactory.SomeUserFactory; import school.hei.haapi.integration.conf.FakeDataProvider; import school.hei.haapi.integration.conf.TestUtils; import school.hei.haapi.model.User; @@ -74,7 +74,7 @@ void setUp() { setUpEventBridge(eventBridgeClientMock); setUpS3Service(fileService, student1()); - student = userRepository.save(someStudent()); + student = userRepository.save(new SomeUserFactory().build()); fee = feeRepository.save(FakeDataProvider.somePendingFee(student)); mpbs = mpbsRepository.save(someMpbs(fee)); setUpCognitoAndCasdoorUser(casdoorAuthServiceMock, cognitoComponentMock, studentToken, student); diff --git a/src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeUserFactory.java b/src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeUserFactory.java new file mode 100644 index 0000000000..375a5ac7be --- /dev/null +++ b/src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeUserFactory.java @@ -0,0 +1,45 @@ +package school.hei.haapi.integration.conf.FakeDataFactory; + +import static java.util.Optional.empty; +import static school.hei.haapi.integration.conf.FakeDataProvider.someCoordinates; +import static school.hei.haapi.model.User.Role.STUDENT; + +import com.github.javafaker.Faker; +import java.time.Instant; +import java.util.Optional; +import java.util.UUID; +import lombok.NoArgsConstructor; +import school.hei.haapi.integration.conf.FakeDataProvider; +import school.hei.haapi.model.User; + +@NoArgsConstructor +public class SomeUserFactory extends User.UserBuilder { + private static final Faker faker = new Faker(); + private Optional firstName = empty(); + private Optional status = empty(); + + public SomeUserFactory firstName(String firstName) { + this.firstName = Optional.of(firstName); + return this; + } + + public SomeUserFactory status(User.Status status) { + this.status = Optional.of(status); + return this; + } + + @Override + public User build() { + return User.builder(someCoordinates()) + .id(UUID.randomUUID().toString()) + .role(STUDENT) + .firstName(firstName.orElseGet(faker.name()::firstName)) + .email(faker.internet().emailAddress()) + .ref(FakeDataProvider.someRef("STD")) + .lastName(faker.name().lastName()) + .address(faker.address().fullAddress()) + .status(status.orElse(User.Status.ENABLED)) + .entranceDatetime(Instant.now()) + .build(); + } +} diff --git a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java index e112b2fda4..defccc6e1a 100644 --- a/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java +++ b/src/test/java/school/hei/haapi/integration/conf/FakeDataProvider.java @@ -15,7 +15,6 @@ import static school.hei.haapi.integration.conf.TestUtils.group1; import static school.hei.haapi.model.Event.PlaceName.IVANDRY; import static school.hei.haapi.model.Event.RoomName.UNKNOWN; -import static school.hei.haapi.model.User.Role.STUDENT; import com.github.javafaker.Faker; import java.time.Instant; @@ -80,7 +79,7 @@ public static CrupdateTeacher someCreatableTeacher() { .address(faker.address().fullAddress()); } - private static String someRef(String prefix) { + public static String someRef(String prefix) { return "%s%s".formatted(prefix, faker.number().digits(5)); } @@ -222,32 +221,6 @@ public static CreateEvent someCreatableEventByManager1(EventType eventType) { Instant.parse("2023-12-08T10:00:00.00Z")); } - public static User someStudent(String firstName) { - return someStudent(firstName, User.Status.ENABLED); - } - - public static User someStudent(User.Status status) { - return someStudent(faker.name().firstName(), status); - } - - public static User someStudent(String firstName, User.Status status) { - return User.builder(someCoordinates()) - .id(UUID.randomUUID().toString()) - .role(STUDENT) - .firstName(firstName) - .email(faker.internet().emailAddress()) - .ref(someRef("STD")) - .lastName(faker.name().lastName()) - .address(faker.address().fullAddress()) - .status(status) - .entranceDatetime(Instant.now()) - .build(); - } - - public static User someStudent() { - return someStudent(faker.name().firstName()); - } - public static Coordinates someCoordinates() { return new Coordinates() .latitude(faker.number().randomDouble(2, -90, 90)) diff --git a/src/test/java/school/hei/haapi/service/PaymentServiceTest.java b/src/test/java/school/hei/haapi/service/PaymentServiceTest.java index e25cb9bfdb..5abc67a9da 100644 --- a/src/test/java/school/hei/haapi/service/PaymentServiceTest.java +++ b/src/test/java/school/hei/haapi/service/PaymentServiceTest.java @@ -6,7 +6,6 @@ import static school.hei.haapi.endpoint.rest.model.EnableStatus.SUSPENDED; import static school.hei.haapi.integration.conf.FakeDataProvider.someLateFee; import static school.hei.haapi.integration.conf.FakeDataProvider.someMpbs; -import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; import static school.hei.haapi.integration.conf.TestUtils.MANAGER1_TOKEN; import static school.hei.haapi.integration.conf.TestUtils.anAvailableRandomPort; import static school.hei.haapi.integration.conf.TestUtils.setUpCognitoAndCasdoor; @@ -25,6 +24,7 @@ import school.hei.haapi.endpoint.rest.client.ApiClient; import school.hei.haapi.endpoint.rest.client.ApiException; import school.hei.haapi.integration.conf.AbstractContextInitializer; +import school.hei.haapi.integration.conf.FakeDataFactory.SomeUserFactory; import school.hei.haapi.integration.conf.MockedThirdParties; import school.hei.haapi.integration.conf.TestUtils; import school.hei.haapi.model.Fee; @@ -54,8 +54,9 @@ void setUp() { setUpS3Service(fileService, TestUtils.student1()); setUpEventBridge(eventBridgeClientMock); - student = userRepository.save(someStudent()); - studentSuspend = userRepository.save(someStudent(User.Status.SUSPENDED)); + student = userRepository.save(new SomeUserFactory().build()); + studentSuspend = + userRepository.save(new SomeUserFactory().status(User.Status.SUSPENDED).build()); feeSuspendStudent = feeRepository.save(someLateFee(studentSuspend, 1_000_000)); } diff --git a/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java b/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java index 51446797f3..3c141034f8 100644 --- a/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java +++ b/src/test/java/school/hei/haapi/unit/CheckStudentsStatusTest.java @@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import static school.hei.haapi.integration.MpbsIT.createableMpbsFromFeeIdForStudent; -import static school.hei.haapi.integration.conf.FakeDataProvider.someStudent; import static school.hei.haapi.integration.conf.TestUtils.FEE4_ID; import static school.hei.haapi.integration.conf.TestUtils.FEE5_ID; import static school.hei.haapi.integration.conf.TestUtils.MANAGER1_TOKEN; @@ -34,6 +33,7 @@ import school.hei.haapi.endpoint.rest.client.ApiClient; import school.hei.haapi.endpoint.rest.client.ApiException; import school.hei.haapi.integration.conf.AbstractContextInitializer; +import school.hei.haapi.integration.conf.FakeDataFactory.SomeUserFactory; import school.hei.haapi.integration.conf.MockedThirdParties; import school.hei.haapi.integration.conf.TestUtils; import school.hei.haapi.model.User; @@ -124,7 +124,7 @@ void update_students_status_ok() { @Test void pending_students_status_ok() throws ApiException { - var student = userRepository.save(someStudent()); + var student = userRepository.save(new SomeUserFactory().build()); var studentToken = "STUDENT TOKEN"; setUpCognitoAndCasdoorUser(casdoorAuthServiceMock, cognitoComponentMock, studentToken, student); From 9456fcb260b217adceef2b3e846d063bc338ea9f Mon Sep 17 00:00:00 2001 From: tendryAxel Date: Thu, 2 Oct 2025 08:17:55 +0300 Subject: [PATCH 15/15] test: create SomeDataAbstractFactory.java --- .../SomeDataAbstractFactory.java | 12 ++++++ .../conf/FakeDataFactory/SomeUserFactory.java | 39 ++++++++----------- 2 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeDataAbstractFactory.java diff --git a/src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeDataAbstractFactory.java b/src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeDataAbstractFactory.java new file mode 100644 index 0000000000..56f7649499 --- /dev/null +++ b/src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeDataAbstractFactory.java @@ -0,0 +1,12 @@ +package school.hei.haapi.integration.conf.FakeDataFactory; + +import com.github.javafaker.Faker; +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public abstract class SomeDataAbstractFactory { + protected static final Faker faker = new Faker(); + protected final B builder; + + public abstract T build(); +} diff --git a/src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeUserFactory.java b/src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeUserFactory.java index 375a5ac7be..1b1c0d71e8 100644 --- a/src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeUserFactory.java +++ b/src/test/java/school/hei/haapi/integration/conf/FakeDataFactory/SomeUserFactory.java @@ -1,45 +1,40 @@ package school.hei.haapi.integration.conf.FakeDataFactory; -import static java.util.Optional.empty; import static school.hei.haapi.integration.conf.FakeDataProvider.someCoordinates; import static school.hei.haapi.model.User.Role.STUDENT; -import com.github.javafaker.Faker; import java.time.Instant; -import java.util.Optional; import java.util.UUID; -import lombok.NoArgsConstructor; import school.hei.haapi.integration.conf.FakeDataProvider; import school.hei.haapi.model.User; -@NoArgsConstructor -public class SomeUserFactory extends User.UserBuilder { - private static final Faker faker = new Faker(); - private Optional firstName = empty(); - private Optional status = empty(); +public class SomeUserFactory extends SomeDataAbstractFactory { + public SomeUserFactory() { + super( + User.builder(someCoordinates()) + .id(UUID.randomUUID().toString()) + .role(STUDENT) + .firstName(faker.name().firstName()) + .email(faker.internet().emailAddress()) + .ref(FakeDataProvider.someRef("STD")) + .lastName(faker.name().lastName()) + .address(faker.address().fullAddress()) + .status(User.Status.ENABLED) + .entranceDatetime(Instant.now())); + } public SomeUserFactory firstName(String firstName) { - this.firstName = Optional.of(firstName); + builder.firstName(firstName); return this; } public SomeUserFactory status(User.Status status) { - this.status = Optional.of(status); + builder.status(status); return this; } @Override public User build() { - return User.builder(someCoordinates()) - .id(UUID.randomUUID().toString()) - .role(STUDENT) - .firstName(firstName.orElseGet(faker.name()::firstName)) - .email(faker.internet().emailAddress()) - .ref(FakeDataProvider.someRef("STD")) - .lastName(faker.name().lastName()) - .address(faker.address().fullAddress()) - .status(status.orElse(User.Status.ENABLED)) - .entranceDatetime(Instant.now()) - .build(); + return builder.build(); } }