Search in sources :

Example 1 with School

use of ca.bc.gov.educ.penreg.api.struct.School 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)

Example 2 with School

use of ca.bc.gov.educ.penreg.api.struct.School in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolCloseDate_ShouldCreateRecordLOADFAILInDB.

@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolCloseDate_ShouldCreateRecordLOADFAILInDB() throws IOException {
    final School school = this.createMockSchool();
    school.setDateClosed("1996-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)

Example 3 with School

use of ca.bc.gov.educ.penreg.api.struct.School in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRegBatchProcessorTest method testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolOpenDateFormat_ShouldCreateRecordLOADFAILInDB.

@Test
@Transactional
public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolOpenDateFormat_ShouldCreateRecordLOADFAILInDB() throws IOException {
    final School school = this.createMockSchool();
    school.setDateOpened("88888888");
    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)

Example 4 with School

use of ca.bc.gov.educ.penreg.api.struct.School in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRegBatchSchedulerTest method createMockSchool.

private School createMockSchool() {
    final School school = new School();
    school.setSchoolName("Marco's school");
    school.setMincode("66510518");
    school.setDateOpened("1953-09-01T00:00:00");
    return school;
}
Also used : School(ca.bc.gov.educ.penreg.api.struct.School)

Example 5 with School

use of ca.bc.gov.educ.penreg.api.struct.School in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRequestBatchFileServiceTest method createMockSchool.

private School createMockSchool() {
    final School school = new School();
    school.setSchoolName("Marco's school");
    school.setMincode("66510518");
    school.setDateOpened("1964-09-01T00:00:00");
    return school;
}
Also used : School(ca.bc.gov.educ.penreg.api.struct.School)

Aggregations

School (ca.bc.gov.educ.penreg.api.struct.School)12 Random (java.util.Random)4 Test (org.junit.Test)4 BasePenRegAPITest (ca.bc.gov.educ.penreg.api.BasePenRegAPITest)3 PenRequestBatchHistoryComparator (ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator)3 PenRequestBatchHistoryEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity)3 File (java.io.File)3 Transactional (org.springframework.transaction.annotation.Transactional)3 PenRequestBatchEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity)2 lombok.val (lombok.val)2 FileUnProcessableException (ca.bc.gov.educ.penreg.api.batch.exception.FileUnProcessableException)1 Faker (com.github.javafaker.Faker)1 DateTimeParseException (java.time.format.DateTimeParseException)1 Before (org.junit.Before)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1