Search in sources :

Example 66 with Configuration

use of freemarker.template.Configuration in project freemarker by apache.

the class SQLTimeZoneTest method testWithDefaultTZAndNullSQL.

@Test
public void testWithDefaultTZAndNullSQL() throws Exception {
    TimeZone prevSysDefTz = TimeZone.getDefault();
    TimeZone.setDefault(GMT_P02);
    try {
        Configuration cfg = getConfiguration();
        cfg.unsetTimeZone();
        assertNull(cfg.getSQLDateAndTimeTimeZone());
        assertEquals(TimeZone.getDefault(), cfg.getTimeZone());
        assertOutput(FTL, OUTPUT_BEFORE_SETTING_GMT_CFG_GMT2 + OUTPUT_AFTER_SETTING_GMT_CFG_SQL_SAME);
    } finally {
        TimeZone.setDefault(prevSysDefTz);
    }
}
Also used : TimeZone(java.util.TimeZone) Configuration(freemarker.template.Configuration) Test(org.junit.Test) TemplateTest(freemarker.test.TemplateTest)

Example 67 with Configuration

use of freemarker.template.Configuration in project freemarker by apache.

the class SQLTimeZoneTest method testCacheFlushings.

@Test
public void testCacheFlushings() throws Exception {
    Configuration cfg = getConfiguration();
    cfg.setTimeZone(DateUtil.UTC);
    cfg.setDateFormat("yyyy-MM-dd E");
    cfg.setTimeFormat("HH:mm:ss E");
    cfg.setDateTimeFormat("yyyy-MM-dd'T'HH:mm:ss E");
    assertOutput("${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n" + "<#setting locale='hu'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n", "2014-07-11 Fri, 10:30:05 Thu, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12 Sat, 10:30:05 Sat\n" + "2014-07-11 P, 10:30:05 Cs, 2014-07-12T10:30:05 Szo, 2014-07-12T10:30:05 Szo, 2014-07-12 Szo, 10:30:05 Szo\n");
    assertOutput("${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n" + "<#setting date_format='yyyy-MM-dd'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n", "2014-07-11 Fri, 10:30:05 Thu, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12 Sat, 10:30:05 Sat\n" + "2014-07-11, 10:30:05 Thu, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12, 10:30:05 Sat\n");
    assertOutput("${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n" + "<#setting time_format='HH:mm:ss'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n", "2014-07-11 Fri, 10:30:05 Thu, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12 Sat, 10:30:05 Sat\n" + "2014-07-11 Fri, 10:30:05, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12 Sat, 10:30:05\n");
    assertOutput("${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n" + "<#setting datetime_format='yyyy-MM-dd\\'T\\'HH:mm:ss'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n", "2014-07-11 Fri, 10:30:05 Thu, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12 Sat, 10:30:05 Sat\n" + "2014-07-11 Fri, 10:30:05 Thu, 2014-07-12T10:30:05, 2014-07-12T10:30:05, 2014-07-12 Sat, 10:30:05 Sat\n");
    cfg.setSQLDateAndTimeTimeZone(GMT_P02);
    assertOutput("${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n" + "<#setting locale='hu'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n", "2014-07-12 Sat, 12:30:05 Thu, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12 Sat, 10:30:05 Sat\n" + "2014-07-12 Szo, 12:30:05 Cs, 2014-07-12T10:30:05 Szo, 2014-07-12T10:30:05 Szo, 2014-07-12 Szo, 10:30:05 Szo\n");
    assertOutput("${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n" + "<#setting date_format='yyyy-MM-dd'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n", "2014-07-12 Sat, 12:30:05 Thu, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12 Sat, 10:30:05 Sat\n" + "2014-07-12, 12:30:05 Thu, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12, 10:30:05 Sat\n");
    assertOutput("${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n" + "<#setting time_format='HH:mm:ss'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n", "2014-07-12 Sat, 12:30:05 Thu, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12 Sat, 10:30:05 Sat\n" + "2014-07-12 Sat, 12:30:05, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12 Sat, 10:30:05\n");
    assertOutput("${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n" + "<#setting datetime_format='yyyy-MM-dd\\'T\\'HH:mm:ss'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}, ${javaDate?date}, ${javaDate?time}\n", "2014-07-12 Sat, 12:30:05 Thu, 2014-07-12T10:30:05 Sat, 2014-07-12T10:30:05 Sat, 2014-07-12 Sat, 10:30:05 Sat\n" + "2014-07-12 Sat, 12:30:05 Thu, 2014-07-12T10:30:05, 2014-07-12T10:30:05, 2014-07-12 Sat, 10:30:05 Sat\n");
}
Also used : Configuration(freemarker.template.Configuration) Test(org.junit.Test) TemplateTest(freemarker.test.TemplateTest)

Example 68 with Configuration

use of freemarker.template.Configuration in project freemarker by apache.

the class SQLTimeZoneTest method testWithGMT2AndNullSQL.

@Test
public void testWithGMT2AndNullSQL() throws Exception {
    Configuration cfg = getConfiguration();
    assertNull(cfg.getSQLDateAndTimeTimeZone());
    cfg.setTimeZone(TimeZone.getTimeZone("GMT+02"));
    assertOutput(FTL, OUTPUT_BEFORE_SETTING_GMT_CFG_GMT2 + OUTPUT_AFTER_SETTING_GMT_CFG_SQL_SAME);
}
Also used : Configuration(freemarker.template.Configuration) Test(org.junit.Test) TemplateTest(freemarker.test.TemplateTest)

Example 69 with Configuration

use of freemarker.template.Configuration in project freemarker by apache.

the class SQLTimeZoneTest method testChangeSettingInTemplate.

@Test
public void testChangeSettingInTemplate() throws Exception {
    Configuration cfg = getConfiguration();
    cfg.setTimeZone(DateUtil.UTC);
    assertNull(cfg.getSQLDateAndTimeTimeZone());
    assertOutput("${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}\n" + "<#setting sql_date_and_time_time_zone='GMT+02'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}\n" + "<#setting sql_date_and_time_time_zone='null'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}\n" + "<#setting time_zone='GMT+03'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}\n" + "<#setting sql_date_and_time_time_zone='GMT+02'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}\n" + "<#setting sql_date_and_time_time_zone='GMT-11'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}\n" + "<#setting date_format='xs fz'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}\n" + "<#setting time_format='xs fz'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}\n" + "<#setting datetime_format='iso m'>\n" + "${sqlDate}, ${sqlTime}, ${sqlTimestamp}, ${javaDate?datetime}\n", "2014-07-11, 10:30:05, 2014-07-12T10:30:05, 2014-07-12T10:30:05\n" + "2014-07-12, 12:30:05, 2014-07-12T10:30:05, 2014-07-12T10:30:05\n" + "2014-07-11, 10:30:05, 2014-07-12T10:30:05, 2014-07-12T10:30:05\n" + "2014-07-12, 13:30:05, 2014-07-12T13:30:05, 2014-07-12T13:30:05\n" + "2014-07-12, 12:30:05, 2014-07-12T13:30:05, 2014-07-12T13:30:05\n" + "2014-07-11, 23:30:05, 2014-07-12T13:30:05, 2014-07-12T13:30:05\n" + "2014-07-11-11:00, 23:30:05, 2014-07-12T13:30:05, 2014-07-12T13:30:05\n" + "2014-07-11-11:00, 23:30:05-11:00, 2014-07-12T13:30:05, 2014-07-12T13:30:05\n" + "2014-07-11-11:00, 23:30:05-11:00, 2014-07-12T13:30+03:00, 2014-07-12T13:30+03:00\n");
}
Also used : Configuration(freemarker.template.Configuration) Test(org.junit.Test) TemplateTest(freemarker.test.TemplateTest)

Example 70 with Configuration

use of freemarker.template.Configuration in project freemarker by apache.

the class SQLTimeZoneTest method createConfiguration.

@Override
protected Configuration createConfiguration() {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
    cfg.setLocale(Locale.US);
    cfg.setDateFormat("yyyy-MM-dd");
    cfg.setTimeFormat("HH:mm:ss");
    cfg.setDateTimeFormat("yyyy-MM-dd'T'HH:mm:ss");
    return cfg;
}
Also used : Configuration(freemarker.template.Configuration)

Aggregations

Configuration (freemarker.template.Configuration)282 Template (freemarker.template.Template)106 Test (org.junit.Test)86 TemplateTest (freemarker.test.TemplateTest)52 HashMap (java.util.HashMap)51 IOException (java.io.IOException)41 StringWriter (java.io.StringWriter)39 File (java.io.File)33 TemplateException (freemarker.template.TemplateException)29 Writer (java.io.Writer)27 ClassTemplateLoader (freemarker.cache.ClassTemplateLoader)19 ConditionalTemplateConfigurationFactory (freemarker.cache.ConditionalTemplateConfigurationFactory)19 StringTemplateLoader (freemarker.cache.StringTemplateLoader)18 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)18 FileNameGlobMatcher (freemarker.cache.FileNameGlobMatcher)17 TemplateLoader (freemarker.cache.TemplateLoader)16 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)15 FileWriter (java.io.FileWriter)13 ArrayList (java.util.ArrayList)13 User (org.vcell.util.document.User)13