use of ca.bc.gov.educ.penreg.api.constants.EventOutcome in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchAPIControllerTest method testPostPenRequest_GivenValidStudentDataPenMatchReturnsNoMatch_ShouldReturn201.
@Test
public void testPostPenRequest_GivenValidStudentDataPenMatchReturnsNoMatch_ShouldReturn201() throws Exception {
Mockito.when(this.restUtils.requestEventResponseFromServicesAPI(ArgumentMatchers.any())).thenReturn(Optional.of(Event.builder().eventOutcome(EventOutcome.VALIDATION_SUCCESS_NO_ERROR_WARNING).build()));
val matchList = new ArrayList<PenMatchRecord>(1);
matchList.add(PenMatchRecord.builder().matchingPEN("123456789").studentID("studentID").build());
final PenMatchResult penMatchResult = PenMatchResult.builder().penStatus("D0").matchingRecords(matchList).build();
Mockito.when(this.restUtils.requestEventResponseFromMatchAPI(ArgumentMatchers.any())).thenReturn(Optional.of(Event.builder().eventOutcome(EventOutcome.PEN_MATCH_PROCESSED).eventPayload(JsonUtil.getJsonStringFromObject(penMatchResult)).build()));
Mockito.when(this.restUtils.getNextPenNumberFromPenServiceAPI(ArgumentMatchers.any())).thenReturn("123456788");
Mockito.when(this.restUtils.getStudentByPEN(ArgumentMatchers.any())).thenReturn(Optional.of(Student.builder().studentID("studentID").pen("123456788").build()));
Mockito.when(this.restUtils.requestEventResponseFromStudentAPI(ArgumentMatchers.any())).thenReturn(Optional.of(Event.builder().eventOutcome(EventOutcome.STUDENT_CREATED).build()));
this.mockMvc.perform(post("/api/v1/pen-request-batch/pen-request").with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_REQUEST_BATCH"))).content("{\n" + " \"localStudentID\": \"102000201\",\n" + " \"legalSurname\": \"AAAA\",\n" + " \"legalGivenName\": \"OM\",\n" + " \"birthDate\": \"19801114\",\n" + " \"gender\": \"M\",\n" + " \"enrolledGradeCode\": \"12\",\n" + " \"postalCode\": \"V8T0E1\",\n" + " \"mincode\": \"10200001\",\n" + " \"createUser\": \"om\",\n" + " \"updateUser\": \"om\"\n" + "}").contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isCreated()).andExpect(jsonPath("$.pen", is("123456788")));
}
use of ca.bc.gov.educ.penreg.api.constants.EventOutcome in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchAPIControllerTest method testPostPenRequest_GivenValidStudentData_ShouldReturnMatchedStudentPen.
@Test
public void testPostPenRequest_GivenValidStudentData_ShouldReturnMatchedStudentPen() throws Exception {
Mockito.when(this.restUtils.requestEventResponseFromServicesAPI(ArgumentMatchers.any())).thenReturn(Optional.of(Event.builder().eventOutcome(EventOutcome.VALIDATION_SUCCESS_NO_ERROR_WARNING).build()));
val matchList = new ArrayList<PenMatchRecord>(1);
matchList.add(PenMatchRecord.builder().matchingPEN("123456789").studentID("studentID").build());
final PenMatchResult penMatchResult = PenMatchResult.builder().penStatus("D1").matchingRecords(matchList).build();
Mockito.when(this.restUtils.requestEventResponseFromMatchAPI(ArgumentMatchers.any())).thenReturn(Optional.of(Event.builder().eventOutcome(EventOutcome.PEN_MATCH_PROCESSED).eventPayload(JsonUtil.getJsonStringFromObject(penMatchResult)).build()));
Mockito.when(this.restUtils.getStudentByPEN("123456789")).thenReturn(Optional.of(Student.builder().studentID("studentID").pen("123456789").build()));
this.mockMvc.perform(post("/api/v1/pen-request-batch/pen-request").with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_REQUEST_BATCH"))).content("{\n" + " \"localStudentID\": \"102000201\",\n" + " \"legalSurname\": \"AAAA\",\n" + " \"legalGivenName\": \"OM\",\n" + " \"birthDate\": \"19801114\",\n" + " \"gender\": \"M\",\n" + " \"enrolledGradeCode\": \"12\",\n" + " \"postalCode\": \"V8T0E1\",\n" + " \"mincode\": \"10200001\",\n" + " \"createUser\": \"om\",\n" + " \"updateUser\": \"om\"\n" + "}").contentType(APPLICATION_JSON)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.pen", is("123456789")));
}
use of ca.bc.gov.educ.penreg.api.constants.EventOutcome in project EDUC-PEN-REG-BATCH-API by bcgov.
the class BaseOrchestrator method replayFromLastEvent.
/**
* This method will restart the saga process from where it was left the last time. which could occur due to various reasons
*
* @param saga the model object.
* @param eventStates the event states corresponding to the saga
* @param t the payload string as an object
* @throws InterruptedException if thread is interrupted.
* @throws TimeoutException if connection to messaging system times out.
* @throws IOException if there is connectivity problem
*/
private void replayFromLastEvent(final Saga saga, final List<SagaEvent> eventStates, final T t) throws InterruptedException, TimeoutException, IOException {
val sagaEventOptional = this.findTheLastEventOccurred(eventStates);
if (sagaEventOptional.isPresent()) {
val sagaEvent = sagaEventOptional.get();
log.trace(sagaEventOptional.toString());
final EventType currentEvent = EventType.valueOf(sagaEvent.getSagaEventState());
final EventOutcome eventOutcome = EventOutcome.valueOf(sagaEvent.getSagaEventOutcome());
final Event event = Event.builder().eventOutcome(eventOutcome).eventType(currentEvent).eventPayload(sagaEvent.getSagaEventResponse()).build();
final Optional<SagaEventState<T>> sagaEventState = this.findNextSagaEventState(currentEvent, eventOutcome, t);
if (sagaEventState.isPresent()) {
log.trace(SYSTEM_IS_GOING_TO_EXECUTE_NEXT_EVENT_FOR_CURRENT_EVENT, sagaEventState.get().getNextEventType(), event.toString(), saga.getSagaId());
this.invokeNextEvent(event, saga, t, sagaEventState.get());
}
}
}
Aggregations