@Test public void testCacheRemoval() throws Exception { StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(new MockServletContext()); wac.refresh(); InternalResourceViewResolver vr = new InternalResourceViewResolver(); vr.setViewClass(JstlView.class); vr.setApplicationContext(wac); View view = vr.resolveViewName("example1", Locale.getDefault()); View cached = vr.resolveViewName("example1", Locale.getDefault()); if (view != cached) { fail("Caching doesn't work"); } vr.removeFromCache("example1", Locale.getDefault()); cached = vr.resolveViewName("example1", Locale.getDefault()); if (view == cached) { // the chance of having the same reference (hashCode) twice if negligible). fail("View wasn't removed from cache"); } }
vr.setAttributesMap(map); vr.setExposedContextBeanNames(new String[] {"myBean2"}); vr.setApplicationContext(wac);
vr.setAttributesMap(map); vr.setExposeContextBeansAsAttributes(true); vr.setApplicationContext(wac);
map.put("key2", new Integer(2)); vr.setAttributesMap(map); vr.setApplicationContext(wac);
@Test public void nestedViewResolverIsNotSpringBean() throws Exception { StaticWebApplicationContext webAppContext = new StaticWebApplicationContext(); webAppContext.setServletContext(new MockServletContext()); webAppContext.refresh(); InternalResourceViewResolver nestedResolver = new InternalResourceViewResolver(); nestedResolver.setApplicationContext(webAppContext); nestedResolver.setViewClass(InternalResourceView.class); viewResolver.setViewResolvers(new ArrayList<>(Arrays.asList(nestedResolver))); FixedContentNegotiationStrategy fixedStrategy = new FixedContentNegotiationStrategy(MediaType.TEXT_HTML); viewResolver.setContentNegotiationManager(new ContentNegotiationManager(fixedStrategy)); viewResolver.afterPropertiesSet(); String viewName = "view"; Locale locale = Locale.ENGLISH; View result = viewResolver.resolveViewName(viewName, locale); assertNotNull("Invalid view", result); }
InternalResourceViewResolver vr = new InternalResourceViewResolver(); vr.setViewClass(JstlView.class); vr.setApplicationContext(wac);
InternalResourceViewResolver vr = new InternalResourceViewResolver(); vr.setViewClass(JstlView.class); vr.setApplicationContext(wac);