Reputation: 129
I am writing a JUnit test, which should test the title of an html page. This project is a SpringBoot, Thymeleaf starter project.
HtmlPath:
private final static String HTML_PATH = "/pages/dashboard/dashboard.html";
JUnitTest:
@Test
public void shouldRenderPageTitle() throws IOException, NodeSelectorException {
Map<String,Object> model = new HashMap<>();
model.put("pageTitle", "expected title");
HtmlElements tags = testEngine.process(HTML_PATH, model);
assertThat(tags.matching("title"), isSingleElementThat(hasOnlyText("expected title")));
}
ThymeleafConfiguration
@Configuration
public class ThymeleafConfig {
@Bean
public TemplateResolver templateResolver() {
TemplateResolver templateResolver = new TemplateResolver();
templateResolver.setPrefix("/resources/templates/");
return templateResolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.addDialect(new LayoutDialect());
templateEngine.addDialect(new SpringStandardDialect());
return templateEngine;
}
@Bean
public ThymeleafViewResolver thymeleafViewResolver() {
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine());
return viewResolver;
}
}
The Error:
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/pages/dashboard/dashboard.html"
Upvotes: 0
Views: 753
Reputation: 91
You have to use
private final static String HTML_PATH = "/pages/dashboard/dashboard"; //no ".html"
Upvotes: 1
Reputation: 2491
Can you try replacing this line of code
templateResolver.setPrefix("/resources/templates/");
with this one
templateResolver.setPrefix("templates/");
Upvotes: 0