DefaultTemplateResolver implements TemplateResolver { protected URL resourceUrl(String templateName, Class<?> viewType) { String path = relativeResourcePath(templateName, viewType); return templateBase.getUrl(path); } DefaultTemplateResolver(FolderResourceFactory templateBase, Charset templateEncoding); @Override Template resolve(String templateName, Class<?> viewType);  }
@Test public void testResourcePath_EmptyBase() throws MalformedURLException { DefaultTemplateResolver resolver = resolver(""); URL expected = baseUrl("io/bootique/mvc/resolver/tName.txt"); assertEquals(expected, resolver.resourceUrl("tName.txt", DefaultTemplateResolverTest.class)); assertEquals(expected, resolver.resourceUrl("/tName.txt", DefaultTemplateResolverTest.class)); }
@Test public void testResourcePath_FilePathBase() throws IOException { DefaultTemplateResolver resolver = resolver("/tmp"); File canonical = new File("/tmp/io/bootique/mvc/resolver/tName.txt").getCanonicalFile(); assertEquals(canonical.toURI().toURL(), resolver.resourceUrl("tName.txt", DefaultTemplateResolverTest.class)); assertEquals(canonical.toURI().toURL(), resolver.resourceUrl("/tName.txt", DefaultTemplateResolverTest.class)); }
@Test public void testResourcePath_FilePathBase_Slash() throws IOException { DefaultTemplateResolver resolver = resolver("/tmp/"); File canonical = new File("/tmp/io/bootique/mvc/resolver/tName.txt").getCanonicalFile(); assertEquals(canonical.toURI().toURL(), resolver.resourceUrl("tName.txt", DefaultTemplateResolverTest.class)); assertEquals(canonical.toURI().toURL(), resolver.resourceUrl("/tName.txt", DefaultTemplateResolverTest.class)); }
@Test public void testResourcePath_UrlBase() { DefaultTemplateResolver resolver = resolver("http: assertEquals("http: resolver.resourceUrl("tName.txt", DefaultTemplateResolverTest.class).toExternalForm()); assertEquals("http: resolver.resourceUrl("/tName.txt", DefaultTemplateResolverTest.class).toExternalForm()); }
@Test public void testResourcePath_UrlBase_Slash() { DefaultTemplateResolver resolver = resolver("http: assertEquals("http: resolver.resourceUrl("tName.txt", DefaultTemplateResolverTest.class).toExternalForm()); assertEquals("http: resolver.resourceUrl("/tName.txt", DefaultTemplateResolverTest.class).toExternalForm()); }
@Test public void testResourcePath_ClasspathBase() throws MalformedURLException { DefaultTemplateResolver resolver = resolver("classpath:"); URL expected = baseClasspathUrl("io/bootique/mvc/resolver/tName.txt"); assertEquals(expected, resolver.resourceUrl("tName.txt", DefaultTemplateResolverTest.class)); assertEquals(expected, resolver.resourceUrl("/tName.txt", DefaultTemplateResolverTest.class)); }
@Test public void testResourcePath_ClasspathBase_Slash() throws MalformedURLException { DefaultTemplateResolver resolver = resolver("classpath:/"); assertEquals(baseClasspathUrl("io/bootique/mvc/resolver/tName.txt"), resolver.resourceUrl("tName.txt", DefaultTemplateResolverTest.class)); }