use of ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchRepostReportsOrchestratorTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.openMocks(this);
this.saga = penRequestBatchTestUtils.createSaga("19337120", "12345678", LOADED.getCode(), TEST_PEN);
final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("mock-pen-coordinator.json")).getFile());
final List<ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator> structs = new ObjectMapper().readValue(file, new TypeReference<>() {
});
when(this.restUtils.getProps()).thenReturn(this.props);
}
use of ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchRepostReportsOrchestratorTest method testSendHasCoordinatorEmail_givenEventAndSagaDataHasPenCoordinatorEmail_and_NotMyEdSchool_shouldBeMarkedNOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT.
@Test
public void testSendHasCoordinatorEmail_givenEventAndSagaDataHasPenCoordinatorEmail_and_NotMyEdSchool_shouldBeMarkedNOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT() throws InterruptedException, TimeoutException, IOException {
final var invocations = mockingDetails(this.messagePublisher).getInvocations().size();
PenRequestBatchEntity penRequestBatchEntity = penRequestBatchTestUtils.createBatchEntity("19337120", "12345679", PenRequestBatchStudentStatusCodes.SYS_NEW_PEN.getCode(), TEST_PEN);
PenRequestBatchArchiveAndReturnSagaData payload = PenRequestBatchArchiveAndReturnSagaData.builder().penRequestBatch(batchMapper.toStructure(penRequestBatchEntity)).penRequestBatchStudents(penRequestBatchEntity.getPenRequestBatchStudentEntities().stream().map(batchStudentMapper::toStructure).collect(Collectors.toList())).penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()).mailingAddress("123 st").fromEmail("test@email.com").facsimile("5555555555").telephone("2222222222").students(PenRequestBatchTestUtils.createStudents(penRequestBatchEntity)).penRequestBatchID(penRequestBatchEntity.getPenRequestBatchID()).build();
this.saga.get(0).setPayload(JsonUtil.getJsonStringFromObject(payload));
this.sagaService.updateAttachedEntityDuringSagaProcess(this.saga.get(0));
final var event = Event.builder().eventType(EventType.GENERATE_PEN_REQUEST_BATCH_REPORTS).eventOutcome(EventOutcome.ARCHIVE_PEN_REQUEST_BATCH_REPORTS_GENERATED).eventPayload(Base64.getEncoder().encodeToString("Heres a pdf report".getBytes())).sagaId(this.saga.get(0).getSagaId()).build();
this.orchestrator.handleEvent(event);
verify(this.messagePublisher, atMost(invocations + 1)).dispatchMessage(eq(SagaTopicsEnum.PROFILE_REQUEST_EMAIL_API_TOPIC.toString()), this.eventCaptor.capture());
final var newEvent = JsonUtil.getJsonObjectFromString(Event.class, new String(this.eventCaptor.getValue()));
assertThat(newEvent.getEventType()).isEqualTo(NOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT);
assertThat(newEvent.getEventPayload()).isNotEmpty();
assertThat(newEvent.getEventPayload()).contains("pen@email.com");
final var sagaFromDB = this.sagaService.findSagaById(this.saga.get(0).getSagaId());
assertThat(sagaFromDB).isPresent();
assertThat(sagaFromDB.get().getSagaState()).isEqualTo(NOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT.toString());
final var sagaStates = this.sagaService.findAllSagaStates(this.saga.get(0));
assertThat(sagaStates.size()).isEqualTo(2);
assertThat(sagaStates.get(0).getSagaEventState()).isEqualTo(GENERATE_PEN_REQUEST_BATCH_REPORTS.toString());
assertThat(sagaStates.get(0).getSagaEventOutcome()).isEqualTo(EventOutcome.ARCHIVE_PEN_REQUEST_BATCH_REPORTS_GENERATED.toString());
assertThat(sagaStates.get(1).getSagaEventState()).isEqualTo(EventType.SAVE_REPORTS.toString());
assertThat(sagaStates.get(1).getSagaEventOutcome()).isEqualTo(EventOutcome.REPORTS_SAVED.toString());
final var penWebBlobsDB = this.prbService.findPenWebBlobBySubmissionNumber(penRequestBatchEntity.getSubmissionNumber());
assertThat(penWebBlobsDB.size()).isEqualTo(2);
}
use of ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchRepostReportsOrchestratorTest method testHandleEvent_givenSTUDENTS_FOUNDEventAndCorrectSagaAndEventData_shouldBeMarkedGENERATE_PEN_REQUEST_BATCH_REPORTS.
@Test
public void testHandleEvent_givenSTUDENTS_FOUNDEventAndCorrectSagaAndEventData_shouldBeMarkedGENERATE_PEN_REQUEST_BATCH_REPORTS() throws IOException, InterruptedException, TimeoutException {
final PenRequestBatchEntity penRequestBatchEntity = penRequestBatchTestUtils.createBatchEntity("19337120", "12345679", PenRequestBatchStudentStatusCodes.SYS_NEW_PEN.getCode(), TEST_PEN);
final PenRequestBatchArchiveAndReturnSagaData payload = PenRequestBatchArchiveAndReturnSagaData.builder().penRequestBatch(this.batchMapper.toStructure(penRequestBatchEntity)).penRequestBatchStudents(penRequestBatchEntity.getPenRequestBatchStudentEntities().stream().map(this.batchStudentMapper::toStructure).collect(Collectors.toList())).penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()).mailingAddress("123 st").fromEmail("test@email.com").facsimile("5555555555").telephone("2222222222").penRequestBatchID(penRequestBatchEntity.getPenRequestBatchID()).updateUser("test user").build();
this.saga.get(0).setPayload(JsonUtil.getJsonStringFromObject(payload));
this.sagaService.updateAttachedEntityDuringSagaProcess(this.saga.get(0));
final var event = Event.builder().eventType(GET_STUDENTS).eventOutcome(EventOutcome.STUDENTS_FOUND).eventPayload("[]").sagaId(this.saga.get(0).getSagaId()).build();
when(this.restUtils.getStudentByPEN(TEST_PEN)).thenReturn(Optional.of(Student.builder().studentID("d332e462-917a-11eb-a8b3-0242ac130003").pen(TEST_PEN).build()));
this.orchestrator.handleEvent(event);
final var sagaFromDB = this.sagaService.findSagaById(this.saga.get(0).getSagaId());
assertThat(sagaFromDB).isPresent();
assertThat(sagaFromDB.get().getSagaState()).isEqualTo(EventType.GENERATE_PEN_REQUEST_BATCH_REPORTS.toString());
final var sagaStates = this.sagaService.findAllSagaStates(sagaFromDB.get());
assertThat(sagaStates.size()).isEqualTo(1);
assertThat(sagaStates.get(0).getSagaEventState()).isEqualTo(GET_STUDENTS.toString());
assertThat(sagaStates.get(0).getSagaEventOutcome()).isEqualTo(EventOutcome.STUDENTS_FOUND.toString());
}
use of ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchRepostReportsOrchestratorTest method testSendHasCoordinatorEmail_givenEventAndSagaDataHasPenCoordinatorEmail_and_MyEdSchool_shouldBeMarkedNOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT.
@Test
public void testSendHasCoordinatorEmail_givenEventAndSagaDataHasPenCoordinatorEmail_and_MyEdSchool_shouldBeMarkedNOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT() throws InterruptedException, TimeoutException, IOException {
final var invocations = mockingDetails(this.messagePublisher).getInvocations().size();
PenRequestBatchEntity penRequestBatchEntity = penRequestBatchTestUtils.createBatchEntity("19337120", "M2345679", PenRequestBatchStudentStatusCodes.SYS_NEW_PEN.getCode(), TEST_PEN);
PenRequestBatchArchiveAndReturnSagaData payload = PenRequestBatchArchiveAndReturnSagaData.builder().penRequestBatch(batchMapper.toStructure(penRequestBatchEntity)).penRequestBatchStudents(penRequestBatchEntity.getPenRequestBatchStudentEntities().stream().map(batchStudentMapper::toStructure).collect(Collectors.toList())).penCoordinator(PenCoordinator.builder().penCoordinatorEmail("pen@email.com").penCoordinatorName("Joe Blow").build()).mailingAddress("123 st").fromEmail("test@email.com").facsimile("5555555555").telephone("2222222222").students(PenRequestBatchTestUtils.createStudents(penRequestBatchEntity)).penRequestBatchID(penRequestBatchEntity.getPenRequestBatchID()).build();
this.saga.get(0).setPayload(JsonUtil.getJsonStringFromObject(payload));
this.sagaService.updateAttachedEntityDuringSagaProcess(this.saga.get(0));
final var event = Event.builder().eventType(EventType.GENERATE_PEN_REQUEST_BATCH_REPORTS).eventOutcome(EventOutcome.ARCHIVE_PEN_REQUEST_BATCH_REPORTS_GENERATED).eventPayload(Base64.getEncoder().encodeToString("Heres a pdf report".getBytes())).sagaId(this.saga.get(0).getSagaId()).build();
this.orchestrator.handleEvent(event);
verify(this.messagePublisher, atMost(invocations + 1)).dispatchMessage(eq(SagaTopicsEnum.PROFILE_REQUEST_EMAIL_API_TOPIC.toString()), this.eventCaptor.capture());
final var newEvent = JsonUtil.getJsonObjectFromString(Event.class, new String(this.eventCaptor.getValue()));
assertThat(newEvent.getEventType()).isEqualTo(NOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT);
assertThat(newEvent.getEventPayload()).isNotEmpty();
assertThat(newEvent.getEventPayload()).contains("pen@email.com");
final var sagaFromDB = this.sagaService.findSagaById(this.saga.get(0).getSagaId());
assertThat(sagaFromDB).isPresent();
assertThat(sagaFromDB.get().getSagaState()).isEqualTo(NOTIFY_PEN_REQUEST_BATCH_ARCHIVE_HAS_CONTACT.toString());
final var sagaStates = this.sagaService.findAllSagaStates(this.saga.get(0));
assertThat(sagaStates.size()).isEqualTo(2);
assertThat(sagaStates.get(0).getSagaEventState()).isEqualTo(GENERATE_PEN_REQUEST_BATCH_REPORTS.toString());
assertThat(sagaStates.get(0).getSagaEventOutcome()).isEqualTo(EventOutcome.ARCHIVE_PEN_REQUEST_BATCH_REPORTS_GENERATED.toString());
assertThat(sagaStates.get(1).getSagaEventState()).isEqualTo(EventType.SAVE_REPORTS.toString());
assertThat(sagaStates.get(1).getSagaEventOutcome()).isEqualTo(EventOutcome.REPORTS_SAVED.toString());
final var penWebBlobsDB = this.prbService.findPenWebBlobBySubmissionNumber(penRequestBatchEntity.getSubmissionNumber());
assertThat(penWebBlobsDB.size()).isEqualTo(2);
}
use of ca.bc.gov.educ.penreg.api.struct.v1.PenCoordinator 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