Search in sources :

Example 1 with ScriptTemplateConfigurer

use of org.springframework.web.servlet.view.script.ScriptTemplateConfigurer 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"));
}
Also used : GroovyMarkupConfigurer(org.springframework.web.servlet.view.groovy.GroovyMarkupConfigurer) ViewResolverComposite(org.springframework.web.servlet.view.ViewResolverComposite) ScriptTemplateConfigurer(org.springframework.web.servlet.view.script.ScriptTemplateConfigurer) ContentNegotiatingViewResolver(org.springframework.web.servlet.view.ContentNegotiatingViewResolver) ScriptTemplateViewResolver(org.springframework.web.servlet.view.script.ScriptTemplateViewResolver) FreeMarkerViewResolver(org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver) ViewResolver(org.springframework.web.servlet.ViewResolver) BeanNameViewResolver(org.springframework.web.servlet.view.BeanNameViewResolver) GroovyMarkupViewResolver(org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver) InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) TilesViewResolver(org.springframework.web.servlet.view.tiles3.TilesViewResolver) FreeMarkerConfigurer(org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer) TilesConfigurer(org.springframework.web.servlet.view.tiles3.TilesConfigurer) GroovyMarkupViewResolver(org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver) ScriptTemplateViewResolver(org.springframework.web.servlet.view.script.ScriptTemplateViewResolver) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) FreeMarkerViewResolver(org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 ViewResolver (org.springframework.web.servlet.ViewResolver)1 BeanNameViewResolver (org.springframework.web.servlet.view.BeanNameViewResolver)1 ContentNegotiatingViewResolver (org.springframework.web.servlet.view.ContentNegotiatingViewResolver)1 InternalResourceViewResolver (org.springframework.web.servlet.view.InternalResourceViewResolver)1 ViewResolverComposite (org.springframework.web.servlet.view.ViewResolverComposite)1 FreeMarkerConfigurer (org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer)1 FreeMarkerViewResolver (org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver)1 GroovyMarkupConfigurer (org.springframework.web.servlet.view.groovy.GroovyMarkupConfigurer)1 GroovyMarkupViewResolver (org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver)1 ScriptTemplateConfigurer (org.springframework.web.servlet.view.script.ScriptTemplateConfigurer)1 ScriptTemplateViewResolver (org.springframework.web.servlet.view.script.ScriptTemplateViewResolver)1 TilesConfigurer (org.springframework.web.servlet.view.tiles3.TilesConfigurer)1 TilesViewResolver (org.springframework.web.servlet.view.tiles3.TilesViewResolver)1