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