use of freemarker.cache.TemplateLookupResult in project freemarker by apache.
the class TemplateNotFoundMessageTest method testOtherMessageDetails.
@Test
public void testOtherMessageDetails() throws IOException {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
cfg.setTemplateLoader(new StringTemplateLoader());
{
String errMsg = failWith("../x", cfg);
showErrorMessage(errMsg);
assertThat(errMsg, allOf(containsStringIgnoringCase("reason"), containsStringIgnoringCase("root directory")));
}
{
String errMsg = failWith("x\u0000y", cfg);
showErrorMessage(errMsg);
assertThat(errMsg, allOf(containsStringIgnoringCase("reason"), containsStringIgnoringCase("null character")));
}
{
String errMsg = failWith("x\\y", cfg);
showErrorMessage(errMsg);
assertThat(errMsg, allOf(containsStringIgnoringCase("warning"), containsStringIgnoringCase("backslash")));
}
{
String errMsg = failWith("x/./y", cfg);
showErrorMessage(errMsg);
assertThat(errMsg, allOf(containsStringIgnoringCase("normalized"), containsStringIgnoringCase("x/y")));
}
{
String errMsg = failWith("/x/y", cfg);
showErrorMessage(errMsg);
assertThat(errMsg, not(containsStringIgnoringCase("normalized")));
}
{
String errMsg = failWith("x/y", cfg);
showErrorMessage(errMsg);
assertThat(errMsg, not(containsStringIgnoringCase("normalized")));
assertThat(errMsg, not(containsStringIgnoringCase("lookup strategy")));
}
cfg.setTemplateLookupStrategy(new TemplateLookupStrategy() {
@Override
public TemplateLookupResult lookup(TemplateLookupContext ctx) throws IOException {
return ctx.lookupWithAcquisitionStrategy(ctx.getTemplateName());
}
});
{
String errMsg = failWith("x/y", cfg);
showErrorMessage(errMsg);
assertThat(errMsg, containsStringIgnoringCase("lookup strategy"));
}
try {
cfg.getTemplate("./missing", null, "example.com", null, true, false);
fail();
} catch (TemplateNotFoundException e) {
showErrorMessage(e.getMessage());
assertThat(e.getMessage(), containsStringIgnoringCase("example.com"));
}
}
Aggregations