Search in sources :

Example 21 with Student

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

the class PenRequestBatchStudentOrchestratorServiceTest method testProcessPenMatchResult_givenSystemMatchScenario_studentShouldBeUpdatedWithDifferentValues.

// @Test
public void testProcessPenMatchResult_givenSystemMatchScenario_studentShouldBeUpdatedWithDifferentValues() throws IOException {
    Mockito.reset(this.restUtils);
    final var prbStudentEntity = JsonUtil.getJsonObjectFromString(PenRequestBatchStudentEntity.class, this.dummyPenRequestBatchStudentDataJson(USR_NEW_PEN.toString()));
    prbStudentEntity.setUpdateDate(LocalDateTime.now());
    final var eventPayload = new PenMatchResult();
    eventPayload.setPenStatus("D1");
    final PenMatchRecord record = new PenMatchRecord();
    final List<PenRequestBatchEntity> batches = this.penRequestBatchRepository.findAll();
    assertThat(batches.size()).isEqualTo(1);
    val firstBatchRecord = batches.get(0);
    final PenRequestBatchStudentEntity studEntity = firstBatchRecord.getPenRequestBatchStudentEntities().stream().findFirst().orElseThrow();
    firstBatchRecord.getPenRequestBatchStudentEntities().clear();
    // make sure only one record exist.
    firstBatchRecord.getPenRequestBatchStudentEntities().add(studEntity);
    this.penRequestBatchRepository.save(firstBatchRecord);
    assertThat(firstBatchRecord.getPenRequestBatchStudentEntities().size()).isEqualTo(1);
    BeanUtils.copyProperties(studEntity, this.sagaData);
    this.sagaData = orchestratorService.scrubPayload(sagaData);
    this.sagaData.setLocalID(" " + studEntity.getLocalID() + " " + studEntity.getLocalID().charAt(0) + " ");
    record.setStudentID(studEntity.getPenRequestBatchStudentID().toString());
    when(this.restUtils.getStudentByStudentID(studEntity.getPenRequestBatchStudentID().toString())).thenReturn(Student.builder().studentID(studEntity.getPenRequestBatchStudentID().toString()).legalFirstName(studEntity.getLegalFirstName()).legalLastName(studEntity.getLegalLastName()).legalMiddleNames(studEntity.getLegalMiddleNames()).usualFirstName(studEntity.getUsualFirstName()).usualLastName(studEntity.getUsualLastName()).usualMiddleNames(studEntity.getUsualMiddleNames()).gradeCode("10").pen(TEST_PEN).build());
    record.setMatchingPEN("123456789");
    eventPayload.setMatchingRecords(new ArrayList<>());
    eventPayload.getMatchingRecords().add(record);
    final ArgumentCaptor<Student> argument = ArgumentCaptor.forClass(Student.class);
    doNothing().when(this.restUtils).updateStudent(argument.capture());
    this.orchestratorService.processPenMatchResult(this.saga, this.sagaData, eventPayload);
    // now check for student updates if it happened for sys match
    final Student studentUpdate = argument.getValue();
    assertThat(studentUpdate).isNotNull();
    assertThat(studentUpdate.getLocalID()).isNotNull();
    assertThat(studentUpdate.getLocalID()).doesNotContainAnyWhitespaces();
    assertThat(studentUpdate.getUsualLastName()).isNull();
    assertThat(studentUpdate.getUsualMiddleNames()).isNull();
    assertThat(studentUpdate.getUsualFirstName()).isNull();
    if (!firstBatchRecord.getMincode().startsWith("102")) {
        assertThat(studentUpdate.getGradeCode()).isEqualTo("12");
        assertThat(studentUpdate.getGradeYear()).isNotNull();
    } else {
        assertThat(studentUpdate.getGradeCode()).isEqualTo("10");
        assertThat(studentUpdate.getGradeYear()).isNull();
    }
    final var sagaFromDB = this.sagaService.findSagaById(this.saga.getSagaId());
    assertThat(sagaFromDB).isPresent();
    val updatedBatch = this.penRequestBatchRepository.findById(firstBatchRecord.getPenRequestBatchID());
    assertThat(updatedBatch).isPresent();
    assertThat(updatedBatch.get().getPenRequestBatchStudentEntities().stream().filter(entity -> entity.getPenRequestBatchStudentID().equals(studEntity.getPenRequestBatchStudentID())).findFirst().orElseThrow().getPenRequestBatchStudentStatusCode()).isEqualTo(PenRequestBatchStudentStatusCodes.SYS_MATCHED.getCode());
}
Also used : PenMatchRecord(ca.bc.gov.educ.penreg.api.struct.PenMatchRecord) lombok.val(lombok.val) java.util(java.util) PEN_REQUEST_BATCH_STUDENT_PROCESSING_SAGA(ca.bc.gov.educ.penreg.api.constants.SagaEnum.PEN_REQUEST_BATCH_STUDENT_PROCESSING_SAGA) RunWith(org.junit.runner.RunWith) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchTestUtils(ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) PenRequestBatchStudentSagaData(ca.bc.gov.educ.penreg.api.struct.PenRequestBatchStudentSagaData) Captor(org.mockito.Captor) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity) PenMatchResult(ca.bc.gov.educ.penreg.api.struct.PenMatchResult) SpringMethodRule(org.springframework.test.context.junit4.rules.SpringMethodRule) ArgumentCaptor(org.mockito.ArgumentCaptor) BadLocalID(ca.bc.gov.educ.penreg.api.constants.BadLocalID) PenMatchRecord(ca.bc.gov.educ.penreg.api.struct.PenMatchRecord) JUnitParamsRunner(junitparams.JUnitParamsRunner) SpringClassRule(org.springframework.test.context.junit4.rules.SpringClassRule) ClassRule(org.junit.ClassRule) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) PenRequestBatchRepository(ca.bc.gov.educ.penreg.api.repository.PenRequestBatchRepository) RestUtils(ca.bc.gov.educ.penreg.api.rest.RestUtils) Before(org.junit.Before) PenRequestBatchStudentStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes) lombok.val(lombok.val) Test(org.junit.Test) IOException(java.io.IOException) USR_NEW_PEN(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes.USR_NEW_PEN) BaseOrchestratorTest(ca.bc.gov.educ.penreg.api.orchestrator.BaseOrchestratorTest) Mockito(org.mockito.Mockito) Slf4j(lombok.extern.slf4j.Slf4j) Student(ca.bc.gov.educ.penreg.api.struct.Student) Rule(org.junit.Rule) Saga(ca.bc.gov.educ.penreg.api.model.v1.Saga) Parameters(junitparams.Parameters) BeanUtils(org.springframework.beans.BeanUtils) Transactional(org.springframework.transaction.annotation.Transactional) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) Student(ca.bc.gov.educ.penreg.api.struct.Student) PenMatchResult(ca.bc.gov.educ.penreg.api.struct.PenMatchResult) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)

Example 22 with Student

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

the class PenRequestBatchTestUtils method createBatchStudents.

/**
 * Create batch students list.
 *
 * @param penRequestBatchRepository the PenRequestBatchRepository
 * @param batchFileName             the json file of batch data
 * @param batchStudentFileName      the json file of batch student data
 * @param total                     the total
 * @param batchConsumer             the function to make changes on the batch entity
 * @return the list
 */
public static List<PenRequestBatchEntity> createBatchStudents(final PenRequestBatchRepository penRequestBatchRepository, final String batchFileName, final String batchStudentFileName, final Integer total, final Consumer<PenRequestBatchEntity> batchConsumer) throws java.io.IOException {
    final File file = new File(Objects.requireNonNull(PenRequestBatchTestUtils.class.getClassLoader().getResource(batchFileName)).getFile());
    final List<PenRequestBatch> entities = new ObjectMapper().readValue(file, new TypeReference<>() {
    });
    final var models = entities.stream().map(mapper::toModel).collect(toList()).stream().map(PenRequestBatchTestUtils::populateAuditColumns).collect(toList());
    for (int i = 0; i < total && i < models.size(); i++) {
        final File student = new File(Objects.requireNonNull(PenRequestBatchTestUtils.class.getClassLoader().getResource(batchStudentFileName)).getFile());
        final List<PenRequestBatchStudentEntity> studentEntities = new ObjectMapper().readValue(student, new TypeReference<>() {
        });
        final PenRequestBatchEntity batch = models.get(i);
        final var students = studentEntities.stream().map(PenRequestBatchTestUtils::populateAuditColumns).peek(el -> el.setPenRequestBatchEntity(batch)).collect(Collectors.toSet());
        if (batchConsumer != null) {
            batchConsumer.accept(batch);
        }
        batch.setPenRequestBatchStudentEntities(students);
    }
    penRequestBatchRepository.saveAll(models);
    return models;
}
Also used : java.util(java.util) MARK_SAGA_COMPLETE(ca.bc.gov.educ.penreg.api.constants.EventType.MARK_SAGA_COMPLETE) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LocalDateTime(java.time.LocalDateTime) DefaultParserFactory(net.sf.flatpack.DefaultParserFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchFileMapper(ca.bc.gov.educ.penreg.api.batch.mappers.PenRequestBatchFileMapper) PenRequestBatchMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchMapper) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) BatchFile(ca.bc.gov.educ.penreg.api.batch.struct.BatchFile) PenRequestBatchArchiveAndReturnSagaData(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchArchiveAndReturnSagaData) PenRequestBatch(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatch) DataSet(net.sf.flatpack.DataSet) ca.bc.gov.educ.penreg.api.constants(ca.bc.gov.educ.penreg.api.constants) Propagation(org.springframework.transaction.annotation.Propagation) Pair(org.springframework.data.util.Pair) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PEN_REQUEST_BATCH_ARCHIVE_AND_RETURN_SAGA(ca.bc.gov.educ.penreg.api.constants.SagaEnum.PEN_REQUEST_BATCH_ARCHIVE_AND_RETURN_SAGA) COMPLETED(ca.bc.gov.educ.penreg.api.constants.SagaStatusEnum.COMPLETED) LOADED(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStatusCodes.LOADED) Files(java.nio.file.Files) PenRequestBatchHistoryMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchHistoryMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) SagaService(ca.bc.gov.educ.penreg.api.service.SagaService) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ca.bc.gov.educ.penreg.api.model.v1(ca.bc.gov.educ.penreg.api.model.v1) Profile(org.springframework.context.annotation.Profile) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) PenRegBatchProcessor(ca.bc.gov.educ.penreg.api.batch.processor.PenRegBatchProcessor) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) Student(ca.bc.gov.educ.penreg.api.struct.Student) PenRequestBatchArchiveAndReturnAllSagaData(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchArchiveAndReturnAllSagaData) java.io(java.io) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) FileUnProcessableException(ca.bc.gov.educ.penreg.api.batch.exception.FileUnProcessableException) ca.bc.gov.educ.penreg.api.repository(ca.bc.gov.educ.penreg.api.repository) Transactional(org.springframework.transaction.annotation.Transactional) PenRequestBatch(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatch) BatchFile(ca.bc.gov.educ.penreg.api.batch.struct.BatchFile) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with Student

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

the class PenRegBatchHelperTest method testExactMatch_givenDiffValues3_shouldReturnFalse.

@Test
public void testExactMatch_givenDiffValues3_shouldReturnFalse() {
    PenRequestBatchStudent penRequestBatchStudent = PenRequestBatchStudent.builder().genderCode("F").dob("20000101").legalFirstName("test").legalMiddleNames("AARON").legalLastName("test").submittedPen("123456789").assignedPEN("123456789").build();
    Student student = Student.builder().sexCode("M").dob("2000-01-01").legalFirstName("test").legalLastName("test").build();
    assertThat(PenRegBatchHelper.exactMatch(penRequestBatchStudent, student)).isFalse();
}
Also used : Student(ca.bc.gov.educ.penreg.api.struct.Student) PenRequestBatchStudent(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent) PenRequestBatchStudent(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent) Test(org.junit.Test)

Example 24 with Student

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

the class PenRegBatchHelperTest method testExactMatch_givenAllValuesSame2_shouldReturnTrue.

@Test
public void testExactMatch_givenAllValuesSame2_shouldReturnTrue() {
    PenRequestBatchStudent penRequestBatchStudent = PenRequestBatchStudent.builder().genderCode("M").dob("20000101").legalMiddleNames("middleName 123").legalFirstName("test").legalLastName("test").submittedPen("123456789").assignedPEN("123456789").build();
    Student student = Student.builder().sexCode("M").dob("2000-01-01").legalFirstName("test").legalMiddleNames("middleName 123").legalLastName("test").build();
    assertThat(PenRegBatchHelper.exactMatch(penRequestBatchStudent, student)).isTrue();
}
Also used : Student(ca.bc.gov.educ.penreg.api.struct.Student) PenRequestBatchStudent(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent) PenRequestBatchStudent(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent) Test(org.junit.Test)

Example 25 with Student

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

the class PenRequestBatchReportDataMapperTest method testToReportUserMatchedListItem_GivenNullStudent_ShouldNotThrowError.

@Test
public void testToReportUserMatchedListItem_GivenNullStudent_ShouldNotThrowError() throws IOException {
    final var batchEntities = PenRequestBatchTestUtils.createBatchStudents(this.repository, "mock_pen_req_batch_repeat.json", "mock_pen_req_batch_student_archived_with_pen.json", 1, (batch) -> batch.setProcessDate(LocalDateTime.parse("2021-03-23T13:04:48.840098")));
    final var student = Student.builder().studentID("566ee980-8e5f-11eb-8dcd-0242ac130009").pen("123456780").build();
    final List<Student> students = new ArrayList<>();
    students.add(student);
    final var sagaData = PenRequestBatchArchiveAndReturnSagaData.builder().facsimile("3333333333").telephone("5555555555").fromEmail("test@abc.com").mailingAddress("mailing address").students(students).penCoordinator(PenCoordinator.builder().penCoordinatorEmail("test@email.com").penCoordinatorName("Joe Blow").build()).schoolName("Cataline").penRequestBatch(mapper.toStructure(batchEntities.get(0))).penRequestBatchStudents(batchEntities.get(0).getPenRequestBatchStudentEntities().stream().map(studentMapper::toStructure).collect(Collectors.toList())).penRequestBatchStudentValidationIssues(new HashMap<>()).build();
    final PenRequestBatchReportData reportData = reportMapper.toReportData(sagaData);
    assertThat(reportData.getDiffList().size()).isEqualTo(1);
}
Also used : HashMap(java.util.HashMap) PenRequestBatchReportData(ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.PenRequestBatchReportData) ArrayList(java.util.ArrayList) Student(ca.bc.gov.educ.penreg.api.struct.Student) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Aggregations

Student (ca.bc.gov.educ.penreg.api.struct.Student)44 Test (org.junit.Test)26 lombok.val (lombok.val)24 Event (ca.bc.gov.educ.penreg.api.struct.Event)17 PenRequestBatchStudent (ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent)16 LocalDateTime (java.time.LocalDateTime)14 Collectors (java.util.stream.Collectors)14 PenRequestBatchEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity)13 RestUtils (ca.bc.gov.educ.penreg.api.rest.RestUtils)13 JsonUtil (ca.bc.gov.educ.penreg.api.util.JsonUtil)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 BasePenRegAPITest (ca.bc.gov.educ.penreg.api.BasePenRegAPITest)12 PenRequestBatchStudentEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)12 SagaEvent (ca.bc.gov.educ.penreg.api.model.v1.SagaEvent)12 SagaService (ca.bc.gov.educ.penreg.api.service.SagaService)12 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 EventOutcome (ca.bc.gov.educ.penreg.api.constants.EventOutcome)11 PenRequestBatchStudentStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes)11 PenMatchRecord (ca.bc.gov.educ.penreg.api.struct.PenMatchRecord)11 PenMatchResult (ca.bc.gov.educ.penreg.api.struct.PenMatchResult)11