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();
}
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();
}
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();
}
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;
}
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;
}
Aggregations