diff --git a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherControllerTest.java index 2e8c92fc..f07cdcfd 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/controller/JobLauncherControllerTest.java @@ -52,6 +52,7 @@ public class JobLauncherControllerTest { private static final String TRANMISSION_TYPE = "transmissionType"; private static final String DISDTO = "distributionSummaryDTO"; private static final String SCHREPORT = "SCHREP"; + private static final String ARCHIVE_STUDENTS = "ARC_STUDENTS"; @Autowired JsonTransformer jsonTransformer; @@ -408,6 +409,24 @@ public void testlaunchYearlyNonGradDistributionRunJob() { assertThat(builder).isNotNull(); } + @Test + public void testArchiveStudentsBatchJob() { + StudentSearchRequest request = new StudentSearchRequest(); + request.setSchoolOfRecords(List.of("12345678")); + boolean exceptionIsThrown = false; + JobParametersBuilder builder = new JobParametersBuilder(); + builder.addLong(TIME, System.currentTimeMillis()).toJobParameters(); + builder.addString(JOB_TRIGGER, MANUAL); + builder.addString(JOB_TYPE, ARCHIVE_STUDENTS); + try { + org.mockito.Mockito.when(jobLauncher.run(jobRegistry.getJob("archiveStudentsBatchJob"), builder.toJobParameters())).thenReturn(new JobExecution(210L)); + jobLauncherController.launchArchiveStudentsJob(request); + } catch (Exception e) { + exceptionIsThrown = true; + } + assertThat(builder).isNotNull(); + } + @Test public void testlaunchUserReqPsiDisRunSpecialJob_1() { boolean exceptionIsThrown = false; diff --git a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java index 8381da60..7baa35c4 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/batchgraduation/util/RestUtilsTest.java @@ -1641,6 +1641,88 @@ public void testGetEDWSnapshotSchools() { assertThat(result).hasSize(2); } + @Test + public void testGetTotalStudentsForArchiving() { + List schools = Arrays.asList("12345678","11223344"); + + mockTokenResponseObject(); + + when(this.webClient.post()).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(String.format(constants.getGradStudentCountUrl(), "CUR"))).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.contentType(any())).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(Long.class)).thenReturn(Mono.just(1L)); + + DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); + + val result = this.restUtils.getTotalStudentsForArchiving(schools, "CUR", summaryDTO); + assertThat(result).isEqualTo(1); + } + + @Test + public void testGetTotalStudentsForArchivingError() { + List schools = Arrays.asList("12345678","11223344"); + + mockTokenResponseObject(); + + when(this.webClient.post()).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(String.format(constants.getGradStudentCountUrl(), "CUR"))).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.contentType(any())).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenThrow(new RuntimeException("Unable to retrieve student counts")); + when(this.responseMock.bodyToMono(Long.class)).thenReturn(Mono.just(1L)); + + DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); + + val result = this.restUtils.getTotalStudentsForArchiving(schools, "CUR", summaryDTO); + assertThat(result).isNotNull(); + assertThat(summaryDTO.getErrors()).isNotEmpty(); + } + + @Test + public void testArchiveStudents() { + List schools = Arrays.asList("12345678","11223344"); + + mockTokenResponseObject(); + + when(this.webClient.post()).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(String.format(constants.getGradArchiveStudentsUrl(), 12345678L, "CUR"))).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.contentType(any())).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(Integer.class)).thenReturn(Mono.just(1)); + + DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); + + val result = this.restUtils.archiveStudents(12345678L, schools,"CUR", summaryDTO); + assertThat(result).isEqualTo(1); + } + + @Test + public void testArchiveStudentsError() { + List schools = Arrays.asList("12345678","11223344"); + + mockTokenResponseObject(); + + when(this.webClient.post()).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.uri(String.format(constants.getGradArchiveStudentsUrl(), 12345678L, "CUR"))).thenReturn(this.requestBodyUriMock); + when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.contentType(any())).thenReturn(this.requestBodyMock); + when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenThrow(new RuntimeException("Unable to archive Students")); + when(this.responseMock.bodyToMono(Integer.class)).thenReturn(Mono.just(0)); + + DistributionSummaryDTO summaryDTO = new DistributionSummaryDTO(); + + val result = this.restUtils.archiveStudents(12345678L, schools,"CUR", summaryDTO); + assertThat(result).isNotNull(); + assertThat(summaryDTO.getErrors()).isNotEmpty(); + } + @Test public void testGetEDWSnapshotStudents() { final Integer gradYear = Integer.parseInt("2023");