use of org.springframework.web.servlet.view.groovy.GroovyMarkupConfigurer in project spring-framework by spring-projects.
the class MvcNamespaceTests method testViewResolution.
@Test
public void testViewResolution() throws Exception {
loadBeanDefinitions("mvc-config-view-resolution.xml", 6);
ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class);
assertNotNull(compositeResolver);
assertEquals("Actual: " + compositeResolver.getViewResolvers(), 8, compositeResolver.getViewResolvers().size());
assertEquals(Ordered.LOWEST_PRECEDENCE, compositeResolver.getOrder());
List<ViewResolver> resolvers = compositeResolver.getViewResolvers();
assertEquals(BeanNameViewResolver.class, resolvers.get(0).getClass());
ViewResolver resolver = resolvers.get(1);
assertEquals(InternalResourceViewResolver.class, resolver.getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(resolver);
assertEquals(InternalResourceView.class, accessor.getPropertyValue("viewClass"));
assertEquals(TilesViewResolver.class, resolvers.get(2).getClass());
resolver = resolvers.get(3);
assertThat(resolver, instanceOf(FreeMarkerViewResolver.class));
accessor = new DirectFieldAccessor(resolver);
assertEquals("freemarker-", accessor.getPropertyValue("prefix"));
assertEquals(".freemarker", accessor.getPropertyValue("suffix"));
assertArrayEquals(new String[] { "my*", "*Report" }, (String[]) accessor.getPropertyValue("viewNames"));
assertEquals(1024, accessor.getPropertyValue("cacheLimit"));
resolver = resolvers.get(4);
assertThat(resolver, instanceOf(GroovyMarkupViewResolver.class));
accessor = new DirectFieldAccessor(resolver);
assertEquals("", accessor.getPropertyValue("prefix"));
assertEquals(".tpl", accessor.getPropertyValue("suffix"));
assertEquals(1024, accessor.getPropertyValue("cacheLimit"));
resolver = resolvers.get(5);
assertThat(resolver, instanceOf(ScriptTemplateViewResolver.class));
accessor = new DirectFieldAccessor(resolver);
assertEquals("", accessor.getPropertyValue("prefix"));
assertEquals("", accessor.getPropertyValue("suffix"));
assertEquals(1024, accessor.getPropertyValue("cacheLimit"));
assertEquals(InternalResourceViewResolver.class, resolvers.get(6).getClass());
assertEquals(InternalResourceViewResolver.class, resolvers.get(7).getClass());
TilesConfigurer tilesConfigurer = appContext.getBean(TilesConfigurer.class);
assertNotNull(tilesConfigurer);
String[] definitions = { "/org/springframework/web/servlet/resource/tiles/tiles1.xml", "/org/springframework/web/servlet/resource/tiles/tiles2.xml" };
accessor = new DirectFieldAccessor(tilesConfigurer);
assertArrayEquals(definitions, (String[]) accessor.getPropertyValue("definitions"));
assertTrue((boolean) accessor.getPropertyValue("checkRefresh"));
assertEquals(UnresolvingLocaleDefinitionsFactory.class, accessor.getPropertyValue("definitionsFactoryClass"));
assertEquals(SpringBeanPreparerFactory.class, accessor.getPropertyValue("preparerFactoryClass"));
FreeMarkerConfigurer freeMarkerConfigurer = appContext.getBean(FreeMarkerConfigurer.class);
assertNotNull(freeMarkerConfigurer);
accessor = new DirectFieldAccessor(freeMarkerConfigurer);
assertArrayEquals(new String[] { "/", "/test" }, (String[]) accessor.getPropertyValue("templateLoaderPaths"));
GroovyMarkupConfigurer groovyMarkupConfigurer = appContext.getBean(GroovyMarkupConfigurer.class);
assertNotNull(groovyMarkupConfigurer);
assertEquals("/test", groovyMarkupConfigurer.getResourceLoaderPath());
assertTrue(groovyMarkupConfigurer.isAutoIndent());
assertFalse(groovyMarkupConfigurer.isCacheTemplates());
ScriptTemplateConfigurer scriptTemplateConfigurer = appContext.getBean(ScriptTemplateConfigurer.class);
assertNotNull(scriptTemplateConfigurer);
assertEquals("render", scriptTemplateConfigurer.getRenderFunction());
assertEquals(MediaType.TEXT_PLAIN_VALUE, scriptTemplateConfigurer.getContentType());
assertEquals(StandardCharsets.ISO_8859_1, scriptTemplateConfigurer.getCharset());
assertEquals("classpath:", scriptTemplateConfigurer.getResourceLoaderPath());
assertFalse(scriptTemplateConfigurer.isSharedEngine());
String[] scripts = { "org/springframework/web/servlet/view/script/nashorn/render.js" };
accessor = new DirectFieldAccessor(scriptTemplateConfigurer);
assertArrayEquals(scripts, (String[]) accessor.getPropertyValue("scripts"));
}
Aggregations