assertEquals(new Integer(2), request.getAttribute("key2"));
}
public void testInternalResourceViewResolverWithContextBeans() throws Exception {
MockServletContext sc = new MockServletContext();
final StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.registerSingleton("myBean", TestBean.class);
wac.registerSingleton("myBean2", TestBean.class);
wac.setServletContext(sc);
wac.refresh();
InternalResourceViewResolver vr = new InternalResourceViewResolver();
Properties props = new Properties();
props.setProperty("key1", "value1");
vr.setAttributes(props);
Map map = new HashMap();
map.put("key2", new Integer(2));
vr.setAttributesMap(map);
vr.setExposeContextBeansAsAttributes(true);
vr.setApplicationContext(wac);
MockHttpServletRequest request = new MockHttpServletRequest(sc) {
public RequestDispatcher getRequestDispatcher(String path) {
return new MockRequestDispatcher(path) {
public void forward(ServletRequest forwardRequest, ServletResponse forwardResponse) {
assertTrue("Correct rc attribute", forwardRequest.getAttribute("rc") == null);
assertEquals("value1", forwardRequest.getAttribute("key1"));
assertEquals(new Integer(2), forwardRequest.getAttribute("key2"));
assertSame(wac.getBean("myBean"), forwardRequest.getAttribute("myBean"));
assertSame(wac.getBean("myBean2"), forwardRequest.getAttribute("myBean2"));
}
};
}
};
HttpServletResponse response = new MockHttpServletResponse();