FREEMARKER-54: Adding autoImports property example in unit test
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/2c5a4fda Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/2c5a4fda Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/2c5a4fda Branch: refs/heads/3 Commit: 2c5a4fda1bd0abed5d62c5b27ec5d26cc452b071 Parents: 87da456 Author: Woonsan Ko <woon...@apache.org> Authored: Mon Jun 19 00:25:14 2017 -0400 Committer: Woonsan Ko <woon...@apache.org> Committed: Mon Jun 19 00:25:14 2017 -0400 ---------------------------------------------------------------------- .../spring/ConfigurationFactoryBeanTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/2c5a4fda/freemarker-spring/src/test/java/org/apache/freemarker/spring/ConfigurationFactoryBeanTest.java ---------------------------------------------------------------------- diff --git a/freemarker-spring/src/test/java/org/apache/freemarker/spring/ConfigurationFactoryBeanTest.java b/freemarker-spring/src/test/java/org/apache/freemarker/spring/ConfigurationFactoryBeanTest.java index cccc9be..010664b 100644 --- a/freemarker-spring/src/test/java/org/apache/freemarker/spring/ConfigurationFactoryBeanTest.java +++ b/freemarker-spring/src/test/java/org/apache/freemarker/spring/ConfigurationFactoryBeanTest.java @@ -37,6 +37,7 @@ import org.apache.freemarker.core.Template; import org.apache.freemarker.core.TemplateLanguage; import org.apache.freemarker.core.Version; import org.apache.freemarker.core.model.impl.RestrictedObjectWrapper; +import org.apache.freemarker.core.outputformat.impl.PlainTextOutputFormat; import org.apache.freemarker.core.templateresolver.CacheStorage; import org.apache.freemarker.core.templateresolver.impl.MruCacheStorage; import org.apache.freemarker.core.templateresolver.impl.StringTemplateLoader; @@ -70,6 +71,7 @@ public class ConfigurationFactoryBeanTest { final Properties settings = new Properties(); settings.setProperty(MutableParsingAndProcessingConfiguration.SOURCE_ENCODING_KEY, "UTF-8"); + settings.setProperty(MutableParsingAndProcessingConfiguration.OUTPUT_FORMAT_KEY, "PlainTextOutputFormat()"); settings.setProperty(MutableParsingAndProcessingConfiguration.WHITESPACE_STRIPPING_KEY, "true"); settings.setProperty(MutableParsingAndProcessingConfiguration.AUTO_ESCAPING_POLICY_KEY, "enableIfSupported"); settings.setProperty(MutableParsingAndProcessingConfiguration.RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY, "true"); @@ -85,6 +87,10 @@ public class ConfigurationFactoryBeanTest { sharedVars.put("sharedVar1", "sharedVal1"); sharedVars.put("sharedVar2", "sharedVal2"); + final Map<String, String> autoImports = new HashMap<>(); + autoImports.put("mylib1", "/libs/mylib1.ftl"); + autoImports.put("mylib2", "/libs/mylib2.ftl"); + final StringTemplateLoader templateLoader = new StringTemplateLoader(); templateLoader.putTemplate("fooTemplate", "foo"); @@ -106,6 +112,12 @@ public class ConfigurationFactoryBeanTest { // <entry key="sharedVar2" value="sharedVal2" /> // </map> // </property> + // <property name="autoImports"> + // <map> + // <entry key="mylib1" value="/libs/mylib1.ftl" /> + // <entry key="mylib2" value="/libs/mylib2.ftl" /> + // </map> + // </property> // <property name="templateUpdateDelayMilliseconds" value="60000" /> // <property name="localizedTemplateLookup" value="false" /> // <property name="templateLoader"> @@ -119,6 +131,7 @@ public class ConfigurationFactoryBeanTest { .addPropertyValue("incompatibleImprovements", "3.0.0") .addPropertyValue("settings", settings) .addPropertyValue("sharedVariables", sharedVars) + .addPropertyValue("autoImports", autoImports) .addPropertyValue("templateUpdateDelayMilliseconds", 60000) .addPropertyValue("localizedTemplateLookup", "false") .addPropertyValue("templateLoader", templateLoader) @@ -135,6 +148,7 @@ public class ConfigurationFactoryBeanTest { assertEquals(new Version(3, 0, 0), config.getIncompatibleImprovements()); assertEquals(Charset.forName("UTF-8"), config.getSourceEncoding()); + assertEquals(PlainTextOutputFormat.INSTANCE.getName(), config.getOutputFormat().getName()); assertTrue(config.isWhitespaceStrippingSet()); assertEquals(AutoEscapingPolicy.ENABLE_IF_SUPPORTED, config.getAutoEscapingPolicy()); assertTrue(config.isRecognizeStandardFileExtensionsSet()); @@ -154,6 +168,9 @@ public class ConfigurationFactoryBeanTest { assertEquals("sharedVal1", config.getSharedVariables().get("sharedVar1")); assertEquals("sharedVal2", config.getSharedVariables().get("sharedVar2")); + assertEquals("/libs/mylib1.ftl", config.getAutoImports().get("mylib1")); + assertEquals("/libs/mylib2.ftl", config.getAutoImports().get("mylib2")); + final Template fooTemplate = config.getTemplate("fooTemplate"); assertEquals("foo", fooTemplate.toString()); }