use of freemarker.template.TemplateMethodModelEx in project freemarker by apache.
the class ErrorMessagesTest method markupOutputParameter.
@Test
public void markupOutputParameter() throws Exception {
TemplateHTMLOutputModel html = HTMLOutputFormat.INSTANCE.fromMarkup("<p>a");
for (Version ici : new Version[] { Configuration.VERSION_2_3_0, Configuration.VERSION_2_3_24 }) {
BeansWrapper bw = new BeansWrapperBuilder(ici).build();
TemplateHashModel thm = (TemplateHashModel) bw.wrap(new TestBean());
{
TemplateMethodModelEx m = (TemplateMethodModelEx) thm.get("m1");
try {
m.exec(Collections.singletonList(html));
fail();
} catch (TemplateModelException e) {
assertThat(e.getMessage(), allOf(containsString("String"), containsString("convert"), containsString("markup_output"), containsString("Tip:"), containsString("?markup_string")));
}
}
{
TemplateMethodModelEx m = (TemplateMethodModelEx) thm.get("m2");
try {
m.exec(Collections.singletonList(html));
fail();
} catch (TemplateModelException e) {
assertThat(e.getMessage(), allOf(containsString("Date"), containsString("convert"), containsString("markup_output"), not(containsString("?markup_string"))));
}
}
for (String methodName : new String[] { "mOverloaded", "mOverloaded3" }) {
TemplateMethodModelEx m = (TemplateMethodModelEx) thm.get(methodName);
try {
m.exec(Collections.singletonList(html));
fail();
} catch (TemplateModelException e) {
assertThat(e.getMessage(), allOf(containsString("No compatible overloaded"), containsString("String"), containsString("markup_output"), containsString("Tip:"), containsString("?markup_string")));
}
}
{
TemplateMethodModelEx m = (TemplateMethodModelEx) thm.get("mOverloaded2");
try {
m.exec(Collections.singletonList(html));
fail();
} catch (TemplateModelException e) {
assertThat(e.getMessage(), allOf(containsString("No compatible overloaded"), containsString("Integer"), containsString("markup_output"), not(containsString("?markup_string"))));
}
}
{
TemplateMethodModelEx m = (TemplateMethodModelEx) thm.get("mOverloaded4");
Object r = m.exec(Collections.singletonList(html));
if (r instanceof TemplateScalarModel) {
r = ((TemplateScalarModel) r).getAsString();
}
assertEquals("<p>a", r);
}
}
}
Aggregations