use of javax.portlet.CacheControl in project uPortal by Jasig.
the class PortletRendererImplTest method doServeResourceCachedContentExpirationMethodTest.
/**
* Mimic workflow when cached portlet data using "expiration" method is available.
*
* @throws PortletContainerException
* @throws IOException
* @throws PortletException
*/
@Test
public void doServeResourceCachedContentExpirationMethodTest() throws PortletException, IOException, PortletContainerException {
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
TestingCacheState<CachedPortletResourceData<Long>, Long> cacheState = new TestingCacheState<CachedPortletResourceData<Long>, Long>();
CacheControl cacheControl = cacheState.getCacheControl();
cacheControl.setUseCachedContent(true);
cacheControl.setExpirationTime(300);
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);
final long expirationTime = System.currentTimeMillis() - 60000;
cachedPortletData.updateExpirationTime(50000);
cacheState.setCachedPortletData(cachedPortletResourceData);
setupPortletExecutionMocks(request);
when(portletCacheControlService.getPortletResourceState(request, portletWindowId)).thenReturn(cacheState);
ResourcePortletOutputHandler handler = new ResourcePortletOutputHandler(response);
portletRenderer.doServeResource(portletWindowId, request, response, handler);
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);
}
Aggregations