diff --git a/api/pom.xml b/api/pom.xml index 21bc6cf6..4bc3ca83 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,7 +6,7 @@ ca.bc.gov.educ educ-grad-student-api - 1.8.46 + 1.8.47 educ-grad-student-api Student Demographics API for GRAD team diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java index 2b844d24..7bc5019d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/constant/Topics.java @@ -8,5 +8,5 @@ public enum Topics { * GradStatus events topic. */ GRAD_STATUS_EVENT_TOPIC, - FETCH_GRAD_STATUS + GRAD_STUDENT_API_FETCH_GRAD_STATUS_TOPIC } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStatusSubscriber.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStatusSubscriber.java index 5a9903a7..cfbd15f8 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStatusSubscriber.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/messaging/jetstream/FetchGradStatusSubscriber.java @@ -1,8 +1,8 @@ package ca.bc.gov.educ.api.gradstudent.messaging.jetstream; +import ca.bc.gov.educ.api.gradstudent.constant.Topics; import ca.bc.gov.educ.api.gradstudent.exception.EntityNotFoundException; import ca.bc.gov.educ.api.gradstudent.model.dc.Event; -import ca.bc.gov.educ.api.gradstudent.model.dto.ChoreographedEvent; import ca.bc.gov.educ.api.gradstudent.service.GraduationStatusService; import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants; import ca.bc.gov.educ.api.gradstudent.util.JsonUtil; @@ -23,7 +23,7 @@ public class FetchGradStatusSubscriber implements MessageHandler { private final GraduationStatusService graduationStatusService; private final EducGradStudentApiConstants constants; - private static final String TOPIC = "FETCH_GRAD_STATUS"; + private static final String TOPIC = Topics.GRAD_STUDENT_API_FETCH_GRAD_STATUS_TOPIC.toString(); @Autowired public FetchGradStatusSubscriber(final Connection natsConnection, GraduationStatusService graduationStatusService, EducGradStudentApiConstants constants) { diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GradTraxStudent.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GradTraxStudent.java new file mode 100644 index 00000000..6dc21e8d --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/model/dto/GradTraxStudent.java @@ -0,0 +1,45 @@ +package ca.bc.gov.educ.api.gradstudent.model.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class GradTraxStudent { + private String pen; + private String program; // inc + private Date programCompletionDate; // inc + private String slpDate; // inc + private String sccDate; + private String gpa; + private String honoursStanding; // inc + private String studentGradData; + private String schoolOfRecord; // inc + private String schoolAtGrad; // inc + private String studentGrade; // inc + private String studentStatus; // inc + private String archiveFlag; // inc + private String frenchCert; + private String englishCert; + private String frenchDogwood; + private String consumerEducationRequirementMet; + private String studentCitizenship; + + // extra + private String graduationRequirementYear; + + // grad or non-grad + private Date distributionDate; + private String transcriptSchoolCategoryCode; + private String certificateSchoolCategoryCode; + // 1950 "AD" + private boolean adult19Rule; +} diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/scheduler/JetStreamEventScheduler.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/scheduler/JetStreamEventScheduler.java index 6124732b..349b3cda 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/scheduler/JetStreamEventScheduler.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/scheduler/JetStreamEventScheduler.java @@ -1,15 +1,15 @@ package ca.bc.gov.educ.api.gradstudent.scheduler; import ca.bc.gov.educ.api.gradstudent.messaging.jetstream.Publisher; +import ca.bc.gov.educ.api.gradstudent.model.entity.GradStatusEvent; import ca.bc.gov.educ.api.gradstudent.repository.GradStatusEventRepository; +import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants; import lombok.extern.slf4j.Slf4j; import net.javacrumbs.shedlock.core.LockAssert; import net.javacrumbs.shedlock.spring.annotation.SchedulerLock; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import java.time.LocalDateTime; - import static ca.bc.gov.educ.api.gradstudent.constant.EventStatus.DB_COMMITTED; /** @@ -23,35 +23,45 @@ public class JetStreamEventScheduler { private final GradStatusEventRepository gradStatusEventRepository; private final Publisher publisher; + private final EducGradStudentApiConstants constants; + /** * Instantiates a new Stan event scheduler. * * @param gradStatusEventRepository the grad status event repository * @param publisher the publisher */ - public JetStreamEventScheduler(GradStatusEventRepository gradStatusEventRepository, Publisher publisher) { + public JetStreamEventScheduler(final GradStatusEventRepository gradStatusEventRepository, + final Publisher publisher, + final EducGradStudentApiConstants constants) { this.gradStatusEventRepository = gradStatusEventRepository; this.publisher = publisher; + this.constants = constants; } /** * Find and publish grad status events to stan. */ - @Scheduled(cron = "${cron.scheduled.process.events.stan.run}") // minimum = every 5 minutes + @Scheduled(cron = "${cron.scheduled.process.events.stan.run}") @SchedulerLock(name = "PUBLISH_GRAD_STATUS_EVENTS_TO_JET_STREAM", lockAtLeastFor = "${cron.scheduled.process.events.stan.lockAtLeastFor}", lockAtMostFor = "${cron.scheduled.process.events.stan.lockAtMostFor}") public void findAndPublishGradStatusEventsToJetStream() { + log.debug("PUBLISH_GRAD_STATUS_EVENTS_TO_JET_STREAM: started - cron {}, lockAtMostFor {}", constants.getGradToTraxCronRun(), constants.getGradToTraxLockAtMostFor()); LockAssert.assertLocked(); var results = gradStatusEventRepository.findByEventStatusOrderByCreateDate(DB_COMMITTED.toString()); if (!results.isEmpty()) { - results.stream() - .filter(el -> el.getUpdateDate().isBefore(LocalDateTime.now().minusMinutes(5))) - .forEach(el -> { - try { - publisher.dispatchChoreographyEvent(el); - } catch (final Exception ex) { - log.error("Exception while trying to publish message", ex); - } - }); + int cnt = 0; + for (GradStatusEvent el : results) { + if (cnt++ >= constants.getGradToTraxProcessingThreshold()) { + log.info(" ==> Reached the processing threshold of {}", constants.getGradToTraxProcessingThreshold()); + break; + } + try { + publisher.dispatchChoreographyEvent(el); + } catch (final Exception ex) { + log.error("Exception while trying to publish message", ex); + } + } + log.debug("PUBLISH_GRAD_STATUS_EVENTS_TO_JET_STREAM: processing is completed"); } } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/CommonService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/CommonService.java index 56d6e047..958217f9 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/CommonService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/CommonService.java @@ -16,6 +16,8 @@ import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants; import ca.bc.gov.educ.api.gradstudent.util.GradValidation; import ca.bc.gov.educ.api.gradstudent.util.ThreadLocalStateUtil; +import jakarta.transaction.Transactional; +import jakarta.validation.Valid; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,9 +26,10 @@ import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.client.WebClient; -import jakarta.transaction.Transactional; -import jakarta.validation.Valid; -import java.util.*; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.UUID; @Service public class CommonService { @@ -202,11 +205,11 @@ public GradStudentAlgorithmData getGradStudentAlgorithmData(String studentID,Str GradStudentAlgorithmData data = new GradStudentAlgorithmData(); GradSearchStudent gradStudent = gradStudentService.getStudentByStudentIDFromStudentAPI(studentID, accessToken); GraduationStudentRecord gradStudentRecord = graduationStatusService.getGraduationStatusForAlgorithm(UUID.fromString(studentID)); - List cpList = new ArrayList<>(); - try { - cpList = getAllGradStudentCareerProgramList(studentID, accessToken); - }catch (Exception e) { - logger.debug("TRAX-API-DOWN {}",e.getLocalizedMessage()); + List cpList = getAllGradStudentCareerProgramList(studentID, accessToken); + GradTraxStudent gradTraxStudent = gradStudentService.getTraxStudentMasterDataByPen(gradStudent.getPen(), accessToken); + if(gradTraxStudent != null) { + gradStudent.setStudentCitizenship(gradTraxStudent.getStudentCitizenship()); + gradStudentRecord.setStudentCitizenship(gradTraxStudent.getStudentCitizenship()); } data.setGradStudent(gradStudent); data.setGraduationStudentRecord(gradStudentRecord); diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java index 225e2fa0..39d277de 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentService.java @@ -8,6 +8,7 @@ import ca.bc.gov.educ.api.gradstudent.util.ThreadLocalStateUtil; import com.fasterxml.jackson.databind.ObjectMapper; import io.github.resilience4j.retry.annotation.Retry; +import jakarta.transaction.Transactional; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,7 +21,6 @@ import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; -import jakarta.transaction.Transactional; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -356,6 +356,24 @@ public GradSearchStudent getStudentByStudentIDFromStudentAPI(String studentID, S return gradStu; } + @Transactional + @Retry(name = "rt-getTraxStudent") + public GradTraxStudent getTraxStudentMasterDataByPen(String pen, String accessToken) { + final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { + }; + List result = this.webClient.get() + .uri(String.format(constants.getTraxStudentMasterDataByPenUrl(), pen)) + .headers(h -> { + h.setBearerAuth(accessToken); + h.set(EducGradStudentApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); + }) + .retrieve().bodyToMono(responseType).block(); + if(result != null && !result.isEmpty()) { + return result.get(0); + } + return null; + } + @Transactional @Retry(name = "searchbyid") public GraduationStudentRecordDistribution getStudentByStudentIDFromGrad(String studentID) { @@ -380,6 +398,18 @@ public List getStudentIDsByStatusCode(List studentIDs, String status if (StringUtils.isBlank(statusCode) || studentIDs.isEmpty()) { return new ArrayList<>(); } - return graduationStatusRepository.filterGivenStudentsByStatusCode(studentIDs, statusCode); + List results = new ArrayList<>(); + int pageSize = 1000; + int pageNum = studentIDs.size() / pageSize + 1; + for (int i = 0; i < pageNum; i++) { + int startIndex = i * pageSize; + int endIndex = Math.min(startIndex + pageSize, studentIDs.size()); + List inputIDs = studentIDs.subList(startIndex, endIndex); + List responseIDs = graduationStatusRepository.filterGivenStudentsByStatusCode(inputIDs, statusCode); + if (responseIDs != null && !responseIDs.isEmpty()) { + results.addAll(responseIDs); + } + } + return results; } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java index e600adad..40247e9e 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiConstants.java @@ -103,6 +103,8 @@ public class EducGradStudentApiConstants { public static final String CONV_STUDENT_OPTIONAL_PROGRAM_BY_STUDENT_ID = "/conv/studentoptionalprogram/{optionalProgramID}/{studentID}"; public static final String CONV_STUDENT_CAREER_PROGRAM_BY_STUDENT_ID = "/conv/studentcareerprogram/{careerProgramCode}/{studentID}"; + public static final String EDW_GRADUATION_STATUS_SNAPSHOT = "/edw/snapshot"; + //Default Date format constants public static final String DEFAULT_CREATED_BY = "API_GRAD_STUDENT"; public static final String DEFAULT_UPDATED_BY = "API_GRAD_STUDENT"; @@ -132,6 +134,9 @@ public class EducGradStudentApiConstants { @Value("${endpoint.grad-trax-api.district-by-district-code.url}") private String districtByDistrictCodeUrl; + @Value("${endpoint.grad-trax-api.get-student-master-data.url}") + private String traxStudentMasterDataByPenUrl; + @Value("${endpoint.grad-program-api.career_program-by-career-code.url}") private String careerProgramByCodeUrl; @@ -189,4 +194,17 @@ public class EducGradStudentApiConstants { // Data Conversion option @Value("${data-conversion.student-guid-pen-xref.enabled}") private boolean studentGuidPenXrefEnabled; + + // Scheduler: ongoing updates from GRAD to TRAX + @Value("${cron.scheduled.process.events.stan.run}") + private String gradToTraxCronRun; + + @Value("${cron.scheduled.process.events.stan.lockAtLeastFor}") + private String gradToTraxLockAtLeastFor; + + @Value("${cron.scheduled.process.events.stan.lockAtMostFor}") + private String gradToTraxLockAtMostFor; + + @Value("${cron.scheduled.process.events.stan.threshold}") + private int gradToTraxProcessingThreshold; } diff --git a/api/src/main/resources/application.yaml b/api/src/main/resources/application.yaml index 90ec9c66..6f1d051c 100644 --- a/api/src/main/resources/application.yaml +++ b/api/src/main/resources/application.yaml @@ -107,6 +107,7 @@ cron: run: ${CRON_SCHEDULED_PROCESS_EVENTS_STAN} lockAtLeastFor: ${CRON_SCHEDULED_PROCESS_EVENTS_STAN_LOCK_AT_LEAST_FOR} lockAtMostFor: ${CRON_SCHEDULED_PROCESS_EVENTS_STAN_LOCK_AT_MOST_FOR} + threshold: ${CRON_SCHEDULED_PROCESS_EVENTS_STAN_THRESHOLD} #Resilience resilience4j.retry: @@ -150,6 +151,8 @@ resilience4j.retry: #Endpoint properties endpoint: grad-trax-api: + get-student-master-data: + url: ${GRAD_TRAX_API}api/v1/trax/common/student-master/%s school-by-min-code: url: ${GRAD_TRAX_API}api/v1/trax/school/%s district-by-district-code: diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java index 81e268b9..84de4a42 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/CommonServiceTest.java @@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.core.ParameterizedTypeReference; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.WebClient; @@ -326,7 +327,8 @@ public void testGetAllStudentStatusCodeList() { obj.setUpdateDate(new Date()); gradStudentStatusList.add(obj); Mockito.when(studentStatusRepository.findAll()).thenReturn(gradStudentStatusList); - commonService.getAllStudentStatusCodeList(); + List result = commonService.getAllStudentStatusCodeList(); + assertThat(result).isNotNull(); } @Test @@ -348,14 +350,16 @@ public void testGetSpecificStudentStatusCode() { objEntity.setUpdateDate(new Date()); Optional ent = Optional.of(objEntity); Mockito.when(studentStatusRepository.findById(reasonCode)).thenReturn(ent); - commonService.getSpecificStudentStatusCode(reasonCode); + StudentStatus result = commonService.getSpecificStudentStatusCode(reasonCode); + assertThat(result).isNotNull(); } @Test public void testGetSpecificStudentStatusCodeReturnsNull() { String reasonCode = "DC"; Mockito.when(studentStatusRepository.findById(reasonCode)).thenReturn(Optional.empty()); - commonService.getSpecificStudentStatusCode(reasonCode); + StudentStatus result = commonService.getSpecificStudentStatusCode(reasonCode); + assertThat(result).isNull(); } @Test @@ -376,7 +380,8 @@ public void testCreateStudentStatus() { objEntity.setUpdateDate(new Date()); Mockito.when(studentStatusRepository.findById(obj.getCode())).thenReturn(Optional.empty()); Mockito.when(studentStatusRepository.save(objEntity)).thenReturn(objEntity); - commonService.createStudentStatus(obj); + StudentStatus result = commonService.createStudentStatus(obj); + assertThat(result).isNotNull(); } @@ -398,7 +403,8 @@ public void testCreateStudentStatus_codeAlreadyExists() { objEntity.setUpdateDate(new Date()); Optional ent = Optional.of(objEntity); Mockito.when(studentStatusRepository.findById(obj.getCode())).thenReturn(ent); - commonService.createStudentStatus(obj); + StudentStatus result = commonService.createStudentStatus(obj); + assertThat(result).isNotNull(); } @@ -421,8 +427,8 @@ public void testUpdateStudentStatus() { Optional ent = Optional.of(objEntity); Mockito.when(studentStatusRepository.findById(obj.getCode())).thenReturn(ent); Mockito.when(studentStatusRepository.save(objEntity)).thenReturn(objEntity); - commonService.updateStudentStatus(obj); - + StudentStatus result = commonService.updateStudentStatus(obj); + assertThat(result).isNotNull(); } @Test @@ -442,8 +448,8 @@ public void testUpdateStudentStatus_noCreatedUpdatedByData() { Optional ent = Optional.of(objEntity); Mockito.when(studentStatusRepository.findById(obj.getCode())).thenReturn(ent); Mockito.when(studentStatusRepository.save(objEntity)).thenReturn(objEntity); - commonService.updateStudentStatus(obj); - + StudentStatus result = commonService.updateStudentStatus(obj); + assertThat(result).isNotNull(); } @Test(expected = GradBusinessRuleException.class) @@ -463,8 +469,8 @@ public void testUpdateStudentStatus_codeAlreadyExists() { objEntity.setCreateDate(new Date()); objEntity.setUpdateDate(new Date()); Mockito.when(studentStatusRepository.findById(obj.getCode())).thenReturn(Optional.empty()); - commonService.updateStudentStatus(obj); - + StudentStatus result = commonService.updateStudentStatus(obj); + assertThat(result).isNotNull(); } @Test @@ -546,6 +552,8 @@ public void testGetSpecificHistoryActivityCodeReturnsNull() { @Test public void testGetGradStudentAlgorithmData() { UUID studentID = UUID.randomUUID(); + String accessToken = "accessToken"; + String pen = "128385861"; // Career Program final CareerProgram gradCareerProgram = new CareerProgram(); @@ -554,10 +562,12 @@ public void testGetGradStudentAlgorithmData() { GradSearchStudent gss = new GradSearchStudent(); gss.setStudentID(studentID.toString()); + gss.setPen(pen); gss.setStudentGrade("12"); GraduationStudentRecord gradStudentRecord = new GraduationStudentRecord(); gradStudentRecord.setStudentID(studentID); + gradStudentRecord.setPen(pen); gradStudentRecord.setStudentGrade("12"); when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); @@ -572,12 +582,42 @@ public void testGetGradStudentAlgorithmData() { spg.setCareerProgramCode("TEST"); cpList.add(spg); - when(gradStudentService.getStudentByStudentIDFromStudentAPI(studentID.toString(), null)).thenReturn(gss); + when(gradStudentService.getStudentByStudentIDFromStudentAPI(studentID.toString(), accessToken)).thenReturn(gss); when(graduationStatusService.getGraduationStatusForAlgorithm(studentID)).thenReturn(gradStudentRecord); when(gradStudentCareerProgramRepository.findByStudentID(studentID)).thenReturn(cpList); - GradStudentAlgorithmData data = commonService.getGradStudentAlgorithmData(studentID.toString(),null); + GradTraxStudent sObj = new GradTraxStudent(); + sObj.setPen(pen); + sObj.setStudentCitizenship("C"); + + final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { + }; + + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getTraxStudentMasterDataByPenUrl(),pen))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(List.of(sObj))); + + when(gradStudentService.getTraxStudentMasterDataByPen(sObj.getPen(), accessToken)).thenReturn(sObj); + + GradStudentAlgorithmData data = commonService.getGradStudentAlgorithmData(studentID.toString(),accessToken); + assertThat(data).isNotNull(); + assertThat(data.getGraduationStudentRecord().getStudentCitizenship()).isNotNull(); + + sObj.setStudentCitizenship(null); + + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getTraxStudentMasterDataByPenUrl(),pen))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(List.of())); + + when(gradStudentService.getTraxStudentMasterDataByPen(sObj.getPen(), accessToken)).thenReturn(sObj); + + data = commonService.getGradStudentAlgorithmData(studentID.toString(),accessToken); assertThat(data).isNotNull(); + assertThat(data.getGraduationStudentRecord().getStudentCitizenship()).isNull(); } @Test diff --git a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java index cf36ef17..bcffe572 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/gradstudent/service/GradStudentServiceTest.java @@ -39,6 +39,8 @@ import java.util.function.Function; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -631,6 +633,35 @@ public void testGetStudentByStudentIDFromStudentAPI() { assertThat(result.getEmailVerified()).isEqualTo(student.getEmailVerified()); } + @Test + public void testGetTraxStudentMasterDataByPen() { + + String pen = "128385861"; + GradTraxStudent sObj = new GradTraxStudent(); + sObj.setPen(pen); + + final ParameterizedTypeReference> responseType = new ParameterizedTypeReference<>() { + }; + + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getTraxStudentMasterDataByPenUrl(),pen))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(List.of(sObj))); + + GradTraxStudent result = gradStudentService.getTraxStudentMasterDataByPen(pen, "accessToken"); + assertNotNull(result); + + when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); + when(this.requestHeadersUriMock.uri(String.format(constants.getTraxStudentMasterDataByPenUrl(),pen))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.headers(any(Consumer.class))).thenReturn(this.requestHeadersMock); + when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); + when(this.responseMock.bodyToMono(responseType)).thenReturn(Mono.just(List.of())); + + result = gradStudentService.getTraxStudentMasterDataByPen(pen, "accessToken"); + assertNull(result); + } + @Test public void testAddNewPenFromStudentAPI() { // ID diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index b87af9df..6a050df6 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -94,10 +94,13 @@ cron: run: 0 0/5 * * * * lockAtLeastFor: 800ms lockAtMostFor: 900ms + threshold: 100 #Endpoint properties endpoint: grad-trax-api: + get-student-master-data: + url: https://educ-grad-trax-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/trax/common/student-master/%s school-by-min-code: url: https://educ-grad-trax-api-77c02f-dev.apps.silver.devops.gov.bc.ca/api/v1/trax/school/%s district-by-district-code: