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