use of ca.bc.gov.educ.penreg.api.struct.PenMatchResult in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchAPIControllerTest method testPostPenRequest_GivenStudentDataWithValidationErrors_ShouldReturnValidationIssues.
@Test
public void testPostPenRequest_GivenStudentDataWithValidationErrors_ShouldReturnValidationIssues() throws Exception {
Mockito.when(this.restUtils.requestEventResponseFromServicesAPI(ArgumentMatchers.any())).thenReturn(Optional.of(Event.builder().eventOutcome(EventOutcome.VALIDATION_SUCCESS_WITH_ERROR).eventPayload(" [\n" + " {\n" + " \"penRequestBatchStudentValidationIssueId\": null,\n" + " \"penRequestBatchValidationIssueSeverityCode\": \"ERROR\",\n" + " \"penRequestBatchValidationIssueTypeCode\": \"REPEATCHARS\",\n" + " \"penRequestBatchValidationFieldCode\": \"LEGALLAST\"\n" + " },\n" + " {\n" + " \"penRequestBatchStudentValidationIssueId\": null,\n" + " \"penRequestBatchValidationIssueSeverityCode\": \"WARNING\",\n" + " \"penRequestBatchValidationIssueTypeCode\": \"OLD4GRADE\",\n" + " \"penRequestBatchValidationFieldCode\": \"GRADECODE\"\n" + " }\n" + " ]").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()));
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("$.validationIssues", hasSize(greaterThan(0)))).andExpect(jsonPath("$.pen", is(emptyOrNullString())));
}
use of ca.bc.gov.educ.penreg.api.struct.PenMatchResult 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.struct.PenMatchResult 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.struct.PenMatchResult in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchStudentOrchestratorServiceTest method testProcessPenMatchResult_givenSummerSchoolForD0_recordMarkedAsFixable.
@Test
public void testProcessPenMatchResult_givenSummerSchoolForD0_recordMarkedAsFixable() throws IOException {
final var prbStudentEntity = JsonUtil.getJsonObjectFromString(PenRequestBatchStudentEntity.class, this.dummyPenRequestBatchStudentDataJson(USR_NEW_PEN.toString()));
prbStudentEntity.setUpdateDate(LocalDateTime.now());
final var eventPayload = new PenMatchResult();
eventPayload.setPenStatus("D0");
final PenMatchRecord record = new PenMatchRecord();
List<PenRequestBatchEntity> batches = this.penRequestBatchRepository.findAll();
final PenRequestBatchStudentEntity studEntity = batches.get(0).getPenRequestBatchStudentEntities().stream().findFirst().orElseThrow();
record.setStudentID(studEntity.getPenRequestBatchStudentID().toString());
when(this.restUtils.getStudentByStudentID(studEntity.getPenRequestBatchStudentID().toString())).thenReturn(Student.builder().studentID(studEntity.getPenRequestBatchStudentID().toString()).pen(TEST_PEN).build());
record.setMatchingPEN("123456789");
eventPayload.setMatchingRecords(new ArrayList<>());
eventPayload.getMatchingRecords().add(record);
this.sagaData.setMincode("03990089");
this.orchestratorService.processPenMatchResult(this.saga, this.sagaData, eventPayload);
final var sagaFromDB = this.sagaService.findSagaById(this.saga.getSagaId());
assertThat(sagaFromDB).isPresent();
batches = this.penRequestBatchRepository.findAll();
assertThat(batches.get(0).getPenRequestBatchStudentEntities().stream().findFirst().orElseThrow().getPenRequestBatchStudentStatusCode()).isEqualTo(PenRequestBatchStudentStatusCodes.FIXABLE.getCode());
}
use of ca.bc.gov.educ.penreg.api.struct.PenMatchResult in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchStudentOrchestratorServiceTest method testProcessPenMatchResult_givenSFASForD1_noUpdatesToStudent.
@Test
public void testProcessPenMatchResult_givenSFASForD1_noUpdatesToStudent() throws IOException {
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();
List<PenRequestBatchEntity> batches = this.penRequestBatchRepository.findAll();
final PenRequestBatchStudentEntity studEntity = batches.get(0).getPenRequestBatchStudentEntities().stream().findFirst().orElseThrow();
record.setStudentID(studEntity.getPenRequestBatchStudentID().toString());
when(this.restUtils.getStudentByStudentID(studEntity.getPenRequestBatchStudentID().toString())).thenReturn(Student.builder().studentID(studEntity.getPenRequestBatchStudentID().toString()).pen(TEST_PEN).build());
record.setMatchingPEN("123456789");
eventPayload.setMatchingRecords(new ArrayList<>());
eventPayload.getMatchingRecords().add(record);
this.sagaData.setMincode("10200030");
this.orchestratorService.processPenMatchResult(this.saga, this.sagaData, eventPayload);
final var sagaFromDB = this.sagaService.findSagaById(this.saga.getSagaId());
assertThat(sagaFromDB).isPresent();
batches = this.penRequestBatchRepository.findAll();
assertThat(batches.get(0).getPenRequestBatchStudentEntities().stream().findFirst().orElseThrow().getPenRequestBatchStudentStatusCode()).isEqualTo(PenRequestBatchStudentStatusCodes.SYS_MATCHED.getCode());
verify(this.restUtils, never()).updateStudent(any());
}
Aggregations