assertEquals("mySurpriseView", response.getContentAsString());
}
@Test
public void portlet20DispatchingController() throws Exception {
DispatcherPortlet portlet = new DispatcherPortlet() {
@Override
protected ApplicationContext createPortletApplicationContext(ApplicationContext parent) throws BeansException {
StaticPortletApplicationContext wac = new StaticPortletApplicationContext();
wac.setPortletContext(new MockPortletContext());
RootBeanDefinition bd = new RootBeanDefinition(MyPortlet20DispatchingController.class);
bd.setScope(WebApplicationContext.SCOPE_REQUEST);
wac.registerBeanDefinition("controller", bd);
wac.registerBeanDefinition("controller2", new RootBeanDefinition(DetailsController.class));
AnnotationConfigUtils.registerAnnotationConfigProcessors(wac);
wac.refresh();
return wac;
}
};
portlet.init(new MockPortletConfig());
MockRenderRequest request = new MockRenderRequest(PortletMode.VIEW);
MockRenderResponse response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myView", response.getContentAsString());
MockActionRequest actionRequest = new MockActionRequest("this");
MockActionResponse actionResponse = new MockActionResponse();
portlet.processAction(actionRequest, actionResponse);
request = new MockRenderRequest(PortletMode.VIEW, WindowState.MAXIMIZED);
request.setParameters(actionResponse.getRenderParameterMap());
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myLargeView-value", response.getContentAsString());
actionRequest = new MockActionRequest("that");
actionResponse = new MockActionResponse();
portlet.processAction(actionRequest, actionResponse);
request = new MockRenderRequest(PortletMode.VIEW, WindowState.MAXIMIZED);
request.setParameters(actionResponse.getRenderParameterMap());
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myLargeView-value2", response.getContentAsString());
actionRequest = new MockActionRequest("else");
actionResponse = new MockActionResponse();
portlet.processAction(actionRequest, actionResponse);
request = new MockRenderRequest(PortletMode.VIEW, WindowState.MAXIMIZED);
request.setParameters(actionResponse.getRenderParameterMap());
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myLargeView-value3", response.getContentAsString());
actionRequest = new MockActionRequest("error");
actionResponse = new MockActionResponse();
portlet.processAction(actionRequest, actionResponse);
request = new MockRenderRequest(PortletMode.VIEW, WindowState.MAXIMIZED);
request.setParameters(actionResponse.getRenderParameterMap());
request.setSession(actionRequest.getPortletSession());
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("XXX", response.getContentAsString());
MockEventRequest eventRequest = new MockEventRequest(new MockEvent("event1"));
MockEventResponse eventResponse = new MockEventResponse();
portlet.processEvent(eventRequest, eventResponse);
request = new MockRenderRequest(PortletMode.VIEW, WindowState.MAXIMIZED);
request.setParameters(eventResponse.getRenderParameterMap());
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myLargeView-value3", response.getContentAsString());
eventRequest = new MockEventRequest(new MockEvent("event2"));
eventResponse = new MockEventResponse();
portlet.processEvent(eventRequest, eventResponse);
request = new MockRenderRequest(PortletMode.VIEW, WindowState.MAXIMIZED);
request.setParameters(eventResponse.getRenderParameterMap());
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myLargeView-value4", response.getContentAsString());
request = new MockRenderRequest(PortletMode.VIEW, WindowState.NORMAL);
request.setParameters(actionResponse.getRenderParameterMap());
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myView", response.getContentAsString());
MockResourceRequest resourceRequest = new MockResourceRequest("resource1");
MockResourceResponse resourceResponse = new MockResourceResponse();
portlet.serveResource(resourceRequest, resourceResponse);
assertEquals("myResource", resourceResponse.getContentAsString());
resourceRequest = new MockResourceRequest("resource2");
resourceResponse = new MockResourceResponse();
portlet.serveResource(resourceRequest, resourceResponse);
assertEquals("myDefaultResource", resourceResponse.getContentAsString());
}