vr.setApplicationContext(wac); View view1 = vr.resolveViewName("example1", Locale.getDefault()); assertTrue("Correct view class", TestView.class.equals(view1.getClass())); assertTrue("Correct URL", "/example1.jsp".equals(((InternalResourceView) view1).getUrl())); View view2 = vr.resolveViewName("example2", Locale.getDefault()); assertTrue("Correct view class", JstlView.class.equals(view2.getClass())); assertTrue("Correct URL", "/example2new.jsp".equals(((InternalResourceView) view2).getUrl()));
@Test public void testXmlViewResolverWithoutCache() throws Exception { StaticWebApplicationContext wac = new StaticWebApplicationContext() { @Override protected Resource getResourceByPath(String path) { assertTrue("Correct default location", XmlViewResolver.DEFAULT_LOCATION.equals(path)); return super.getResourceByPath(path); } }; wac.setServletContext(new MockServletContext()); wac.refresh(); XmlViewResolver vr = new XmlViewResolver(); vr.setCache(false); try { vr.setApplicationContext(wac); } catch (ApplicationContextException ex) { fail("Should not have thrown ApplicationContextException: " + ex.getMessage()); } try { vr.resolveViewName("example1", Locale.getDefault()); fail("Should have thrown BeanDefinitionStoreException"); } catch (BeanDefinitionStoreException ex) { // expected } }