Skip to content

Commit 34528af

Browse files
Code coverage improvements.
1 parent 857435e commit 34528af

File tree

2 files changed

+84
-32
lines changed

2 files changed

+84
-32
lines changed

api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteCodeServiceTest.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import ca.bc.gov.educ.api.trax.messaging.jetstream.Publisher;
77
import ca.bc.gov.educ.api.trax.messaging.jetstream.Subscriber;
88
import ca.bc.gov.educ.api.trax.model.dto.ResponseObj;
9+
import ca.bc.gov.educ.api.trax.model.dto.institute.School;
910
import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolCategoryCode;
1011
import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolFundingGroupCode;
1112
import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolCategoryCodeEntity;
@@ -17,6 +18,7 @@
1718
import ca.bc.gov.educ.api.trax.service.RESTService;
1819
import ca.bc.gov.educ.api.trax.util.EducGradTraxApiConstants;
1920
import ca.bc.gov.educ.api.trax.util.RestUtils;
21+
import org.checkerframework.checker.nullness.Opt;
2022
import org.junit.Test;
2123
import org.junit.jupiter.api.extension.ExtendWith;
2224
import org.junit.runner.RunWith;
@@ -42,6 +44,7 @@
4244
import java.util.ArrayList;
4345
import java.util.Arrays;
4446
import java.util.List;
47+
import java.util.Optional;
4548
import java.util.function.Consumer;
4649

4750
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -164,6 +167,87 @@ public void whenGetSchoolCategoryCodesFromInstituteApi_returnsListOfSchoolCatego
164167
assertDoesNotThrow(() -> codeService.loadSchoolCategoryCodesFromInstituteApiIntoRedisCacheAsync());
165168
}
166169

170+
@Test
171+
public void whenGetSchoolCategoryCodeFromRedisCache_returnSchoolCategoryCode() {
172+
SchoolCategoryCodeEntity scce = new SchoolCategoryCodeEntity();
173+
List<SchoolCategoryCodeEntity> scces = new ArrayList<SchoolCategoryCodeEntity>();
174+
scce.setSchoolCategoryCode("SCC1");
175+
scce.setLabel("SCC1-label");
176+
scces.add(scce);
177+
scce = new SchoolCategoryCodeEntity();
178+
scce.setSchoolCategoryCode("SCC2");
179+
scce.setLabel("SCC2-label");
180+
scces.add(scce);
181+
182+
SchoolCategoryCode scc = new SchoolCategoryCode();
183+
List<SchoolCategoryCode> sccs = new ArrayList<SchoolCategoryCode>();
184+
scc.setSchoolCategoryCode("SCC1");
185+
scc.setLabel("SCC1-label");
186+
scc.setDescription("Desc");
187+
scc.setLegacyCode("SCC1-legacy");
188+
scc.setDisplayOrder("10");
189+
scc.setEffectiveDate("01-01-2024");
190+
scc.setExpiryDate("01-01-2024");
191+
sccs.add(scc);
192+
scc = new SchoolCategoryCode();
193+
scc.setSchoolCategoryCode("SCC2");
194+
scc.setLabel("SCC2-label");
195+
scc.setDescription("Desc");
196+
scc.setLegacyCode("SCC2-legacy");
197+
scc.setDisplayOrder("20");
198+
scc.setEffectiveDate("01-01-2024");
199+
scc.setExpiryDate("01-01-2024");
200+
sccs.add(scc);
201+
202+
when(this.schoolCategoryCodeRedisRepository.findById("SCC1"))
203+
.thenReturn(Optional.of(scce));
204+
assertNotNull(codeService.getSchoolCategoryCodeFromRedisCache("SCC1"));
205+
}
206+
207+
@Test
208+
public void whenGetSchoolCategoryCodeFromRedisCache_NotFound_returnSchoolCategoryCode() {
209+
SchoolCategoryCodeEntity scce = new SchoolCategoryCodeEntity();
210+
List<SchoolCategoryCodeEntity> scces = new ArrayList<SchoolCategoryCodeEntity>();
211+
scce.setSchoolCategoryCode("SCC1");
212+
scce.setLabel("SCC1-label");
213+
scces.add(scce);
214+
scce = new SchoolCategoryCodeEntity();
215+
scce.setSchoolCategoryCode("SCC2");
216+
scce.setLabel("SCC2-label");
217+
scces.add(scce);
218+
219+
SchoolCategoryCode scc = new SchoolCategoryCode();
220+
List<SchoolCategoryCode> sccs = new ArrayList<SchoolCategoryCode>();
221+
scc.setSchoolCategoryCode("SCC1");
222+
scc.setLabel("SCC1-label");
223+
scc.setDescription("Desc");
224+
scc.setLegacyCode("SCC1-legacy");
225+
scc.setDisplayOrder("10");
226+
scc.setEffectiveDate("01-01-2024");
227+
scc.setExpiryDate("01-01-2024");
228+
sccs.add(scc);
229+
scc = new SchoolCategoryCode();
230+
scc.setSchoolCategoryCode("SCC2");
231+
scc.setLabel("SCC2-label");
232+
scc.setDescription("Desc");
233+
scc.setLegacyCode("SCC2-legacy");
234+
scc.setDisplayOrder("20");
235+
scc.setEffectiveDate("01-01-2024");
236+
scc.setExpiryDate("01-01-2024");
237+
sccs.add(scc);
238+
239+
when(restServiceMock.get(constants.getAllSchoolCategoryCodesFromInstituteApiUrl(), List.class, instWebClient)).thenReturn(scces);
240+
when(schoolCategoryCodeTransformer.transformToDTO(scces))
241+
.thenReturn(sccs);
242+
List<SchoolCategoryCode> result = codeService.getSchoolCategoryCodesFromInstituteApi();
243+
assertNotNull(result);
244+
assertDoesNotThrow(() -> codeService.loadSchoolCategoryCodesFromInstituteApiIntoRedisCacheAsync());
245+
246+
when(this.schoolCategoryCodeRedisRepository.findById("SCC1"))
247+
.thenReturn(Optional.empty());
248+
assertNotNull(codeService.getSchoolCategoryCodeFromRedisCache("SCC1"));
249+
}
250+
167251
@Test
168252
public void whenGetSchoolFundingGroupCodesFromInstituteApi_returnsListOfSchoolFundingGroupCode() {
169253
List<SchoolFundingGroupCodeEntity> schoolFundingGroupCodes = new ArrayList<>();

api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/InstituteSchoolServiceTest.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -412,38 +412,6 @@ void whenInitializeSchoolCache_DoNothing() {
412412
Assertions.assertDoesNotThrow(() -> schoolService.initializeSchoolCache(false));
413413
}
414414

415-
@Test
416-
void whenInitializeSchoolCache() {
417-
List<SchoolEntity> schoolEntities = new ArrayList<>();
418-
SchoolEntity schoolEntity = new SchoolEntity();
419-
420-
schoolEntity.setSchoolId("ID");
421-
schoolEntity.setDistrictId("DistID");
422-
schoolEntity.setSchoolNumber("12345");
423-
schoolEntity.setSchoolCategoryCode("SCC");
424-
schoolEntity.setEmail("[email protected]");
425-
schoolEntity.setDisplayName("Tk̓emlúps te Secwépemc");
426-
schoolEntity.setDisplayNameNoSpecialChars("Tkkemlups te Secwepemc");
427-
schoolEntities.add(schoolEntity);
428-
429-
List<School> schools = new ArrayList<>();
430-
School school = new School();
431-
school.setSchoolId("ID");
432-
school.setDistrictId("DistID");
433-
school.setSchoolNumber("12345");
434-
school.setSchoolCategoryCode("SCC");
435-
school.setEmail("[email protected]");
436-
school.setDisplayName("Tk̓emlúps te Secwépemc");
437-
school.setDisplayNameNoSpecialChars("Tkkemlups te Secwepemc");
438-
schools.add(school);
439-
440-
441-
when(this.schoolTransformer.transformToDTO(schoolEntities)).thenReturn(schools);
442-
when(this.restServiceMock.get(constants.getAllSchoolsFromInstituteApiUrl(),
443-
List.class, instWebClient)).thenReturn(schoolEntities);
444-
assertDoesNotThrow( () -> serviceHelperMock.initializeCache(true, CacheKey.SCHOOL_CACHE, serviceHelperMock));
445-
}
446-
447415
@Test
448416
void whenGetSchoolDetailsFromInstituteApi_returnsListOfSchoolDetails() {
449417
List<School> schools = new ArrayList<>();

0 commit comments

Comments
 (0)