use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchAPIControllerTest method testReadPenRequestBatchPaginated_GivenSchoolNameAndInvalidStudentName_ShouldReturnStatusOk.
/**
* Test read pen request batch paginated given school name and invalid student name should return empty list.
*
* @throws Exception the exception
*/
@Test
public void testReadPenRequestBatchPaginated_GivenSchoolNameAndInvalidStudentName_ShouldReturnStatusOk() throws Exception {
final String batchIDs = this.createBatchStudentRecords(2);
final SearchCriteria criteria = SearchCriteria.builder().key("schoolName").operation(FilterOperation.STARTS_WITH).value("Brae").valueType(ValueType.STRING).build();
final SearchCriteria criteria2 = SearchCriteria.builder().key("penRequestBatchStudentEntities.legalLastName").condition(AND).operation(FilterOperation.STARTS_WITH).value("AB").valueType(ValueType.STRING).build();
final List<SearchCriteria> criteriaList = new ArrayList<>();
criteriaList.add(criteria);
criteriaList.add(criteria2);
final List<Search> searches = new LinkedList<>();
searches.add(Search.builder().searchCriteriaList(criteriaList).build());
final ObjectMapper objectMapper = new ObjectMapper();
final String criteriaJSON = objectMapper.writeValueAsString(searches);
final MvcResult result = this.mockMvc.perform(get("/api/v1/pen-request-batch/paginated").with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_REQUEST_BATCH"))).param("searchCriteriaList", criteriaJSON).contentType(APPLICATION_JSON)).andReturn();
this.mockMvc.perform(asyncDispatch(result)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.content", hasSize(0)));
}
use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.
the class RestUtilsTest method testCreateStudent_givenAPICallSuccess_shouldReturnCreatedData.
@Test
public void testCreateStudent_givenAPICallSuccess_shouldReturnCreatedData() {
final String studentID = UUID.randomUUID().toString();
final var invocations = mockingDetails(this.webClient).getInvocations().size();
final Student student = new Student();
student.setPen("123456789");
student.setStudentID(studentID);
when(this.webClient.post()).thenReturn(this.requestBodyUriMock);
when(this.requestBodyUriMock.uri(this.applicationProperties.getStudentApiURL())).thenReturn(this.requestBodyUriMock);
when(this.requestBodyUriMock.header(any(), any())).thenReturn(this.returnMockBodySpec());
when(this.requestBodyMock.body(any(), (Class<?>) any(Object.class))).thenReturn(this.requestHeadersMock);
when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock);
when(this.responseMock.bodyToMono(Student.class)).thenReturn(Mono.just(student));
final Student createdStudent = this.restUtils.createStudent(student);
verify(this.webClient, atMost(invocations + 1)).post();
assertThat(createdStudent).isNotNull();
assertThat(createdStudent.getStudentID()).isEqualTo(studentID);
}
use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.
the class RestUtilsTest method testGetStudentByPEN_givenAPICallSuccess_shouldReturnData.
@Test
public void testGetStudentByPEN_givenAPICallSuccess_shouldReturnData() throws JsonProcessingException {
final Student student = new Student();
student.setPen("123456789");
Message natsResponse = NatsMessageImpl.builder().data(new ObjectMapper().writeValueAsBytes(student)).build();
when(this.messagePublisher.requestMessage(eq(STUDENT_API_TOPIC.toString()), any())).thenReturn(CompletableFuture.completedFuture(natsResponse));
val result = this.restUtils.getStudentByPEN("123456789");
assertThat(result).isNotNull().isPresent();
assertThat(result.get().getPen()).isEqualTo("123456789");
}
use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchStudentOrchestratorServiceTest method testProcessPenMatchResult_givenSummerSchoolForD1_mincodeLocalIDisUpdated.
@Test
public void testProcessPenMatchResult_givenSummerSchoolForD1_mincodeLocalIDisUpdated() 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);
final ArgumentCaptor<Student> argument = ArgumentCaptor.forClass(Student.class);
doNothing().when(this.restUtils).updateStudent(argument.capture());
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.SYS_MATCHED.getCode());
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();
assertThat(studentUpdate.getMincode()).isNotNull();
assertThat(studentUpdate.getMincode()).doesNotContainAnyWhitespaces();
}
use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.
the class PenRequestBatchStudentOrchestratorServiceTest method testProcessPenMatchResult_givenSystemMatchScenarioWithBadLocalID_studentLocalIDShouldBeUpdatedWithNull.
@Test
public void testProcessPenMatchResult_givenSystemMatchScenarioWithBadLocalID_studentLocalIDShouldBeUpdatedWithNull() 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();
final List<PenRequestBatchEntity> batches = this.penRequestBatchRepository.findAll();
val firstBatchRecord = batches.get(0);
final PenRequestBatchStudentEntity studEntity = firstBatchRecord.getPenRequestBatchStudentEntities().stream().findFirst().orElseThrow();
this.sagaData.setLocalID("N#A");
this.penRequestBatchRepository.save(firstBatchRecord);
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.getLocalID()).isNull();
// localID after update should not match any of the bad localID
for (BadLocalID info : EnumSet.allOf(BadLocalID.class)) {
assertThat(info.getLabel()).isNotEqualTo(studentUpdate.getLocalID());
}
}
Aggregations