Search in sources :

Example 1 with PortletTitlePlaceholderEventSource

use of org.apereo.portal.character.stream.PortletTitlePlaceholderEventSource 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)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 StartElement (javax.xml.stream.events.StartElement)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 PortletTitlePlaceholderEventSource (org.apereo.portal.character.stream.PortletTitlePlaceholderEventSource)1 CharacterEvent (org.apereo.portal.character.stream.events.CharacterEvent)1 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)1 IPortletWindowRegistry (org.apereo.portal.portlet.registry.IPortletWindowRegistry)1 Test (org.junit.Test)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1