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