Search in sources :

Example 6 with MockPortletDefinitionId

use of org.apereo.portal.mock.portlet.om.MockPortletDefinitionId in project uPortal by Jasig.

the class PortletCacheControlServiceImplTest method testCachePrivateRenderRoundTrip.

@Test
public void testCachePrivateRenderRoundTrip() {
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    MockPortletWindowId portletWindowId = new MockPortletWindowId("123");
    MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(789);
    when(portletDescriptor.getCacheScope()).thenReturn(MimeResponse.PUBLIC_SCOPE);
    when(portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId)).thenReturn(portletWindow);
    when(portletWindow.getPortletWindowId()).thenReturn(portletWindowId);
    when(portletWindow.getPortletEntity()).thenReturn(portletEntity);
    when(portletWindow.getWindowState()).thenReturn(WindowState.NORMAL);
    when(portletWindow.getPortletMode()).thenReturn(PortletMode.VIEW);
    when(portletEntity.getPortletDefinitionId()).thenReturn(portletDefinitionId);
    when(portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId)).thenReturn(portletDescriptor);
    when(urlSyntaxProvider.getPortalRequestInfo(httpRequest)).thenReturn(portalRequestInfo);
    when(this.urlSyntaxProvider.getPortalRequestInfo(httpRequest)).thenReturn(portalRequestInfo);
    when(portalRequestInfo.getPortletRequestInfoMap()).thenReturn(Collections.EMPTY_MAP);
    //Get the initial cache state
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> firstCacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
    //Fake Render execution
    final CacheControl cacheControl = firstCacheState.getCacheControl();
    cacheControl.setExpirationTime(300);
    final PortletRenderResult renderResult = new PortletRenderResult("title", null, 0, 1000l);
    final String output = "{ \"hello\": \"world\" }";
    final CachedPortletData<PortletRenderResult> cachedPortletData = new CachedPortletData<PortletRenderResult>(renderResult, output, null, null, false, cacheControl.getETag(), cacheControl.getExpirationTime());
    firstCacheState.setCachedPortletData(cachedPortletData);
    assertTrue(cacheControlService.shouldOutputBeCached(cacheControl));
    //Cache the results
    cacheControlService.cachePortletRenderOutput(portletWindowId, httpRequest, firstCacheState, cachedPortletData);
    //Check the cached results
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> secondCacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
    assertNotNull(secondCacheState);
    final CachedPortletData<PortletRenderResult> actualCachedPortletData = secondCacheState.getCachedPortletData();
    assertNotNull(actualCachedPortletData);
}
Also used : MockPortletDefinitionId(org.apereo.portal.mock.portlet.om.MockPortletDefinitionId) PortletRenderResult(org.apereo.portal.portlet.rendering.PortletRenderResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) CacheControl(javax.portlet.CacheControl) Test(org.junit.Test)

Example 7 with MockPortletDefinitionId

use of org.apereo.portal.mock.portlet.om.MockPortletDefinitionId in project uPortal by Jasig.

the class PortletCacheControlServiceImplTest method testGetCacheControlDefault.

@Test
public void testGetCacheControlDefault() {
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    MockPortletWindowId portletWindowId = new MockPortletWindowId("123");
    MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(789);
    when(portletDescriptor.getCacheScope()).thenReturn(null);
    final IPortletWindowRegistry portletWindowRegistry = mock(IPortletWindowRegistry.class);
    final IPortletWindow portletWindow = mock(IPortletWindow.class);
    final IPortletEntity portletEntity = mock(IPortletEntity.class);
    when(portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId)).thenReturn(portletWindow);
    when(portletWindow.getPortletEntity()).thenReturn(portletEntity);
    when(portletWindow.getWindowState()).thenReturn(WindowState.NORMAL);
    when(portletWindow.getPortletMode()).thenReturn(PortletMode.VIEW);
    when(portletEntity.getPortletDefinitionId()).thenReturn(portletDefinitionId);
    when(portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId)).thenReturn(portletDescriptor);
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
    final CacheControl cacheControl = cacheState.getCacheControl();
    assertFalse(cacheControl.isPublicScope());
    assertNull(cacheControl.getETag());
}
Also used : MockPortletDefinitionId(org.apereo.portal.mock.portlet.om.MockPortletDefinitionId) IPortletWindowRegistry(org.apereo.portal.portlet.registry.IPortletWindowRegistry) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) PortletRenderResult(org.apereo.portal.portlet.rendering.PortletRenderResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) CacheControl(javax.portlet.CacheControl) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) Test(org.junit.Test)

Aggregations

MockPortletDefinitionId (org.apereo.portal.mock.portlet.om.MockPortletDefinitionId)7 Test (org.junit.Test)7 CacheControl (javax.portlet.CacheControl)6 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 PortletRenderResult (org.apereo.portal.portlet.rendering.PortletRenderResult)5 PortletDefinition (org.apache.pluto.container.om.portlet.PortletDefinition)2 Event (javax.portlet.Event)1 QName (javax.xml.namespace.QName)1 EventDefinition (org.apache.pluto.container.om.portlet.EventDefinition)1 EventDefinitionReference (org.apache.pluto.container.om.portlet.EventDefinitionReference)1 PortletApplicationDefinition (org.apache.pluto.container.om.portlet.PortletApplicationDefinition)1 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)1 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)1 IPortletWindowRegistry (org.apereo.portal.portlet.registry.IPortletWindowRegistry)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1