use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class UrlSyntaxProviderImplTest method testSingleFolderPortletDelegationFnameSubscribeIdMinimizedRenderUrlParsing.
@Test
public void testSingleFolderPortletDelegationFnameSubscribeIdMinimizedRenderUrlParsing() 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&pCd_pw2=pw1&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("pCd_pw2", "pw1");
request.addParameter("pCm_pw2", "help");
request.addParameter("pP_pw2_a", "b");
request.addParameter("pP_pw2_b", "c");
request.addParameter("postedParameter", "foobar");
final MockPortletWindowId portletWindowId1 = new MockPortletWindowId("pw1");
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(portletWindowId1);
when(this.portletWindowRegistry.getPortletWindowId(request, "pw2")).thenReturn(portletWindowId2);
when(this.portletWindowRegistry.getPortletWindowId(request, "pw1")).thenReturn(portletWindowId1);
final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
assertNotNull(portalRequestInfo);
assertEquals("n2", portalRequestInfo.getTargetedLayoutNodeId());
assertEquals(portletWindowId1, 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(portletWindowId1);
assertNotNull(portletRequestInfo);
assertEquals(portletWindowId1, portletRequestInfo.getPortletWindowId());
assertEquals(ImmutableMap.of("action", Arrays.asList("dashboard")), portletRequestInfo.getPortletParameters());
assertEquals(WindowState.MINIMIZED, portletRequestInfo.getWindowState());
assertNull(portletRequestInfo.getPortletMode());
assertNull(portletRequestInfo.getDelegateParentWindowId());
final IPortletRequestInfo portletRequestInfo2 = portletRequestInfoMap.get(portletWindowId2);
assertNotNull(portletRequestInfo2);
assertEquals(portletWindowId2, portletRequestInfo2.getPortletWindowId());
assertEquals(ImmutableMap.of("a", Arrays.asList("b"), "b", Arrays.asList("c"), "postedParameter", Arrays.asList("foobar")), portletRequestInfo2.getPortletParameters());
assertNull(portletRequestInfo2.getWindowState());
assertEquals(PortletMode.HELP, portletRequestInfo2.getPortletMode());
assertEquals(portletWindowId1, portletRequestInfo2.getDelegateParentWindowId());
}
use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class JacksonPortalEventTest method verifyOutputFormat.
@Test
public void verifyOutputFormat() throws Exception {
final String sessionId = "1234567890123_system_AAAAAAAAAAA";
final PortalEvent.PortalEventBuilder eventBuilder = new PortalEvent.PortalEventBuilder(this, "example.com", sessionId, SystemPerson.INSTANCE, null);
final PortletExecutionEvent.PortletExecutionEventBuilder portletExecutionEventBuilder = new PortletExecutionEvent.PortletExecutionEventBuilder(eventBuilder, new MockPortletWindowId("pw1"), "fname", 12345, Collections.EMPTY_MAP, WindowState.NORMAL, PortletMode.VIEW);
PortalEvent event;
// TODO: Will uncomment once we add in attribute swapper event processing.
/*event = new AttributeSwapEvent(eventBuilder, Collections.EMPTY_MAP);
assertEventJsonEquals("{\"@c\":\".AttributeSwapEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"swappedAttributes\":{}}", event);
event = new AttributeSwapResetEvent(eventBuilder);
assertEventJsonEquals("{\"@c\":\".AttributeSwapResetEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
event = new IdentitySwapStartEvent(eventBuilder, "originalUserName", "originalEventSessionId");
assertEventJsonEquals("{\"@c\":\".IdentitySwapStartEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"originalUserName\":\"originalUserName\",\"originalEventSessionId\":\"originalEventSessionId\"}", event);
event = new IdentitySwapStopEvent(eventBuilder, "targetUserName");
assertEventJsonEquals("{\"@c\":\".IdentitySwapStopEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"targetUserName\":\"targetUserName\"}", event);
*/
event = new FolderAddedToLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "newFolderId");
assertEventJsonEquals("{\"@c\":\".FolderAddedToLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"newFolderId\":\"newFolderId\"}", event);
event = new FolderDeletedFromLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "deletedFolderId", "deletedFolderName");
assertEventJsonEquals("{\"@c\":\".FolderDeletedFromLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"oldParentFolderId\":\"oldParentFolderId\",\"deletedFolderId\":\"deletedFolderId\",\"deletedFolderName\":\"deletedFolderName\"}", event);
event = new FolderMovedInLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "movedFolderId");
assertEventJsonEquals("{\"@c\":\".FolderMovedInLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"oldParentFolderId\":\"oldParentFolderId\",\"movedFolderId\":\"movedFolderId\"}", event);
event = new PortletAddedToLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "parentFolderId", "fname");
assertEventJsonEquals("{\"@c\":\".PortletAddedToLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"fname\":\"fname\",\"parentFolderId\":\"parentFolderId\"}", event);
event = new PortletDeletedFromLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "fname");
assertEventJsonEquals("{\"@c\":\".PortletDeletedFromLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"fname\":\"fname\",\"oldParentFolderId\":\"oldParentFolderId\"}", event);
event = new PortletMovedInLayoutPortalEvent(eventBuilder, SystemPerson.INSTANCE, 1, "oldParentFolderId", "newParentFolderId", "fname");
assertEventJsonEquals("{\"@c\":\".PortletMovedInLayoutPortalEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"layoutId\":1,\"layoutOwner\":\"system\",\"fname\":\"fname\",\"oldParentFolderId\":\"oldParentFolderId\",\"newParentFolderId\":\"newParentFolderId\"}", event);
event = new LoginEvent(eventBuilder, Collections.EMPTY_SET, Collections.EMPTY_MAP);
assertEventJsonEquals("{\"@c\":\".LoginEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"groups\":[],\"attributes\":{}}", event);
event = new LogoutEvent(eventBuilder);
assertEventJsonEquals("{\"@c\":\".LogoutEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
event = new PortalRenderEvent(eventBuilder, "requestPathInfo", 12345, UrlState.NORMAL, UrlType.RENDER, Collections.EMPTY_MAP, "targetedLayoutNodeId");
assertEventJsonEquals("{\"@c\":\".PortalRenderEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"requestPathInfo\":\"requestPathInfo\",\"urlState\":\"NORMAL\",\"urlType\":\"RENDER\",\"parameters\":{},\"targetedLayoutNodeId\":\"targetedLayoutNodeId\",\"executionTimeNano\":12345}", event);
event = new PortletActionExecutionEvent(portletExecutionEventBuilder);
assertEventJsonEquals("{\"@c\":\".PortletActionExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{}}", event);
event = new PortletEventExecutionEvent(portletExecutionEventBuilder, new QName("http://example.com/uri", "EventName"));
assertEventJsonEquals("{\"@c\":\".PortletEventExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"eventName\":\"{http://example.com/uri}EventName\"}", event);
event = new PortletRenderExecutionEvent(portletExecutionEventBuilder, true, false);
assertEventJsonEquals("{\"@c\":\".PortletRenderExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"targeted\":true,\"usedPortalCache\":false}", event);
event = new PortletRenderHeaderExecutionEvent(portletExecutionEventBuilder, true, false);
assertEventJsonEquals("{\"@c\":\".PortletRenderHeaderExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"targeted\":true,\"cached\":false}", event);
event = new PortletResourceExecutionEvent(portletExecutionEventBuilder, "resourceId", false, false);
assertEventJsonEquals("{\"@c\":\".PortletResourceExecutionEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\",\"windowState\":\"normal\",\"portletMode\":\"view\",\"executionTimeNano\":12345,\"parameters\":{},\"resourceId\":\"resourceId\",\"usedBrowserCache\":false,\"usedPortalCache\":false}", event);
final IPortletExecutionWorker hungWorker = mock(IPortletExecutionWorker.class);
when(hungWorker.getPortletFname()).thenReturn("fname");
event = new PortletHungCompleteEvent(eventBuilder, hungWorker);
assertEventJsonEquals("{\"@c\":\".PortletHungCompleteEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\"}", event);
event = new PortletHungEvent(eventBuilder, hungWorker);
assertEventJsonEquals("{\"@c\":\".PortletHungEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\",\"fname\":\"fname\"}", event);
final ITenant tenant = new ITenant() {
private static final long serialVersionUID = 1L;
@Override
public int compareTo(ITenant o) {
return 0;
}
@Override
public long getId() {
return 1L;
}
@Override
public String getName() {
return "Mordor";
}
@Override
public void setName(String name) {
}
@Override
public String getFname() {
return "mordor";
}
@Override
public void setFname(String fname) {
}
@Override
public String getAttribute(String name) {
return null;
}
@Override
public void setAttribute(String name, String value) {
}
@Override
public Map<String, String> getAttributesMap() {
return Collections.emptyMap();
}
};
event = new TenantCreatedTenantEvent(eventBuilder, tenant);
assertEventJsonEquals("{\"@c\":\".TenantCreatedTenantEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
event = new TenantUpdatedTenantEvent(eventBuilder, tenant);
assertEventJsonEquals("{\"@c\":\".TenantUpdatedTenantEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
event = new TenantRemovedTenantEvent(eventBuilder, tenant);
assertEventJsonEquals("{\"@c\":\".TenantRemovedTenantEvent\",\"timestamp\":1371745598080,\"serverId\":\"example.com\",\"eventSessionId\":\"1234567890123_system_AAAAAAAAAAA\",\"userName\":\"system\"}", event);
}
use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class PortletCacheControlServiceImplTest method testCachePrivateRenderRoundTrip.
@Test
public void testCachePrivateRenderRoundTrip() {
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);
when(this.urlSyntaxProvider.getPortalRequestInfo(httpRequest)).thenReturn(portalRequestInfo);
when(portalRequestInfo.getPortletRequestInfoMap()).thenReturn(Collections.EMPTY_MAP);
// Get the initial cache state
final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> firstCacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
// Fake Render execution
final CacheControl cacheControl = firstCacheState.getCacheControl();
cacheControl.setExpirationTime(300);
final PortletRenderResult renderResult = new PortletRenderResult("title", null, 0, 1000l);
final String output = "{ \"hello\": \"world\" }";
final CachedPortletData<PortletRenderResult> cachedPortletData = new CachedPortletData<PortletRenderResult>(renderResult, output, null, null, false, cacheControl.getETag(), cacheControl.getExpirationTime());
firstCacheState.setCachedPortletData(cachedPortletData);
assertTrue(cacheControlService.shouldOutputBeCached(cacheControl));
// Cache the results
cacheControlService.cachePortletRenderOutput(portletWindowId, httpRequest, firstCacheState, cachedPortletData);
// Check the cached results
final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> secondCacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
assertNotNull(secondCacheState);
final CachedPortletData<PortletRenderResult> actualCachedPortletData = secondCacheState.getCachedPortletData();
assertNotNull(actualCachedPortletData);
}
use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class PortalUrlProviderImplTest method testGetPortalUrlBuilderByMissingPortletLayoutNode.
@Test(expected = IllegalArgumentException.class)
public void testGetPortalUrlBuilderByMissingPortletLayoutNode() {
// Setup mock objects
when(urlProviderLayoutHelper.getDefaultLayoutNodeId(request)).thenReturn(folderNodeId);
when(userInstanceManager.getUserInstance(request)).thenReturn(userInstance);
when(userInstance.getPreferencesManager()).thenReturn(preferencesManager);
when(preferencesManager.getUserLayoutManager()).thenReturn(userLayoutManager);
// Run the test
final IPortalUrlBuilder urlBuilder = portalUrlProvider.getPortalUrlBuilderByLayoutNode(request, folderNodeId, UrlType.RENDER);
assertNotNull(urlBuilder);
assertEquals(folderNodeId, urlBuilder.getTargetFolderId());
assertEquals(new MockPortletWindowId(portletDefinitionIdStr), urlBuilder.getTargetPortletWindowId());
assertEquals(UrlType.RENDER, urlBuilder.getUrlType());
}
use of org.apereo.portal.mock.portlet.om.MockPortletWindowId in project uPortal by Jasig.
the class UrlSyntaxProviderImplTest method testSingleFolderPortletDelegationFnameSubscribeIdPostUrlParsing.
@Test
public void testSingleFolderPortletDelegationFnameSubscribeIdPostUrlParsing() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("/uPortal");
request.setRequestURI("/p/portlet-admin.ctf3/max/resource.uP");
request.setQueryString("?pCa=30_dlg-16-ctf3-5_5&pCd_30_dlg-16-ctf3-5_5=16_ctf3_5&pCr_30_dlg-16-ctf3-5_5=preview&pP_execution=e2s3&pP__eventId=configModeAction");
request.addParameter("pCa", "30_dlg-16-ctf3-5_5");
request.addParameter("pCd_30_dlg-16-ctf3-5_5", "16_ctf3_5");
request.addParameter("pCr_30_dlg-16-ctf3-5_5", "preview");
request.addParameter("pP_execution", "e2s3");
request.addParameter("pP__eventId", "configModeAction");
// not on URL, was posted
request.addParameter("content", "<div>some content</div>");
final MockPortletWindowId portletWindowId1 = new MockPortletWindowId("16_ctf3_5");
final MockPortletWindowId portletWindowId2 = new MockPortletWindowId("30_dlg-16-ctf3-5_5");
when(this.portalRequestUtils.getOriginalPortalRequest(request)).thenReturn(request);
when(urlNodeSyntaxHelperRegistry.getCurrentUrlNodeSyntaxHelper(request)).thenReturn(urlNodeSyntaxHelper);
when(this.urlNodeSyntaxHelper.getPortletForFolderName(request, null, "portlet-admin.ctf3")).thenReturn(portletWindowId1);
when(this.portletWindowRegistry.getPortletWindowId(request, "30_dlg-16-ctf3-5_5")).thenReturn(portletWindowId2);
when(this.portletWindowRegistry.getPortletWindowId(request, "16_ctf3_5")).thenReturn(portletWindowId1);
final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
assertNotNull(portalRequestInfo);
assertNull(portalRequestInfo.getTargetedLayoutNodeId());
assertEquals(portletWindowId1, portalRequestInfo.getTargetedPortletWindowId());
assertEquals(UrlState.MAX, portalRequestInfo.getUrlState());
assertEquals(UrlType.RESOURCE, portalRequestInfo.getUrlType());
final Map<IPortletWindowId, ? extends IPortletRequestInfo> portletRequestInfoMap = portalRequestInfo.getPortletRequestInfoMap();
assertNotNull(portletRequestInfoMap);
assertEquals(2, portletRequestInfoMap.size());
final IPortletRequestInfo portletRequestInfo = portletRequestInfoMap.get(portletWindowId1);
assertNotNull(portletRequestInfo);
assertEquals(portletWindowId1, portletRequestInfo.getPortletWindowId());
assertEquals(ImmutableMap.of("execution", Arrays.asList("e2s3"), "_eventId", Arrays.asList("configModeAction")), portletRequestInfo.getPortletParameters());
assertNull(portletRequestInfo.getDelegateParentWindowId());
final IPortletRequestInfo portletRequestInfo2 = portletRequestInfoMap.get(portletWindowId2);
assertNotNull(portletRequestInfo2);
assertEquals(portletWindowId2, portletRequestInfo2.getPortletWindowId());
assertEquals(ImmutableMap.of("content", Arrays.asList("<div>some content</div>")), portletRequestInfo2.getPortletParameters());
assertEquals(portletWindowId1, portletRequestInfo2.getDelegateParentWindowId());
}
Aggregations