Search in sources :

Example 1 with MockPortletDefinitionId

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

the class PortletEventCoordinatationServiceTest method testSupportedEventResolution.

@Test
public void testSupportedEventResolution() throws Exception {
    final QName searchRequestName = new QName("https://source.jasig.org/schemas/uportal/search", "SearchRequest");
    final QName searchResultsName = new QName("https://source.jasig.org/schemas/uportal/search", "SearchResults");
    //org.apereo.portal.search.SearchQuery
    final Event event = mock(Event.class);
    final MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(1);
    final PortletApplicationDefinition portletApplicationDefinition = mock(PortletApplicationDefinition.class);
    final PortletDefinition portletDefinition = mock(PortletDefinition.class);
    final EventDefinitionReference searchRequestEventDefinitionReference = mock(EventDefinitionReference.class);
    final EventDefinitionReference searchResultsEventDefinitionReference = mock(EventDefinitionReference.class);
    final EventDefinition searchRequestEventDefinition = mock(EventDefinition.class);
    final EventDefinition searchResultsEventDefinition = mock(EventDefinition.class);
    when(event.getQName()).thenReturn(searchRequestName);
    when(searchRequestEventDefinitionReference.getQualifiedName(anyString())).thenReturn(searchRequestName);
    when(searchRequestEventDefinitionReference.getQName()).thenReturn(searchRequestName);
    when(searchResultsEventDefinitionReference.getQualifiedName(anyString())).thenReturn(searchResultsName);
    when(searchResultsEventDefinitionReference.getQName()).thenReturn(searchResultsName);
    when(searchRequestEventDefinition.getQName()).thenReturn(searchRequestName);
    when(searchRequestEventDefinition.getQualifiedName(anyString())).thenReturn(searchRequestName);
    when(searchResultsEventDefinition.getQName()).thenReturn(searchResultsName);
    when(searchResultsEventDefinition.getQualifiedName(anyString())).thenReturn(searchResultsName);
    when(this.portletDefinitionRegistry.getParentPortletApplicationDescriptor(portletDefinitionId)).thenReturn(portletApplicationDefinition);
    when(this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId)).thenReturn(portletDefinition);
    final List<? extends EventDefinition> eventDefinitions = Arrays.asList(searchRequestEventDefinition, searchResultsEventDefinition);
    when(portletApplicationDefinition.getEventDefinitions()).thenReturn((List) eventDefinitions);
    final List<? extends EventDefinitionReference> supportedProcessingEvents = Collections.singletonList(searchRequestEventDefinitionReference);
    when(portletDefinition.getSupportedProcessingEvents()).thenReturn((List) supportedProcessingEvents);
    final boolean supportsEvent = portletEventCoordinatationService.supportsEvent(event, portletDefinitionId);
    assertTrue(supportsEvent);
}
Also used : MockPortletDefinitionId(org.apereo.portal.mock.portlet.om.MockPortletDefinitionId) EventDefinitionReference(org.apache.pluto.container.om.portlet.EventDefinitionReference) PortletApplicationDefinition(org.apache.pluto.container.om.portlet.PortletApplicationDefinition) QName(javax.xml.namespace.QName) Event(javax.portlet.Event) EventDefinition(org.apache.pluto.container.om.portlet.EventDefinition) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) Test(org.junit.Test)

Example 2 with MockPortletDefinitionId

use of org.apereo.portal.mock.portlet.om.MockPortletDefinitionId 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());
}
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) PortletDefinition(org.apache.pluto.container.om.portlet.PortletDefinition) Test(org.junit.Test)

Example 3 with MockPortletDefinitionId

use of org.apereo.portal.mock.portlet.om.MockPortletDefinitionId 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());
}
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 4 with MockPortletDefinitionId

use of org.apereo.portal.mock.portlet.om.MockPortletDefinitionId 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 5 with MockPortletDefinitionId

use of org.apereo.portal.mock.portlet.om.MockPortletDefinitionId 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)

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