use of javax.cache.CacheBuilder in project carbon-apimgt by wso2.
the class DefaultClaimsRetrieverTestCase method testGetClaimsWhenCacheNonEmpty.
@Test
public void testGetClaimsWhenCacheNonEmpty() throws Exception {
DefaultClaimsRetriever defaultClaimsRetriever = new DefaultClaimsRetriever();
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.JWT_CLAIM_CACHE_EXPIRY)).thenReturn("3600");
CacheBuilder cacheBuilder = Mockito.mock(CacheBuilder.class);
Mockito.when(cacheManager.createCacheBuilder(APIConstants.CLAIMS_APIM_CACHE)).thenReturn(cacheBuilder);
Cache cache = Mockito.mock(Cache.class);
Mockito.when(cacheBuilder.setStoreByValue(false)).thenReturn(cacheBuilder);
Mockito.when(cacheBuilder.setExpiry(Matchers.any(CacheConfiguration.ExpiryType.class), Matchers.any(CacheConfiguration.Duration.class))).thenReturn(cacheBuilder);
Mockito.when(cacheBuilder.build()).thenReturn(cache);
PowerMockito.mockStatic(APIUtil.class);
PowerMockito.when(APIUtil.getTenantId(USER_NAME)).thenReturn(TENANT_ID);
SortedMap<String, String> claimValues = new TreeMap<String, String>();
claimValues.put("claim1", "http://wso2.org/claim1");
claimValues.put("claim2", "http://wso2.org/claim2");
UserClaims userClaims = new UserClaims(claimValues);
Mockito.when(cache.get(Matchers.any(ClaimCacheKey.class))).thenReturn(userClaims);
SortedMap<String, String> claims = defaultClaimsRetriever.getClaims(USER_NAME);
Assert.assertNotNull(claims);
Assert.assertEquals(claimValues, claims);
}
Aggregations