Search in sources :

Example 1 with TemplateHTMLOutputModel

use of freemarker.core.TemplateHTMLOutputModel 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);
        }
    }
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) TemplateHashModel(freemarker.template.TemplateHashModel) Version(freemarker.template.Version) TemplateMethodModelEx(freemarker.template.TemplateMethodModelEx) TemplateScalarModel(freemarker.template.TemplateScalarModel) TemplateHTMLOutputModel(freemarker.core.TemplateHTMLOutputModel) Test(org.junit.Test)

Aggregations

TemplateHTMLOutputModel (freemarker.core.TemplateHTMLOutputModel)1 TemplateHashModel (freemarker.template.TemplateHashModel)1 TemplateMethodModelEx (freemarker.template.TemplateMethodModelEx)1 TemplateModelException (freemarker.template.TemplateModelException)1 TemplateScalarModel (freemarker.template.TemplateScalarModel)1 Version (freemarker.template.Version)1 Test (org.junit.Test)1