use of ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes.DUPLICATE in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_GivenExistingRecordThatIsAlsoDuplicate_ShouldShowDuplicate.
/**
* Test that duplicate student request is not marked as a repeat
*
* @throws IOException the io exception
*/
@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_GivenExistingRecordThatIsAlsoDuplicate_ShouldShowDuplicate() throws IOException {
when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(this.createMockSchool()));
this.penRequestBatchTestUtils.createBatchStudentsInSingleTransaction(this.repository, "mock_pen_req_batch_repeat.json", "mock_pen_req_batch_student_repeat.json", 1, (batch) -> batch.setProcessDate(LocalDateTime.now().minusDays(3)));
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_5_K12_Duplicate_And_Repeat.txt")).getFile());
final byte[] bFile = Files.readAllBytes(file.toPath());
final var randomNum = (new Random().nextLong() * (MAX - MIN + 1) + MIN);
var tsw = PENWebBlobEntity.builder().penWebBlobId(1L).mincode("66510518").sourceApplication("MYED").tswAccount((randomNum + "").substring(0, 8)).fileName("sample_5_K12_Duplicate_And_Repeat").fileType("PEN").fileContents(bFile).insertDateTime(LocalDateTime.now()).submissionNumber(("T" + randomNum).substring(0, 8)).build();
tsw = this.penRequestBatchTestUtils.savePenWebBlob(tsw);
this.penRegBatchProcessor.processPenRegBatchFileFromPenWebBlob(tsw);
final var result = this.repository.findAll();
assertThat(result.size()).isEqualTo(2);
final var entity = result.get(1);
assertThat(entity.getPenRequestBatchID()).isNotNull();
assertThat(entity.getPenRequestBatchStatusCode()).isEqualTo(REPEATS_CHECKED.getCode());
assertThat(entity.getSchoolGroupCode()).isEqualTo(K12.getCode());
assertThat(entity.getPenRequestBatchStatusReason()).isNull();
assertThat(entity.getRepeatCount()).isZero();
final var students = this.studentRepository.findAllByPenRequestBatchEntity(result.get(1));
assertThat(entity.getPenRequestBatchHistoryEntities().size()).isEqualTo(2);
assertThat(students.stream().filter(s -> DUPLICATE.getCode().equals(s.getPenRequestBatchStudentStatusCode())).count()).isEqualTo(2);
}
Aggregations