use of ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_BatchToBeHeldBackForSFAS_ShouldCreateRecordLOADHELDSIZEInDB.
@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_BatchToBeHeldBackForSFAS_ShouldCreateRecordLOADHELDSIZEInDB() throws IOException {
when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(this.createMockSchool()));
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_5_PSI_OK.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("10200030").sourceApplication("MYED").tswAccount((randomNum + "").substring(0, 8)).fileName("sample_5_PSI_OK").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(1);
final var entity = result.get(0);
assertThat(entity.getPenRequestBatchID()).isNotNull();
assertThat(entity.getSchoolGroupCode()).isEqualTo(PSI.getCode());
assertThat(entity.getPenRequestBatchStatusCode()).isEqualTo(HOLD_FOR_REVIEW.getCode());
assertThat(entity.getPenRequestBatchHistoryEntities().size()).isEqualTo(1);
final Optional<PenRequestBatchHistoryEntity> penRequestBatchHistoryEntityOptional = entity.getPenRequestBatchHistoryEntities().stream().min(new PenRequestBatchHistoryComparator());
assertThat(penRequestBatchHistoryEntityOptional).isPresent();
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchEventCode()).isEqualTo(STATUS_CHANGED.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusCode()).isEqualTo(HOLD_FOR_REVIEW.getCode());
}
use of ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_Given8RowInvalidFileWithHeaderAndRecordLengthShort_ShouldCreateLOADFAILRecordsInDB.
/**
* Test process pen reg batch file from tsw given 30 row valid file should create records in db.
*
* @throws IOException the io exception
*/
@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_Given8RowInvalidFileWithHeaderAndRecordLengthShort_ShouldCreateLOADFAILRecordsInDB() throws IOException {
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_8_records_Header_Short_Length.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_8_records_Header_Short_Length").fileType("PEN").fileContents(bFile).insertDateTime(LocalDateTime.now()).submissionNumber(("T" + randomNum).substring(0, 8)).build();
System.out.println(JsonUtil.getJsonStringFromObject(tsw));
System.out.println(JsonUtil.getJsonObjectFromString(PENWebBlobEntity.class, JsonUtil.getJsonStringFromObject(tsw)));
tsw = this.penRequestBatchTestUtils.savePenWebBlob(tsw);
this.penRegBatchProcessor.processPenRegBatchFileFromPenWebBlob(tsw);
final var result = this.repository.findAll();
assertThat(result.size()).isEqualTo(1);
final var entity = result.get(0);
assertThat(entity.getPenRequestBatchID()).isNotNull();
assertThat(entity.getPenRequestBatchStatusCode()).isEqualTo(LOAD_FAIL.getCode());
assertThat(entity.getPenRequestBatchStatusReason()).containsIgnoringCase("Detail record 1 is missing characters");
assertThat(entity.getPenRequestBatchHistoryEntities().size()).isEqualTo(1);
final Optional<PenRequestBatchHistoryEntity> penRequestBatchHistoryEntityOptional = entity.getPenRequestBatchHistoryEntities().stream().min(new PenRequestBatchHistoryComparator());
assertThat(penRequestBatchHistoryEntityOptional).isPresent();
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchEventCode()).isEqualTo(STATUS_CHANGED.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusCode()).isEqualTo(LOAD_FAIL.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusReason()).containsIgnoringCase("Detail record 1 is missing characters");
final var students = this.studentRepository.findAllByPenRequestBatchEntity(result.get(0));
assertThat(students.size()).isZero();
}
use of ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_GivenRecordCountDoesNotMatchActualCount_ShouldCreateRecordLOADFAILInDB.
/**
* Test process pen reg batch file from tsw given record count does not match actual count should create record loadfail in db.
*
* @throws IOException the io exception
*/
@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_GivenRecordCountDoesNotMatchActualCount_ShouldCreateRecordLOADFAILInDB() throws IOException {
when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(this.createMockSchool()));
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_10_records_student_count_mismatch.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_10_records_student_count_mismatch").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(1);
final var entity = result.get(0);
assertThat(entity.getPenRequestBatchID()).isNotNull();
assertThat(entity.getPenRequestBatchStatusCode()).isEqualTo(LOAD_FAIL.getCode());
assertThat(entity.getPenRequestBatchStatusReason()).containsIgnoringCase("Invalid count in trailer record. Stated was 30, Actual was 10");
assertThat(entity.getPenRequestBatchHistoryEntities().size()).isEqualTo(1);
final Optional<PenRequestBatchHistoryEntity> penRequestBatchHistoryEntityOptional = entity.getPenRequestBatchHistoryEntities().stream().min(new PenRequestBatchHistoryComparator());
assertThat(penRequestBatchHistoryEntityOptional).isPresent();
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchEventCode()).isEqualTo(STATUS_CHANGED.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusCode()).isEqualTo(LOAD_FAIL.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusReason()).containsIgnoringCase("Invalid count in trailer record. Stated was 30, Actual was 10");
final var students = this.studentRepository.findAllByPenRequestBatchEntity(result.get(0));
assertThat(students.size()).isZero();
}
use of ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_BatchToBeHeldBackForSize_ShouldCreateRecordLOADHELDSIZEInDB.
/**
* Test process pen reg batch file from tsw given record count does not match actual count should create record loadfail in db.
*
* @throws IOException the io exception
*/
@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_BatchToBeHeldBackForSize_ShouldCreateRecordLOADHELDSIZEInDB() throws IOException {
when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(this.createMockSchool()));
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_5000_records_OK.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("10210518").sourceApplication("MYED").tswAccount((randomNum + "").substring(0, 8)).fileName("sample_5000_records_OK").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(1);
final var entity = result.get(0);
assertThat(entity.getPenRequestBatchID()).isNotNull();
assertThat(entity.getSchoolGroupCode()).isEqualTo(PSI.getCode());
assertThat(entity.getPenRequestBatchStatusCode()).isEqualTo(HOLD_FOR_REVIEW.getCode());
assertThat(entity.getPenRequestBatchHistoryEntities().size()).isEqualTo(1);
final Optional<PenRequestBatchHistoryEntity> penRequestBatchHistoryEntityOptional = entity.getPenRequestBatchHistoryEntities().stream().min(new PenRequestBatchHistoryComparator());
assertThat(penRequestBatchHistoryEntityOptional).isPresent();
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchEventCode()).isEqualTo(STATUS_CHANGED.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusCode()).isEqualTo(HOLD_FOR_REVIEW.getCode());
}
use of ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolOpenDate_ShouldCreateRecordLOADFAILInDB.
@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolOpenDate_ShouldCreateRecordLOADFAILInDB() throws IOException {
final School school = this.createMockSchool();
school.setDateOpened("2024-09-01T00:00:00");
when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(school));
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_5_K12_OK.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_OK").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(1);
final var entity = result.get(0);
assertThat(entity.getPenRequestBatchID()).isNotNull();
assertThat(entity.getPenRequestBatchStatusCode()).isEqualTo(LOAD_FAIL.getCode());
assertThat(entity.getSchoolGroupCode()).isEqualTo(K12.getCode());
assertThat(entity.getPenRequestBatchHistoryEntities().size()).isEqualTo(1);
final Optional<PenRequestBatchHistoryEntity> penRequestBatchHistoryEntityOptional = entity.getPenRequestBatchHistoryEntities().stream().min(new PenRequestBatchHistoryComparator());
assertThat(penRequestBatchHistoryEntityOptional).isPresent();
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchEventCode()).isEqualTo(STATUS_CHANGED.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusCode()).isEqualTo(LOAD_FAIL.getCode());
assertThat(penRequestBatchHistoryEntityOptional.get().getPenRequestBatchStatusReason()).isEqualTo("Invalid Mincode in Header record - school is closed.");
final var students = this.studentRepository.findAllByPenRequestBatchEntity(result.get(0));
assertThat(students.size()).isZero();
}
Aggregations