Search in sources :

Example 1 with PenRequestBatchHistoryComparator

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());
}
Also used : PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) PenRequestBatchHistoryComparator(ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator) Random(java.util.Random) File(java.io.File) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with PenRequestBatchHistoryComparator

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();
}
Also used : PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) PenRequestBatchHistoryComparator(ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator) Random(java.util.Random) PENWebBlobEntity(ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity) File(java.io.File) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with PenRequestBatchHistoryComparator

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();
}
Also used : PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) PenRequestBatchHistoryComparator(ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator) Random(java.util.Random) File(java.io.File) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with PenRequestBatchHistoryComparator

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());
}
Also used : PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) PenRequestBatchHistoryComparator(ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator) Random(java.util.Random) File(java.io.File) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with PenRequestBatchHistoryComparator

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();
}
Also used : School(ca.bc.gov.educ.penreg.api.struct.School) PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) PenRequestBatchHistoryComparator(ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator) Random(java.util.Random) File(java.io.File) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BasePenRegAPITest (ca.bc.gov.educ.penreg.api.BasePenRegAPITest)17 PenRequestBatchHistoryComparator (ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator)17 PenRequestBatchHistoryEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity)17 File (java.io.File)17 Random (java.util.Random)17 Test (org.junit.Test)17 Transactional (org.springframework.transaction.annotation.Transactional)17 PenRequestBatchStudentEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)6 School (ca.bc.gov.educ.penreg.api.struct.School)5 PENWebBlobEntity (ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity)3 STATUS_CHANGED (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchEventCodes.STATUS_CHANGED)2 PenRequestBatchStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStatusCodes)2 PenRequestBatchStudentStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes)2 DUPLICATE (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes.DUPLICATE)2 SchoolGroupCodes (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes)2 K12 (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes.K12)2 PSI (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes.PSI)2 MessagePublisher (ca.bc.gov.educ.penreg.api.messaging.MessagePublisher)2 PenRequestBatchRepository (ca.bc.gov.educ.penreg.api.repository.PenRequestBatchRepository)2 PenRequestBatchStudentRepository (ca.bc.gov.educ.penreg.api.repository.PenRequestBatchStudentRepository)2