Search in sources :

Example 1 with EventOutcome

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")));
}
Also used : lombok.val(lombok.val) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) ArgumentMatchers(org.mockito.ArgumentMatchers) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) PenRequestBatchStudentValidationIssueEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentValidationIssueEntity) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchTestUtils(ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils) PenRequestBatchMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchMapper) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity) MockitoAnnotations(org.mockito.MockitoAnnotations) PENWebBlobEntity(ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity) PenMatchRecord(ca.bc.gov.educ.penreg.api.struct.PenMatchRecord) OR(ca.bc.gov.educ.penreg.api.struct.v1.Condition.OR) TypeReference(com.fasterxml.jackson.core.type.TypeReference) RestUtils(ca.bc.gov.educ.penreg.api.rest.RestUtils) ValueType(ca.bc.gov.educ.penreg.api.struct.v1.ValueType) MockMvcResultHandlers.print(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print) EventOutcome(ca.bc.gov.educ.penreg.api.constants.EventOutcome) PenRequestBatchSubmission(ca.bc.gov.educ.penreg.api.struct.v1.external.PenRequestBatchSubmission) Collectors(java.util.stream.Collectors) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) java.util(java.util) PenRequestBatchStudentMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchStudentMapper) LocalDateTime(java.time.LocalDateTime) AND(ca.bc.gov.educ.penreg.api.struct.v1.Condition.AND) MockMvc(org.springframework.test.web.servlet.MockMvc) PenMatchResult(ca.bc.gov.educ.penreg.api.struct.PenMatchResult) PenRequestBatch(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatch) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MvcResult(org.springframework.test.web.servlet.MvcResult) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) SchoolGroupCodes(ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes) Before(org.junit.Before) SecurityMockMvcRequestPostProcessors.jwt(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt) FilterOperation(ca.bc.gov.educ.penreg.api.filter.FilterOperation) PenRequestBatchStudentStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA(ca.bc.gov.educ.penreg.api.constants.SagaEnum.PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA) SagaService(ca.bc.gov.educ.penreg.api.service.SagaService) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) Matchers(org.hamcrest.Matchers) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) File(java.io.File) Event(ca.bc.gov.educ.penreg.api.struct.Event) Mockito(org.mockito.Mockito) Collectors.toList(java.util.stream.Collectors.toList) Student(ca.bc.gov.educ.penreg.api.struct.Student) ca.bc.gov.educ.penreg.api.repository(ca.bc.gov.educ.penreg.api.repository) PenMatchResult(ca.bc.gov.educ.penreg.api.struct.PenMatchResult) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Example 2 with EventOutcome

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")));
}
Also used : lombok.val(lombok.val) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) ArgumentMatchers(org.mockito.ArgumentMatchers) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) PenRequestBatchStudentValidationIssueEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentValidationIssueEntity) Autowired(org.springframework.beans.factory.annotation.Autowired) PenRequestBatchTestUtils(ca.bc.gov.educ.penreg.api.support.PenRequestBatchTestUtils) PenRequestBatchMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchMapper) JsonUtil(ca.bc.gov.educ.penreg.api.util.JsonUtil) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity) MockitoAnnotations(org.mockito.MockitoAnnotations) PENWebBlobEntity(ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity) PenMatchRecord(ca.bc.gov.educ.penreg.api.struct.PenMatchRecord) OR(ca.bc.gov.educ.penreg.api.struct.v1.Condition.OR) TypeReference(com.fasterxml.jackson.core.type.TypeReference) RestUtils(ca.bc.gov.educ.penreg.api.rest.RestUtils) ValueType(ca.bc.gov.educ.penreg.api.struct.v1.ValueType) MockMvcResultHandlers.print(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print) EventOutcome(ca.bc.gov.educ.penreg.api.constants.EventOutcome) PenRequestBatchSubmission(ca.bc.gov.educ.penreg.api.struct.v1.external.PenRequestBatchSubmission) Collectors(java.util.stream.Collectors) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) java.util(java.util) PenRequestBatchStudentMapper(ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchStudentMapper) LocalDateTime(java.time.LocalDateTime) AND(ca.bc.gov.educ.penreg.api.struct.v1.Condition.AND) MockMvc(org.springframework.test.web.servlet.MockMvc) PenMatchResult(ca.bc.gov.educ.penreg.api.struct.PenMatchResult) PenRequestBatch(ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatch) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MvcResult(org.springframework.test.web.servlet.MvcResult) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) SchoolGroupCodes(ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes) Before(org.junit.Before) SecurityMockMvcRequestPostProcessors.jwt(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt) FilterOperation(ca.bc.gov.educ.penreg.api.filter.FilterOperation) PenRequestBatchStudentStatusCodes(ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) lombok.val(lombok.val) PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA(ca.bc.gov.educ.penreg.api.constants.SagaEnum.PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA) SagaService(ca.bc.gov.educ.penreg.api.service.SagaService) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) Matchers(org.hamcrest.Matchers) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) File(java.io.File) Event(ca.bc.gov.educ.penreg.api.struct.Event) Mockito(org.mockito.Mockito) Collectors.toList(java.util.stream.Collectors.toList) Student(ca.bc.gov.educ.penreg.api.struct.Student) ca.bc.gov.educ.penreg.api.repository(ca.bc.gov.educ.penreg.api.repository) PenMatchResult(ca.bc.gov.educ.penreg.api.struct.PenMatchResult) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Example 3 with EventOutcome

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());
        }
    }
}
Also used : lombok.val(lombok.val) EventOutcome(ca.bc.gov.educ.penreg.api.constants.EventOutcome) EventType(ca.bc.gov.educ.penreg.api.constants.EventType) SagaEvent(ca.bc.gov.educ.penreg.api.model.v1.SagaEvent) Event(ca.bc.gov.educ.penreg.api.struct.Event) NotificationEvent(ca.bc.gov.educ.penreg.api.struct.NotificationEvent)

Aggregations

EventOutcome (ca.bc.gov.educ.penreg.api.constants.EventOutcome)3 Event (ca.bc.gov.educ.penreg.api.struct.Event)3 lombok.val (lombok.val)3 BasePenRegAPITest (ca.bc.gov.educ.penreg.api.BasePenRegAPITest)2 PenRequestBatchStudentStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes)2 PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA (ca.bc.gov.educ.penreg.api.constants.SagaEnum.PEN_REQUEST_BATCH_USER_MATCH_PROCESSING_SAGA)2 SchoolGroupCodes (ca.bc.gov.educ.penreg.api.constants.SchoolGroupCodes)2 FilterOperation (ca.bc.gov.educ.penreg.api.filter.FilterOperation)2 PenRequestBatchMapper (ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchMapper)2 PenRequestBatchStudentMapper (ca.bc.gov.educ.penreg.api.mappers.v1.PenRequestBatchStudentMapper)2 PENWebBlobEntity (ca.bc.gov.educ.penreg.api.model.v1.PENWebBlobEntity)2 PenRequestBatchEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity)2 PenRequestBatchStudentEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)2 PenRequestBatchStudentValidationIssueEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentValidationIssueEntity)2 ca.bc.gov.educ.penreg.api.repository (ca.bc.gov.educ.penreg.api.repository)2 RestUtils (ca.bc.gov.educ.penreg.api.rest.RestUtils)2 SagaService (ca.bc.gov.educ.penreg.api.service.SagaService)2 PenMatchRecord (ca.bc.gov.educ.penreg.api.struct.PenMatchRecord)2 PenMatchResult (ca.bc.gov.educ.penreg.api.struct.PenMatchResult)2 Student (ca.bc.gov.educ.penreg.api.struct.Student)2