use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.
the class InvalidateByCacheConfigVisitorTest method getInvalidateByCacheConfigVisitor.
private InvalidateByCacheConfigVisitor getInvalidateByCacheConfigVisitor(long delta, boolean knows) throws Exception {
final DynamicClassLoaderManager dclm = mock(DynamicClassLoaderManager.class);
final CacheKey cacheKey = mockCacheKey();
final HttpCacheConfig cacheConfig;
if (knows) {
cacheConfig = mockCacheStore(cacheKey);
} else {
cacheConfig = mockCacheStore();
}
final InvalidateByCacheConfigVisitor visitor = new InvalidateByCacheConfigVisitor(11, delta, cacheConfig, dclm);
final InvalidateByCacheConfigVisitor spy = spy(visitor);
when(spy, "getCacheKey", any(Node.class)).thenReturn(mockCacheKey());
return spy;
}
use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.
the class InvalidateByCacheConfigVisitorTest method mockCacheStore.
private HttpCacheConfig mockCacheStore(final CacheKey key) throws HttpCacheKeyCreationException {
final HttpCacheConfig config = mock(HttpCacheConfig.class);
when(config.knows(any(CacheKey.class))).thenReturn(true);
return config;
}
use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.
the class EntryNodeMapVisitorTest method test5entries.
@Test
public void test5entries() throws Exception {
final RootNodeMockFactory.Settings settings = new RootNodeMockFactory.Settings();
settings.setEntryNodeCount(5);
final Node rootNode = new RootNodeMockFactory(settings).build();
final EntryNodeMapVisitor visitor = getMockedNodeMapVisitor();
visitor.visit(rootNode);
final Map<CacheKey, CacheContent> cache = visitor.getCache();
assertEquals(5, cache.size());
}
use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.
the class EntryNodeMapVisitorTest method test10entries.
@Test
public void test10entries() throws Exception {
final RootNodeMockFactory.Settings settings = new RootNodeMockFactory.Settings();
settings.setEntryNodeCount(10);
final Node rootNode = new RootNodeMockFactory(settings).build();
final EntryNodeMapVisitor visitor = getMockedNodeMapVisitor();
visitor.visit(rootNode);
final Map<CacheKey, CacheContent> cache = visitor.getCache();
assertEquals(10, cache.size());
}
use of com.adobe.acs.commons.httpcache.keys.CacheKey in project acs-aem-commons by Adobe-Consulting-Services.
the class BucketNodeFactoryTest method buildNodeFactoryWithMocks.
private BucketNodeFactory buildNodeFactoryWithMocks(MockSettings settings) throws RepositoryException, BucketNodeFactoryException {
final CacheKey cacheKey = mockCacheKey(settings);
when(session.nodeExists(MockSettings.VALID_ROOT_PATH)).thenReturn(true);
when(session.getNode(MockSettings.VALID_ROOT_PATH)).thenReturn(cacheRootNode);
final BucketNodeFactory bucketNodeFactory = new BucketNodeFactory(session, settings.cacheRootPath, cacheKey, settings.bucketNodeDepth);
final int hashCode = cacheKey.hashCode();
if (hashCode > 0) {
final String hashString = StringUtils.leftPad(String.valueOf(hashCode), (int) HASHCODE_LENGTH, "0");
final int increment = (int) Math.ceil(HASHCODE_LENGTH / settings.bucketNodeDepth);
final String[] pathArray = new String[settings.bucketNodeDepth];
for (int position = 0, i = 0; i < settings.bucketNodeDepth; position += increment, i++) {
int endIndex = (position + increment > hashString.length()) ? hashString.length() : position + increment;
String nodeName = StringUtils.leftPad(hashString.substring(position, endIndex), 5, "0");
pathArray[i] = nodeName;
}
Node targetNode = cacheRootNode;
for (String nodeName : pathArray) {
Node childNode = mock(Node.class);
when(childNode.getName()).thenReturn(nodeName);
when(targetNode.hasNode(nodeName)).thenReturn(true);
when(targetNode.getNode(nodeName)).thenReturn(childNode);
when(childNode.getParent()).thenReturn(targetNode);
targetNode = childNode;
}
}
return bucketNodeFactory;
}
Aggregations