Skip to content

Commit

Permalink
GRAD2-2283
Browse files Browse the repository at this point in the history
Student Archive Process - Backend endpoints To COMPLETE
  • Loading branch information
arybakov-cgi committed Jul 10, 2024
1 parent 42868c0 commit 4b5c116
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,88 @@ public void testGetEDWSnapshotSchools() {
assertThat(result).hasSize(2);
}

@Test
public void testGetTotalStudentsForArchiving() {
List<String> 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<String> 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<String> 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<String> 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");
Expand Down

0 comments on commit 4b5c116

Please sign in to comment.