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);
}
use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class XsltPortalUrlProviderTest method testPortletUrlById.
@Test
public void testPortletUrlById() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final IPortletWindowId portletWindowId = new MockPortletWindowId("w1");
when(portalUrlProvider.getPortalUrlBuilderByLayoutNode(request, "foo", UrlType.RENDER)).thenReturn(portalUrlBuilder);
when(portalUrlBuilder.getPortletUrlBuilder(portletWindowId)).thenReturn(portletUrlBuilder);
when(portalUrlBuilder.getUrlString()).thenReturn("/uPortal/home/normal/render.uP?layoutUrl");
when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(request, "foo")).thenReturn(portletWindow);
when(portletWindow.getPortletWindowId()).thenReturn(portletWindowId);
final Transformer transformer = xslTemplate.newTransformer();
transformer.setParameter(XsltPortalUrlProvider.XSLT_PORTAL_URL_PROVIDER, xsltPortalUrlProvider);
transformer.setParameter("CURRENT_REQUEST", request);
// xsl template mode to use
transformer.setParameter("TEST", "portletUrlById");
// set up configuration in the transformer impl
final StringWriter resultWriter = new StringWriter();
transformer.transform(xmlSource, new StreamResult(resultWriter));
verify(portalUrlBuilder).addParameter("pageNum", "42");
verify(portalUrlBuilder).getPortletUrlBuilder(portletWindowId);
verify(portalUrlBuilder).getUrlString();
verifyNoMoreInteractions(portalUrlBuilder);
verify(portletUrlBuilder).setWindowState(new WindowState("maximized"));
verify(portletUrlBuilder).addParameter("tmp", "blah");
verify(portletUrlBuilder).setCopyCurrentRenderParameters(false);
verifyNoMoreInteractions(portletUrlBuilder);
final String result = resultWriter.getBuffer().toString();
logger.debug(result);
XMLUnit.setIgnoreWhitespace(true);
Diff d = new Diff(expected, result);
assertTrue("Transformation result differs from what's expected" + d, d.similar());
}
use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class XsltPortalUrlProviderTest method testMultiPortletUrlById.
@Test
public void testMultiPortletUrlById() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final IPortletWindowId portletWindowId = new MockPortletWindowId("w1");
final IPortletWindow portletWindow2 = mock(IPortletWindow.class);
final IPortletWindowId portletWindowId2 = new MockPortletWindowId("w2");
final IPortletUrlBuilder portletUrlBuilder2 = mock(IPortletUrlBuilder.class);
when(portalUrlProvider.getPortalUrlBuilderByLayoutNode(request, "foo", UrlType.RENDER)).thenReturn(portalUrlBuilder);
when(portalUrlBuilder.getPortletUrlBuilder(portletWindowId)).thenReturn(portletUrlBuilder);
when(portalUrlBuilder.getUrlString()).thenReturn("/uPortal/home/normal/render.uP?layoutUrl");
when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(request, "foo")).thenReturn(portletWindow);
when(portletWindow.getPortletWindowId()).thenReturn(portletWindowId);
when(portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, "my-portlet")).thenReturn(portletWindow2);
when(portletWindow2.getPortletWindowId()).thenReturn(portletWindowId2);
when(portalUrlBuilder.getPortletUrlBuilder(portletWindowId2)).thenReturn(portletUrlBuilder2);
final Transformer transformer = xslTemplate.newTransformer();
transformer.setParameter(XsltPortalUrlProvider.XSLT_PORTAL_URL_PROVIDER, xsltPortalUrlProvider);
transformer.setParameter("CURRENT_REQUEST", request);
// xsl template mode to use
transformer.setParameter("TEST", "multiPortletUrlById");
// set up configuration in the transformer impl
final StringWriter resultWriter = new StringWriter();
transformer.transform(xmlSource, new StreamResult(resultWriter));
verify(portalUrlBuilder).addParameter("pageNum", "42");
verify(portalUrlBuilder).getPortletUrlBuilder(portletWindowId);
verify(portalUrlBuilder).getPortletUrlBuilder(portletWindowId2);
verify(portalUrlBuilder).getUrlString();
verifyNoMoreInteractions(portalUrlBuilder);
verify(portletUrlBuilder).addParameter("tmp", "blah");
verify(portletUrlBuilder).setCopyCurrentRenderParameters(false);
verifyNoMoreInteractions(portletUrlBuilder);
verify(portletUrlBuilder2).setWindowState(new WindowState("minimized"));
verify(portletUrlBuilder2).addParameter("event", "param");
verify(portletUrlBuilder2).setCopyCurrentRenderParameters(false);
verifyNoMoreInteractions(portletUrlBuilder2);
final String result = resultWriter.getBuffer().toString();
logger.debug(result);
XMLUnit.setIgnoreWhitespace(true);
Diff d = new Diff(expected, result);
assertTrue("Transformation result differs from what's expected" + d, d.similar());
}
use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class UrlSyntaxProviderImplTest method testSingleFolderMultiplePortletFnameSubscribeIdMinimizedRenderUrlParsing.
@Test
public void testSingleFolderMultiplePortletFnameSubscribeIdMinimizedRenderUrlParsing() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("/uPortal");
request.setRequestURI("/f/n2/normal/render.uP");
request.setQueryString("?pCt=fname.s3&pCs=minimized&pP_action=dashboard&pCm_pw2=help&pP_pw2_a=b&pP_pw2_b=c&pCa=pw2");
request.addParameter("pCt", "fname.s3");
request.addParameter("pCs", "minimized");
request.addParameter("pP_action", "dashboard");
request.addParameter("pCa", "pw2");
request.addParameter("pCm_pw2", "help");
request.addParameter("pP_pw2_a", "b");
request.addParameter("pP_pw2_b", "c");
request.addParameter("postedParameter", "foobar");
final MockPortletWindowId portletWindowId = new MockPortletWindowId("s3");
final MockPortletWindowId portletWindowId2 = new MockPortletWindowId("pw2");
when(this.portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
when(urlNodeSyntaxHelperRegistry.getCurrentUrlNodeSyntaxHelper(request)).thenReturn(urlNodeSyntaxHelper);
when(this.urlNodeSyntaxHelper.getLayoutNodeForFolderNames(request, Arrays.asList("n2"))).thenReturn("n2");
when(this.urlNodeSyntaxHelper.getPortletForFolderName(request, "n2", "fname.s3")).thenReturn(portletWindowId);
when(this.portletWindowRegistry.getPortletWindowId(request, "pw2")).thenReturn(portletWindowId2);
final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
assertNotNull(portalRequestInfo);
assertEquals("n2", portalRequestInfo.getTargetedLayoutNodeId());
assertEquals(portletWindowId, portalRequestInfo.getTargetedPortletWindowId());
assertEquals(UrlState.NORMAL, portalRequestInfo.getUrlState());
assertEquals(UrlType.RENDER, portalRequestInfo.getUrlType());
final Map<IPortletWindowId, ? extends IPortletRequestInfo> portletRequestInfoMap = portalRequestInfo.getPortletRequestInfoMap();
assertNotNull(portletRequestInfoMap);
assertEquals(2, portletRequestInfoMap.size());
final IPortletRequestInfo portletRequestInfo = portletRequestInfoMap.get(portletWindowId);
assertNotNull(portletRequestInfo);
assertEquals(portletWindowId, portletRequestInfo.getPortletWindowId());
assertEquals(ImmutableMap.of("action", Arrays.asList("dashboard"), "postedParameter", Arrays.asList("foobar")), portletRequestInfo.getPortletParameters());
assertEquals(WindowState.MINIMIZED, portletRequestInfo.getWindowState());
assertNull(portletRequestInfo.getPortletMode());
final IPortletRequestInfo portletRequestInfo2 = portletRequestInfoMap.get(portletWindowId2);
assertNotNull(portletRequestInfo2);
assertEquals(portletWindowId2, portletRequestInfo2.getPortletWindowId());
assertEquals(ImmutableMap.of("a", Arrays.asList("b"), "b", Arrays.asList("c")), portletRequestInfo2.getPortletParameters());
assertNull(portletRequestInfo2.getWindowState());
assertEquals(PortletMode.HELP, portletRequestInfo2.getPortletMode());
}
Aggregations