Search in sources :

Example 1 with CharacterPipelineComponent

use of org.apereo.portal.rendering.CharacterPipelineComponent 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);
}
Also used : CharacterPipelineComponent(org.apereo.portal.rendering.CharacterPipelineComponent) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Element(net.sf.ehcache.Element) CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) Ehcache(net.sf.ehcache.Ehcache) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CacheKey(org.apereo.portal.utils.cache.CacheKey) Test(org.junit.Test)

Example 2 with CharacterPipelineComponent

use of org.apereo.portal.rendering.CharacterPipelineComponent in project uPortal by Jasig.

the class CachingCharacterPipelineComponentTest method testCacheMiss.

@Test
public void testCacheMiss() {
    final MockHttpServletRequest mockReq = new MockHttpServletRequest();
    final MockHttpServletResponse mockRes = new MockHttpServletResponse();
    final CacheKey cacheKey = CacheKey.build("testCacheKey");
    final List<CharacterEvent> eventBuffer = Collections.emptyList();
    final PipelineEventReader<CharacterEventReader, CharacterEvent> eventReader = new PipelineEventReaderImpl<CharacterEventReader, CharacterEvent>(new CharacterEventBufferReader(eventBuffer.listIterator()));
    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(null);
    expect(targetComponent.getEventReader(mockReq, mockRes)).andReturn(eventReader);
    cache.put((Element) notNull());
    expectLastCall();
    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);
}
Also used : CharacterPipelineComponent(org.apereo.portal.rendering.CharacterPipelineComponent) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) CharacterEventBufferReader(org.apereo.portal.character.stream.CharacterEventBufferReader) ResourcesElementsProvider(org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider) PipelineEventReaderImpl(org.apereo.portal.rendering.PipelineEventReaderImpl) Ehcache(net.sf.ehcache.Ehcache) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) CacheKey(org.apereo.portal.utils.cache.CacheKey) Test(org.junit.Test)

Aggregations

Ehcache (net.sf.ehcache.Ehcache)2 CharacterEventReader (org.apereo.portal.character.stream.CharacterEventReader)2 CharacterEvent (org.apereo.portal.character.stream.events.CharacterEvent)2 CharacterPipelineComponent (org.apereo.portal.rendering.CharacterPipelineComponent)2 CacheKey (org.apereo.portal.utils.cache.CacheKey)2 ResourcesElementsProvider (org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider)2 Test (org.junit.Test)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 Element (net.sf.ehcache.Element)1 CharacterEventBufferReader (org.apereo.portal.character.stream.CharacterEventBufferReader)1 PipelineEventReaderImpl (org.apereo.portal.rendering.PipelineEventReaderImpl)1