use of org.apereo.portal.portlet.container.cache.CachedPortletData in project uPortal by Jasig.
the class PortletRendererImplTest method doServeResourceUseBrowserContentTest.
/**
* Same as {@link #doServeResourceCachedContentValidationMethodTest()}, but simulate browser
* sending If-None-Match header that matches the etag. Verify no content returned and a 304
* status code.
*
* @throws PortletException
* @throws IOException
* @throws PortletContainerException
*/
@Test
public void doServeResourceUseBrowserContentTest() throws PortletException, IOException, PortletContainerException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("If-None-Match", "123456");
MockHttpServletResponse response = new MockHttpServletResponse();
TestingCacheState<CachedPortletResourceData<Long>, Long> cacheState = new TestingCacheState<CachedPortletResourceData<Long>, Long>();
cacheState.setUseBrowserData(true);
CacheControl cacheControl = cacheState.getCacheControl();
cacheControl.setUseCachedContent(true);
cacheControl.setExpirationTime(300);
cacheControl.setETag("123456");
final String output = "{ \"hello\": \"world\" }";
final CachedPortletData<Long> cachedPortletData = new CachedPortletData<Long>(1000l, output, null, "application/json", false, cacheControl.getETag(), cacheControl.getExpirationTime());
final CachedPortletResourceData<Long> cachedPortletResourceData = new CachedPortletResourceData<Long>(cachedPortletData, Collections.EMPTY_MAP, null, null, null, null);
cacheState.setCachedPortletData(cachedPortletResourceData);
setupPortletExecutionMocks(request);
when(portletCacheControlService.getPortletResourceState(request, portletWindowId)).thenReturn(cacheState);
ResourcePortletOutputHandler handler = new ResourcePortletOutputHandler(response);
portletRenderer.doServeResource(portletWindowId, request, response, handler);
//byte [] fromResponse = response.getContentAsByteArray();
Assert.assertEquals(0, response.getContentLength());
Assert.assertEquals(304, response.getStatus());
verify(portletCacheControlService, times(1)).getPortletResourceState(request, portletWindowId);
verifyNoMoreInteractions(portletContainer, portletCacheControlService);
}
use of org.apereo.portal.portlet.container.cache.CachedPortletData in project uPortal by Jasig.
the class PortletRendererImplTest method doRenderMarkupCachedContentExpirationMethodTest.
/**
* Mimic workflow when cached portlet data using "expiration" method is available.
*
* @throws PortletContainerException
* @throws IOException
* @throws PortletException
*/
@Test
public void doRenderMarkupCachedContentExpirationMethodTest() throws PortletException, IOException, PortletContainerException {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
TestingCacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = new TestingCacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult>();
cacheState.setUseCachedData(true);
CacheControl cacheControl = cacheState.getCacheControl();
final PortletRenderResult portletResult = new PortletRenderResult("title", null, 0, 100);
final String output = "<p>Some content</p>";
CachedPortletData<PortletRenderResult> cachedPortletData = new CachedPortletData<PortletRenderResult>(portletResult, output, null, null, false, null, cacheControl.getExpirationTime());
cacheState.setCachedPortletData(cachedPortletData);
setupPortletExecutionMocks(request);
when(portletCacheControlService.getPortletRenderState(request, portletWindowId)).thenReturn(cacheState);
when(portalRequestInfo.getTargetedPortletWindowId()).thenReturn(portletWindowId);
RenderPortletOutputHandler handler = new RenderPortletOutputHandler("UTF-8");
portletRenderer.doRenderMarkup(portletWindowId, request, response, handler);
Assert.assertEquals(output, handler.getOutput());
verify(portletCacheControlService, times(1)).getPortletRenderState(request, portletWindowId);
verifyNoMoreInteractions(portletContainer, portletCacheControlService);
}
use of org.apereo.portal.portlet.container.cache.CachedPortletData in project uPortal by Jasig.
the class PortletRendererImplTest method doServeResourceCachedContentValidationMethodNotModifiedInternalCacheExpiredTest.
/**
* Same as {@link #doServeResourceCachedContentValidationMethodNotModifiedTest()}, however the
* CachedPortletData is older than it's expiration time. Verify the renderer still detects the
* etag and returns 304 not modified.
*
* @throws PortletException
* @throws IOException
* @throws PortletContainerException
*/
@Test
public void doServeResourceCachedContentValidationMethodNotModifiedInternalCacheExpiredTest() throws PortletException, IOException, PortletContainerException {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("If-None-Match", "123456");
MockHttpServletResponse response = new MockHttpServletResponse();
TestingCacheState<CachedPortletResourceData<Long>, Long> cacheState = new TestingCacheState<CachedPortletResourceData<Long>, Long>();
cacheState.setBrowserSetEtag(true);
CacheControl cacheControl = cacheState.getCacheControl();
cacheControl.setUseCachedContent(true);
cacheControl.setExpirationTime(300);
cacheControl.setETag("123456");
final String output = "{ \"hello\": \"world\" }";
final CachedPortletData<Long> cachedPortletData = new CachedPortletData<Long>(1000l, output, null, "application/json", false, cacheControl.getETag(), cacheControl.getExpirationTime());
final CachedPortletResourceData<Long> cachedPortletResourceData = new CachedPortletResourceData<Long>(cachedPortletData, Collections.EMPTY_MAP, null, null, null, null);
cacheState.setCachedPortletData(cachedPortletResourceData);
setupPortletExecutionMocks(request);
when(portletCacheControlService.getPortletResourceState(request, portletWindowId)).thenReturn(cacheState);
ResourcePortletOutputHandler handler = new ResourcePortletOutputHandler(response);
portletRenderer.doServeResource(portletWindowId, request, response, handler);
Assert.assertEquals(0, response.getContentLength());
Assert.assertEquals(304, response.getStatus());
verify(portletCacheControlService, times(1)).getPortletResourceState(request, portletWindowId);
verify(portletCacheControlService, times(1)).getCacheSizeThreshold();
verify(portletContainer, times(1)).doServeResource(eq(plutoPortletWindow), isA(PortletHttpServletRequestWrapper.class), isA(PortletResourceHttpServletResponseWrapper.class));
verify(portletCacheControlService).cachePortletResourceOutput(eq(portletWindowId), isA(PortletHttpServletRequestWrapper.class), eq(cacheState), eq(cachedPortletResourceData));
verifyNoMoreInteractions(portletContainer, portletCacheControlService);
}
use of org.apereo.portal.portlet.container.cache.CachedPortletData in project uPortal by Jasig.
the class PortletRendererImplTest method doRenderMarkupCachedContentValidationMethodExpiredTest.
/**
* Mimic workflow when data cached portlet data using "validation" method is available.
*
* @throws PortletContainerException
* @throws IOException
* @throws PortletException
*/
@Test
public void doRenderMarkupCachedContentValidationMethodExpiredTest() throws PortletException, IOException, PortletContainerException {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
TestingCacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = new TestingCacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult>();
CacheControl cacheControl = cacheState.getCacheControl();
// by setting useCachedContent to true, we are saying even though content is expired, replay it anyways (since etag is still valid)
cacheControl.setUseCachedContent(true);
cacheControl.setETag("123456");
cacheControl.setExpirationTime(300);
final PortletRenderResult portletResult = new PortletRenderResult("title", null, 0, 100);
final String output = "<p>Some content</p>";
CachedPortletData<PortletRenderResult> cachedPortletData = new CachedPortletData<PortletRenderResult>(portletResult, output, null, null, false, cacheControl.getETag(), 1);
cacheState.setCachedPortletData(cachedPortletData);
final long expTime = cachedPortletData.getExpirationTime();
setupPortletExecutionMocks(request);
when(portletCacheControlService.getPortletRenderState(request, portletWindowId)).thenReturn(cacheState);
when(portalRequestInfo.getTargetedPortletWindowId()).thenReturn(portletWindowId);
RenderPortletOutputHandler handler = new RenderPortletOutputHandler("UTF-8");
portletRenderer.doRenderMarkup(portletWindowId, request, response, handler);
Assert.assertEquals(output, handler.getOutput());
// verify the expiration time has been updated
Assert.assertNotSame(expTime, cachedPortletData.getTimeStored());
verify(portletCacheControlService, times(1)).getPortletRenderState(request, portletWindowId);
verify(portletCacheControlService, times(1)).getCacheSizeThreshold();
verify(portletContainer, times(1)).doRender(eq(plutoPortletWindow), isA(PortletHttpServletRequestWrapper.class), isA(PortletHttpServletResponseWrapper.class));
verify(portletCacheControlService, times(1)).cachePortletRenderOutput(eq(portletWindowId), isA(PortletHttpServletRequestWrapper.class), eq(cacheState), isA(CachedPortletData.class));
verifyNoMoreInteractions(portletContainer, portletCacheControlService);
}
Aggregations