diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/CommonController.java b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/CommonController.java index e5161588..158a40cd 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/CommonController.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/controller/v2/CommonController.java @@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; +import java.util.UUID; @CrossOrigin @RestController @@ -47,22 +48,22 @@ public ResponseEntity> getAllSchoolsForClobData() { return response.GET(commonService.getSchoolsForClobDataFromRedisCache()); } - @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_CLOB_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_SCHOOL_BY_CODE_MAPPING) + @GetMapping(EducGradTraxApiConstants.GRAD_SCHOOL_CLOB_URL_MAPPING_V2 + EducGradTraxApiConstants.GET_SCHOOL_BY_SCHOOL_ID) @PreAuthorize(PermissionsConstants.READ_SCHOOL_DATA) - @Operation(summary = "Find a School Clob data by MinCode for GRAD Algorithm Data from cache", description = "Get a School Clob data by MinCode for GRAD Algorithm Data from cache", tags = { "Algorithm Data" }) + @Operation(summary = "Find a School Clob data by SchoolId for GRAD Algorithm Data from cache", description = "Get a School Clob data by SchoolId for GRAD Algorithm Data from cache", tags = { "Algorithm Data" }) @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST"), @ApiResponse(responseCode = "422", description = "UNPROCESSABLE CONTENT"), @ApiResponse(responseCode = "204", description = "NO CONTENT")}) - public ResponseEntity getSchoolForClobDataByMinCode(@PathVariable String minCode) { - log.debug("getSchoolClobData by minCode: {}", minCode); - validation.requiredField(minCode, "minCode"); + public ResponseEntity getSchoolForClobDataBySchoolId(@PathVariable UUID schoolId) { + log.debug("getSchoolClobData by schoolId: {}", schoolId); + validation.requiredField(schoolId, "schoolId"); if (validation.hasErrors()) { validation.stopOnErrors(); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } - School schoolResponse = commonService.getSchoolForClobDataByMinCodeFromRedisCache(minCode); + School schoolResponse = commonService.getSchoolForClobDataBySchoolIdFromRedisCache(schoolId); if (schoolResponse != null) { return response.GET(schoolResponse); } else { diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/School.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/School.java index 37662f2e..0cc622af 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/School.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/School.java @@ -23,7 +23,7 @@ public class School implements Comparable { private String postal; private String openFlag; private String schoolCategoryCode; - private String schoolCategoryCodeInstitute; + private String schoolCategoryLegacyCode; public String getSchoolName() { return schoolName != null ? schoolName.trim(): ""; @@ -69,7 +69,7 @@ public int hashCode() { @Override public String toString() { - return "School [minCode=" + minCode + ", schoolId=" + schoolId + ", schoolCategoryCode=" + schoolCategoryCode + ", schoolCategoryCodeInstitute=" + schoolCategoryCodeInstitute + return "School [minCode=" + minCode + ", schoolId=" + schoolId + ", schoolCategoryCode=" + schoolCategoryCode + ", schoolCategoryLegacyCode=" + schoolCategoryLegacyCode + ", schoolName=" + schoolName + ", districtName=" + districtName + ", transcriptEligibility=" + transcriptEligibility + ", certificateEligibility=" + certificateEligibility + ", address1=" + address1 + ", address2=" + address2 + ", city=" + city + ", provCode=" + provCode + ", countryCode=" + countryCode + ", postal=" + postal + ", openFlag=" + openFlag + "]"; diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/DistrictRedisRepository.java b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/DistrictRedisRepository.java index 5b42704c..b38fcbb4 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/DistrictRedisRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/DistrictRedisRepository.java @@ -4,9 +4,11 @@ import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository public interface DistrictRedisRepository extends CrudRepository { String HASH_KEY = "District"; - DistrictEntity findByDistrictNumber(String districtNumber); + Optional findByDistrictNumber(String districtNumber); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolDetailRedisRepository.java b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolDetailRedisRepository.java index 9b788dc5..b851e7ef 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolDetailRedisRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolDetailRedisRepository.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface SchoolDetailRedisRepository extends CrudRepository { @@ -14,5 +15,5 @@ public interface SchoolDetailRedisRepository extends CrudRepository findByDistrictId(String districtId); - SchoolDetailEntity findByMincode(String mincode); + Optional findByMincode(String mincode); } \ No newline at end of file diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolRedisRepository.java b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolRedisRepository.java index c0bec73f..e4f4684c 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolRedisRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/repository/redis/SchoolRedisRepository.java @@ -5,12 +5,13 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface SchoolRedisRepository extends CrudRepository { String HASH_KEY = "School"; - SchoolEntity findByMincode(String mincode); + Optional findByMincode(String mincode); List findAllByDistrictIdAndMincode(String districtId, String mincode); List findAllByDistrictId(String districtId); } \ No newline at end of file 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 03b81492..ea87c80a 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 @@ -43,7 +43,14 @@ public List getSchoolsForClobDataFromR public ca.bc.gov.educ.api.trax.model.dto.School getSchoolForClobDataByMinCodeFromRedisCache(String minCode) { log.debug("Get a School Clob data by MinCode from Redis Cache: {}", minCode); SchoolDetail schoolDetail = schoolService.getSchoolDetailByMincodeFromRedisCache(minCode); - return schoolDetail != null? convertSchoolDetailIntoSchoolClob(schoolDetail) : null; + return schoolDetail != null? convertSchoolDetailIntoSchoolClob((schoolDetail)) : null; + } + + // School Clob data for Algorithm Data by schoolId from RedisCache + public ca.bc.gov.educ.api.trax.model.dto.School getSchoolForClobDataBySchoolIdFromRedisCache(UUID schoolId) { + log.debug("Get a School Clob data by SchoolId from Redis Cache: {}", schoolId); + SchoolDetail schoolDetail = schoolService.getSchoolDetailBySchoolId(schoolId); + return schoolDetail != null? convertSchoolDetailIntoSchoolClob((schoolDetail)) : null; } public UUID getSchoolIdFromRedisCache(String minCode) { @@ -81,8 +88,8 @@ private School convertSchoolDetailIntoSchoolClob(ca.bc.gov.educ.api.trax.model.d school.setDistrictName(district.getDisplayName()); } - // School Category Code - school.setSchoolCategoryCodeInstitute(schoolDetail.getSchoolCategoryCode()); + // School Category + school.setSchoolCategoryCode(schoolDetail.getSchoolCategoryCode()); populateSchoolCategoryLegacyCode(school, schoolDetail.getSchoolCategoryCode()); // Address @@ -112,7 +119,7 @@ private void populateSchoolCategoryLegacyCode(School school, String schoolCatego if (StringUtils.isNotBlank(schoolCategoryCode)) { SchoolCategoryCode schoolCategoryCodeObj = codeService.getSchoolCategoryCodeFromRedisCache(schoolCategoryCode); if (schoolCategoryCodeObj != null) { - school.setSchoolCategoryCode(schoolCategoryCodeObj.getLegacyCode()); + school.setSchoolCategoryLegacyCode(schoolCategoryCodeObj.getLegacyCode()); } } } 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 1e284b7f..b79cd393 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 @@ -90,12 +90,12 @@ public void initializeDistrictCache(boolean force) { public District getDistrictByDistNoFromRedisCache(String districtNumber) { log.debug("**** Getting district by district no. from Redis Cache."); - return districtTransformer.transformToDTO(districtRedisRepository.findByDistrictNumber(districtNumber)); + return districtRedisRepository.findByDistrictNumber(districtNumber).map(districtTransformer::transformToDTO).orElse(null); } public District getDistrictByIdFromRedisCache(String districtId) { log.debug("**** Getting district by ID from Redis Cache."); - return districtTransformer.transformToDTO(districtRedisRepository.findById(districtId)); + return districtRedisRepository.findById(districtId).map(districtTransformer::transformToDTO).orElse(null); } public List getDistrictsBySchoolCategoryCode(String schoolCategoryCode) { 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 d44085d2..0cb19d37 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 @@ -72,12 +72,12 @@ public List getSchoolsFromRedisCache() { public School getSchoolByMinCodeFromRedisCache(String minCode) { log.debug("Get School by Mincode from Redis Cache: {}", minCode); - return schoolTransformer.transformToDTO(schoolRedisRepository.findByMincode(minCode)); + return schoolRedisRepository.findByMincode(minCode).map(schoolTransformer::transformToDTO).orElse(null); } public boolean checkIfSchoolExists(String minCode) { - SchoolEntity schoolEntity = schoolRedisRepository.findByMincode(minCode); - return schoolEntity != null; + Optional schoolOptional = schoolRedisRepository.findByMincode(minCode); + return schoolOptional.isPresent(); } public void initializeSchoolCache(boolean force) { @@ -121,7 +121,12 @@ public List getSchoolDetailsFromRedisCache() { public SchoolDetail getSchoolDetailByMincodeFromRedisCache(String mincode) { log.debug("**** Getting school Details By Mincode from Redis Cache."); - return schoolDetailTransformer.transformToDTO(schoolDetailRedisRepository.findByMincode(mincode)); + return schoolDetailRedisRepository.findByMincode(mincode).map(schoolDetailTransformer::transformToDTO).orElse(null); + } + + public SchoolDetail getSchoolDetailBySchoolId(UUID schoolId) { + log.debug("**** Getting school Details By SchoolId from Redis Cache."); + return schoolDetailRedisRepository.findById(String.valueOf(schoolId)).map(schoolDetailTransformer::transformToDTO).orElse(null); } public void initializeSchoolDetailCache(boolean force) { @@ -183,8 +188,8 @@ public List getSchoolsByParams(UUID districtId, String mincode) { } else if (mincode == null) { return schoolTransformer.transformToDTO(schoolRedisRepository.findAllByDistrictId(String.valueOf(districtId))); } else if(districtId == null) { - SchoolEntity schoolEntity = schoolRedisRepository.findByMincode(mincode); - return schoolEntity != null ? List.of(schoolTransformer.transformToDTO(schoolEntity)) : Collections.emptyList(); + 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)); } diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/controller/CommonControllerTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/controller/CommonControllerTest.java index 5abd62a8..208fdae2 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/controller/CommonControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/controller/CommonControllerTest.java @@ -71,28 +71,29 @@ public void testGetSchoolsForClobDataByDistrictNumber() { @Test public void testGetSchoolClobData() { School school = new School(); - school.setSchoolId(UUID.randomUUID().toString()); + UUID schoolId = UUID.randomUUID(); + school.setSchoolId(schoolId.toString()); school.setSchoolName("Test School"); school.setMinCode("12345678"); - Mockito.when(commonService.getSchoolForClobDataByMinCodeFromRedisCache(school.getMinCode())).thenReturn(school); - commonController.getSchoolForClobDataByMinCode(school.getMinCode()); - Mockito.verify(commonService).getSchoolForClobDataByMinCodeFromRedisCache(school.getMinCode()); + Mockito.when(commonService.getSchoolForClobDataBySchoolIdFromRedisCache(schoolId)).thenReturn(school); + commonController.getSchoolForClobDataBySchoolId(schoolId); + Mockito.verify(commonService).getSchoolForClobDataBySchoolIdFromRedisCache(schoolId); } @Test public void testGetSchoolClobData_whenMinCode_isNot_Provided() { Mockito.when(validation.hasErrors()).thenReturn(true); - commonController.getSchoolForClobDataByMinCode(""); + commonController.getSchoolForClobDataBySchoolId(null); Mockito.verify(validation).stopOnErrors(); } @Test public void testGetSchoolClobData_whenMinCode_isNot_Found() { - String minCode = "12345678"; - Mockito.when(commonService.getSchoolForClobDataByMinCodeFromRedisCache(minCode)).thenReturn(null); - commonController.getSchoolForClobDataByMinCode(minCode); - Mockito.verify(commonService).getSchoolForClobDataByMinCodeFromRedisCache(minCode); + UUID schoolId = UUID.randomUUID(); + Mockito.when(commonService.getSchoolForClobDataBySchoolIdFromRedisCache(schoolId)).thenReturn(null); + commonController.getSchoolForClobDataBySchoolId(schoolId); + Mockito.verify(commonService).getSchoolForClobDataBySchoolIdFromRedisCache(schoolId); } } diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/CommonServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/CommonServiceTest.java index 21dfa551..90f74371 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/CommonServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/CommonServiceTest.java @@ -17,6 +17,7 @@ import redis.clients.jedis.JedisCluster; import java.util.List; +import java.util.Optional; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; @@ -50,9 +51,10 @@ public class CommonServiceTest { @Test public void testGetSchoolIdFromRedisCache() { + UUID schoolId = UUID.randomUUID(); String minCode = "12345678"; String distNo = "123"; - SchoolDetail schoolDetail = mockInstituteData(minCode, distNo, "PUBLIC", "01"); + SchoolDetail schoolDetail = mockInstituteData(schoolId, minCode, distNo, "PUBLIC", "01"); var result = commonService.getSchoolIdFromRedisCache(minCode); assertThat(result).isEqualTo(UUID.fromString(schoolDetail.getSchoolId())); @@ -60,9 +62,10 @@ public void testGetSchoolIdFromRedisCache() { @Test public void testGetSchoolIdStrFromRedisCache() { + UUID schoolId = UUID.randomUUID(); String minCode = "12345678"; String distNo = "123"; - SchoolDetail schoolDetail = mockInstituteData(minCode, distNo, "PUBLIC", "01"); + SchoolDetail schoolDetail = mockInstituteData(schoolId, minCode, distNo, "PUBLIC", "01"); var result = commonService.getSchoolIdStrFromRedisCache(minCode); assertThat(result).isEqualTo(schoolDetail.getSchoolId()); @@ -70,9 +73,10 @@ public void testGetSchoolIdStrFromRedisCache() { @Test public void testGetAllSchoolClobs() { + UUID schoolId = UUID.randomUUID(); String minCode = "12345678"; String distNo = "123"; - SchoolDetail schoolDetail = mockInstituteData(minCode, distNo, "PUBLIC", "01"); + SchoolDetail schoolDetail = mockInstituteData(schoolId, minCode, distNo, "PUBLIC", "01"); var result = commonService.getSchoolsForClobDataFromRedisCache(); assertThat(result).hasSize(1); @@ -81,9 +85,10 @@ public void testGetAllSchoolClobs() { @Test public void testGetSchoolsByDistrictNumber() { + UUID schoolId = UUID.randomUUID(); String minCode = "12345678"; String distNo = "123"; - SchoolDetail schoolDetail = mockInstituteData(minCode, distNo, "PUBLIC", "01"); + SchoolDetail schoolDetail = mockInstituteData(schoolId, minCode, distNo, "PUBLIC", "01"); when(schoolService.getSchoolDetailsByDistrictFromRedisCache(schoolDetail.getDistrictId())).thenReturn(List.of(schoolDetail)); @@ -100,12 +105,13 @@ public void testGetSchoolsByDistrictNumber_returnEmptyList() { @Test public void testGetSchoolClob() { + UUID schoolId = UUID.randomUUID(); String minCode = "12345678"; String distNo = "123"; String schoolCategoryLegacyCode = "01"; - SchoolDetail schoolDetail = mockInstituteData(minCode, distNo, "PUBLIC", schoolCategoryLegacyCode); + SchoolDetail schoolDetail = mockInstituteData(schoolId, minCode, distNo, "PUBLIC", schoolCategoryLegacyCode); - var result = commonService.getSchoolForClobDataByMinCodeFromRedisCache(minCode); + var result = commonService.getSchoolForClobDataBySchoolIdFromRedisCache(schoolId); assertThat(result).isNotNull(); assertThat(result.getSchoolId()).isEqualTo(schoolDetail.getSchoolId()); assertThat(result.getMinCode()).isEqualTo(schoolDetail.getMincode()); @@ -114,7 +120,7 @@ public void testGetSchoolClob() { assertThat(result.getAddress1()).isNotNull(); } - public SchoolDetail mockInstituteData(String minCode, String distNo, String schoolCategoryCode, String schoolCategoryLegacyCode) { + public SchoolDetail mockInstituteData(UUID schoolId, String minCode, String distNo, String schoolCategoryCode, String schoolCategoryLegacyCode) { District district = new District(); district.setDistrictId(UUID.randomUUID().toString()); district.setDistrictNumber(distNo); @@ -125,7 +131,7 @@ public SchoolDetail mockInstituteData(String minCode, String distNo, String scho schoolCategory.setSchoolCategoryCode(schoolCategoryCode); SchoolDetail schoolDetail = new SchoolDetail(); - schoolDetail.setSchoolId(UUID.randomUUID().toString()); + schoolDetail.setSchoolId(schoolId.toString()); schoolDetail.setMincode(minCode); schoolDetail.setDisplayName("Test School"); schoolDetail.setDistrictId(district.getDistrictId()); @@ -151,10 +157,11 @@ public SchoolDetail mockInstituteData(String minCode, String distNo, String scho when(this.codeService.getSchoolCategoryCodeFromRedisCache(schoolCategoryCode)).thenReturn(schoolCategory); when(this.districtService.getDistrictByIdFromRedisCache(district.getDistrictId())).thenReturn(district); when(this.districtService.getDistrictByDistNoFromRedisCache(district.getDistrictNumber())).thenReturn(district); + when(this.schoolService.getSchoolDetailBySchoolId(schoolId)).thenReturn(schoolDetail); when(this.schoolService.getSchoolDetailByMincodeFromRedisCache(minCode)).thenReturn(schoolDetail); when(this.schoolService.getSchoolDetailsFromRedisCache()).thenReturn(List.of(schoolDetail)); - when(this.schoolService.getSchoolDetailByMincodeFromRedisCache(minCode)).thenReturn(schoolDetail); when(this.schoolService.getSchoolByMinCodeFromRedisCache(minCode)).thenReturn(school); + when(this.schoolService.getSchoolBySchoolId(schoolId)).thenReturn(Optional.of(school)); return schoolDetail; } diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java index 53c70f24..3f544659 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteDistrictServiceTest.java @@ -309,7 +309,7 @@ public void whenGetDistrictByDistNoFromRedisCache_ReturnDistrict() { districtEntity.setContacts(Arrays.asList(new DistrictContactEntity(), new DistrictContactEntity())); when(this.districtRedisRepository.findByDistrictNumber(distNo)) - .thenReturn(districtEntity); + .thenReturn(Optional.of(districtEntity)); when(this.districtTransformerMock.transformToDTO(districtEntity)) .thenReturn(district); assertEquals(district, districtService.getDistrictByDistNoFromRedisCache(distNo)); 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 e74bd550..8da741b8 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 @@ -1,9 +1,6 @@ package ca.bc.gov.educ.api.trax.service.institute; import ca.bc.gov.educ.api.trax.constant.CacheKey; -import ca.bc.gov.educ.api.trax.messaging.NatsConnection; -import ca.bc.gov.educ.api.trax.messaging.jetstream.Publisher; -import ca.bc.gov.educ.api.trax.messaging.jetstream.Subscriber; import ca.bc.gov.educ.api.trax.model.dto.ResponseObj; import ca.bc.gov.educ.api.trax.model.dto.institute.School; import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolDetail; @@ -211,7 +208,7 @@ void whenGetSchoolByMincodeFromRedisCache_ReturnSchool() { schoolEntity.setEmail("abc@xyz.ca"); when(this.schoolRedisRepository.findByMincode(mincode)) - .thenReturn(schoolEntity); + .thenReturn(Optional.of(schoolEntity)); when(this.schoolTransformer.transformToDTO(schoolEntity)) .thenReturn(school); assertEquals(school, schoolService.getSchoolByMinCodeFromRedisCache(mincode)); @@ -261,14 +258,14 @@ void whenCheckIfSchoolExists_returnTrue() { schoolEntity.setSchoolCategoryCode("SCC"); schoolEntity.setEmail("abc@xyz.ca"); - when(schoolRedisRepository.findByMincode(minCode)).thenReturn(schoolEntity); + when(schoolRedisRepository.findByMincode(minCode)).thenReturn(Optional.of(schoolEntity)); assertEquals(true, schoolService.checkIfSchoolExists(minCode)); } @Test void whenCheckIfSchoolExists_returnFalse() { String minCode = "12345678"; - when(schoolRedisRepository.findByMincode(minCode)).thenReturn(null); + when(schoolRedisRepository.findByMincode(minCode)).thenReturn(Optional.empty()); assertEquals(false, schoolService.checkIfSchoolExists(minCode)); } @@ -440,7 +437,7 @@ void whenGetSchoolDetailByMincodeFromRedisCache_ReturnSchoolDetail() { schoolDetailEntity.setEmail("abc@xyz.ca"); when(this.schoolDetailRedisRepository.findByMincode(mincode)) - .thenReturn(schoolDetailEntity); + .thenReturn(Optional.of(schoolDetailEntity)); when(this.schoolDetailTransformer.transformToDTO(schoolDetailEntity)) .thenReturn(schoolDetail); assertEquals(schoolDetail, schoolService.getSchoolDetailByMincodeFromRedisCache(mincode)); @@ -536,7 +533,7 @@ void testGetSchoolsByParams() { Mockito.when(schoolRedisRepository.findAll()).thenReturn(List.of(schoolEntity)); Mockito.when(schoolRedisRepository.findAllByDistrictId(districtId.toString())).thenReturn(List.of(schoolEntity)); - Mockito.when(schoolRedisRepository.findByMincode(mincode)).thenReturn(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); @@ -569,7 +566,7 @@ void testGetSchoolsByParams_EmptyResults() { Mockito.when(schoolRedisRepository.findAll()).thenReturn(Collections.emptyList()); Mockito.when(schoolRedisRepository.findAllByDistrictId(districtId.toString())).thenReturn(Collections.emptyList()); - Mockito.when(schoolRedisRepository.findByMincode(mincode)).thenReturn(null); + 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