Search in sources :

Example 6 with MockPortletWindowId

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());
}
Also used : MockPortletDefinitionId(org.apereo.portal.mock.portlet.om.MockPortletDefinitionId) PortletRenderResult(org.apereo.portal.portlet.rendering.PortletRenderResult) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpSession(org.springframework.mock.web.MockHttpSession) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) CacheControl(javax.portlet.CacheControl) Test(org.junit.Test)

Example 7 with MockPortletWindowId

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);
}
Also used : MockPortletDefinitionId(org.apereo.portal.mock.portlet.om.MockPortletDefinitionId) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) CacheControl(javax.portlet.CacheControl) Test(org.junit.Test)

Example 8 with MockPortletWindowId

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());
}
Also used : WindowState(javax.portlet.WindowState) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) Diff(org.custommonkey.xmlunit.Diff) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) Test(org.junit.Test)

Example 9 with MockPortletWindowId

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());
}
Also used : WindowState(javax.portlet.WindowState) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) Diff(org.custommonkey.xmlunit.Diff) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) Test(org.junit.Test)

Example 10 with MockPortletWindowId

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());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) Test(org.junit.Test)

Aggregations

MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)35 Test (org.junit.Test)33 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)30 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)16 CacheControl (javax.portlet.CacheControl)6 MockPortletDefinitionId (org.apereo.portal.mock.portlet.om.MockPortletDefinitionId)6 PortletRenderResult (org.apereo.portal.portlet.rendering.PortletRenderResult)5 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)3 StringWriter (java.io.StringWriter)2 WindowState (javax.portlet.WindowState)2 QName (javax.xml.namespace.QName)2 Transformer (javax.xml.transform.Transformer)2 StreamResult (javax.xml.transform.stream.StreamResult)2 IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)2 Diff (org.custommonkey.xmlunit.Diff)2 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1