diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolController.java b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolController.java index 225dfc79..ee2a90f1 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolController.java @@ -122,13 +122,28 @@ public ResponseEntity> getSchoolsBySchoolCategory(@RequestPar return response.GET(schoolService.getSchoolDetailsBySchoolCategoryCode(schoolCategoryCode)); } - @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_DETAIL_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_SCHOOL_BY_CODE_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_DETAIL_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_SCHOOL_BY_SCHOOL_ID) + @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) + @Operation(summary = "Find School Details by ID from cache", description = "Get School Details by ID from cache", tags = { "School" }) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "204", description = "NO CONTENT")}) + public ResponseEntity getSchoolDetailsById(@PathVariable UUID schoolId) { + log.debug("getSchoolDetailsById V2 : "); + SchoolDetail schoolDetailResponse = schoolService.getSchoolDetailBySchoolId(schoolId); + if(schoolDetailResponse != null) { + return response.GET(schoolDetailResponse); + }else { + return response.NOT_FOUND(); + } + } + + @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_DETAIL_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_SCHOOL_DETAIL_SEARCH_MAPPING) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) @Operation(summary = "Find School Details by Mincode from cache", description = "Get School Details by Mincode from cache", tags = { "School" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "204", description = "NO CONTENT")}) - public ResponseEntity getSchoolDetailsByMincode(@PathVariable String minCode) { - log.debug("getSchoolDetails V2 : "); + public ResponseEntity getSchoolDetailsByParams(@RequestParam(required = false) String minCode) { + log.debug("getSchoolDetailsByParams V2 : "); SchoolDetail schoolDetailResponse = schoolService.getSchoolDetailByMincodeFromRedisCache(minCode); if(schoolDetailResponse != null) { return response.GET(schoolDetailResponse); @@ -136,15 +151,28 @@ public ResponseEntity getSchoolDetailsByMincode(@PathVariable Stri return response.NOT_FOUND(); } } + + /** + * School wildcard Search with given params + * @param districtId + * @param mincode + * @param displayName + * @param distNo + * @return + */ @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_SCHOOL_SEARCH_MAPPING) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) - @Operation(summary = "Search for a school", description = "Search for a School", tags = { "School" }) + @Operation(summary = "Search for a school v2", description = "Search for a School v2", tags = { "School" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST")}) public ResponseEntity> getSchoolsByParams( - @RequestParam(value = "districtId", required = false) UUID districtId, - @RequestParam(value = "mincode", required = false) String mincode) { - return response.GET(schoolService.getSchoolsByParams(districtId, mincode)); + @RequestParam(value = "districtId", required = false) String districtId, + @RequestParam(value = "mincode", required = false) String mincode, + @RequestParam(value = "displayName", required = false) String displayName, + @RequestParam(value = "distNo", required = false) String distNo) + { + log.debug("getSchoolsByParams V2 : "); + return response.GET(schoolService.getSchoolsByParams(districtId, mincode, displayName, distNo)); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolEventBaseService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolEventBaseService.java index d9a04254..1b4e6fa8 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolEventBaseService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolEventBaseService.java @@ -3,6 +3,7 @@ import ca.bc.gov.educ.api.trax.model.dto.institute.School; import ca.bc.gov.educ.api.trax.service.institute.SchoolService; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; @Service @@ -11,7 +12,7 @@ public abstract class SchoolEventBaseService extends EventBaseService { protected SchoolService schoolService; - protected SchoolEventBaseService(SchoolService schoolService) { + protected SchoolEventBaseService(@Qualifier("instituteSchoolService") SchoolService schoolService) { this.schoolService = schoolService; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolMovedService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolMovedService.java index 3890ba81..f519ed6c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolMovedService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/SchoolMovedService.java @@ -8,6 +8,7 @@ import ca.bc.gov.educ.api.trax.service.institute.SchoolService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import java.util.Arrays; @@ -17,7 +18,7 @@ public class SchoolMovedService extends SchoolEventBaseService { @Autowired - public SchoolMovedService(SchoolService schoolService) { + public SchoolMovedService(@Qualifier("instituteSchoolService") SchoolService schoolService) { super(schoolService); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CodeService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CodeService.java index 23afeac4..7eada39c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CodeService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CodeService.java @@ -21,7 +21,7 @@ import java.util.List; @Slf4j -@Service("InstituteCodeService") +@Service("instituteCodeService") public class CodeService { @Autowired diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CommonService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CommonService.java index ea87c80a..60cb5aef 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CommonService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/CommonService.java @@ -23,9 +23,9 @@ public class CommonService { private SchoolService schoolService; @Autowired - public CommonService(@Qualifier("InstituteCodeService") CodeService codeService, - @Qualifier("InstituteDistrictService") DistrictService districtService, - @Qualifier("InstituteSchoolService") SchoolService schoolService) { + public CommonService(@Qualifier("instituteCodeService") CodeService codeService, + @Qualifier("instituteDistrictService") DistrictService districtService, + @Qualifier("instituteSchoolService") SchoolService schoolService) { this.codeService = codeService; this.districtService = districtService; this.schoolService = schoolService; diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/DistrictService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/DistrictService.java index b79cd393..63aa20c4 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/DistrictService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/DistrictService.java @@ -21,7 +21,7 @@ import java.util.List; @Slf4j -@Service("InstituteDistrictService") +@Service("instituteDistrictService") public class DistrictService { @Autowired diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolSearchCriteria.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolSearchCriteria.java new file mode 100644 index 00000000..c61c44f0 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolSearchCriteria.java @@ -0,0 +1,19 @@ +package ca.bc.gov.educ.api.trax.service.institute; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@Builder +public class SchoolSearchCriteria { + private String districtId; + private String mincode; + private String displayName; + private String distNo; + + public String toString() { + return String.format("DistrictId: %s, Mincode: %s, DisplayName: %s, DisNo: %s", districtId, mincode, displayName, distNo); + } +} \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java index 0cb19d37..c097afd6 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java @@ -12,11 +12,13 @@ import ca.bc.gov.educ.api.trax.repository.redis.SchoolRedisRepository; import ca.bc.gov.educ.api.trax.service.RESTService; import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants; +import com.google.common.base.Strings; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClientResponseException; @@ -24,7 +26,7 @@ @Slf4j @RequiredArgsConstructor -@Service("InstituteSchoolService") +@Service("instituteSchoolService") public class SchoolService { @Autowired @@ -56,7 +58,7 @@ public List getSchoolsFromInstituteApi() { } catch (Exception e) { log.error(String.format("Error getting data from Institute api: %s", e.getMessage())); } - return null; + return Collections.emptyList(); } public void loadSchoolsIntoRedisCache(List schools) { @@ -182,16 +184,53 @@ public Optional getSchoolBySchoolId(UUID schoolId) { return schoolRedisRepository.findById(String.valueOf(schoolId)).map(schoolTransformer::transformToDTO); } - public List getSchoolsByParams(UUID districtId, String mincode) { - if(districtId == null && mincode == null) { - return schoolTransformer.transformToDTO(schoolRedisRepository.findAll()); - } else if (mincode == null) { - return schoolTransformer.transformToDTO(schoolRedisRepository.findAllByDistrictId(String.valueOf(districtId))); - } else if(districtId == null) { - Optional schoolOptional = schoolRedisRepository.findByMincode(mincode); - return schoolOptional.map(schoolEntity -> List.of(schoolTransformer.transformToDTO(schoolEntity))).orElse(Collections.emptyList()); - } else { - return schoolTransformer.transformToDTO(schoolRedisRepository.findAllByDistrictIdAndMincode(String.valueOf(districtId), mincode)); + /** + * Get a list of schools that match the given params with wildcards + * @param districtId + * @param mincode + * @param displayName + * @param distNo + * @return + */ + @Transactional(readOnly = true) + public List getSchoolsByParams(String districtId, String mincode, String displayName, String distNo) { + + SchoolSearchCriteria criteria = SchoolSearchCriteria.builder() + .districtId(transformToWildcard(districtId)) + .mincode(transformToWildcard(mincode)) + .displayName(transformToWildcard(displayName)) + .distNo(transformToWildcard(distNo)) + .build(); + + log.debug(criteria.toString()); + List schools = filterByCriteria(criteria, schoolRedisRepository.findAll()); + return schoolTransformer.transformToDTO(schools); + } + + /** + * Filter a list of SchoolEntities by given criteria + * @param criteria + * @param schoolEntities + * @return + */ + private List filterByCriteria(SchoolSearchCriteria criteria, Iterable schoolEntities) { + List schools = new ArrayList<>(); + for (SchoolEntity school : schoolEntities) { + if (school.getDistrictId().matches(criteria.getDistrictId()) + && school.getMincode().matches(criteria.getMincode()) + && school.getDisplayName().matches(criteria.getDisplayName()) + && school.getMincode().substring(0, 3).matches(criteria.getDistNo())) + schools.add(school); } + return schools; + } + + /** + * Transform '*' wildcard into Regex format + * @param value + * @return + */ + private String transformToWildcard(String value) { + return Strings.isNullOrEmpty(value) ? "(.*)" : "*".concat(value).concat("*").replaceAll("\\*", "(.*)"); } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java index 222411a6..71c7197c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/util/EducGradTraxApiConstants.java @@ -63,6 +63,7 @@ public class EducGradTraxApiConstants { public static final String GET_COMMON_SCHOOL_BY_CODE_MAPPING = GET_COMMON_SCHOOLS + GET_SCHOOL_BY_CODE_MAPPING; public static final String GET_SCHOOL_SEARCH_MAPPING = "/search"; + public static final String GET_SCHOOL_DETAIL_SEARCH_MAPPING = "/search"; public static final String GET_PSI_BY_CODE_MAPPING = "/{psiCode}"; public static final String GET_PSI_SEARCH_MAPPING="/search"; diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/controller/SchoolControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/controller/SchoolControllerTest.java index 2384c34b..c82fbed3 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/controller/SchoolControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/controller/SchoolControllerTest.java @@ -226,7 +226,7 @@ public void whenGetSchoolDetailsByMincode_ReturnsSchoolDetail() { schoolDetail.setMincode(mincode); Mockito.when(schoolServiceV2.getSchoolDetailByMincodeFromRedisCache(mincode)).thenReturn(schoolDetail); - schoolControllerV2.getSchoolDetailsByMincode(mincode); + schoolControllerV2.getSchoolDetailsByParams(mincode); Mockito.verify(schoolServiceV2).getSchoolDetailByMincodeFromRedisCache(mincode); } @@ -239,9 +239,9 @@ public void whenGetSchoolDetailsByMincode_Return_NOT_FOUND() { schoolDetail.setMincode(mincode); Mockito.when(schoolServiceV2.getSchoolDetailByMincodeFromRedisCache(mincode)).thenReturn(null); - schoolControllerV2.getSchoolDetailsByMincode(mincode); + schoolControllerV2.getSchoolDetailsByParams(mincode); Mockito.verify(schoolServiceV2).getSchoolDetailByMincodeFromRedisCache(mincode); - assertEquals(responseHelper.NOT_FOUND(), schoolControllerV2.getSchoolDetailsByMincode(mincode)); + assertEquals(responseHelper.NOT_FOUND(), schoolControllerV2.getSchoolDetailsByParams(mincode)); } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolControllerIntegrationTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolControllerIntegrationTest.java index c8701e3a..ec5ba070 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolControllerIntegrationTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/controller/v2/SchoolControllerIntegrationTest.java @@ -52,8 +52,8 @@ class SchoolControllerIntegrationTest { @Autowired private SchoolDetailTransformer schoolDetailTransformer; - private final String schoolId = UUID.randomUUID().toString(); - private final String districtId = UUID.randomUUID().toString(); + private final UUID schoolId = UUID.randomUUID(); + private final UUID districtId = UUID.randomUUID(); @BeforeEach void setup() { @@ -61,14 +61,14 @@ void setup() { schoolDetailRedisRepository.deleteAll(); School school = new School(); - school.setSchoolId(schoolId); + school.setSchoolId(schoolId.toString()); school.setMincode("1234567"); - school.setDistrictId(districtId); + school.setDistrictId(districtId.toString()); schoolRedisRepository.save(schoolTransformer.transformToEntity(school)); SchoolDetail schoolDetail = new SchoolDetail(); - schoolDetail.setSchoolId(schoolId); - schoolDetail.setDistrictId(districtId); + schoolDetail.setSchoolId(schoolId.toString()); + schoolDetail.setDistrictId(districtId.toString()); schoolDetailRedisRepository.save(schoolDetailTransformer.transformToEntity(schoolDetail)); } @@ -79,7 +79,7 @@ void testGetSchoolDetails_givenValidPayload_shouldReturnOk() throws Exception { .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$.schoolId").value(schoolId)) + .andExpect(jsonPath("$.schoolId").value(schoolId.toString())) .andExpect(jsonPath("$.mincode").value("1234567")); } @@ -104,13 +104,14 @@ void testGetSchoolDetails_givenInvalidScope_shouldReturnUnauthorized() throws Ex @Test void testGetSchoolsByParams_givenValidPayload_shouldReturnOk() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v2/trax/school/search") - .param("districtId", districtId) + .param("districtId", districtId.toString()) .with(jwt().jwt(jwt -> jwt.claim("scope", "READ_GRAD_SCHOOL_DATA"))) .param("mincode", "1234567") + .param("displayName", "School name") + .param("distNo", "123") .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(content().json("[{\"schoolId\":\""+schoolId+"\",\"districtId\":\""+districtId+"\"}]")); + .andExpect(status().isBadRequest()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)); } @Test @@ -131,18 +132,22 @@ void testGetSchoolsByParams_givenBadDistrictId_shouldReturnBadRequest() throws E .param("districtId", "BAD_ID123") .with(jwt().jwt(jwt -> jwt.claim("scope", "READ_GRAD_SCHOOL_DATA"))) .param("mincode", "1234567") + .param("displayName", "School name") + .param("distNo", "123") .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()) + .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$.message").value("Parameter 'districtId' with value 'BAD_ID123' could not be converted to type 'UUID'.")); + .andExpect(content().json("[]")); } @Test void testGetSchoolsByParams_givenScope_shouldReturnForbidden() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v2/trax/school/search") - .param("districtId", districtId) + .param("districtId", districtId.toString()) .with(jwt().jwt(jwt -> jwt.claim("scope", "BAD_SCOPE"))) .param("mincode", "1234567") + .param("displayName", "School name") + .param("distNo", "123") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isForbidden()); } diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxCommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxCommonServiceTest.java index c69b9870..591d8e05 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxCommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/TraxCommonServiceTest.java @@ -67,7 +67,7 @@ public class TraxCommonServiceTest { SchoolService schoolService; @MockBean - @Qualifier("InstituteSchoolService") + @Qualifier("instituteSchoolService") ca.bc.gov.educ.api.trax.service.institute.SchoolService schoolServiceV2; // NATS diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java index 8da741b8..5a570453 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java @@ -128,7 +128,7 @@ void whenGetSchoolsFromInstituteApi_returnsListOfSchools() { when(webClientMock.get()) .thenReturn(requestHeadersUriSpecMock); - List result = schoolService.getSchoolsFromInstituteApi(); + schoolService.getSchoolsFromInstituteApi(); } @Test @@ -521,71 +521,71 @@ void testGetSchoolBySchoolId_NotFound() { @Test void testGetSchoolsByParams() { - UUID districtId = UUID.randomUUID(); + String districtId = UUID.randomUUID().toString(); String mincode = "1234567"; + String displayName = "ABC Elementary School"; SchoolEntity schoolEntity = new SchoolEntity(); schoolEntity.setSchoolId(UUID.randomUUID().toString()); schoolEntity.setMincode(mincode); + schoolEntity.setDistrictId(districtId); + schoolEntity.setDisplayName(displayName); School school = new School(); school.setSchoolId(schoolEntity.getSchoolId()); school.setMincode(mincode); + school.setDistrictId(districtId); + school.setDisplayName(displayName); Mockito.when(schoolRedisRepository.findAll()).thenReturn(List.of(schoolEntity)); - Mockito.when(schoolRedisRepository.findAllByDistrictId(districtId.toString())).thenReturn(List.of(schoolEntity)); - Mockito.when(schoolRedisRepository.findByMincode(mincode)).thenReturn(Optional.of(schoolEntity)); - Mockito.when(schoolRedisRepository.findAllByDistrictIdAndMincode(districtId.toString(), mincode)).thenReturn(List.of(schoolEntity)); Mockito.when(schoolTransformer.transformToDTO(List.of(schoolEntity))).thenReturn(List.of(school)); Mockito.when(schoolTransformer.transformToDTO(schoolEntity)).thenReturn(school); // Test case when both districtId and mincode are null - List result = schoolService.getSchoolsByParams(null, null); + List result = schoolService.getSchoolsByParams(null, null, null, null); assertNotNull(result); assertEquals(1, result.size()); // Test case when mincode is null - result = schoolService.getSchoolsByParams(districtId, null); + result = schoolService.getSchoolsByParams(districtId, null, displayName, "12*"); assertNotNull(result); assertEquals(1, result.size()); // Test case when districtId is null - result = schoolService.getSchoolsByParams(null, mincode); + result = schoolService.getSchoolsByParams(null, mincode, "ABC*", "12*"); assertNotNull(result); assertEquals(1, result.size()); // Test case when both districtId and mincode are provided - result = schoolService.getSchoolsByParams(districtId, mincode); + result = schoolService.getSchoolsByParams(districtId, mincode, "ABC*", "12*"); assertNotNull(result); assertEquals(1, result.size()); } @Test void testGetSchoolsByParams_EmptyResults() { - UUID districtId = UUID.randomUUID(); + String districtId = UUID.randomUUID().toString(); String mincode = "1234567"; + String displayName = "ABC Elementary School"; Mockito.when(schoolRedisRepository.findAll()).thenReturn(Collections.emptyList()); - Mockito.when(schoolRedisRepository.findAllByDistrictId(districtId.toString())).thenReturn(Collections.emptyList()); - Mockito.when(schoolRedisRepository.findByMincode(mincode)).thenReturn(Optional.empty()); - Mockito.when(schoolRedisRepository.findAllByDistrictIdAndMincode(districtId.toString(), mincode)).thenReturn(Collections.emptyList()); // Test case when both districtId and mincode are null - List result = schoolService.getSchoolsByParams(null, null); + List result = schoolService.getSchoolsByParams(null, null, null, null); assertNotNull(result); assertTrue(result.isEmpty()); // Test case when mincode is null - result = schoolService.getSchoolsByParams(districtId, null); + result = schoolService.getSchoolsByParams(districtId, null, displayName, "12*"); assertNotNull(result); assertTrue(result.isEmpty()); // Test case when districtId is null - result = schoolService.getSchoolsByParams(null, mincode); + result = schoolService.getSchoolsByParams(null, mincode, "ABC*", "12*"); assertNotNull(result); assertTrue(result.isEmpty()); // Test case when both districtId and mincode are provided - result = schoolService.getSchoolsByParams(districtId, mincode); + result = schoolService.getSchoolsByParams(districtId, mincode, "ABC*", "12*"); assertNotNull(result); assertTrue(result.isEmpty()); }