Search in sources :

Example 16 with Student

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)));
}
Also used : 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) Search(ca.bc.gov.educ.penreg.api.struct.v1.Search) MvcResult(org.springframework.test.web.servlet.MvcResult) SearchCriteria(ca.bc.gov.educ.penreg.api.struct.v1.SearchCriteria) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Example 17 with Student

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);
}
Also used : Student(ca.bc.gov.educ.penreg.api.struct.Student) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with Student

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");
}
Also used : lombok.val(lombok.val) Message(io.nats.client.Message) Student(ca.bc.gov.educ.penreg.api.struct.Student) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with Student

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();
}
Also used : PenMatchRecord(ca.bc.gov.educ.penreg.api.struct.PenMatchRecord) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) Student(ca.bc.gov.educ.penreg.api.struct.Student) PenMatchResult(ca.bc.gov.educ.penreg.api.struct.PenMatchResult) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity) Test(org.junit.Test) BaseOrchestratorTest(ca.bc.gov.educ.penreg.api.orchestrator.BaseOrchestratorTest)

Example 20 with Student

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());
    }
}
Also used : PenMatchRecord(ca.bc.gov.educ.penreg.api.struct.PenMatchRecord) lombok.val(lombok.val) BadLocalID(ca.bc.gov.educ.penreg.api.constants.BadLocalID) PenRequestBatchEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity) Student(ca.bc.gov.educ.penreg.api.struct.Student) PenMatchResult(ca.bc.gov.educ.penreg.api.struct.PenMatchResult) PenRequestBatchStudentEntity(ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity) Test(org.junit.Test) BaseOrchestratorTest(ca.bc.gov.educ.penreg.api.orchestrator.BaseOrchestratorTest)

Aggregations

Student (ca.bc.gov.educ.penreg.api.struct.Student)44 Test (org.junit.Test)26 lombok.val (lombok.val)24 Event (ca.bc.gov.educ.penreg.api.struct.Event)17 PenRequestBatchStudent (ca.bc.gov.educ.penreg.api.struct.v1.PenRequestBatchStudent)16 LocalDateTime (java.time.LocalDateTime)14 Collectors (java.util.stream.Collectors)14 PenRequestBatchEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchEntity)13 RestUtils (ca.bc.gov.educ.penreg.api.rest.RestUtils)13 JsonUtil (ca.bc.gov.educ.penreg.api.util.JsonUtil)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 BasePenRegAPITest (ca.bc.gov.educ.penreg.api.BasePenRegAPITest)12 PenRequestBatchStudentEntity (ca.bc.gov.educ.penreg.api.model.v1.PenRequestBatchStudentEntity)12 SagaEvent (ca.bc.gov.educ.penreg.api.model.v1.SagaEvent)12 SagaService (ca.bc.gov.educ.penreg.api.service.SagaService)12 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 EventOutcome (ca.bc.gov.educ.penreg.api.constants.EventOutcome)11 PenRequestBatchStudentStatusCodes (ca.bc.gov.educ.penreg.api.constants.PenRequestBatchStudentStatusCodes)11 PenMatchRecord (ca.bc.gov.educ.penreg.api.struct.PenMatchRecord)11 PenMatchResult (ca.bc.gov.educ.penreg.api.struct.PenMatchResult)11