use of org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider in project uPortal by Jasig.
the class CachingCharacterPipelineComponentTest method testCacheHit.
@Test
public void testCacheHit() {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockRes = new MockHttpServletResponse();
final CacheKey cacheKey = CacheKey.build("testCacheKey");
final CachedEventReader<CharacterEvent> eventReader = new CachedEventReader<CharacterEvent>(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
final Element cacheElement = new Element(cacheKey, eventReader);
final Ehcache cache = createMock(Ehcache.class);
final CharacterPipelineComponent targetComponent = createMock(CharacterPipelineComponent.class);
final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
expect(targetComponent.getCacheKey(mockReq, mockRes)).andReturn(cacheKey);
expect(cache.get(cacheKey)).andReturn(cacheElement);
replay(cache, targetComponent, elementsProvider);
final CachingCharacterPipelineComponent cachingComponent = new CachingCharacterPipelineComponent();
cachingComponent.setCache(cache);
cachingComponent.setWrappedComponent(targetComponent);
cachingComponent.setResourcesElementsProvider(elementsProvider);
final PipelineEventReader<CharacterEventReader, CharacterEvent> actualEventReader = cachingComponent.getEventReader(mockReq, mockRes);
Assert.assertNotNull(actualEventReader);
Assert.assertNotNull(actualEventReader.getEventReader());
Assert.assertFalse(actualEventReader.getEventReader().hasNext());
verify(cache, targetComponent, elementsProvider);
}
use of org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider in project uPortal by Jasig.
the class CachingStAXPipelineComponentTest method testCacheMiss.
@Test
public void testCacheMiss() {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockRes = new MockHttpServletResponse();
final CacheKey cacheKey = CacheKey.build("testCacheKey");
final List<XMLEvent> eventBuffer = Collections.emptyList();
final PipelineEventReader<XMLEventReader, XMLEvent> eventReader = new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(new XMLEventBufferReader(eventBuffer.listIterator()));
final Ehcache cache = createMock(Ehcache.class);
final StAXPipelineComponent targetComponent = createMock(StAXPipelineComponent.class);
final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
expect(targetComponent.getCacheKey(mockReq, mockRes)).andReturn(cacheKey);
expect(cache.get(cacheKey)).andReturn(null);
expect(targetComponent.getEventReader(mockReq, mockRes)).andReturn(eventReader);
cache.put((Element) notNull());
expectLastCall();
replay(cache, targetComponent, elementsProvider);
final CachingStAXPipelineComponent cachingComponent = new CachingStAXPipelineComponent();
cachingComponent.setCache(cache);
cachingComponent.setWrappedComponent(targetComponent);
cachingComponent.setResourcesElementsProvider(elementsProvider);
final PipelineEventReader<XMLEventReader, XMLEvent> actualEventReader = cachingComponent.getEventReader(mockReq, mockRes);
Assert.assertNotNull(actualEventReader);
Assert.assertNotNull(actualEventReader.getEventReader());
Assert.assertFalse(actualEventReader.getEventReader().hasNext());
verify(cache, targetComponent, elementsProvider);
}
use of org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider in project uPortal by Jasig.
the class CachingResourceLoaderImplTest method testUncachedLoad.
@Test
public void testUncachedLoad() throws Exception {
final Resource doc1Resouce = new FileSystemResource(doc1);
final CachingResourceLoaderImpl loader = new CachingResourceLoaderImpl();
final Ehcache cache = createMock(Ehcache.class);
final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
expect(cache.getInternalContext()).andReturn(null).anyTimes();
expect(cache.getCacheConfiguration()).andReturn(new CacheConfiguration());
expect(cache.get(doc1Resouce)).andReturn(null);
expect(cache.getQuiet(doc1Resouce)).andReturn(null);
cache.put(anyObject(Element.class));
expectLastCall();
replay(cache, elementsProvider);
loader.setResourceCache(cache);
loader.setResourcesElementsProvider(elementsProvider);
final CachedResource<String> cachedResource1 = loader.getResource(doc1Resouce, StringResourceBuilder.INSTANCE);
verify(cache, elementsProvider);
assertNotNull(cachedResource1);
final String expected = IOUtils.toString(new FileReader(doc1));
assertEquals(expected, cachedResource1.getCachedResource());
}
use of org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider in project uPortal by Jasig.
the class CachingStAXPipelineComponentTest method testCacheHit.
@Test
public void testCacheHit() {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockRes = new MockHttpServletResponse();
final CacheKey cacheKey = CacheKey.build("testCacheKey");
final CachedEventReader<XMLEvent> eventReader = new CachedEventReader<XMLEvent>(Collections.EMPTY_LIST, Collections.EMPTY_MAP);
final Element cacheElement = new Element(cacheKey, eventReader);
final Ehcache cache = createMock(Ehcache.class);
final StAXPipelineComponent targetComponent = createMock(StAXPipelineComponent.class);
final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
expect(targetComponent.getCacheKey(mockReq, mockRes)).andReturn(cacheKey);
expect(cache.get(cacheKey)).andReturn(cacheElement);
replay(cache, targetComponent, elementsProvider);
final CachingStAXPipelineComponent cachingComponent = new CachingStAXPipelineComponent();
cachingComponent.setCache(cache);
cachingComponent.setWrappedComponent(targetComponent);
cachingComponent.setResourcesElementsProvider(elementsProvider);
final PipelineEventReader<XMLEventReader, XMLEvent> actualEventReader = cachingComponent.getEventReader(mockReq, mockRes);
Assert.assertNotNull(actualEventReader);
Assert.assertNotNull(actualEventReader.getEventReader());
Assert.assertFalse(actualEventReader.getEventReader().hasNext());
verify(cache, targetComponent, elementsProvider);
}
Aggregations