use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class RenderingPipelineIntegrationTest method testRenderingPipeline.
@Test
public void testRenderingPipeline() throws Exception {
final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
final DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
final Document doc = builder.newDocument();
final DocumentFragment headFragment = doc.createDocumentFragment();
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final IPortalUrlBuilder portalUrlBuilder = mock(IPortalUrlBuilder.class);
final IPortletUrlBuilder portletUrlBuilder = mock(IPortletUrlBuilder.class);
when(portalUrlBuilder.getUrlString()).thenReturn("URL_PLACEHOLDER");
when(portletUrlBuilder.getPortalUrlBuilder()).thenReturn(portalUrlBuilder);
when(portalUrlBuilder.getTargetedPortletUrlBuilder()).thenReturn(portletUrlBuilder);
when(portalUrlBuilder.getPortletUrlBuilder(any(IPortletWindowId.class))).thenReturn(portletUrlBuilder);
when(this.resourcesElementsProvider.getResourcesXmlFragment(any(HttpServletRequest.class), eq("/media/skins/respondr/defaultSkin/skin.xml"))).thenReturn(headFragment.getChildNodes());
when(this.portalUrlProvider.getDefaultUrl(any(HttpServletRequest.class))).thenReturn(portalUrlBuilder);
when(this.portalUrlProvider.getPortalUrlBuilderByLayoutNode(any(HttpServletRequest.class), any(String.class), any(UrlType.class))).thenReturn(portalUrlBuilder);
when(this.portalUrlProvider.getPortalUrlBuilderByPortletFName(any(HttpServletRequest.class), any(String.class), any(UrlType.class))).thenReturn(portalUrlBuilder);
final IPortletWindow portletWindow = mock(IPortletWindow.class);
when(portletWindowRegistry.getPortletWindow(any(HttpServletRequest.class), any(StartElement.class))).thenReturn(new Tuple<IPortletWindow, StartElement>(portletWindow, null));
when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(any(HttpServletRequest.class), any(String.class))).thenReturn(portletWindow);
when(portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(any(HttpServletRequest.class), anyString())).thenReturn(portletWindow);
when(portletWindow.getPortletWindowId()).thenReturn(new MockPortletWindowId("1"));
final PipelineEventReader<?, ?> eventReader = this.component.getEventReader(request, response);
for (final Object event : eventReader) {
logger.debug(toString(event));
}
final String mediaType = eventReader.getOutputProperty(OutputKeys.MEDIA_TYPE);
assertEquals("text/html", mediaType);
}
use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class PortletCacheControlServiceImplTest method testDetermineCacheScopePortletDefinitionPrivate.
@Test
public void testDetermineCacheScopePortletDefinitionPrivate() {
MockHttpServletRequest httpRequest = new MockHttpServletRequest();
MockPortletWindowId portletWindowId = new MockPortletWindowId("123");
MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(789);
PortletDefinition portletDefinition = mock(PortletDefinition.class);
when(portletDefinition.getCacheScope()).thenReturn("private");
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(portletDefinition);
when(urlSyntaxProvider.getPortalRequestInfo(httpRequest)).thenReturn(portalRequestInfo);
cacheControlService.setPortletWindowRegistry(portletWindowRegistry);
cacheControlService.setPortletDefinitionRegistry(portletDefinitionRegistry);
final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
final CacheControl cacheControl = cacheState.getCacheControl();
assertFalse(cacheControl.isPublicScope());
}
use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class PortletCacheControlServiceImplTest method testDetermineCacheScopePortletDefinitionPublic.
@Test
public void testDetermineCacheScopePortletDefinitionPublic() {
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);
cacheControlService.setPortletWindowRegistry(portletWindowRegistry);
cacheControlService.setPortletDefinitionRegistry(portletDefinitionRegistry);
final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
final CacheControl cacheControl = cacheState.getCacheControl();
assertTrue(cacheControl.isPublicScope());
}
use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class PortletCacheControlServiceImplTest method testGetCacheControlDataExistsInPrivateCache.
@Test
public void testGetCacheControlDataExistsInPrivateCache() {
// mock 2 requests, have to share sessionId for private cache
MockHttpSession mockSession = new MockHttpSession();
MockHttpServletRequest httpRequest = new MockHttpServletRequest();
httpRequest.setSession(mockSession);
MockHttpServletRequest nextHttpRequest = new MockHttpServletRequest();
nextHttpRequest.setSession(mockSession);
MockPortletWindowId portletWindowId = new MockPortletWindowId("123");
MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(789);
// use private cache
when(portletDescriptor.getCacheScope()).thenReturn("private");
when(portletDescriptor.getExpirationCache()).thenReturn(300);
when(portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId)).thenReturn(portletWindow);
when(portletWindowRegistry.getPortletWindow(nextHttpRequest, 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);
final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
final CacheControl cacheControl = cacheState.getCacheControl();
assertFalse(cacheControl.isPublicScope());
cacheControl.setETag("123456");
final PortletRenderResult portletResult = new PortletRenderResult("title", null, 0, 1);
final String content = "<p>Cached content</p>";
final CachedPortletData<PortletRenderResult> cachedPortletData = new CachedPortletData<PortletRenderResult>(portletResult, content, null, null, cacheControl.isPublicScope(), cacheControl.getETag(), -2);
cacheControlService.cachePortletRenderOutput(portletWindowId, nextHttpRequest, cacheState, cachedPortletData);
when(urlSyntaxProvider.getPortalRequestInfo(nextHttpRequest)).thenReturn(portalRequestInfo);
final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> afterCacheState = cacheControlService.getPortletRenderState(nextHttpRequest, portletWindowId);
// retrieve cachecontrol again, and return should have etag set
// note using 'nextHttpRequest'
Assert.assertEquals("123456", afterCacheState.getCacheControl().getETag());
}
use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class PortletCacheControlServiceImplTest method testCachePrivateResourceRoundTrip.
@Test
public void testCachePrivateResourceRoundTrip() {
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(this.urlSyntaxProvider.getPortalRequestInfo(httpRequest)).thenReturn(portalRequestInfo);
when(portalRequestInfo.getPortletRequestInfoMap()).thenReturn(Collections.EMPTY_MAP);
// Get the initial cache state
final CacheState<CachedPortletResourceData<Long>, Long> firstCacheState = cacheControlService.getPortletResourceState(httpRequest, portletWindowId);
// Fake resource execution
final CacheControl cacheControl = firstCacheState.getCacheControl();
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);
firstCacheState.setCachedPortletData(cachedPortletResourceData);
assertTrue(cacheControlService.shouldOutputBeCached(cacheControl));
// Cache the results
cacheControlService.cachePortletResourceOutput(portletWindowId, httpRequest, firstCacheState, cachedPortletResourceData);
// Check the cached results
final CacheState<CachedPortletResourceData<Long>, Long> secondCacheState = cacheControlService.getPortletResourceState(httpRequest, portletWindowId);
assertNotNull(secondCacheState);
final CachedPortletResourceData<Long> actualCachedPortletData = secondCacheState.getCachedPortletData();
assertNotNull(actualCachedPortletData);
}
Aggregations