portlet.render(request, response);
assertEquals("mySurpriseView", response.getContentAsString());
}
public void testTypeLevelParameterDispatchingController() throws Exception {
DispatcherPortlet portlet = new DispatcherPortlet() {
protected ApplicationContext createPortletApplicationContext(ApplicationContext parent) throws BeansException {
StaticPortletApplicationContext wac = new StaticPortletApplicationContext();
wac.setPortletContext(new MockPortletContext());
RootBeanDefinition bd = new RootBeanDefinition(MyTypeLevelParameterDispatchingController.class);
bd.setScope(WebApplicationContext.SCOPE_REQUEST);
wac.registerBeanDefinition("controller", bd);
RootBeanDefinition bd2 = new RootBeanDefinition(MySpecialParameterDispatchingController.class);
bd2.setScope(WebApplicationContext.SCOPE_REQUEST);
wac.registerBeanDefinition("controller2", bd2);
RootBeanDefinition bd3 = new RootBeanDefinition(MyOtherSpecialParameterDispatchingController.class);
bd3.setScope(WebApplicationContext.SCOPE_REQUEST);
wac.registerBeanDefinition("controller3", bd3);
RootBeanDefinition bd4 = new RootBeanDefinition(MyParameterDispatchingController.class);
bd4.setScope(WebApplicationContext.SCOPE_REQUEST);
wac.registerBeanDefinition("controller4", bd4);
AnnotationConfigUtils.registerAnnotationConfigProcessors(wac);
wac.refresh();
return wac;
}
};
portlet.init(new MockPortletConfig());
MockRenderRequest request = new MockRenderRequest(PortletMode.EDIT);
MockRenderResponse response = new MockRenderResponse();
try {
portlet.render(request, response);
fail("Should have thrown UnavailableException");
}
catch (UnavailableException ex) {
// expected
}
request = new MockRenderRequest(PortletMode.EDIT);
request.addParameter("myParam", "myValue");
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myView", response.getContentAsString());
request = new MockRenderRequest(PortletMode.EDIT);
request.addParameter("myParam", "mySpecialValue");
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("mySpecialView", response.getContentAsString());
request = new MockRenderRequest(PortletMode.EDIT);
request.addParameter("myParam", "myOtherSpecialValue");
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myOtherSpecialView", response.getContentAsString());
request = new MockRenderRequest(PortletMode.VIEW);
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myView", response.getContentAsString());
request = new MockRenderRequest(PortletMode.EDIT);
request.addParameter("myParam", "myValue");
request.addParameter("view", "other");
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myOtherView", response.getContentAsString());
request = new MockRenderRequest(PortletMode.EDIT);
request.addParameter("myParam", "myValue");
request.addParameter("view", "my");
request.addParameter("lang", "de");
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("myLangView", response.getContentAsString());
request = new MockRenderRequest(PortletMode.EDIT);
request.addParameter("myParam", "myValue");
request.addParameter("surprise", "!");
response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("mySurpriseView", response.getContentAsString());
}