Skip to content

Commit

Permalink
GRAD2-2637 - Cache institute api data into Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
kamal-mohammed committed Jun 18, 2024
1 parent df18bd6 commit 91e5b9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Component("SchoolCategoryCodeTransformer")
public class SchoolCategoryCodeTransformer {
Expand Down Expand Up @@ -36,7 +37,13 @@ public SchoolCategoryCodeEntity transformToEntity(SchoolCategoryCode schoolCateg
return modelMapper.map(schoolCategoryCode, SchoolCategoryCodeEntity.class);
}

public List<SchoolCategoryCodeEntity> transformToEntity (Iterable<SchoolCategoryCode> schoolCategoryCodes ) {
return modelMapper.map(schoolCategoryCodes, new TypeToken<List<SchoolCategoryCodeEntity>>(){}.getType());
public List<SchoolCategoryCodeEntity> transformToEntity (List<SchoolCategoryCode> schoolCategoryCodes ) {
if (schoolCategoryCodes == null)
return null;

return schoolCategoryCodes
.stream()
.map(scc -> modelMapper.map(scc, SchoolCategoryCodeEntity.class))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,25 +295,23 @@ public void whenInitializeSchoolCategoryCodeCache_WithLoadingAndTrue_ThenForceLo
when(this.schoolCategoryCodeEntitiesMock.block())
.thenReturn(scces);

when(this.restUtils.getTokenResponseObject(anyString(), anyString()))
.thenReturn(responseObjectMock);
when(this.responseObjectMock.getAccess_token())
.thenReturn("accessToken");

when(redisTemplateMock.opsForValue())
.thenReturn(valueOperationsMock);
when(valueOperationsMock.get(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name()))
.thenReturn(String.valueOf(CacheStatus.LOADING));
doNothing().when(valueOperationsMock).set(CacheKey.SCHOOL_CATEGORY_CODE_CACHE.name(), CacheStatus.LOADING.name());

when(this.restUtils.getTokenResponseObject(anyString(), anyString()))
.thenReturn(responseObjectMock);
when(this.responseObjectMock.getAccess_token())
.thenReturn("accessToken");

CodeService codeServicemock = mock(CodeService.class);
when(codeServicemock.getSchoolCategoryCodesFromInstituteApi()).thenReturn(sccs);
doNothing().when(codeServicemock).loadSchoolCategoryCodesIntoRedisCache(sccs);

codeService.initializeSchoolCategoryCodeCache(true);

//verify(codeService).loadSchoolCategoryCodesIntoRedisCache(sccs);
//verify(codeServicemock).loadSchoolCategoryCodesIntoRedisCache(sccs);
}

@Test
Expand Down

0 comments on commit 91e5b9a

Please sign in to comment.