Search in sources :

Example 1 with GetLastModifiedEvent

use of freemarker.test.MonitoredTemplateLoader.GetLastModifiedEvent in project freemarker by apache.

the class TemplateCacheTest method testWrongEncodingReload.

@Test
public void testWrongEncodingReload() throws IOException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_22);
    cfg.setLocale(Locale.US);
    MonitoredTemplateLoader tl = new MonitoredTemplateLoader();
    tl.putTemplate("utf-8_en.ftl", "<#ftl encoding='utf-8'>Foo");
    tl.putTemplate("utf-8.ftl", "Bar");
    cfg.setTemplateLoader(tl);
    {
        Template t = cfg.getTemplate("utf-8.ftl", "Utf-8");
        assertEquals("utf-8.ftl", t.getName());
        assertEquals("utf-8_en.ftl", t.getSourceName());
        assertEquals("Utf-8", t.getEncoding());
        assertEquals("Foo", t.toString());
        assertEquals(ImmutableList.of(new FindTemplateSourceEvent("utf-8_en_US.ftl", false), new FindTemplateSourceEvent("utf-8_en.ftl", true), new GetLastModifiedEvent("utf-8_en.ftl"), // Attempt 1
        new GetReaderEvent("utf-8_en.ftl"), new CloseTemplateSourceEvent("utf-8_en.ftl")), tl.getEvents());
    }
    {
        tl.clearEvents();
        Template t = cfg.getTemplate("utf-8.ftl", "Utf-16");
        assertEquals("utf-8.ftl", t.getName());
        assertEquals("utf-8_en.ftl", t.getSourceName());
        assertEquals("utf-8", t.getEncoding());
        assertEquals("Foo", t.toString());
        assertEquals(ImmutableList.of(new FindTemplateSourceEvent("utf-8_en_US.ftl", false), new FindTemplateSourceEvent("utf-8_en.ftl", true), new GetLastModifiedEvent("utf-8_en.ftl"), // Attempt 1
        new GetReaderEvent("utf-8_en.ftl"), // Attempt 2
        new GetReaderEvent("utf-8_en.ftl"), new CloseTemplateSourceEvent("utf-8_en.ftl")), tl.getEvents());
    }
}
Also used : GetReaderEvent(freemarker.test.MonitoredTemplateLoader.GetReaderEvent) Configuration(freemarker.template.Configuration) CloseTemplateSourceEvent(freemarker.test.MonitoredTemplateLoader.CloseTemplateSourceEvent) FindTemplateSourceEvent(freemarker.test.MonitoredTemplateLoader.FindTemplateSourceEvent) MonitoredTemplateLoader(freemarker.test.MonitoredTemplateLoader) Template(freemarker.template.Template) GetLastModifiedEvent(freemarker.test.MonitoredTemplateLoader.GetLastModifiedEvent) Test(org.junit.Test)

Aggregations

Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 MonitoredTemplateLoader (freemarker.test.MonitoredTemplateLoader)1 CloseTemplateSourceEvent (freemarker.test.MonitoredTemplateLoader.CloseTemplateSourceEvent)1 FindTemplateSourceEvent (freemarker.test.MonitoredTemplateLoader.FindTemplateSourceEvent)1 GetLastModifiedEvent (freemarker.test.MonitoredTemplateLoader.GetLastModifiedEvent)1 GetReaderEvent (freemarker.test.MonitoredTemplateLoader.GetReaderEvent)1 Test (org.junit.Test)1