From 788c8687b25fcd360b33cc5a9bb7a1a15cfbcccd Mon Sep 17 00:00:00 2001 From: mightycox Date: Thu, 16 Jan 2025 12:03:17 -0800 Subject: [PATCH 1/3] GRAD2-3037 - updates for report count endpoint and StudentSearchRequest object --- .../controller/v2/CommonController.java | 24 +++- .../model/dto/v2/StudentSearchRequest.java | 8 +- .../repository/v2/SchoolReportRepository.java | 6 + .../grad/report/service/v2/CommonService.java | 50 ++++--- .../service/v2/DistrictReportService.java | 5 +- .../service/v2/SchoolReportService.java | 5 +- .../controller/v2/CommonControllerTest.java | 22 +-- .../report/service/v2/CommonServiceTest.java | 131 +++++++----------- 8 files changed, 121 insertions(+), 130 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonController.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonController.java index 643857a..ce49413 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonController.java @@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.UUID; @RestController("commonControllerV2") @RequestMapping(EducGradReportApiConstants.GRAD_REPORT_API_V2_ROOT_MAPPING) @@ -28,7 +29,6 @@ public class CommonController { private static final Logger logger = LoggerFactory.getLogger(CommonController.class); - private static final String BEARER = "Bearer "; final CommonService commonService; final GradValidation validation; @@ -47,13 +47,12 @@ public CommonController(CommonService commonService, GradValidation validation, @Operation(summary = "Read All Student Transcripts/Certificates for User Req Distribution", description = "Read All Student Credentials for Distribution", tags = { "Certificates" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity> getStudentCredentialsForUserRequestDisRun( - @PathVariable String credentialType, @RequestBody StudentSearchRequest studentSearchRequest, - @RequestHeader(name="Authorization") String accessToken) { + @PathVariable String credentialType, @RequestBody StudentSearchRequest studentSearchRequest) { logger.debug("getStudentCredentialsForUserRequestDisRun : "); boolean isPenNumberSearch = studentSearchRequest.getPens() != null && !studentSearchRequest.getPens().isEmpty() && !studentSearchRequest.getPens().stream().filter(StringUtils::isNotBlank).toList().isEmpty(); boolean onlyWithNullDistributionDate = !isPenNumberSearch && studentSearchRequest.getGradDateFrom() == null && studentSearchRequest.getGradDateTo() == null && !StringUtils.equalsAnyIgnoreCase(credentialType, "OT", "RT"); - return response.GET(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,studentSearchRequest,onlyWithNullDistributionDate,accessToken.replace(BEARER, ""))); + return response.GET(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,studentSearchRequest,onlyWithNullDistributionDate)); } @PostMapping(EducGradReportApiConstants.USER_REQUEST_DIS_RUN_WITH_NULL_DISTRIBUTION_DATE) @@ -61,11 +60,22 @@ public ResponseEntity> getStudentCredentials @Operation(summary = "Read All Student Transcripts/Certificates with Null Distribution Date for User Req Distribution", description = "Read All Student Credentials with Null Distribution Date for Distribution", tags = { "Certificates" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) public ResponseEntity> getStudentCredentialsForUserRequestDisRunWithNullDistributionDate( - @PathVariable String credentialType, @RequestBody StudentSearchRequest studentSearchRequest, - @RequestHeader(name="Authorization") String accessToken) { + @PathVariable String credentialType, @RequestBody StudentSearchRequest studentSearchRequest) { logger.debug("getStudentCredentialsForUserRequestDisRunWithNullDistributionDate : "); boolean isPenNumberSearch = studentSearchRequest.getPens()!= null && !studentSearchRequest.getPens().isEmpty() && !studentSearchRequest.getPens().stream().filter(StringUtils::isNotBlank).toList().isEmpty(); - return response.GET(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,studentSearchRequest,!isPenNumberSearch,accessToken.replace(BEARER, ""))); + return response.GET(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,studentSearchRequest,!isPenNumberSearch)); + } + + @PostMapping (EducGradReportApiConstants.REPORT_COUNT) + @PreAuthorize(PermissionsConstants.READ_GRADUATION_STUDENT_REPORTS) + @Operation(summary = "Get Reports Count by id and status", description = "Get Students Count by id and status", tags = { "Business" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")}) + public ResponseEntity getReportsCount(@RequestParam String reportType, @RequestBody List reportContainerIds) { + if(StringUtils.containsAnyIgnoreCase(reportType, "ACHV")) { + return response.GET(commonService.countByStudentGuidsAndReportType(reportContainerIds, reportType)); + } else { + return response.GET(commonService.countBySchoolOfRecordsAndReportType(reportContainerIds, reportType)); + } } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/v2/StudentSearchRequest.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/v2/StudentSearchRequest.java index 595cd01..acb05d2 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/v2/StudentSearchRequest.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/model/dto/v2/StudentSearchRequest.java @@ -14,8 +14,8 @@ @Data public class StudentSearchRequest implements Serializable { - private List schoolOfRecordIds = new ArrayList<>(); - private List districts = new ArrayList<>(); + private List schoolIds = new ArrayList<>(); + private List districtIds = new ArrayList<>(); private List schoolCategoryCodes = new ArrayList<>(); private List pens = new ArrayList<>(); private List programs = new ArrayList<>(); @@ -37,8 +37,8 @@ public class StudentSearchRequest implements Serializable { @JsonIgnore public boolean isEmpty() { - return (schoolOfRecordIds == null || schoolOfRecordIds.isEmpty()) && - (districts == null || districts.isEmpty()) && + return (schoolIds == null || schoolIds.isEmpty()) && + (districtIds == null || districtIds.isEmpty()) && (schoolCategoryCodes == null || schoolCategoryCodes.isEmpty()) && (pens == null || pens.isEmpty()) && (studentIDs == null || studentIDs.isEmpty()); diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/v2/SchoolReportRepository.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/v2/SchoolReportRepository.java index 3a66e21..a9436cb 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/v2/SchoolReportRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/repository/v2/SchoolReportRepository.java @@ -11,6 +11,12 @@ @Repository("schoolReportsRepositoryV2") public interface SchoolReportRepository extends JpaRepository, JpaSpecificationExecutor { + List deleteAllByReportTypeCode(String reportTypeCode); + Optional findBySchoolOfRecordIdAndReportTypeCode(UUID schoolOfRecordId, String reportTypeCode); + + Integer countBySchoolOfRecordIdInAndReportTypeCode(List schoolOfRecordIds, String reportType); + + Integer countByReportTypeCode(String reportType); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/CommonService.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/CommonService.java index 87f2040..e72873a 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/CommonService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/CommonService.java @@ -4,13 +4,11 @@ import ca.bc.gov.educ.api.grad.report.model.dto.StudentCredentialDistribution; import ca.bc.gov.educ.api.grad.report.model.dto.v2.StudentSearchRequest; import ca.bc.gov.educ.api.grad.report.repository.*; +import ca.bc.gov.educ.api.grad.report.repository.v2.SchoolReportRepository; import ca.bc.gov.educ.api.grad.report.service.BaseService; -import ca.bc.gov.educ.api.grad.report.util.EducGradReportApiConstants; -import ca.bc.gov.educ.api.grad.report.util.ThreadLocalStateUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.web.reactive.function.BodyInserters; import java.util.*; @@ -19,22 +17,28 @@ public class CommonService extends BaseService { final GradStudentCertificatesRepository gradStudentCertificatesRepository; final GradStudentTranscriptsRepository gradStudentTranscriptsRepository; + final GradStudentReportsRepository gradStudentReportsRepository; + final SchoolReportRepository schoolReportRepository; + final RESTService restService; @Autowired - public CommonService(GradStudentCertificatesRepository gradStudentCertificatesRepository, GradStudentTranscriptsRepository gradStudentTranscriptsRepository) { + public CommonService(GradStudentCertificatesRepository gradStudentCertificatesRepository, GradStudentTranscriptsRepository gradStudentTranscriptsRepository, GradStudentReportsRepository gradStudentReportsRepository, SchoolReportRepository schoolReportRepository, RESTService restService) { this.gradStudentCertificatesRepository = gradStudentCertificatesRepository; this.gradStudentTranscriptsRepository = gradStudentTranscriptsRepository; + this.gradStudentReportsRepository = gradStudentReportsRepository; + this.schoolReportRepository = schoolReportRepository; + this.restService = restService; } - public List getStudentCredentialsForUserRequestDisRun(String credentialType, StudentSearchRequest studentSearchRequest, boolean onlyWithNullDistributionDate, String accessToken) { + public List getStudentCredentialsForUserRequestDisRun(String credentialType, StudentSearchRequest studentSearchRequest, boolean onlyWithNullDistributionDate) { List scdList = new ArrayList<>(); if(StringUtils.isBlank(studentSearchRequest.getActivityCode())) { studentSearchRequest.setActivityCode("USERDIST" + StringUtils.upperCase(credentialType)); } List studentIDs = studentSearchRequest.getStudentIDs(); if(studentIDs == null || studentIDs.isEmpty()) { - studentIDs = getStudentsForSpecialGradRun(studentSearchRequest, accessToken); + studentIDs = getStudentsForSpecialGradRun(studentSearchRequest); } if (!studentIDs.isEmpty()) { int partitionSize = 1000; @@ -87,19 +91,31 @@ private void processTranscript(List> partitions, StudentSearchRequest } } - public List getStudentsForSpecialGradRun(StudentSearchRequest req, String accessToken) { - GraduationStudentRecordSearchResult res = this.webClient.post() - .uri(constants.getGradStudentApiStudentForSpcGradListUrl()) - .headers(h -> { - h.setBearerAuth(accessToken); - h.set(EducGradReportApiConstants.CORRELATION_ID, ThreadLocalStateUtil.getCorrelationID()); - }) - .body(BodyInserters.fromValue(req)) - .retrieve() - .bodyToMono(GraduationStudentRecordSearchResult.class) - .block(); + public List getStudentsForSpecialGradRun(StudentSearchRequest req) { + GraduationStudentRecordSearchResult res = this.restService.post(constants.getGradStudentApiStudentForSpcGradListUrl(), req, GraduationStudentRecordSearchResult.class); if (res != null && !res.getStudentIDs().isEmpty()) return res.getStudentIDs(); return new ArrayList<>(); } + + public Integer countByStudentGuidsAndReportType(List studentGuidsString, String reportType) { + Integer reportsCount = 0; + if(studentGuidsString != null && !studentGuidsString.isEmpty()) { + List studentGuids = new ArrayList<>(studentGuidsString); + reportsCount += gradStudentReportsRepository.countByStudentGuidsAndReportType(studentGuids, reportType); + } else { + reportsCount += gradStudentReportsRepository.countByReportType(reportType); + } + return reportsCount; + } + + public Integer countBySchoolOfRecordsAndReportType(List schoolOfRecords, String reportType) { + Integer reportsCount = 0; + if(schoolOfRecords != null && !schoolOfRecords.isEmpty()) { + reportsCount += schoolReportRepository.countBySchoolOfRecordIdInAndReportTypeCode(schoolOfRecords, reportType); + } else { + reportsCount += schoolReportRepository.countByReportTypeCode(reportType); + } + return reportsCount; + } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/DistrictReportService.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/DistrictReportService.java index e652633..a4ea840 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/DistrictReportService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/DistrictReportService.java @@ -10,7 +10,6 @@ import ca.bc.gov.educ.api.grad.report.repository.v2.DistrictReportLightRepository; import ca.bc.gov.educ.api.grad.report.repository.v2.DistrictReportRepository; import ca.bc.gov.educ.api.grad.report.service.BaseService; -import ca.bc.gov.educ.api.grad.report.service.CommonService; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -31,15 +30,13 @@ public class DistrictReportService extends BaseService { DistrictReportRepository districtReportsRepository; DistrictReportLightRepository districtReportLightRepository; DistrictReportTransformer districtReportTransformer; - CommonService commonService; InstituteService instituteService; private static final Logger logger = LoggerFactory.getLogger(DistrictReportService.class); @Autowired - public DistrictReportService(DistrictReportRepository districtReportsRepository, CommonService commonService, DistrictReportLightRepository districtReportLightRepository, InstituteService instituteService, DistrictReportTransformer districtReportTransformer) { + public DistrictReportService(DistrictReportRepository districtReportsRepository, DistrictReportLightRepository districtReportLightRepository, InstituteService instituteService, DistrictReportTransformer districtReportTransformer) { this.districtReportsRepository = districtReportsRepository; - this.commonService = commonService; this.districtReportLightRepository = districtReportLightRepository; this.instituteService = instituteService; this.districtReportTransformer = districtReportTransformer; diff --git a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/SchoolReportService.java b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/SchoolReportService.java index bb78e75..a832122 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/SchoolReportService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/grad/report/service/v2/SchoolReportService.java @@ -11,7 +11,6 @@ import ca.bc.gov.educ.api.grad.report.repository.v2.SchoolReportLightRepository; import ca.bc.gov.educ.api.grad.report.repository.v2.SchoolReportRepository; import ca.bc.gov.educ.api.grad.report.service.BaseService; -import ca.bc.gov.educ.api.grad.report.service.CommonService; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -32,16 +31,14 @@ public class SchoolReportService extends BaseService { SchoolReportRepository schoolReportsRepository; SchoolReportLightRepository schoolReportsLightRepository; SchoolReportTransformer schoolReportsTransformer; - CommonService commonService; InstituteService instituteService; private static final Logger logger = LoggerFactory.getLogger(SchoolReportService.class); @Autowired - public SchoolReportService(SchoolReportRepository schoolReportsRepository, SchoolReportTransformer schoolReportsTransformer, CommonService commonService, SchoolReportLightRepository schoolReportsLightRepository, InstituteService instituteService) { + public SchoolReportService(SchoolReportRepository schoolReportsRepository, SchoolReportTransformer schoolReportsTransformer, SchoolReportLightRepository schoolReportsLightRepository, InstituteService instituteService) { this.schoolReportsRepository = schoolReportsRepository; this.schoolReportsTransformer = schoolReportsTransformer; - this.commonService = commonService; this.schoolReportsLightRepository = schoolReportsLightRepository; this.instituteService = instituteService; } diff --git a/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java index da815c2..b09a20f 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java @@ -3,8 +3,6 @@ import ca.bc.gov.educ.api.grad.report.model.dto.StudentCredentialDistribution; import ca.bc.gov.educ.api.grad.report.model.dto.v2.StudentSearchRequest; import ca.bc.gov.educ.api.grad.report.service.v2.CommonService; -import ca.bc.gov.educ.api.grad.report.util.GradValidation; -import ca.bc.gov.educ.api.grad.report.util.ResponseHelper; import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; @@ -26,12 +24,6 @@ public class CommonControllerTest { @Mock private CommonService commonService; - @Mock - ResponseHelper responseHelper; - - @Mock - GradValidation validation; - @InjectMocks private CommonController commonController; @@ -48,9 +40,9 @@ public void testGetAllStudentCredentialDistributionList() { final StudentCredentialDistribution cred = new StudentCredentialDistribution(UUID.randomUUID(),"BC2018-IND",studentID,"YED4","COMPL", new Date()); list.add(cred); - Mockito.when(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,false,"accessToken")).thenReturn(list); - commonController.getStudentCredentialsForUserRequestDisRun(credentialType,req,"accessToken"); - Mockito.verify(commonService).getStudentCredentialsForUserRequestDisRun(credentialType,req,false,"accessToken"); + Mockito.when(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,false)).thenReturn(list); + commonController.getStudentCredentialsForUserRequestDisRun(credentialType,req); + Mockito.verify(commonService).getStudentCredentialsForUserRequestDisRun(credentialType,req,false); } @Test @@ -59,15 +51,15 @@ public void testGetAllStudentCredentialDistributionListWithNullDistributionDate( final UUID studentID = UUID.randomUUID(); final String credentialType = "E"; final StudentSearchRequest req = new StudentSearchRequest(); - req.setDistricts(List.of("005")); + req.setDistrictIds(List.of(UUID.randomUUID())); // Student Certificate Types final List list = new ArrayList<>(); final StudentCredentialDistribution cred = new StudentCredentialDistribution(UUID.randomUUID(),"BC2018-IND",studentID,"YED4","COMPL", new Date()); list.add(cred); - Mockito.when(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,true,"accessToken")).thenReturn(list); - commonController.getStudentCredentialsForUserRequestDisRunWithNullDistributionDate(credentialType,req,"accessToken"); - Mockito.verify(commonService).getStudentCredentialsForUserRequestDisRun(credentialType,req,true,"accessToken"); + Mockito.when(commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,true)).thenReturn(list); + commonController.getStudentCredentialsForUserRequestDisRunWithNullDistributionDate(credentialType,req); + Mockito.verify(commonService).getStudentCredentialsForUserRequestDisRun(credentialType,req,true); } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/v2/CommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/v2/CommonServiceTest.java index 600e17b..69556f0 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/v2/CommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/grad/report/service/v2/CommonServiceTest.java @@ -6,27 +6,20 @@ import ca.bc.gov.educ.api.grad.report.model.dto.v2.StudentSearchRequest; import ca.bc.gov.educ.api.grad.report.repository.*; import ca.bc.gov.educ.api.grad.report.repository.v2.SchoolReportRepository; -import ca.bc.gov.educ.api.grad.report.util.EducGradReportApiConstants; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mock; import org.mockito.Mockito; 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.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.web.reactive.function.BodyInserter; -import org.springframework.web.reactive.function.client.WebClient; -import reactor.core.publisher.Mono; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.UUID; -import java.util.function.Consumer; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -38,33 +31,30 @@ @ActiveProfiles("test") public class CommonServiceTest { - @Autowired EducGradReportApiConstants constants; @Autowired CommonService commonService; + @MockBean GradStudentCertificatesRepository gradStudentCertificatesRepository; - @MockBean GradStudentTranscriptsRepository gradStudentTranscriptsRepository; + + @MockBean + GradStudentTranscriptsRepository gradStudentTranscriptsRepository; + + @MockBean + RESTService restService; + + @MockBean + GradStudentReportsRepository gradStudentReportsRepository; + @MockBean - SchoolReportRepository schoolReportsRepository; - @MockBean WebClient webClient; + SchoolReportRepository schoolReportRepository; - @Mock - WebClient.RequestHeadersSpec requestHeadersMock; - @Mock WebClient.RequestHeadersUriSpec requestHeadersUriMock; - @Mock WebClient.ResponseSpec responseMock; - @Mock WebClient.RequestBodySpec requestBodyMock; - @Mock WebClient.RequestBodyUriSpec requestBodyUriMock; @Before public void setUp() { openMocks(this); } - @After - public void tearDown() { - - } - @Test public void testGetStudentCredentialsForUserRequestDisRun_OC() { @@ -85,12 +75,7 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC() { List studentList = new ArrayList<>(); studentList.add(new UUID(1,1)); - when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(constants.getGradStudentApiStudentForSpcGradListUrl())).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); - when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); + when(this.restService.post(any(), any(), any())).thenReturn(res); Mockito.when(gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); Mockito.when(gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); @@ -102,7 +87,7 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC() { Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList); - List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),false,null); + List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),false); assertThat(result).isNotEmpty(); } @@ -126,12 +111,7 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC_SearchRequest() { List studentList = new ArrayList<>(); studentList.add(new UUID(1,1)); - when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(constants.getGradStudentApiStudentForSpcGradListUrl())).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); - when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); + when(this.restService.post(any(), any(), any())).thenReturn(res); StudentSearchRequest searchRequest = new StudentSearchRequest(); searchRequest.setPens(new ArrayList<>()); @@ -147,12 +127,12 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC_SearchRequest() { Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList); - List result = commonService.getStudentCredentialsForUserRequestDisRun("OC",searchRequest,true,"accessToken"); + List result = commonService.getStudentCredentialsForUserRequestDisRun("OC",searchRequest,true); assertThat(result).isNotEmpty(); searchRequest.setActivityCode("USERDIST"); - result = commonService.getStudentCredentialsForUserRequestDisRun("OT",searchRequest,false,"accessToken"); + result = commonService.getStudentCredentialsForUserRequestDisRun("OT",searchRequest,false); assertThat(result).isNotEmpty(); } @@ -177,12 +157,7 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC_with_Null_Distribut List studentList = new ArrayList<>(); studentList.add(new UUID(1,1)); - when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(constants.getGradStudentApiStudentForSpcGradListUrl())).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); - when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); + when(this.restService.post(any(), any(), any())).thenReturn(res); Mockito.when(gradStudentCertificatesRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); Mockito.when(gradStudentCertificatesRepository.findRecordsForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); @@ -190,7 +165,7 @@ public void testGetStudentCredentialsForUserRequestDisRun_OC_with_Null_Distribut Mockito.when(gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList); - List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),true,null); + List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,new StudentSearchRequest(),true); assertThat(result).isNotEmpty(); } @@ -213,14 +188,9 @@ public void testGetStudentCredentialsForSpecialGradRun() { studentList.add(rec.getStudentID()); res.setStudentIDs(studentList); - when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(constants.getGradStudentApiStudentForSpcGradListUrl())).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); - when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); + when(this.restService.post(any(), any(), any())).thenReturn(res); - List result = commonService.getStudentsForSpecialGradRun(req,"accessToken"); + List result = commonService.getStudentsForSpecialGradRun(req); assertThat(result).hasSize(1); } @@ -250,16 +220,11 @@ public void testGetStudentCredentialsForUserRequestDisRun_OT() { penList.add("13123111"); req.setPens(penList); - when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(constants.getGradStudentApiStudentForSpcGradListUrl())).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); - when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); + when(this.restService.post(any(), any(), any())).thenReturn(res); Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); - List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,false,null); + List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,false); assertThat(result).hasSize(1); } @@ -289,16 +254,11 @@ public void testGetStudentCredentialsWithNullDistributionDateForUserRequestDisRu penList.add("13123111"); req.setPens(penList); - when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(constants.getGradStudentApiStudentForSpcGradListUrl())).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); - when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); + when(this.restService.post(any(), any(), any())).thenReturn(res); Mockito.when(gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequestByStudentIdOnly(studentList)).thenReturn(scdSubList); - List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,true,null); + List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,true); assertThat(result).hasSize(1); } @@ -329,16 +289,11 @@ public void testGetStudentCredentialsForUserRequestDisRun_OT_Prgm() { req.setPrograms(pgList); req.setPens(new ArrayList<>()); - when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(constants.getGradStudentApiStudentForSpcGradListUrl())).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); - when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); + when(this.restService.post(any(), any(), any())).thenReturn(res); Mockito.when(gradStudentTranscriptsRepository.findRecordsForUserRequest(studentList)).thenReturn(scdSubList); - List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,false,null); + List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,false); assertThat(result).hasSize(1); } @@ -369,17 +324,35 @@ public void testGetStudentCredentialsWithNullDistributionDateForUserRequestDisRu req.setPrograms(pgList); req.setPens(new ArrayList<>()); - when(this.webClient.post()).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.uri(constants.getGradStudentApiStudentForSpcGradListUrl())).thenReturn(this.requestBodyUriMock); - when(this.requestBodyUriMock.headers(any(Consumer.class))).thenReturn(this.requestBodyMock); - when(this.requestBodyMock.body(any(BodyInserter.class))).thenReturn(this.requestHeadersMock); - when(this.requestHeadersMock.retrieve()).thenReturn(this.responseMock); - when(this.responseMock.bodyToMono(GraduationStudentRecordSearchResult.class)).thenReturn(Mono.just(res)); + when(this.restService.post(any(), any(), any())).thenReturn(res); Mockito.when(gradStudentTranscriptsRepository.findRecordsWithNullDistributionDateForUserRequest(studentList)).thenReturn(scdSubList); - List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,true,null); + List result = commonService.getStudentCredentialsForUserRequestDisRun(credentialType,req,true); assertThat(result).hasSize(1); + } + @Test + public void testCountByStudentGuidsAndReportType() { + UUID uuid = UUID.randomUUID(); + Mockito.when(gradStudentReportsRepository.countByStudentGuidsAndReportType(List.of(uuid), "reportType")).thenReturn(1); + Integer count = commonService.countByStudentGuidsAndReportType(List.of(uuid), "reportType"); + assertThat(count).isNotNull().isEqualTo(1); + + Mockito.when(gradStudentReportsRepository.countByReportType("reportType")).thenReturn(1); + count = commonService.countByStudentGuidsAndReportType(List.of(), "reportType"); + assertThat(count).isNotNull().isEqualTo(1); + } + + @Test + public void testCountBySchoolOfRecordsAndReportType() { + UUID schoolId = UUID.randomUUID(); + Mockito.when(schoolReportRepository.countBySchoolOfRecordIdInAndReportTypeCode(List.of(schoolId), "reportType")).thenReturn(1); + Integer count = commonService.countBySchoolOfRecordsAndReportType(List.of(schoolId), "reportType"); + assertThat(count).isNotNull().isEqualTo(1); + + Mockito.when(schoolReportRepository.countByReportTypeCode("reportType")).thenReturn(1); + count = commonService.countBySchoolOfRecordsAndReportType(List.of(), "reportType"); + assertThat(count).isNotNull().isEqualTo(1); } } From d7fcd36e90e05771b7f4c95229d82c43f2d467cc Mon Sep 17 00:00:00 2001 From: mightycox Date: Thu, 16 Jan 2025 12:16:46 -0800 Subject: [PATCH 2/3] GRAD2-3037 - fixes ut bug --- .../grad/report/controller/v2/CommonControllerTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java index b09a20f..f94f87c 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java @@ -3,6 +3,8 @@ import ca.bc.gov.educ.api.grad.report.model.dto.StudentCredentialDistribution; import ca.bc.gov.educ.api.grad.report.model.dto.v2.StudentSearchRequest; import ca.bc.gov.educ.api.grad.report.service.v2.CommonService; +import ca.bc.gov.educ.api.grad.report.util.GradValidation; +import ca.bc.gov.educ.api.grad.report.util.ResponseHelper; import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.runner.RunWith; @@ -24,6 +26,12 @@ public class CommonControllerTest { @Mock private CommonService commonService; + @Mock + ResponseHelper responseHelper; + + @Mock + GradValidation validation; + @InjectMocks private CommonController commonController; From 6f8f596fd08ee345b273f5a62b0dbd24221a9d68 Mon Sep 17 00:00:00 2001 From: mightycox Date: Thu, 16 Jan 2025 12:24:51 -0800 Subject: [PATCH 3/3] GRAD2-3037 - ups ut coverage --- .../controller/v2/CommonControllerTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java index f94f87c..c66516b 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/grad/report/controller/v2/CommonControllerTest.java @@ -70,4 +70,26 @@ public void testGetAllStudentCredentialDistributionListWithNullDistributionDate( commonController.getStudentCredentialsForUserRequestDisRunWithNullDistributionDate(credentialType,req); Mockito.verify(commonService).getStudentCredentialsForUserRequestDisRun(credentialType,req,true); } + + @Test + public void testGetReportsCount_givenACHV() { + final String reportType = "ACHV"; + final List reportContainerIds = List.of(UUID.randomUUID(), UUID.randomUUID()); + final Integer expectedCount = 5; + + Mockito.when(commonService.countByStudentGuidsAndReportType(reportContainerIds, reportType)).thenReturn(expectedCount); + commonController.getReportsCount(reportType, reportContainerIds); + Mockito.verify(commonService).countByStudentGuidsAndReportType(reportContainerIds, reportType); + } + + @Test + public void testGetReportsCount_givenNotACHV() { + final String reportType = "TEST"; + final List reportContainerIds = List.of(UUID.randomUUID(), UUID.randomUUID()); + final Integer expectedCount = 5; + + Mockito.when(commonService.countBySchoolOfRecordsAndReportType(reportContainerIds, reportType)).thenReturn(expectedCount); + commonController.getReportsCount(reportType, reportContainerIds); + Mockito.verify(commonService).countBySchoolOfRecordsAndReportType(reportContainerIds, reportType); + } }