Search in sources :

Example 1 with IPortletWindowRegistry

use of org.apereo.portal.portlet.registry.IPortletWindowRegistry in project uPortal by Jasig.

the class RequestAttributeServiceImplTest method testControl.

/**
 * Default test for function, returns the multivalued attribute map with one multi-valued
 * attribute.
 */
@Test
public void testControl() {
    MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
    httpServletRequest.setRemoteUser("username");
    Map<String, List<Object>> attributes = new HashMap<String, List<Object>>();
    attributes.put("attribute1", Arrays.asList(new Object[] { "value1", "value2", "value3" }));
    NamedPersonImpl personAttributes = new NamedPersonImpl("username", attributes);
    PortletWindow plutoPortletWindow = mock(PortletWindow.class);
    IPortletWindow portletWindow = mock(IPortletWindow.class);
    IPortletEntity portletEntity = mock(IPortletEntity.class);
    when(portletWindow.getPortletEntity()).thenReturn(portletEntity);
    IPortletDefinition portletDefinition = mock(IPortletDefinition.class);
    when(portletEntity.getPortletDefinition()).thenReturn(portletDefinition);
    IPortletDefinitionId portletDefinitionId = mock(IPortletDefinitionId.class);
    when(portletDefinition.getPortletDefinitionId()).thenReturn(portletDefinitionId);
    IPersonAttributeDao personAttributeDao = mock(IPersonAttributeDao.class);
    when(personAttributeDao.getPerson("username")).thenReturn(personAttributes);
    IPortletWindowRegistry portletWindowRegistry = mock(IPortletWindowRegistry.class);
    when(portletWindowRegistry.convertPortletWindow(httpServletRequest, plutoPortletWindow)).thenReturn(portletWindow);
    List<UserAttributeType> userAttributesList = new ArrayList<UserAttributeType>();
    UserAttributeType userAttribute = new UserAttributeType();
    userAttribute.setName("attribute1");
    userAttributesList.add(userAttribute);
    PortletAppType portletApplicationDefinition = new PortletAppType();
    portletApplicationDefinition.addUserAttribute("attribute1");
    IPortletDefinitionRegistry portletDefinitionRegistry = mock(IPortletDefinitionRegistry.class);
    when(portletDefinitionRegistry.getParentPortletApplicationDescriptor(portletDefinitionId)).thenReturn(portletApplicationDefinition);
    RequestAttributeServiceImpl service = new RequestAttributeServiceImpl();
    service.setPersonAttributeDao(personAttributeDao);
    service.setPortletDefinitionRegistry(portletDefinitionRegistry);
    service.setPortletWindowRegistry(portletWindowRegistry);
    Object attribute = service.getAttribute(httpServletRequest, plutoPortletWindow, IPortletRenderer.MULTIVALUED_USERINFO_MAP_ATTRIBUTE);
    Assert.assertNotNull(attribute);
    Assert.assertTrue(attribute instanceof Map);
    @SuppressWarnings("unchecked") Map<String, List<Object>> attributeMap = (Map<String, List<Object>>) attribute;
    List<Object> values = attributeMap.get("attribute1");
    Assert.assertEquals(3, values.size());
    Assert.assertTrue(values.contains("value1"));
    Assert.assertTrue(values.contains("value2"));
    Assert.assertTrue(values.contains("value3"));
}
Also used : IPortletWindowRegistry(org.apereo.portal.portlet.registry.IPortletWindowRegistry) PortletAppType(org.apache.pluto.container.om.portlet.impl.PortletAppType) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ArrayList(java.util.ArrayList) UserAttributeType(org.apache.pluto.container.om.portlet.impl.UserAttributeType) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletDefinitionId(org.apereo.portal.portlet.om.IPortletDefinitionId) IPortletDefinitionRegistry(org.apereo.portal.portlet.registry.IPortletDefinitionRegistry) NamedPersonImpl(org.apereo.services.persondir.support.NamedPersonImpl) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) ArrayList(java.util.ArrayList) List(java.util.List) PortletWindow(org.apache.pluto.container.PortletWindow) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) HashMap(java.util.HashMap) Map(java.util.Map) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) Test(org.junit.Test)

Example 2 with IPortletWindowRegistry

use of org.apereo.portal.portlet.registry.IPortletWindowRegistry in project uPortal by Jasig.

the class StAXSerializingComponentTest method testSerializing.

@Test
public void testSerializing() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final IPortletWindowRegistry portletWindowRegistry = mock(IPortletWindowRegistry.class);
    when(xmlUtilities.getHtmlOutputFactory()).thenReturn(XMLOutputFactory.newFactory());
    // Setup a simple pass-through parent
    staxSerializingComponent.setWrappedComponent(new SimpleStAXSource());
    staxSerializingComponent.setXmlUtilities(xmlUtilities);
    final IPortletWindow portletWindow = mock(IPortletWindow.class);
    when(portletWindowRegistry.getPortletWindow(ArgumentMatchers.eq(request), ArgumentMatchers.any(StartElement.class))).thenReturn(new Tuple<IPortletWindow, StartElement>(portletWindow, null));
    when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(ArgumentMatchers.eq(request), ArgumentMatchers.anyString())).thenReturn(portletWindow);
    final PortletContentPlaceholderEventSource contentPlaceholderEventSource = new PortletContentPlaceholderEventSource();
    contentPlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
    final PortletHeaderPlaceholderEventSource headerPlaceholderEventSource = new PortletHeaderPlaceholderEventSource();
    headerPlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
    final PortletTitlePlaceholderEventSource portletTitlePlaceholderEventSource = new PortletTitlePlaceholderEventSource();
    portletTitlePlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
    final PortletHelpPlaceholderEventSource portletHelpPlaceholderEventSource = new PortletHelpPlaceholderEventSource();
    portletHelpPlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
    final Map<String, CharacterEventSource> chunkingElements = new LinkedHashMap<String, CharacterEventSource>();
    chunkingElements.put("portlet", contentPlaceholderEventSource);
    chunkingElements.put("portlet-header", headerPlaceholderEventSource);
    staxSerializingComponent.setChunkingElements(chunkingElements);
    final Map<String, CharacterEventSource> chunkingPatterns = new LinkedHashMap<String, CharacterEventSource>();
    chunkingPatterns.put("\\{up-portlet-title\\(([^\\)]+)\\)\\}", portletTitlePlaceholderEventSource);
    chunkingPatterns.put("\\{up-portlet-help\\(([^\\)]+)\\)\\}", portletHelpPlaceholderEventSource);
    staxSerializingComponent.setChunkingPatterns(chunkingPatterns);
    final PipelineEventReader<CharacterEventReader, CharacterEvent> eventReader = staxSerializingComponent.getEventReader(request, response);
    // Expected events structure, leaving the data out to make it at least a little simpler
    final List<? extends CharacterEvent> expectedEvents = this.getExpectedEvents();
    final Iterator<CharacterEvent> eventItr = eventReader.iterator();
    final Iterator<? extends CharacterEvent> expectedEventsItr = expectedEvents.iterator();
    int eventCount = 0;
    while (expectedEventsItr.hasNext()) {
        eventCount++;
        assertTrue("The number of events returned by the eventReader less than the expected event count of: " + expectedEvents.size() + " was: " + eventCount, eventItr.hasNext());
        final CharacterEvent expectedEvent = expectedEventsItr.next();
        final CharacterEvent event = eventItr.next();
        assertEquals("Events at index " + eventCount + " do not match\n" + expectedEvent + "\n" + event, expectedEvent, event);
    }
    assertFalse("The number of events returned by the eventReader is more than the expected event count of: " + expectedEvents.size(), eventItr.hasNext());
}
Also used : PortletHeaderPlaceholderEventSource(org.apereo.portal.character.stream.PortletHeaderPlaceholderEventSource) IPortletWindowRegistry(org.apereo.portal.portlet.registry.IPortletWindowRegistry) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) LinkedHashMap(java.util.LinkedHashMap) StartElement(javax.xml.stream.events.StartElement) CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) PortletHelpPlaceholderEventSource(org.apereo.portal.character.stream.PortletHelpPlaceholderEventSource) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) PortletTitlePlaceholderEventSource(org.apereo.portal.character.stream.PortletTitlePlaceholderEventSource) CharacterEventSource(org.apereo.portal.character.stream.CharacterEventSource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) PortletContentPlaceholderEventSource(org.apereo.portal.character.stream.PortletContentPlaceholderEventSource) Test(org.junit.Test)

Example 3 with IPortletWindowRegistry

use of org.apereo.portal.portlet.registry.IPortletWindowRegistry in project uPortal by Jasig.

the class PortletCacheControlServiceImplTest method testGetCacheControlDefault.

@Test
public void testGetCacheControlDefault() {
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    MockPortletWindowId portletWindowId = new MockPortletWindowId("123");
    MockPortletDefinitionId portletDefinitionId = new MockPortletDefinitionId(789);
    when(portletDescriptor.getCacheScope()).thenReturn(null);
    final IPortletWindowRegistry portletWindowRegistry = mock(IPortletWindowRegistry.class);
    final IPortletWindow portletWindow = mock(IPortletWindow.class);
    final IPortletEntity portletEntity = mock(IPortletEntity.class);
    when(portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId)).thenReturn(portletWindow);
    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);
    final CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> cacheState = cacheControlService.getPortletRenderState(httpRequest, portletWindowId);
    final CacheControl cacheControl = cacheState.getCacheControl();
    assertFalse(cacheControl.isPublicScope());
    assertNull(cacheControl.getETag());
}
Also used : MockPortletDefinitionId(org.apereo.portal.mock.portlet.om.MockPortletDefinitionId) IPortletWindowRegistry(org.apereo.portal.portlet.registry.IPortletWindowRegistry) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) 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) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) Test(org.junit.Test)

Aggregations

IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)3 IPortletWindowRegistry (org.apereo.portal.portlet.registry.IPortletWindowRegistry)3 Test (org.junit.Test)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 CacheControl (javax.portlet.CacheControl)1 StartElement (javax.xml.stream.events.StartElement)1 PortletWindow (org.apache.pluto.container.PortletWindow)1 PortletAppType (org.apache.pluto.container.om.portlet.impl.PortletAppType)1 UserAttributeType (org.apache.pluto.container.om.portlet.impl.UserAttributeType)1 CharacterEventReader (org.apereo.portal.character.stream.CharacterEventReader)1 CharacterEventSource (org.apereo.portal.character.stream.CharacterEventSource)1 PortletContentPlaceholderEventSource (org.apereo.portal.character.stream.PortletContentPlaceholderEventSource)1 PortletHeaderPlaceholderEventSource (org.apereo.portal.character.stream.PortletHeaderPlaceholderEventSource)1 PortletHelpPlaceholderEventSource (org.apereo.portal.character.stream.PortletHelpPlaceholderEventSource)1