Search in sources :

Example 1 with DUPLICATE

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);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LocalDateTime(java.time.LocalDateTime) DUPLICATE(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes.DUPLICATE) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchTestUtils(ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) PenRequestBatchStudentRepository(ca.bc.gov.educ.penreg.api.repository.PenRequestBatchStudentRepository) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity) Message(io.nats.client.Message) Subscription(io.nats.client.Subscription) PENWebBlobEntity(ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity) PSI(ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes.PSI) Faker(com.github.javafaker.Faker) Connection(io.nats.client.Connection) Duration(java.time.Duration) PenRequestBatchHistoryComparator(ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator) K12(ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes.K12) PenRequestBatchHistoryEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity) STATUS_CHANGED(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchEventCodes.STATUS_CHANGED) SchoolGroupCodes(ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes) PenRequestBatchRepository(ca.bc.gov.educ.penreg.api.repository.PenRequestBatchRepository) RestUtils(ca.bc.gov.educ.penreg.api.rest.RestUtils) Before(org.junit.Before) Status(io.nats.client.support.Status) PenRequestBatchStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStatusCodes) PenCoordinator(ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator) PenRequestBatchStudentStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes) Files(java.nio.file.Files) School(ca.bc.gov.educ.penreg.api.struct.School) Headers(io.nats.client.impl.Headers) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) File(java.io.File) SchoolGroupCode(ca.bc.gov.educ.penreg.api.struct.v1.SchoolGroupCode) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) PenWebBlobRepository(ca.bc.gov.educ.penreg.api.repository.PenWebBlobRepository) Optional(java.util.Optional) MessagePublisher(ca.bc.gov.educ.penreg.api.messaging.MessagePublisher) Comparator(java.util.Comparator) NatsJetStreamMetaData(io.nats.client.impl.NatsJetStreamMetaData) Transactional(org.springframework.transaction.annotation.Transactional) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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)1 PenRequestBatchHistoryComparator (ca.bc.gov.educ.penreg.api.compare.PenRequestBatchHistoryComparator)1 STATUS_CHANGED (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchEventCodes.STATUS_CHANGED)1 PenRequestBatchStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStatusCodes)1 PenRequestBatchStudentStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes)1 DUPLICATE (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes.DUPLICATE)1 SchoolGroupCodes (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes)1 K12 (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes.K12)1 PSI (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes.PSI)1 MessagePublisher (ca.bc.gov.educ.penreg.api.messaging.MessagePublisher)1 PENWebBlobEntity (ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity)1 PenRequestBatchHistoryEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchHistoryEntity)1 PenRequestBatchStudentEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)1 PenRequestBatchRepository (ca.bc.gov.educ.penreg.api.repository.PenRequestBatchRepository)1 PenRequestBatchStudentRepository (ca.bc.gov.educ.penreg.api.repository.PenRequestBatchStudentRepository)1 PenWebBlobRepository (ca.bc.gov.educ.penreg.api.repository.PenWebBlobRepository)1 RestUtils (ca.bc.gov.educ.penreg.api.rest.RestUtils)1 School (ca.bc.gov.educ.penreg.api.struct.School)1 PenCoordinator (ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator)1 SchoolGroupCode (ca.bc.gov.educ.penreg.api.struct.v1.SchoolGroupCode)1