Repository: incubator-freemarker Updated Branches: refs/heads/3 1870d0294 -> 053afbf5d
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/ConfigurableTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ConfigurableTest.java b/src/test/java/org/apache/freemarker/core/ConfigurableTest.java index 539f220..9b643b9 100644 --- a/src/test/java/org/apache/freemarker/core/ConfigurableTest.java +++ b/src/test/java/org/apache/freemarker/core/ConfigurableTest.java @@ -37,7 +37,7 @@ public class ConfigurableTest { @Test public void testGetSettingNamesAreSorted() throws Exception { - Configurable cfgable = createConfigurable(); + MutableProcessingConfiguration cfgable = createConfigurable(); for (boolean camelCase : new boolean[] { false, true }) { Collection<String> names = cfgable.getSettingNames(camelCase); String prevName = null; @@ -52,7 +52,7 @@ public class ConfigurableTest { @Test public void testStaticFieldKeysCoverAllGetSettingNames() throws Exception { - Configurable cfgable = createConfigurable(); + MutableProcessingConfiguration cfgable = createConfigurable(); Collection<String> names = cfgable.getSettingNames(false); for (String name : names) { assertTrue("No field was found for " + name, keyFieldExists(name)); @@ -61,10 +61,10 @@ public class ConfigurableTest { @Test public void testGetSettingNamesCoversAllStaticKeyFields() throws Exception { - Configurable cfgable = createConfigurable(); + MutableProcessingConfiguration cfgable = createConfigurable(); Collection<String> names = cfgable.getSettingNames(false); - for (Field f : Configurable.class.getFields()) { + for (Field f : MutableProcessingConfiguration.class.getFields()) { if (f.getName().endsWith("_KEY")) { final Object name = f.get(null); assertTrue("Missing setting name: " + name, names.contains(name)); @@ -74,19 +74,19 @@ public class ConfigurableTest { @Test public void testKeyStaticFieldsHasAllVariationsAndCorrectFormat() throws IllegalArgumentException, IllegalAccessException { - ConfigurableTest.testKeyStaticFieldsHasAllVariationsAndCorrectFormat(Configurable.class); + ConfigurableTest.testKeyStaticFieldsHasAllVariationsAndCorrectFormat(MutableProcessingConfiguration.class); } @Test public void testGetSettingNamesNameConventionsContainTheSame() throws Exception { - Configurable cfgable = createConfigurable(); + MutableProcessingConfiguration cfgable = createConfigurable(); ConfigurableTest.testGetSettingNamesNameConventionsContainTheSame( new ArrayList<>(cfgable.getSettingNames(false)), new ArrayList<>(cfgable.getSettingNames(true))); } public static void testKeyStaticFieldsHasAllVariationsAndCorrectFormat( - Class<? extends Configurable> confClass) throws IllegalArgumentException, IllegalAccessException { + Class<? extends MutableProcessingConfiguration> confClass) throws IllegalArgumentException, IllegalAccessException { // For all _KEY fields there must be a _KEY_CAMEL_CASE and a _KEY_SNAKE_CASE field. // Their content must not contradict the expected naming convention. // They _KEY filed value must be deducable from the field name @@ -160,13 +160,13 @@ public class ConfigurableTest { } } - private Configurable createConfigurable() throws IOException { + private MutableProcessingConfiguration createConfigurable() throws IOException { return new Template(null, "", new Configuration(Configuration.VERSION_3_0_0)); } private boolean keyFieldExists(String name) throws Exception { try { - Configurable.class.getField(name.toUpperCase() + "_KEY"); + MutableProcessingConfiguration.class.getField(name.toUpperCase() + "_KEY"); } catch (NoSuchFieldException e) { return false; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ConfigurationTest.java b/src/test/java/org/apache/freemarker/core/ConfigurationTest.java index ab10de1..c7e3636 100644 --- a/src/test/java/org/apache/freemarker/core/ConfigurationTest.java +++ b/src/test/java/org/apache/freemarker/core/ConfigurationTest.java @@ -259,7 +259,7 @@ public class ConfigurationTest extends TestCase { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); cfg.setLocale(Locale.GERMAN); - cfg.setDefaultEncoding(latin1); + cfg.setEncoding(latin1); TemplateConfiguration huTC = new TemplateConfiguration(); huTC.setEncoding(latin2); @@ -489,14 +489,14 @@ public class ConfigurationTest extends TestCase { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); { - cfg.setSetting(Configurable.OBJECT_WRAPPER_KEY, "defAult"); + cfg.setSetting(MutableProcessingConfiguration.OBJECT_WRAPPER_KEY, "defAult"); assertSame(Configuration.getDefaultObjectWrapper(Configuration.VERSION_3_0_0), cfg.getObjectWrapper()); DefaultObjectWrapper dow = (DefaultObjectWrapper) cfg.getObjectWrapper(); assertEquals(Configuration.VERSION_3_0_0, dow.getIncompatibleImprovements()); } { - cfg.setSetting(Configurable.OBJECT_WRAPPER_KEY, "restricted"); + cfg.setSetting(MutableProcessingConfiguration.OBJECT_WRAPPER_KEY, "restricted"); assertThat(cfg.getObjectWrapper(), instanceOf(RestrictedObjectWrapper.class)); } } @@ -780,13 +780,13 @@ public class ConfigurationTest extends TestCase { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); assertEquals(sysDefTZ, cfg.getTimeZone()); - cfg.setSetting(Configurable.TIME_ZONE_KEY, "JVM default"); + cfg.setSetting(MutableProcessingConfiguration.TIME_ZONE_KEY, "JVM default"); assertEquals(sysDefTZ, cfg.getTimeZone()); TimeZone newSysDefTZ = TimeZone.getTimeZone("GMT+09"); TimeZone.setDefault(newSysDefTZ); assertEquals(sysDefTZ, cfg.getTimeZone()); - cfg.setSetting(Configurable.TIME_ZONE_KEY, "JVM default"); + cfg.setSetting(MutableProcessingConfiguration.TIME_ZONE_KEY, "JVM default"); assertEquals(newSysDefTZ, cfg.getTimeZone()); } finally { TimeZone.setDefault(origSysDefTZ); @@ -805,10 +805,10 @@ public class ConfigurationTest extends TestCase { cfg.setSQLDateAndTimeTimeZone(null); assertNull(cfg.getSQLDateAndTimeTimeZone()); - cfg.setSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY, "JVM default"); + cfg.setSetting(MutableProcessingConfiguration.SQL_DATE_AND_TIME_TIME_ZONE_KEY, "JVM default"); assertEquals(sysDefTZ, cfg.getSQLDateAndTimeTimeZone()); - cfg.setSetting(Configurable.SQL_DATE_AND_TIME_TIME_ZONE_KEY, "null"); + cfg.setSetting(MutableProcessingConfiguration.SQL_DATE_AND_TIME_TIME_ZONE_KEY, "null"); assertNull(cfg.getSQLDateAndTimeTimeZone()); } finally { TimeZone.setDefault(origSysDefTZ); @@ -891,7 +891,7 @@ public class ConfigurationTest extends TestCase { public void testSetLogTemplateExceptionsViaSetSettingAPI() throws ConfigurationException { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); assertFalse(cfg.getLogTemplateExceptions()); - cfg.setSetting(Configurable.LOG_TEMPLATE_EXCEPTIONS_KEY, "true"); + cfg.setSetting(MutableProcessingConfiguration.LOG_TEMPLATE_EXCEPTIONS_KEY, "true"); assertTrue(cfg.getLogTemplateExceptions()); } @@ -952,7 +952,7 @@ public class ConfigurationTest extends TestCase { new Template(null, "${1?api}", cfg).process(null, _NullWriter.INSTANCE); fail(); } catch (TemplateException e) { - assertThat(e.getMessage(), containsString(Configurable.API_BUILTIN_ENABLED_KEY)); + assertThat(e.getMessage(), containsString(MutableProcessingConfiguration.API_BUILTIN_ENABLED_KEY)); } cfg.setAPIBuiltinEnabled(true); @@ -1050,13 +1050,13 @@ public class ConfigurationTest extends TestCase { assertThat(e.getMessage(), containsString("@wrong")); } - cfg.setSetting(Configurable.CUSTOM_NUMBER_FORMATS_KEY_CAMEL_CASE, + cfg.setSetting(MutableProcessingConfiguration.CUSTOM_NUMBER_FORMATS_KEY_CAMEL_CASE, "{ 'base': " + BaseNTemplateNumberFormatFactory.class.getName() + "() }"); assertEquals( Collections.singletonMap("base", BaseNTemplateNumberFormatFactory.INSTANCE), cfg.getCustomNumberFormats()); - cfg.setSetting(Configurable.CUSTOM_NUMBER_FORMATS_KEY_SNAKE_CASE, + cfg.setSetting(MutableProcessingConfiguration.CUSTOM_NUMBER_FORMATS_KEY_SNAKE_CASE, "{ " + "'base': " + BaseNTemplateNumberFormatFactory.class.getName() + "(), " + "'hex': " + HexTemplateNumberFormatFactory.class.getName() + "()" @@ -1067,11 +1067,11 @@ public class ConfigurationTest extends TestCase { "hex", HexTemplateNumberFormatFactory.INSTANCE), cfg.getCustomNumberFormats()); - cfg.setSetting(Configurable.CUSTOM_NUMBER_FORMATS_KEY, "{}"); + cfg.setSetting(MutableProcessingConfiguration.CUSTOM_NUMBER_FORMATS_KEY, "{}"); assertEquals(Collections.emptyMap(), cfg.getCustomNumberFormats()); try { - cfg.setSetting(Configurable.CUSTOM_NUMBER_FORMATS_KEY_CAMEL_CASE, + cfg.setSetting(MutableProcessingConfiguration.CUSTOM_NUMBER_FORMATS_KEY_CAMEL_CASE, "{ 'x': " + EpochMillisTemplateDateFormatFactory.class.getName() + "() }"); fail(); } catch (ConfigurationException e) { @@ -1176,13 +1176,13 @@ public class ConfigurationTest extends TestCase { assertThat(e.getMessage(), containsString("@wrong")); } - cfg.setSetting(Configurable.CUSTOM_DATE_FORMATS_KEY_CAMEL_CASE, + cfg.setSetting(MutableProcessingConfiguration.CUSTOM_DATE_FORMATS_KEY_CAMEL_CASE, "{ 'epoch': " + EpochMillisTemplateDateFormatFactory.class.getName() + "() }"); assertEquals( Collections.singletonMap("epoch", EpochMillisTemplateDateFormatFactory.INSTANCE), cfg.getCustomDateFormats()); - cfg.setSetting(Configurable.CUSTOM_DATE_FORMATS_KEY_SNAKE_CASE, + cfg.setSetting(MutableProcessingConfiguration.CUSTOM_DATE_FORMATS_KEY_SNAKE_CASE, "{ " + "'epoch': " + EpochMillisTemplateDateFormatFactory.class.getName() + "(), " + "'epochDiv': " + EpochMillisDivTemplateDateFormatFactory.class.getName() + "()" @@ -1193,11 +1193,11 @@ public class ConfigurationTest extends TestCase { "epochDiv", EpochMillisDivTemplateDateFormatFactory.INSTANCE), cfg.getCustomDateFormats()); - cfg.setSetting(Configurable.CUSTOM_DATE_FORMATS_KEY, "{}"); + cfg.setSetting(MutableProcessingConfiguration.CUSTOM_DATE_FORMATS_KEY, "{}"); assertEquals(Collections.emptyMap(), cfg.getCustomDateFormats()); try { - cfg.setSetting(Configurable.CUSTOM_DATE_FORMATS_KEY_CAMEL_CASE, + cfg.setSetting(MutableProcessingConfiguration.CUSTOM_DATE_FORMATS_KEY_CAMEL_CASE, "{ 'x': " + HexTemplateNumberFormatFactory.class.getName() + "() }"); fail(); } catch (ConfigurationException e) { @@ -1339,20 +1339,20 @@ public class ConfigurationTest extends TestCase { String defaultFileEncoding = System.getProperty("file.encoding"); assertNotNull(defaultFileEncoding); - assertEquals(defaultFileEncoding, cfg.getDefaultEncoding()); + assertEquals(defaultFileEncoding, cfg.getEncoding()); assertFalse(cfg.isDefaultEncodingExplicitlySet()); String nonDefault = defaultFileEncoding.equalsIgnoreCase("UTF-8") ? "ISO-8859-1" : "UTF-8"; - cfg.setDefaultEncoding(nonDefault); + cfg.setEncoding(nonDefault); assertTrue(cfg.isDefaultEncodingExplicitlySet()); - assertEquals(nonDefault, cfg.getDefaultEncoding()); + assertEquals(nonDefault, cfg.getEncoding()); cfg.unsetDefaultEncoding(); - assertEquals(defaultFileEncoding, cfg.getDefaultEncoding()); + assertEquals(defaultFileEncoding, cfg.getEncoding()); assertFalse(cfg.isDefaultEncodingExplicitlySet()); - cfg.setSetting(Configuration.DEFAULT_ENCODING_KEY, "JVM default"); - assertEquals(defaultFileEncoding, cfg.getDefaultEncoding()); + cfg.setSetting(Configuration.ENCODING_KEY, "JVM default"); + assertEquals(defaultFileEncoding, cfg.getEncoding()); assertTrue(cfg.isDefaultEncodingExplicitlySet()); } @@ -1421,7 +1421,7 @@ public class ConfigurationTest extends TestCase { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); Collection<String> names = cfg.getSettingNames(false); - for (Class<? extends Configurable> cfgableClass : new Class[] { Configuration.class, Configurable.class }) { + for (Class<? extends MutableProcessingConfiguration> cfgableClass : new Class[] { Configuration.class, MutableProcessingConfiguration.class }) { for (Field f : cfgableClass.getFields()) { if (f.getName().endsWith("_KEY")) { final Object name = f.get(null); @@ -1441,7 +1441,7 @@ public class ConfigurationTest extends TestCase { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); Collection<String> names = cfg.getSettingNames(false); - for (Field f : Configurable.class.getFields()) { + for (Field f : MutableProcessingConfiguration.class.getFields()) { if (f.getName().endsWith("_KEY")) { final Object name = f.get(null); assertTrue("Missing setting name: " + name, names.contains(name)); @@ -1453,10 +1453,10 @@ public class ConfigurationTest extends TestCase { public void testSetSettingSupportsBothNamingConventions() throws Exception { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); - cfg.setSetting(Configuration.DEFAULT_ENCODING_KEY_CAMEL_CASE, "UTF-16LE"); - assertEquals("UTF-16LE", cfg.getDefaultEncoding()); - cfg.setSetting(Configuration.DEFAULT_ENCODING_KEY_SNAKE_CASE, "UTF-8"); - assertEquals("UTF-8", cfg.getDefaultEncoding()); + cfg.setSetting(Configuration.ENCODING_KEY_CAMEL_CASE, "UTF-16LE"); + assertEquals("UTF-16LE", cfg.getEncoding()); + cfg.setSetting(Configuration.ENCODING_KEY_SNAKE_CASE, "UTF-8"); + assertEquals("UTF-8", cfg.getEncoding()); for (String nameCC : cfg.getSettingNames(true)) { for (String value : new String[] { "1", "default", "true" }) { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/CustomAttributeTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/CustomAttributeTest.java b/src/test/java/org/apache/freemarker/core/CustomAttributeTest.java index 6b0c1d9..cf336bd 100644 --- a/src/test/java/org/apache/freemarker/core/CustomAttributeTest.java +++ b/src/test/java/org/apache/freemarker/core/CustomAttributeTest.java @@ -24,7 +24,6 @@ import static org.junit.Assert.*; import java.math.BigDecimal; import java.util.Arrays; -import org.apache.freemarker.core.util._NullWriter; import org.junit.Test; import com.google.common.collect.ImmutableList; @@ -44,13 +43,8 @@ public class CustomAttributeTest { "s", BigDecimal.valueOf(2), Boolean.TRUE, ImmutableMap.of("a", "A")); private static final Object VALUE_BIGDECIMAL = BigDecimal.valueOf(22); - private static final CustomAttribute CUST_ATT_TMP_1 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE); - private static final CustomAttribute CUST_ATT_TMP_2 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE); - private static final CustomAttribute CUST_ATT_ENV_1 = new CustomAttribute(CustomAttribute.SCOPE_ENVIRONMENT); - private static final CustomAttribute CUST_ATT_ENV_2 = new CustomAttribute(CustomAttribute.SCOPE_ENVIRONMENT); - private static final CustomAttribute CUST_ATT_CFG_1 = new CustomAttribute(CustomAttribute.SCOPE_CONFIGURATION); - private static final CustomAttribute CUST_ATT_CFG_2 = new CustomAttribute(CustomAttribute.SCOPE_CONFIGURATION); - + private static final Object CUST_ATT_KEY = new Object(); + @Test public void testStringKey() throws Exception { Template t = new Template(null, "", new Configuration(Configuration.VERSION_3_0_0)); @@ -160,65 +154,13 @@ public class CustomAttributeTest { @Test public void testObjectKey() throws Exception { - Template t = new Template(null, "", new Configuration(Configuration.VERSION_3_0_0)); - assertNull(CUST_ATT_TMP_1.get(t)); - - CUST_ATT_TMP_1.set(VALUE_1, t); - assertSame(VALUE_1, CUST_ATT_TMP_1.get(t)); - assertEquals(0, t.getCustomAttributeNames().length); - - t.setCustomAttribute(KEY_2, VALUE_2); - assertArrayEquals(new String[] { KEY_2 }, t.getCustomAttributeNames()); - assertSame(VALUE_1, CUST_ATT_TMP_1.get(t)); - assertSame(VALUE_2, t.getCustomAttribute(KEY_2)); - - CUST_ATT_TMP_2.set(VALUE_3, t); - assertSame(VALUE_3, CUST_ATT_TMP_2.get(t)); - assertArrayEquals(new String[] { KEY_2 }, t.getCustomAttributeNames()); + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); + Template t = new Template(null, "", cfg); + assertNull(t.getCustomAttribute(CUST_ATT_KEY)); + cfg.setCustomAttribute(CUST_ATT_KEY, "cfg"); + assertEquals("cfg", t.getCustomAttribute(CUST_ATT_KEY)); + t.setCustomAttribute(CUST_ATT_KEY, "t"); + assertEquals("t", t.getCustomAttribute(CUST_ATT_KEY)); } - @Test - public void testScopes() throws Exception { - try { - assertNull(CUST_ATT_ENV_1.get()); - fail(); - } catch (IllegalStateException e) { - // Expected - } - try { - assertNull(CUST_ATT_CFG_1.get()); - fail(); - } catch (IllegalStateException e) { - // Expected - } - - final Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); - - final Template t = new Template(null, "${testScopesFromTemplateStep1()}", cfg); - Environment env = t.createProcessingEnvironment(this, _NullWriter.INSTANCE); - CUST_ATT_TMP_2.set(123, env); - CUST_ATT_ENV_2.set(1234, env); - CUST_ATT_CFG_2.set(12345, env); - env.process(); - } - - public void testScopesFromTemplateStep1() throws Exception { - assertNull(CUST_ATT_TMP_1.get()); - assertEquals(123, CUST_ATT_TMP_2.get()); - - assertNull(CUST_ATT_ENV_1.get()); - assertEquals(1234, CUST_ATT_ENV_2.get()); - - assertNull(CUST_ATT_CFG_1.get()); - assertEquals(12345, CUST_ATT_CFG_2.get()); - } - - public void testScopesFromTemplateStep2() throws Exception { - - } - - public void testScopesFromTemplateStep3() throws Exception { - - } - } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/EncodingOverrideTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/EncodingOverrideTest.java b/src/test/java/org/apache/freemarker/core/EncodingOverrideTest.java index 30d9e69..dd46cf9 100644 --- a/src/test/java/org/apache/freemarker/core/EncodingOverrideTest.java +++ b/src/test/java/org/apache/freemarker/core/EncodingOverrideTest.java @@ -59,7 +59,7 @@ public class EncodingOverrideTest { private Configuration createConfig(String charset) { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); cfg.setClassForTemplateLoading(EncodingOverrideTest.class, ""); - cfg.setDefaultEncoding(charset); + cfg.setEncoding(charset); return cfg; } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/EnvironmentCustomStateTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/EnvironmentCustomStateTest.java b/src/test/java/org/apache/freemarker/core/EnvironmentCustomStateTest.java deleted file mode 100644 index 7c9d935..0000000 --- a/src/test/java/org/apache/freemarker/core/EnvironmentCustomStateTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.freemarker.core; - -import static org.junit.Assert.*; - -import org.junit.Test; - -public class EnvironmentCustomStateTest { - - private static final Object KEY_1 = new Object(); - private static final Object KEY_2 = new Object(); - - @Test - public void test() throws Exception { - Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); - Template t = new Template(null, "", cfg); - Environment env = t.createProcessingEnvironment(null, null); - assertNull(env.getCustomState(KEY_1)); - assertNull(env.getCustomState(KEY_2)); - env.setCustomState(KEY_1, "a"); - env.setCustomState(KEY_2, "b"); - assertEquals("a", env.getCustomState(KEY_1)); - assertEquals("b", env.getCustomState(KEY_2)); - env.setCustomState(KEY_1, "c"); - env.setCustomState(KEY_2, null); - assertEquals("c", env.getCustomState(KEY_1)); - assertNull(env.getCustomState(KEY_2)); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/IncludeAndImportConfigurableLayersTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/IncludeAndImportConfigurableLayersTest.java b/src/test/java/org/apache/freemarker/core/IncludeAndImportConfigurableLayersTest.java index 3092145..a267645 100644 --- a/src/test/java/org/apache/freemarker/core/IncludeAndImportConfigurableLayersTest.java +++ b/src/test/java/org/apache/freemarker/core/IncludeAndImportConfigurableLayersTest.java @@ -301,7 +301,7 @@ public class IncludeAndImportConfigurableLayersTest extends TemplateTest { assertEquals(expectedOutput, sw.toString()); } - private void setLazynessOfConfigurable(Configurable cfg, Boolean lazyImports, Boolean lazyAutoImports, + private void setLazynessOfConfigurable(MutableProcessingConfiguration cfg, Boolean lazyImports, Boolean lazyAutoImports, boolean setLazyAutoImports) { if (lazyImports != null) { cfg.setLazyImports(lazyImports); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java b/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java index 1b36efe..66bdef6 100644 --- a/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java +++ b/src/test/java/org/apache/freemarker/core/ObjectBuilderSettingsTest.java @@ -357,17 +357,17 @@ public class ObjectBuilderSettingsTest { { Properties props = new Properties(); - props.setProperty(Configurable.OBJECT_WRAPPER_KEY, + props.setProperty(MutableProcessingConfiguration.OBJECT_WRAPPER_KEY, "org.apache.freemarker.core.model.impl.DefaultObjectWrapper(3.0.0)"); - props.setProperty(Configurable.ARITHMETIC_ENGINE_KEY, + props.setProperty(MutableProcessingConfiguration.ARITHMETIC_ENGINE_KEY, "org.apache.freemarker.core.ObjectBuilderSettingsTest$DummyArithmeticEngine"); - props.setProperty(Configurable.TEMPLATE_EXCEPTION_HANDLER_KEY, + props.setProperty(MutableProcessingConfiguration.TEMPLATE_EXCEPTION_HANDLER_KEY, "org.apache.freemarker.core.ObjectBuilderSettingsTest$DummyTemplateExceptionHandler"); props.setProperty(Configuration.CACHE_STORAGE_KEY, "org.apache.freemarker.core.ObjectBuilderSettingsTest$DummyCacheStorage()"); - props.setProperty(Configurable.NEW_BUILTIN_CLASS_RESOLVER_KEY, + props.setProperty(MutableProcessingConfiguration.NEW_BUILTIN_CLASS_RESOLVER_KEY, "org.apache.freemarker.core.ObjectBuilderSettingsTest$DummyNewBuiltinClassResolver()"); - props.setProperty(Configuration.DEFAULT_ENCODING_KEY, "utf-8"); + props.setProperty(Configuration.ENCODING_KEY, "utf-8"); props.setProperty(Configuration.TEMPLATE_LOADER_KEY, "org.apache.freemarker.core.ObjectBuilderSettingsTest$DummyTemplateLoader()"); cfg.setSettings(props); @@ -379,19 +379,19 @@ public class ObjectBuilderSettingsTest { assertEquals(DummyCacheStorage.class, cfg.getCacheStorage().getClass()); assertEquals(DummyNewBuiltinClassResolver.class, cfg.getNewBuiltinClassResolver().getClass()); assertEquals(DummyTemplateLoader.class, cfg.getTemplateLoader().getClass()); - assertEquals("utf-8", cfg.getDefaultEncoding()); + assertEquals("utf-8", cfg.getEncoding()); } { Properties props = new Properties(); - props.setProperty(Configurable.OBJECT_WRAPPER_KEY, "defAult"); - props.setProperty(Configurable.ARITHMETIC_ENGINE_KEY, + props.setProperty(MutableProcessingConfiguration.OBJECT_WRAPPER_KEY, "defAult"); + props.setProperty(MutableProcessingConfiguration.ARITHMETIC_ENGINE_KEY, "org.apache.freemarker.core.ObjectBuilderSettingsTest$DummyArithmeticEngine(x = 1)"); - props.setProperty(Configurable.TEMPLATE_EXCEPTION_HANDLER_KEY, + props.setProperty(MutableProcessingConfiguration.TEMPLATE_EXCEPTION_HANDLER_KEY, "org.apache.freemarker.core.ObjectBuilderSettingsTest$DummyTemplateExceptionHandler(x = 1)"); props.setProperty(Configuration.CACHE_STORAGE_KEY, "soft: 500, strong: 100"); - props.setProperty(Configurable.NEW_BUILTIN_CLASS_RESOLVER_KEY, + props.setProperty(MutableProcessingConfiguration.NEW_BUILTIN_CLASS_RESOLVER_KEY, "allows_nothing"); cfg.setSettings(props); assertEquals(DefaultObjectWrapper.class, cfg.getObjectWrapper().getClass()); @@ -401,14 +401,14 @@ public class ObjectBuilderSettingsTest { ((DefaultObjectWrapper) cfg.getObjectWrapper()).getIncompatibleImprovements()); assertEquals(500, ((MruCacheStorage) cfg.getCacheStorage()).getSoftSizeLimit()); assertEquals(TemplateClassResolver.ALLOWS_NOTHING_RESOLVER, cfg.getNewBuiltinClassResolver()); - assertEquals("utf-8", cfg.getDefaultEncoding()); + assertEquals("utf-8", cfg.getEncoding()); } { Properties props = new Properties(); - props.setProperty(Configurable.OBJECT_WRAPPER_KEY, "Default"); - props.setProperty(Configurable.ARITHMETIC_ENGINE_KEY, "bigdecimal"); - props.setProperty(Configurable.TEMPLATE_EXCEPTION_HANDLER_KEY, "rethrow"); + props.setProperty(MutableProcessingConfiguration.OBJECT_WRAPPER_KEY, "Default"); + props.setProperty(MutableProcessingConfiguration.ARITHMETIC_ENGINE_KEY, "bigdecimal"); + props.setProperty(MutableProcessingConfiguration.TEMPLATE_EXCEPTION_HANDLER_KEY, "rethrow"); cfg.setSettings(props); assertEquals(DefaultObjectWrapper.class, cfg.getObjectWrapper().getClass()); assertSame(BigDecimalArithmeticEngine.INSTANCE, cfg.getArithmeticEngine()); @@ -419,7 +419,7 @@ public class ObjectBuilderSettingsTest { { Properties props = new Properties(); - props.setProperty(Configurable.OBJECT_WRAPPER_KEY, "DefaultObjectWrapper(3.0.0)"); + props.setProperty(MutableProcessingConfiguration.OBJECT_WRAPPER_KEY, "DefaultObjectWrapper(3.0.0)"); cfg.setSettings(props); assertEquals(DefaultObjectWrapper.class, cfg.getObjectWrapper().getClass()); assertEquals( http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java b/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java index 2690905..07c3a35 100644 --- a/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java +++ b/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java @@ -30,6 +30,7 @@ import java.io.StringReader; import java.io.StringWriter; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -50,6 +51,7 @@ import org.apache.freemarker.core.outputformat.impl.UndefinedOutputFormat; import org.apache.freemarker.core.outputformat.impl.XMLOutputFormat; import org.apache.freemarker.core.templateresolver.ConditionalTemplateConfigurationFactory; import org.apache.freemarker.core.templateresolver.FileExtensionMatcher; +import org.apache.freemarker.core.templateresolver.FileNameGlobMatcher; import org.apache.freemarker.core.templateresolver.impl.StringTemplateLoader; import org.apache.freemarker.core.userpkg.BaseNTemplateNumberFormatFactory; import org.apache.freemarker.core.userpkg.EpochMillisDivTemplateDateFormatFactory; @@ -60,6 +62,7 @@ import org.apache.freemarker.core.userpkg.LocaleSensitiveTemplateNumberFormatFac import org.apache.freemarker.core.util._NullArgumentException; import org.apache.freemarker.core.valueformat.TemplateDateFormatFactory; import org.apache.freemarker.core.valueformat.TemplateNumberFormatFactory; +import org.apache.freemarker.test.MonitoredTemplateLoader; import org.junit.Test; import com.google.common.collect.ImmutableList; @@ -146,7 +149,7 @@ public class TemplateConfigurationTest { private static final String NON_DEFAULT_ENCODING; static { - String defaultEncoding = DEFAULT_CFG.getDefaultEncoding(); + String defaultEncoding = DEFAULT_CFG.getEncoding(); String encoding = "UTF-16"; if (encoding.equals(defaultEncoding)) { encoding = "UTF-8"; @@ -162,7 +165,7 @@ public class TemplateConfigurationTest { static { SETTING_ASSIGNMENTS = new HashMap<>(); - // "Configurable" settings: + // "MutableProcessingConfiguration" settings: SETTING_ASSIGNMENTS.put("APIBuiltinEnabled", true); SETTING_ASSIGNMENTS.put("SQLDateAndTimeTimeZone", NON_DEFAULT_TZ); SETTING_ASSIGNMENTS.put("URLEscapingCharset", "utf-16"); @@ -185,6 +188,7 @@ public class TemplateConfigurationTest { ImmutableMap.of("dummy", HexTemplateNumberFormatFactory.INSTANCE)); SETTING_ASSIGNMENTS.put("customDateFormats", ImmutableMap.of("dummy", EpochMillisTemplateDateFormatFactory.INSTANCE)); + SETTING_ASSIGNMENTS.put("customAttributes", ImmutableMap.of("dummy", 123)); // Parser-only settings: SETTING_ASSIGNMENTS.put("templateLanguage", TemplateLanguage.STATIC_TEXT); @@ -256,7 +260,7 @@ public class TemplateConfigurationTest { static { CONFIGURABLE_PROP_NAMES = new HashSet<>(); try { - for (PropertyDescriptor propDesc : Introspector.getBeanInfo(Configurable.class).getPropertyDescriptors()) { + for (PropertyDescriptor propDesc : Introspector.getBeanInfo(MutableProcessingConfiguration.class).getPropertyDescriptors()) { String propName = propDesc.getName(); if (!IGNORED_PROP_NAMES.contains(propName)) { CONFIGURABLE_PROP_NAMES.add(propName); @@ -273,10 +277,11 @@ public class TemplateConfigurationTest { // It's an interface; can't use standard Inrospector for (Method m : ParserConfiguration.class.getMethods()) { String propertyName; - if (m.getName().startsWith("get")) { - propertyName = m.getName().substring(3); - } else if (m.getName().startsWith("is")) { - propertyName = m.getName().substring(2); + String name = m.getName(); + if (name.startsWith("get")) { + propertyName = name.substring(3); + } else if (name.startsWith("is") && !name.endsWith("Set")) { + propertyName = name.substring(2); } else { propertyName = null; } @@ -295,10 +300,10 @@ public class TemplateConfigurationTest { SPECIAL_PROP_NAMES.add("encoding"); } - private static final CustomAttribute CA1 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE); - private static final CustomAttribute CA2 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE); - private static final CustomAttribute CA3 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE); - private static final CustomAttribute CA4 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE); + private static final Object CA1 = new Object(); + private static final Object CA2 = new Object(); + private static final Object CA3 = new Object(); + private static final Object CA4 = new Object(); @Test public void testMergeBasicFunctionality() throws Exception { @@ -415,19 +420,19 @@ public class TemplateConfigurationTest { tc1.setCustomAttribute("k1", "v1"); tc1.setCustomAttribute("k2", "v1"); tc1.setCustomAttribute("k3", "v1"); - CA1.set("V1", tc1); - CA2.set("V1", tc1); - CA3.set("V1", tc1); + tc1.setCustomAttribute(CA1, "V1"); + tc1.setCustomAttribute(CA2, "V1"); + tc1.setCustomAttribute(CA3, "V1"); TemplateConfiguration tc2 = new TemplateConfiguration(); tc2.setCustomAttribute("k1", "v2"); tc2.setCustomAttribute("k2", "v2"); - CA1.set("V2", tc2); - CA2.set("V2", tc2); + tc2.setCustomAttribute(CA1, "V2"); + tc2.setCustomAttribute(CA2, "V2"); TemplateConfiguration tc3 = new TemplateConfiguration(); tc3.setCustomAttribute("k1", "v3"); - CA1.set("V3", tc2); + tc3.setCustomAttribute(CA1, "V3"); tc1.merge(tc2); tc1.merge(tc3); @@ -435,37 +440,35 @@ public class TemplateConfigurationTest { assertEquals("v3", tc1.getCustomAttribute("k1")); assertEquals("v2", tc1.getCustomAttribute("k2")); assertEquals("v1", tc1.getCustomAttribute("k3")); - assertEquals("V3", CA1.get(tc1)); - assertEquals("V2", CA2.get(tc1)); - assertEquals("V1", CA3.get(tc1)); + assertEquals("V3", tc1.getCustomAttribute(CA1)); + assertEquals("V2", tc1.getCustomAttribute(CA2)); + assertEquals("V1", tc1.getCustomAttribute(CA3)); } - + @Test public void testMergeNullCustomAttributes() throws Exception { TemplateConfiguration tc1 = new TemplateConfiguration(); tc1.setCustomAttribute("k1", "v1"); tc1.setCustomAttribute("k2", "v1"); - tc1.setCustomAttribute(null, "v1"); - CA1.set("V1", tc1); - CA2.set("V1", tc1); - CA3.set(null, tc1); - + tc1.setCustomAttribute(CA1, "V1"); + tc1.setCustomAttribute(CA2,"V1"); + assertEquals("v1", tc1.getCustomAttribute("k1")); assertEquals("v1", tc1.getCustomAttribute("k2")); assertNull("v1", tc1.getCustomAttribute("k3")); - assertEquals("V1", CA1.get(tc1)); - assertEquals("V1", CA2.get(tc1)); - assertNull(CA3.get(tc1)); + assertEquals("V1", tc1.getCustomAttribute(CA1)); + assertEquals("V1", tc1.getCustomAttribute(CA2)); + assertNull(tc1.getCustomAttribute(CA3)); TemplateConfiguration tc2 = new TemplateConfiguration(); tc2.setCustomAttribute("k1", "v2"); tc2.setCustomAttribute("k2", null); - CA1.set("V2", tc2); - CA2.set(null, tc2); + tc2.setCustomAttribute(CA1, "V2"); + tc2.setCustomAttribute(CA2, null); TemplateConfiguration tc3 = new TemplateConfiguration(); tc3.setCustomAttribute("k1", null); - CA1.set(null, tc2); + tc2.setCustomAttribute(CA1, null); tc1.merge(tc2); tc1.merge(tc3); @@ -473,24 +476,24 @@ public class TemplateConfigurationTest { assertNull(tc1.getCustomAttribute("k1")); assertNull(tc1.getCustomAttribute("k2")); assertNull(tc1.getCustomAttribute("k3")); - assertNull(CA1.get(tc1)); - assertNull(CA2.get(tc1)); - assertNull(CA3.get(tc1)); - + assertNull(tc1.getCustomAttribute(CA1)); + assertNull(tc1.getCustomAttribute(CA2)); + assertNull(tc1.getCustomAttribute(CA3)); + TemplateConfiguration tc4 = new TemplateConfiguration(); tc4.setCustomAttribute("k1", "v4"); - CA1.set("V4", tc4); - + tc4.setCustomAttribute(CA1, "V4"); + tc1.merge(tc4); - + assertEquals("v4", tc1.getCustomAttribute("k1")); assertNull(tc1.getCustomAttribute("k2")); assertNull(tc1.getCustomAttribute("k3")); - assertEquals("V4", CA1.get(tc1)); - assertNull(CA2.get(tc1)); - assertNull(CA3.get(tc1)); + assertEquals("V4", tc1.getCustomAttribute(CA1)); + assertNull(tc1.getCustomAttribute(CA2)); + assertNull(tc1.getCustomAttribute(CA3)); } - + @Test public void applyOrder() throws Exception { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); @@ -567,17 +570,17 @@ public class TemplateConfigurationTest { tc.setCustomAttribute("k4", "tc"); tc.setCustomAttribute("k5", "tc"); tc.setCustomAttribute("k6", "tc"); - CA1.set("tc", tc); - CA2.set("tc", tc); - CA3.set("tc", tc); + tc.setCustomAttribute(CA1, "tc"); + tc.setCustomAttribute(CA2,"tc"); + tc.setCustomAttribute(CA3,"tc"); Template t = new Template(null, "", cfg); t.setCustomAttribute("k5", "t"); t.setCustomAttribute("k6", null); t.setCustomAttribute("k7", "t"); - CA2.set("t", t); - CA3.set(null, t); - CA4.set("t", t); + t.setCustomAttribute(CA2, "t"); + t.setCustomAttribute(CA3, null); + t.setCustomAttribute(CA4, "t"); tc.setParentConfiguration(cfg); tc.apply(t); @@ -589,10 +592,10 @@ public class TemplateConfigurationTest { assertEquals("t", t.getCustomAttribute("k5")); assertNull(t.getCustomAttribute("k6")); assertEquals("t", t.getCustomAttribute("k7")); - assertEquals("tc", CA1.get(t)); - assertEquals("t", CA2.get(t)); - assertNull(CA3.get(t)); - assertEquals("t", CA4.get(t)); + assertEquals("tc", t.getCustomAttribute(CA1)); + assertEquals("t", t.getCustomAttribute(CA2)); + assertNull(t.getCustomAttribute(CA3)); + assertEquals("t", t.getCustomAttribute(CA4)); } @Test @@ -711,7 +714,42 @@ public class TemplateConfigurationTest { testedProps.add(Configuration.TEMPLATE_LANGUAGE_KEY_CAMEL_CASE); } - assertEquals("Check that you have tested all parser settings; ", PARSER_PROP_NAMES, testedProps); + { + // As the TemplateLanguage-based parser selection happens in the TemplateResolver, we can't use + // assertOutput here, as that hard-coded to create an FTL Template. + + TemplateConfiguration tc = new TemplateConfiguration(); + tc.setEncoding("ISO-8859-1"); + + Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); + cfg.setEncoding("utf-8"); + cfg.setTemplateConfigurations(new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher + ("latin1.ftl"), tc)); + + MonitoredTemplateLoader templateLoader = new MonitoredTemplateLoader(); + templateLoader.putBinaryTemplate("utf8.ftl", "próba", StandardCharsets.UTF_8, 1); + templateLoader.putBinaryTemplate("latin1.ftl", "próba", StandardCharsets.ISO_8859_1, 1); + cfg.setTemplateLoader(templateLoader); + + { + StringWriter out = new StringWriter(); + cfg.getTemplate("utf8.ftl").process(null, out); + assertEquals("próba", out.toString()); + } + { + StringWriter out = new StringWriter(); + cfg.getTemplate("latin1.ftl").process(null, out); + assertEquals("próba", out.toString()); + } + + testedProps.add(Configuration.ENCODING_KEY_CAMEL_CASE); + } + + if (!PARSER_PROP_NAMES.equals(testedProps)) { + Set<String> diff = new HashSet<>(PARSER_PROP_NAMES); + diff.removeAll(testedProps); + fail("Some settings weren't checked: " + diff); + } } @Test @@ -940,7 +978,7 @@ public class TemplateConfigurationTest { String cfgMethodName = readMethod.getName(); if (cfgMethodName.equals("getEncoding")) { // Because Configuration has local-to-encoding map too, this has a different name there. - cfgMethodName = "getDefaultEncoding"; + cfgMethodName = "getEncoding"; } Method cfgMethod = DEFAULT_CFG.getClass().getMethod(cfgMethodName, readMethod.getParameterTypes()); Object defaultSettingValue = cfgMethod.invoke(DEFAULT_CFG); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java b/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java index 700e718..34068e5 100644 --- a/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java +++ b/src/test/java/org/apache/freemarker/core/TemplateConfigurationWithDefaltTemplateResolverTest.java @@ -37,8 +37,8 @@ public class TemplateConfigurationWithDefaltTemplateResolverTest { private static final String TEXT_WITH_ACCENTS = "pr\u00F3ba"; - private static final CustomAttribute CUST_ATT_1 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE); - private static final CustomAttribute CUST_ATT_2 = new CustomAttribute(CustomAttribute.SCOPE_TEMPLATE); + private static final Object CUST_ATT_1 = new Object(); + private static final Object CUST_ATT_2 = new Object(); @Test public void testEncoding() throws Exception { @@ -168,12 +168,12 @@ public class TemplateConfigurationWithDefaltTemplateResolverTest { tc1.setCustomAttribute("a1", "a1tc1"); tc1.setCustomAttribute("a2", "a2tc1"); tc1.setCustomAttribute("a3", "a3tc1"); - CUST_ATT_1.set("ca1tc1", tc1); - CUST_ATT_2.set("ca2tc1", tc1); + tc1.setCustomAttribute(CUST_ATT_1, "ca1tc1"); + tc1.setCustomAttribute(CUST_ATT_2, "ca2tc1"); TemplateConfiguration tc2 = new TemplateConfiguration(); tc2.setCustomAttribute("a1", "a1tc2"); - CUST_ATT_1.set("ca1tc2", tc2); + tc2.setCustomAttribute(CUST_ATT_1, "ca1tc2"); cfg.setTemplateConfigurations( new MergingTemplateConfigurationFactory( @@ -195,32 +195,32 @@ public class TemplateConfigurationWithDefaltTemplateResolverTest { assertEquals("a1tc1", t.getCustomAttribute("a1")); assertEquals("a2tc1", t.getCustomAttribute("a2")); assertEquals("a3temp", t.getCustomAttribute("a3")); - assertEquals("ca1tc1", CUST_ATT_1.get(t)); - assertEquals("ca2tc1", CUST_ATT_2.get(t)); + assertEquals("ca1tc1", t.getCustomAttribute(CUST_ATT_1)); + assertEquals("ca2tc1", t.getCustomAttribute(CUST_ATT_2)); } { Template t = cfg.getTemplate("(tc1)noHeader"); assertEquals("a1tc1", t.getCustomAttribute("a1")); assertEquals("a2tc1", t.getCustomAttribute("a2")); assertEquals("a3tc1", t.getCustomAttribute("a3")); - assertEquals("ca1tc1", CUST_ATT_1.get(t)); - assertEquals("ca2tc1", CUST_ATT_2.get(t)); + assertEquals("ca1tc1", t.getCustomAttribute(CUST_ATT_1)); + assertEquals("ca2tc1", t.getCustomAttribute(CUST_ATT_2)); } { Template t = cfg.getTemplate("(tc2)"); assertEquals("a1tc2", t.getCustomAttribute("a1")); assertNull(t.getCustomAttribute("a2")); assertEquals("a3temp", t.getCustomAttribute("a3")); - assertEquals("ca1tc2", CUST_ATT_1.get(t)); - assertNull(CUST_ATT_2.get(t)); + assertEquals("ca1tc2", t.getCustomAttribute(CUST_ATT_1)); + assertNull(t.getCustomAttribute(CUST_ATT_2)); } { Template t = cfg.getTemplate("(tc1)(tc2)"); assertEquals("a1tc2", t.getCustomAttribute("a1")); assertEquals("a2tc1", t.getCustomAttribute("a2")); assertEquals("a3temp", t.getCustomAttribute("a3")); - assertEquals("ca1tc2", CUST_ATT_1.get(t)); - assertEquals("ca2tc1", CUST_ATT_2.get(t)); + assertEquals("ca1tc2", t.getCustomAttribute(CUST_ATT_1)); + assertEquals("ca2tc1", t.getCustomAttribute(CUST_ATT_2)); } } @@ -232,7 +232,7 @@ public class TemplateConfigurationWithDefaltTemplateResolverTest { private Configuration createCommonEncodingTesterConfig() throws UnsupportedEncodingException { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); - cfg.setDefaultEncoding("iso-8859-1"); + cfg.setEncoding("iso-8859-1"); cfg.setLocale(Locale.US); ByteArrayTemplateLoader tl = new ByteArrayTemplateLoader(); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java b/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java index cec01d7..3a83bca 100644 --- a/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java +++ b/src/test/java/org/apache/freemarker/core/TemplateConstructorsTest.java @@ -35,7 +35,7 @@ public class TemplateConstructorsTest { @Test public void test() throws IOException { final Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); - //cfg.setDefaultEncoding("ISO-8859-1"); + //cfg.setEncoding("ISO-8859-1"); final String name = "foo/bar.ftl"; final String sourceName = "foo/bar_de.ftl"; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java b/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java index c387d36..9669369 100644 --- a/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java +++ b/src/test/java/org/apache/freemarker/core/TemplateGetEncodingTest.java @@ -34,7 +34,7 @@ public class TemplateGetEncodingTest { public void test() throws IOException { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); { - cfg.setDefaultEncoding("ISO-8859-2"); + cfg.setEncoding("ISO-8859-2"); MonitoredTemplateLoader tl = new MonitoredTemplateLoader(); tl.putBinaryTemplate("bin", "test"); tl.putBinaryTemplate("bin-static", "<#test>"); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java b/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java index a80305d..598df6b 100644 --- a/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java +++ b/src/test/java/org/apache/freemarker/core/templateresolver/DefaultTemplateResolverTest.java @@ -273,7 +273,7 @@ public class DefaultTemplateResolverTest { public void testWrongEncodingReload() throws IOException { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); cfg.setLocale(Locale.US); - cfg.setDefaultEncoding("utf-8"); + cfg.setEncoding("utf-8"); MonitoredTemplateLoader tl = new MonitoredTemplateLoader(); tl.putBinaryTemplate("utf-8_en.ftl", "<#ftl encoding='utf-8'>Béka"); @@ -320,7 +320,7 @@ public class DefaultTemplateResolverTest { public void testNoWrongEncodingForTemplateLoader2WithReader() throws IOException { Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); cfg.setLocale(Locale.US); - cfg.setDefaultEncoding("utf-8"); + cfg.setEncoding("utf-8"); MonitoredTemplateLoader tl = new MonitoredTemplateLoader(); tl.putTextTemplate("foo_en.ftl", "<#ftl encoding='utf-8'>Å"); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/manualtest/GettingStartedExample.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/manualtest/GettingStartedExample.java b/src/test/java/org/apache/freemarker/manualtest/GettingStartedExample.java index 04fa57d..f03e417 100644 --- a/src/test/java/org/apache/freemarker/manualtest/GettingStartedExample.java +++ b/src/test/java/org/apache/freemarker/manualtest/GettingStartedExample.java @@ -38,7 +38,7 @@ public class GettingStartedExample { /* Create and adjust the configuration singleton */ Configuration cfg = new Configuration(Configuration.VERSION_3_0_0); cfg.setClassForTemplateLoading(GettingStartedExample.class, ""); - cfg.setDefaultEncoding("UTF-8"); + cfg.setEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setLogTemplateExceptions(false); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java b/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java index b2d6476..bd84755 100644 --- a/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java +++ b/src/test/java/org/apache/freemarker/manualtest/TemplateConfigurationExamples.java @@ -115,7 +115,7 @@ public class TemplateConfigurationExamples extends ExamplesTest { @Test public void example3() throws Exception { Configuration cfg = getConfiguration(); - cfg.setDefaultEncoding("ISO-8859-1"); + cfg.setEncoding("ISO-8859-1"); cfg.setSharedVariable("ts", new Date(1440431606011L)); addTemplate("t.stats.html", "${ts?datetime} ${ts?date} ${ts?time}"); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java b/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java index 28edd83..0a3da35 100644 --- a/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java +++ b/src/test/java/org/apache/freemarker/servlet/FreemarkerServletTest.java @@ -412,7 +412,7 @@ public class FreemarkerServletTest { } MockServletConfig servletConfig = new MockServletConfig(servletContext); - servletConfig.addInitParameter(Configuration.DEFAULT_ENCODING_KEY, "UTF-8"); + servletConfig.addInitParameter(Configuration.ENCODING_KEY, "UTF-8"); if (ctInitParam != null) { servletConfig.addInitParameter(INIT_PARAM_CONTENT_TYPE, ctInitParam); } @@ -540,7 +540,7 @@ public class FreemarkerServletTest { // Set a test runner environment independent default locale: cfg.setLocale(DEFAULT_LOCALE); - cfg.setDefaultEncoding(CFG_DEFAULT_ENCODING); + cfg.setEncoding(CFG_DEFAULT_ENCODING); { TemplateConfiguration outUtf8TC = new TemplateConfiguration(); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/test/TemplateTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/test/TemplateTest.java b/src/test/java/org/apache/freemarker/test/TemplateTest.java index d2eeb72..31ad3e0 100644 --- a/src/test/java/org/apache/freemarker/test/TemplateTest.java +++ b/src/test/java/org/apache/freemarker/test/TemplateTest.java @@ -78,7 +78,7 @@ public abstract class TemplateTest { configuration.setLocale(Locale.US); } if (!configuration.isDefaultEncodingExplicitlySet()) { - configuration.setDefaultEncoding(StandardCharsets.UTF_8.name()); + configuration.setEncoding(StandardCharsets.UTF_8.name()); } if (!configuration.isTimeZoneExplicitlySet()) { configuration.setTimeZone(TimeZone.getTimeZone("GMT+1")); http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java b/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java index b2f8c26..fccef43 100644 --- a/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java +++ b/src/test/java/org/apache/freemarker/test/templatesuite/TemplateTestCase.java @@ -147,7 +147,7 @@ public class TemplateTestCase extends FileTestCase { String alias = st.nextToken(); conf.addAutoImport(alias, libname); } else if ("input_encoding".equals(param)) { - conf.setDefaultEncoding(value); + conf.setEncoding(value); // INCOMPATIBLE_IMPROVEMENTS is a list here, and was already set in the constructor. } else if (!Configuration.INCOMPATIBLE_IMPROVEMENTS_KEY.equals(param)) { try { http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/basic/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/basic/WEB-INF/web.xml b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/basic/WEB-INF/web.xml index e8ce83e..e84ca81 100644 --- a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/basic/WEB-INF/web.xml +++ b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/basic/WEB-INF/web.xml @@ -71,7 +71,7 @@ <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. --> </init-param> <init-param> - <param-name>default_encoding</param-name> + <param-name>encoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param> @@ -110,7 +110,7 @@ <param-value>en_US</param-value> </init-param> <init-param> - <param-name>default_encoding</param-name> + <param-name>encoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/multipleLoaders/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/multipleLoaders/WEB-INF/web.xml b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/multipleLoaders/WEB-INF/web.xml index 72e1c6e..f83c942 100644 --- a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/multipleLoaders/WEB-INF/web.xml +++ b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/multipleLoaders/WEB-INF/web.xml @@ -51,7 +51,7 @@ <param-value>rethrow</param-value> </init-param> <init-param> - <param-name>default_encoding</param-name> + <param-name>encoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/tldDiscovery/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/tldDiscovery/WEB-INF/web.xml b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/tldDiscovery/WEB-INF/web.xml index 0b6e76f..3508238 100644 --- a/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/tldDiscovery/WEB-INF/web.xml +++ b/src/test/resources/org/apache/freemarker/servlet/jsp/webapps/tldDiscovery/WEB-INF/web.xml @@ -71,7 +71,7 @@ <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. --> </init-param> <init-param> - <param-name>default_encoding</param-name> + <param-name>encoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param> @@ -125,7 +125,7 @@ <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. --> </init-param> <init-param> - <param-name>default_encoding</param-name> + <param-name>encoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/053afbf5/src/test/resources/org/apache/freemarker/test/servlet/web.xml ---------------------------------------------------------------------- diff --git a/src/test/resources/org/apache/freemarker/test/servlet/web.xml b/src/test/resources/org/apache/freemarker/test/servlet/web.xml index 51eb42a..b54ea92 100644 --- a/src/test/resources/org/apache/freemarker/test/servlet/web.xml +++ b/src/test/resources/org/apache/freemarker/test/servlet/web.xml @@ -69,7 +69,7 @@ <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. --> </init-param> <init-param> - <param-name>default_encoding</param-name> + <param-name>encoding</param-name> <param-value>UTF-8</param-value> <!-- The encoding of the template files. --> </init-param> <init-param>
