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);
}
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());
}
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());
}
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);
}
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());
}
Aggregations