Search in sources :

Example 26 with Student

use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.

the class PenRequestBatchReportDataMapperTest method testToReportUserMatchedListItem_GivenNullValues_ShouldMapSuccessfully.

@Test
public void testToReportUserMatchedListItem_GivenNullValues_ShouldMapSuccessfully() throws IOException {
    final var batchEntities = PenRequestBatchTestUtils.createBatchStudents(this.repository, "mock_pen_req_batch_repeat.json", "mock_pen_req_batch_student_null_data.json", 1, (batch) -> batch.setProcessDate(LocalDateTime.parse("2021-03-23T13:04:48.840098")));
    final var student1 = Student.builder().studentID("566ee980-8e5f-11eb-8dcd-0242ac130002").pen("123456785").demogCode("C").build();
    final var student2 = Student.builder().studentID("566ee980-8e5f-11eb-8dcd-0242ac130003").pen("123456780").legalLastName("BILL").build();
    final List<Student> students = new ArrayList<>();
    students.add(student1);
    students.add(student2);
    final var sagaData = PenRequestBatchArchiveAndReturnSagaData.builder().facsimile("3333333333").telephone("5555555555").fromEmail("test@abc.com").mailingAddress("mailing address").schoolName("Cataline").penRequestBatch(mapper.toStructure(batchEntities.get(0))).penRequestBatchStudents(batchEntities.get(0).getPenRequestBatchStudentEntities().stream().map(studentMapper::toStructure).collect(Collectors.toList())).penRequestBatchStudentValidationIssues(new HashMap<>()).students(students).build();
    final PenRequestBatchReportData reportData = reportMapper.toReportData(sagaData);
    assertThat(reportData.getProcessDate()).isEqualTo("2021/03/23");
    assertThat(reportData.getProcessTime()).isEqualTo("13:04");
    assertThat(reportData.getSubmissionNumber()).isEqualTo(batchEntities.get(0).getSubmissionNumber());
    assertThat(reportData.getReportDate()).isEqualTo("2021-MAR-23");
    assertThat(reportData.getReviewer()).isEqualTo("School PEN Coordinator");
    assertThat(reportData.getMincode()).isEqualTo(formatMincode(batchEntities.get(0).getMincode()));
    assertThat(reportData.getSchoolName()).isEqualTo("Cataline");
    assertThat(reportData.getFascimile()).isEqualTo("3333333333");
    assertThat(reportData.getTelephone()).isEqualTo("5555555555");
    assertThat(reportData.getMailingAddress()).isEqualTo("mailing address");
    assertThat(reportData.getPenCordinatorEmail()).isEqualTo("test@abc.com");
    assertThat(reportData.getDiffList().size()).isEqualTo(1);
    assertThat(reportData.getDiffList().get(0).getMin().getBirthDate()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getMin().getGender()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getMin().getGivenName()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getMin().getLegalMiddleNames()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getMin().getPen()).isEqualTo("123456780");
    assertThat(reportData.getDiffList().get(0).getMin().getReason()).isEqualTo(null);
    assertThat(reportData.getDiffList().get(0).getMin().getSchoolID()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getMin().getSurname()).isEqualTo("BILL");
    assertThat(reportData.getDiffList().get(0).getMin().getUsualName()).isEqualTo("");
    assertThat(reportData.getDiffList().size()).isEqualTo(1);
    assertThat(reportData.getDiffList().get(0).getSchool().getBirthDate()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getSchool().getGender()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getSchool().getGivenName()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getSchool().getLegalMiddleNames()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getSchool().getPen()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getSchool().getReason()).isEqualTo(null);
    assertThat(reportData.getDiffList().get(0).getSchool().getSchoolID()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getSchool().getSurname()).isEqualTo("");
    assertThat(reportData.getDiffList().get(0).getSchool().getUsualName()).isEqualTo("");
    assertThat(reportData.getSysMatchedList().size()).isEqualTo(2);
    assertThat(reportData.getSysMatchedList().get(1).getBirthDate()).isEqualTo("");
    assertThat(reportData.getSysMatchedList().get(1).getGender()).isEqualTo("");
    assertThat(reportData.getSysMatchedList().get(1).getGivenName()).isEqualTo("");
    assertThat(reportData.getSysMatchedList().get(1).getLegalMiddleNames()).isEqualTo("");
    assertThat(reportData.getSysMatchedList().get(1).getPen()).isEqualTo("");
    assertThat(reportData.getSysMatchedList().get(1).getReason()).isEqualTo(null);
    assertThat(reportData.getSysMatchedList().get(1).getSchoolID()).isEqualTo("");
    assertThat(reportData.getSysMatchedList().get(1).getSurname()).isEqualTo("");
    assertThat(reportData.getSysMatchedList().get(1).getUsualName()).isEqualTo("");
    assertThat(reportData.getNewPenList().size()).isEqualTo(2);
    assertThat(reportData.getPendingList().size()).isEqualTo(4);
    assertThat(reportData.getSysMatchedList().size()).isEqualTo(2);
}
Also used : PenRequestBatchReportData(ca.bc.gov.educ.penreg.api.struct.v1.reportstructs.PenRequestBatchReportData) ArrayList(java.util.ArrayList) Student(ca.bc.gov.educ.penreg.api.struct.Student) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Example 27 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 testUpdatePenRequestBatchStudent_GivenPenRequestBatchStudent_ShouldReturnStatusOk.

/**
 * Test update pen request batch student given pen request batch student should return status ok.
 *
 * @throws Exception the exception
 */
@Test
public void testUpdatePenRequestBatchStudent_GivenPenRequestBatchStudent_ShouldReturnStatusOk() throws Exception {
    final var models = this.createBatchStudents(1);
    final var student = studentMapper.toStructure(models.get(0).getPenRequestBatchStudentEntities().stream().findFirst().orElseThrow());
    student.setPenRequestBatchStudentStatusCode("FIXABLE");
    student.setInfoRequest("Test Info");
    final var request = new ObjectMapper().writeValueAsString(student);
    this.mockMvc.perform(put(String.format("/api/v1/pen-request-batch/%s/student/%s", student.getPenRequestBatchID(), student.getPenRequestBatchStudentID())).with(jwt().jwt((jwt) -> jwt.claim("scope", "WRITE_PEN_REQUEST_BATCH"))).contentType(APPLICATION_JSON).accept(APPLICATION_JSON).content(request)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.penRequestBatchStudentStatusCode", is("FIXABLE"))).andExpect(jsonPath("$.infoRequest", is("Test Info")));
}
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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BasePenRegAPITest(ca.bc.gov.educ.penreg.api.BasePenRegAPITest) Test(org.junit.Test)

Example 28 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 testReadPenRequestBatchStudentPaginated_GivenPenRequestBatchIdsAndStudentStatusCodes_ShouldReturnStatusOk.

/**
 * Test read pen request batch student paginated given pen request batch ids and student status codes should return status ok.
 *
 * @throws Exception the exception
 */
@Test
public void testReadPenRequestBatchStudentPaginated_GivenPenRequestBatchIdsAndStudentStatusCodes_ShouldReturnStatusOk() throws Exception {
    final String batchIDs = this.createBatchStudentRecords(2);
    final SearchCriteria criteria = SearchCriteria.builder().key("penRequestBatchEntity.penRequestBatchID").operation(FilterOperation.IN).value(batchIDs).valueType(ValueType.UUID).build();
    final List<SearchCriteria> criteriaList = new LinkedList<>();
    criteriaList.add(criteria);
    final SearchCriteria criteria1 = SearchCriteria.builder().key("penRequestBatchStudentStatusCode").operation(FilterOperation.IN).value("LOADED,ERROR,FIXABLE").valueType(ValueType.STRING).build();
    final List<SearchCriteria> criteriaList1 = new LinkedList<>();
    criteriaList1.add(criteria1);
    final List<Search> searches = new LinkedList<>();
    searches.add(Search.builder().searchCriteriaList(criteriaList).build());
    searches.add(Search.builder().condition(AND).searchCriteriaList(criteriaList1).build());
    final ObjectMapper objectMapper = new ObjectMapper();
    final String criteriaJSON = objectMapper.writeValueAsString(searches);
    final String sort = this.createSortParam();
    final MvcResult result = this.mockMvc.perform(get("/api/v1/pen-request-batch/student/paginated").with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_REQUEST_BATCH"))).param("searchCriteriaList", criteriaJSON).param("sort", sort).param("pageSize", "3").contentType(APPLICATION_JSON)).andReturn();
    this.mockMvc.perform(asyncDispatch(result)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.content", hasSize(3)));
}
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 29 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 testReadPenRequestBatchStudentPaginated_GivenPenRequestBatchIdsAndAllStudentStatusCodesAndOtherConditions_ShouldReturnStatusOk.

/**
 * Test read pen request batch student paginated given pen request batch ids and all student status codes and other conditions should return status ok.
 *
 * @throws Exception the exception
 */
@Test
public void testReadPenRequestBatchStudentPaginated_GivenPenRequestBatchIdsAndAllStudentStatusCodesAndOtherConditions_ShouldReturnStatusOk() throws Exception {
    final String batchIDs = this.createBatchStudentRecords(2);
    final SearchCriteria criteria = SearchCriteria.builder().key("penRequestBatchEntity.penRequestBatchID").operation(FilterOperation.IN).value(batchIDs).valueType(ValueType.UUID).build();
    final List<SearchCriteria> criteriaList = new LinkedList<>();
    criteriaList.add(criteria);
    final SearchCriteria criteria2 = SearchCriteria.builder().key("penRequestBatchStudentStatusCode").operation(FilterOperation.NOT_EQUAL).value("FIXABLE").valueType(ValueType.STRING).build();
    final SearchCriteria criteria3 = SearchCriteria.builder().key("penRequestBatchEntity.mincode").condition(AND).operation(FilterOperation.STARTS_WITH_IGNORE_CASE).value("1").valueType(ValueType.STRING).build();
    final SearchCriteria criteria4 = SearchCriteria.builder().key("legalLastName").condition(AND).operation(FilterOperation.STARTS_WITH_IGNORE_CASE).value("j").valueType(ValueType.STRING).build();
    final List<SearchCriteria> criteriaList1 = new LinkedList<>();
    criteriaList1.add(criteria2);
    criteriaList1.add(criteria3);
    criteriaList1.add(criteria4);
    final List<Search> searches = new LinkedList<>();
    searches.add(Search.builder().searchCriteriaList(criteriaList).build());
    searches.add(Search.builder().condition(AND).searchCriteriaList(criteriaList1).build());
    final ObjectMapper objectMapper = new ObjectMapper();
    final String criteriaJSON = objectMapper.writeValueAsString(searches);
    final String sort = this.createSortParam();
    final MvcResult result = this.mockMvc.perform(get("/api/v1/pen-request-batch/student/paginated").with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_PEN_REQUEST_BATCH"))).param("searchCriteriaList", criteriaJSON).param("sort", sort).param("pageSize", "3").contentType(APPLICATION_JSON)).andReturn();
    this.mockMvc.perform(asyncDispatch(result)).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("$.content", hasSize(3)));
}
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 30 with Student

use of ca.bc.gov.educ.penreg.api.struct.Student in project EDUC-PEN-REG-BATCH-API by bcgov.

the class RestUtils method getStudentByPEN.

/**
 * Gets student by pen.
 *
 * @param pen the pen
 * @return the student by pen
 */
public Optional<Student> getStudentByPEN(final String pen) {
    val getStudentByPenEvent = Event.builder().eventType(EventType.GET_STUDENT).eventPayload(pen).sagaId(UUID.randomUUID()).build();
    try {
        log.info("calling getStudentByPEN :: {} via NATS for pen :: {}", STUDENT_API_TOPIC, pen);
        val eventResponse = this.messagePublisher.requestMessage(STUDENT_API_TOPIC.toString(), JsonUtil.getJsonString(getStudentByPenEvent).orElseThrow().getBytes(StandardCharsets.UTF_8)).get(30, TimeUnit.SECONDS).getData();
        log.info("got response from NATS for pen :: {}, student found :: {}", pen, eventResponse.length > 0);
        if (eventResponse.length > 0) {
            return Optional.of(JsonUtil.getJsonObjectFromByteArray(Student.class, eventResponse));
        }
    } catch (final InterruptedException | ExecutionException | TimeoutException | IOException e) {
        Thread.currentThread().interrupt();
        log.error("Exception while get student by pen", e);
    }
    return Optional.empty();
}
Also used : lombok.val(lombok.val) IOException(java.io.IOException) Student(ca.bc.gov.educ.penreg.api.struct.Student) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

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