freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [2/4] incubator-freemarker git commit: Made Template immutable (via public API-s). Template-specific settings now can only come from the TemplateConfiguration associated to the template, or from the #ftl header for some settings (most notably for custom
Date Tue, 11 Apr 2017 20:05:16 GMT
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0356b30b/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/OutputFormatTest.java b/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
index 224e953..64fad5f 100644
--- a/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
+++ b/src/test/java/org/apache/freemarker/core/OutputFormatTest.java
@@ -276,23 +276,23 @@ public class OutputFormatTest extends TemplateTest {
             {
                 Template t = cfg.getTemplate("t");
                 if (cfgAutoEscaping) {
-                    assertTrue(t.getAutoEscaping());
+                    assertEquals(Configuration.ENABLE_IF_DEFAULT_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
                     assertOutput(t, "a&b");
                 } else {
-                    assertFalse(t.getAutoEscaping());
+                    assertEquals(Configuration.DISABLE_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
                     assertOutput(t, "a&b");
                 }
             }
             
             {
                 Template t = cfg.getTemplate("tWithHeaderFalse");
-                assertFalse(t.getAutoEscaping());
+                assertEquals(Configuration.DISABLE_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
                 assertOutput(t, "a&b");
             }
             
             {
                 Template t = cfg.getTemplate("tWithHeaderTrue");
-                assertTrue(t.getAutoEscaping());
+                assertEquals(Configuration.ENABLE_IF_SUPPORTED_AUTO_ESCAPING_POLICY, t.getAutoEscapingPolicy());
                 assertOutput(t, "a&b");
             }
             

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0356b30b/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 6f6b7f3..5d57e48 100644
--- a/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java
+++ b/src/test/java/org/apache/freemarker/core/TemplateConfigurationTest.java
@@ -18,7 +18,6 @@
  */
 package org.apache.freemarker.core;
 
-import static org.hamcrest.Matchers.*;
 import static org.junit.Assert.*;
 
 import java.beans.BeanInfo;
@@ -60,7 +59,6 @@ import org.apache.freemarker.core.userpkg.EpochMillisTemplateDateFormatFactory;
 import org.apache.freemarker.core.userpkg.HexTemplateNumberFormatFactory;
 import org.apache.freemarker.core.userpkg.LocAndTZSensitiveTemplateDateFormatFactory;
 import org.apache.freemarker.core.userpkg.LocaleSensitiveTemplateNumberFormatFactory;
-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;
@@ -276,9 +274,9 @@ public class TemplateConfigurationTest {
     }
 
     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();
+    private static final String CA2 = "ca2";
+    private static final String CA3 = "ca3";
+    private static final String CA4 = "ca4";
 
     @Test
     public void testMergeBasicFunctionality() throws Exception {
@@ -472,52 +470,6 @@ public class TemplateConfigurationTest {
     }
 
     @Test
-    public void applyOrder() throws Exception {
-        Configuration cfg = new Configuration(Configuration.VERSION_3_0_0);
-        Template t = new Template(null, "", cfg);
-        
-        {
-            TemplateConfiguration.Builder  tcb = new TemplateConfiguration.Builder();
-            tcb.setBooleanFormat("Y,N");
-            tcb.setAutoImports(ImmutableMap.of("a", "a.ftl", "b", "b.ftl", "c", "c.ftl"));
-            tcb.setAutoIncludes(ImmutableList.of("i1.ftl", "i2.ftl", "i3.ftl"));
-            tcb.setCustomNumberFormats(ImmutableMap.of(
-                    "a", HexTemplateNumberFormatFactory.INSTANCE,
-                    "b", LocaleSensitiveTemplateNumberFormatFactory.INSTANCE));
-
-            TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(cfg);
-            tc.apply(t);
-        }
-        assertEquals("Y,N", t.getBooleanFormat());
-        assertEquals(ImmutableMap.of("a", "a.ftl", "b", "b.ftl", "c", "c.ftl"), t.getAutoImports());
-        assertEquals(ImmutableList.of("a", "b", "c"), new ArrayList<>(t.getAutoImports().keySet()));
-        assertEquals(ImmutableList.of("i1.ftl", "i2.ftl", "i3.ftl"), t.getAutoIncludes());
-        
-        {
-            TemplateConfiguration.Builder  tcb = new TemplateConfiguration.Builder();
-            tcb.setBooleanFormat("J,N");
-            tcb.setAutoImports(ImmutableMap.of("b", "b2.ftl", "d", "d.ftl"));
-            tcb.setAutoIncludes(ImmutableList.of("i2.ftl", "i4.ftl"));
-            tcb.setCustomNumberFormats(ImmutableMap.of(
-                    "b", BaseNTemplateNumberFormatFactory.INSTANCE,
-                    "c", BaseNTemplateNumberFormatFactory.INSTANCE));
-            TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(cfg);
-            tc.apply(t);
-        }
-        assertEquals("Y,N", t.getBooleanFormat());
-        assertEquals(ImmutableMap.of("d", "d.ftl", "a", "a.ftl", "b", "b.ftl", "c", "c.ftl"),
t.getAutoImports());
-        assertEquals(ImmutableList.of("d", "a", "b", "c"), new ArrayList<>(t.getAutoImports().keySet()));
-        assertEquals(ImmutableList.of("i4.ftl", "i1.ftl", "i2.ftl", "i3.ftl"), t.getAutoIncludes());
-        assertEquals(ImmutableMap.of( //
-                "b", LocaleSensitiveTemplateNumberFormatFactory.INSTANCE, //
-                "c", BaseNTemplateNumberFormatFactory.INSTANCE, //
-                "a", HexTemplateNumberFormatFactory.INSTANCE), //
-                t.getCustomNumberFormats());
-    }
-
-    @Test
     public void testConfigureNonParserConfig() throws Exception {
         for (PropertyDescriptor pd : getTemplateConfigurationSettingPropDescs(
                 TemplateConfiguration.Builder.class, false)) {
@@ -526,14 +478,16 @@ public class TemplateConfigurationTest {
             Object newValue = SETTING_ASSIGNMENTS.get(pd.getName());
             pd.getWriteMethod().invoke(tcb, newValue);
             
-            Template t = new Template(null, "", DEFAULT_CFG);
-            Method tReaderMethod = t.getClass().getMethod(pd.getReadMethod().getName());
-            
-            assertNotEquals("For \"" + pd.getName() + "\"", newValue, tReaderMethod.invoke(t));
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
-            tc.apply(t);
-            assertEquals("For \"" + pd.getName() + "\"", newValue, tReaderMethod.invoke(t));
+
+            Method tReaderMethod = Template.class.getMethod(pd.getReadMethod().getName());
+
+            // Without TC
+            assertNotEquals("For \"" + pd.getName() + "\"", newValue,
+                    tReaderMethod.invoke(new Template(null, "", DEFAULT_CFG)));
+            // With TC
+            assertEquals("For \"" + pd.getName() + "\"", newValue,
+                    tReaderMethod.invoke(new Template(null, "", DEFAULT_CFG, tc)));
         }
     }
     
@@ -554,7 +508,8 @@ public class TemplateConfigurationTest {
         tcb.setCustomAttribute(CA2,"tc");
         tcb.setCustomAttribute(CA3,"tc");
 
-        Template t = new Template(null, "", cfg);
+        TemplateConfiguration tc = tcb.build();
+        Template t = new Template(null, "", cfg, tc);
         t.setCustomAttribute("k5", "t");
         t.setCustomAttribute("k6", null);
         t.setCustomAttribute("k7", "t");
@@ -562,10 +517,6 @@ public class TemplateConfigurationTest {
         t.setCustomAttribute(CA3, null);
         t.setCustomAttribute(CA4, "t");
 
-        TemplateConfiguration tc = tcb.build();
-        tc.setParentConfiguration(cfg);
-        tc.apply(t);
-        
         assertEquals("c", t.getCustomAttribute("k1"));
         assertEquals("tc", t.getCustomAttribute("k2"));
         assertNull(t.getCustomAttribute("k3"));
@@ -587,7 +538,6 @@ public class TemplateConfigurationTest {
             TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
             tcb.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX);
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
             assertOutputWithoutAndWithTC(tc, "[#if true]y[/#if]", "[#if true]y[/#if]", "y");
             testedProps.add(Configuration.TAG_SYNTAX_KEY_CAMEL_CASE);
         }
@@ -596,7 +546,6 @@ public class TemplateConfigurationTest {
             TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
             tcb.setNamingConvention(Configuration.CAMEL_CASE_NAMING_CONVENTION);
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
             assertOutputWithoutAndWithTC(tc, "<#if true>y<#elseif false>n</#if>",
"y", null);
             testedProps.add(Configuration.NAMING_CONVENTION_KEY_CAMEL_CASE);
         }
@@ -605,7 +554,6 @@ public class TemplateConfigurationTest {
             TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
             tcb.setWhitespaceStripping(false);
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
             assertOutputWithoutAndWithTC(tc, "<#if true>\nx\n</#if>\n", "x\n",
"\nx\n\n");
             testedProps.add(Configuration.WHITESPACE_STRIPPING_KEY_CAMEL_CASE);
         }
@@ -614,7 +562,6 @@ public class TemplateConfigurationTest {
             TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
             tcb.setArithmeticEngine(new DummyArithmeticEngine());
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
             assertOutputWithoutAndWithTC(tc, "${1} ${1+1}", "1 2", "11 22");
             testedProps.add(Configuration.ARITHMETIC_ENGINE_KEY_CAMEL_CASE);
         }
@@ -623,7 +570,6 @@ public class TemplateConfigurationTest {
             TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
             tcb.setOutputFormat(XMLOutputFormat.INSTANCE);
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
             assertOutputWithoutAndWithTC(tc, "${.outputFormat} ${\"a'b\"}",
                     UndefinedOutputFormat.INSTANCE.getName() + " a'b",
                     XMLOutputFormat.INSTANCE.getName() + " a&apos;b");
@@ -635,7 +581,6 @@ public class TemplateConfigurationTest {
             tcb.setOutputFormat(XMLOutputFormat.INSTANCE);
             tcb.setAutoEscapingPolicy(Configuration.DISABLE_AUTO_ESCAPING_POLICY);
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
             assertOutputWithoutAndWithTC(tc, "${'a&b'}", "a&b", "a&b");
             testedProps.add(Configuration.AUTO_ESCAPING_POLICY_KEY_CAMEL_CASE);
         }
@@ -654,7 +599,6 @@ public class TemplateConfigurationTest {
             TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
             tcb.setRecognizeStandardFileExtensions(false);
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
             assertOutputWithoutAndWithTC(tc, "adhoc.ftlh", "${.outputFormat}",
                     HTMLOutputFormat.INSTANCE.getName(), UndefinedOutputFormat.INSTANCE.getName());
             testedProps.add(Configuration.RECOGNIZE_STANDARD_FILE_EXTENSIONS_KEY_CAMEL_CASE);
@@ -665,7 +609,6 @@ public class TemplateConfigurationTest {
             tcb.setLogTemplateExceptions(false);
             tcb.setTabSize(3);
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
             assertOutputWithoutAndWithTC(tc,
                     "<#attempt><@'\\t$\\{1+}'?interpret/><#recover>"
                     + "${.error?replace('(?s).*?column ([0-9]+).*', '$1', 'r')}"
@@ -744,17 +687,16 @@ public class TemplateConfigurationTest {
     
     @Test
     public void testArithmeticEngine() throws TemplateException, IOException {
-        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
-        tcb.setArithmeticEngine(new DummyArithmeticEngine());
-        TemplateConfiguration tc = tcb.build();
-        tc.setParentConfiguration(DEFAULT_CFG);
+        TemplateConfiguration tc = new TemplateConfiguration.Builder()
+                .arithmeticEngine(new DummyArithmeticEngine())
+                .build();
         assertOutputWithoutAndWithTC(tc,
                 "<#setting locale='en_US'>${1} ${1+1} ${1*3} <#assign x = 1>${x
+ x} ${x * 3}",
                 "1 2 3 2 3", "11 22 33 22 33");
         
-        // Doesn't affect template.arithmeticEngine, only affects the parsing:
+        // Does affect template.arithmeticEngine (unlike in FM2)
         Template t = new Template(null, null, new StringReader(""), DEFAULT_CFG, tc, null);
-        assertEquals(DEFAULT_CFG.getArithmeticEngine(), t.getArithmeticEngine());
+        assertEquals(tc.getArithmeticEngine(), t.getArithmeticEngine());
     }
 
     @Test
@@ -762,7 +704,6 @@ public class TemplateConfigurationTest {
         TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
         tcb.setAutoImports(ImmutableMap.of("t1", "t1.ftl", "t2", "t2.ftl"));
         TemplateConfiguration tc = tcb.build();
-        tc.setParentConfiguration(DEFAULT_CFG);
         assertOutputWithoutAndWithTC(tc, "<#import 't3.ftl' as t3>${loaded}", "t3;",
"t1;t2;t3;");
     }
 
@@ -771,23 +712,21 @@ public class TemplateConfigurationTest {
         TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
         tcb.setAutoIncludes(ImmutableList.of("t1.ftl", "t2.ftl"));
         TemplateConfiguration tc = tcb.build();
-        tc.setParentConfiguration(DEFAULT_CFG);
         assertOutputWithoutAndWithTC(tc, "<#include 't3.ftl'>", "In t3;", "In t1;In
t2;In t3;");
     }
     
     @Test
     public void testStringInterpolate() throws TemplateException, IOException {
-        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
-        tcb.setArithmeticEngine(new DummyArithmeticEngine());
-        TemplateConfiguration tc = tcb.build();
-        tc.setParentConfiguration(DEFAULT_CFG);
+        TemplateConfiguration tc = new TemplateConfiguration.Builder()
+                .arithmeticEngine(new DummyArithmeticEngine())
+                .build();
         assertOutputWithoutAndWithTC(tc,
                 "<#setting locale='en_US'>${'${1} ${1+1} ${1*3}'} <#assign x = 1>${'${x
+ x} ${x * 3}'}",
                 "1 2 3 2 3", "11 22 33 22 33");
         
-        // Doesn't affect template.arithmeticEngine, only affects the parsing:
+        // Does affect template.arithmeticEngine (unlike in FM2):
         Template t = new Template(null, null, new StringReader(""), DEFAULT_CFG, tc, null);
-        assertEquals(DEFAULT_CFG.getArithmeticEngine(), t.getArithmeticEngine());
+        assertEquals(tc.getArithmeticEngine(), t.getArithmeticEngine());
     }
     
     @Test
@@ -796,7 +735,6 @@ public class TemplateConfigurationTest {
         tcb.setArithmeticEngine(new DummyArithmeticEngine());
         {
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
             assertOutputWithoutAndWithTC(tc,
                     "<#setting locale='en_US'><#assign src = r'${1} <#assign
x = 1>${x + x}'><@src?interpret />",
                     "1 2", "11 22");
@@ -804,7 +742,6 @@ public class TemplateConfigurationTest {
         tcb.setWhitespaceStripping(false);
         {
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
             assertOutputWithoutAndWithTC(tc,
                     "<#if true>\nX</#if><#assign src = r'<#if true>\nY</#if>'><@src?interpret
/>",
                     "XY", "\nX\nY");
@@ -817,7 +754,6 @@ public class TemplateConfigurationTest {
             TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
             tcb.setArithmeticEngine(new DummyArithmeticEngine());
             TemplateConfiguration tc = tcb.build();
-            tc.setParentConfiguration(DEFAULT_CFG);
             assertOutputWithoutAndWithTC(tc,
                     "<#assign x = 1>${r'1 + x'?eval?c}",
                     "2", "22");
@@ -836,7 +772,6 @@ public class TemplateConfigurationTest {
 
             {
                 TemplateConfiguration tc = tcb.build();
-                tc.setParentConfiguration(DEFAULT_CFG);
 
                 // Default is re-auto-detecting in ?eval:
                 assertOutputWithoutAndWithTC(tc, legacyNCFtl, "null", outputEncoding.name());
@@ -848,7 +783,6 @@ public class TemplateConfigurationTest {
                 tcb.setNamingConvention(Configuration.CAMEL_CASE_NAMING_CONVENTION);
 
                 TemplateConfiguration tc = tcb.build();
-                tc.setParentConfiguration(DEFAULT_CFG);
 
                 assertOutputWithoutAndWithTC(tc, legacyNCFtl, "null", null);
                 assertOutputWithoutAndWithTC(tc, camelCaseNCFtl, "null", outputEncoding.name());
@@ -859,7 +793,6 @@ public class TemplateConfigurationTest {
                 tcb.setNamingConvention(Configuration.LEGACY_NAMING_CONVENTION);
 
                 TemplateConfiguration tc = tcb.build();
-                tc.setParentConfiguration(DEFAULT_CFG);
 
                 assertOutputWithoutAndWithTC(tc, legacyNCFtl, "null", outputEncoding.name());
                 assertOutputWithoutAndWithTC(tc, camelCaseNCFtl, "null", null);
@@ -867,40 +800,6 @@ public class TemplateConfigurationTest {
         }
     }
     
-    @Test
-    public void testSetParentConfiguration() throws IOException {
-        TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
-        TemplateConfiguration tc = tcb.build();
-
-        Template t = new Template(null, "", DEFAULT_CFG);
-        try {
-            tc.apply(t);
-            fail();
-        } catch (IllegalStateException e) {
-            assertThat(e.getMessage(), containsString("Configuration"));
-        }
-        
-        tc.setParentConfiguration(DEFAULT_CFG);
-        
-        try {
-            tc.setParentConfiguration(new Configuration());
-            fail();
-        } catch (IllegalStateException e) {
-            assertThat(e.getMessage(), containsString("Configuration"));
-        }
-
-        try {
-            tc.setParentConfiguration(null);
-            fail();
-        } catch (_NullArgumentException e) {
-            // expected
-        }
-        
-        tc.setParentConfiguration(DEFAULT_CFG);
-        
-        tc.apply(t);
-    }
-
     private void assertOutputWithoutAndWithTC(
             TemplateConfiguration tc, String ftl, String expectedDefaultOutput,
             String expectedConfiguredOutput) throws TemplateException, IOException {
@@ -917,24 +816,17 @@ public class TemplateConfigurationTest {
         assertOutput(tc, templateName, ftl, expectedConfiguredOutput);
     }
 
-    private void assertOutput(TemplateConfiguration tc, String templateName, String ftl,
String expectedConfiguredOutput)
+    private void assertOutput(TemplateConfiguration tc, String templateName, String ftl,
String
+            expectedConfiguredOutput)
             throws TemplateException, IOException {
         StringWriter sw = new StringWriter();
         try {
-            Configuration cfg = tc != null ? tc.getParentConfiguration() : DEFAULT_CFG;
-            Template t = new Template(templateName, null, new StringReader(ftl), cfg, tc,
null);
-            if (tc != null) {
-                tc.apply(t);
-            }
+            Template t = new Template(templateName, null, new StringReader(ftl), DEFAULT_CFG,
tc, null);
             t.process(null, sw);
             if (expectedConfiguredOutput == null) {
                 fail("Template should have fail.");
             }
-        } catch (TemplateException e) {
-            if (expectedConfiguredOutput != null) {
-                throw e;
-            }
-        } catch (ParseException e) {
+        } catch (TemplateException|ParseException e) {
             if (expectedConfiguredOutput != null) {
                 throw e;
             }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0356b30b/src/test/java/org/apache/freemarker/core/TemplateLevelSettings.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/TemplateLevelSettings.java b/src/test/java/org/apache/freemarker/core/TemplateLevelSettings.java
deleted file mode 100644
index 178e518..0000000
--- a/src/test/java/org/apache/freemarker/core/TemplateLevelSettings.java
+++ /dev/null
@@ -1,103 +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 java.io.IOException;
-import java.io.StringWriter;
-
-import org.apache.freemarker.core.templateresolver.impl.StringTemplateLoader;
-import org.apache.freemarker.core.templateresolver.impl.StrongCacheStorage;
-import org.junit.Test;
-
-public class TemplateLevelSettings {
-    
-    private static final String IMPORTED_FTL = "imported.ftl";
-    private static final String INCLUDED_FTL = "included.ftl";
-    private static final String MAIN_FTL = "main.ftl";
-    private static final StringTemplateLoader TEMPLATES = new StringTemplateLoader();
-    static {
-        TEMPLATES.putTemplate(MAIN_FTL,
-                "${true}<#include '" + INCLUDED_FTL + "'>"
-                + "${true}<#import '" + IMPORTED_FTL + "' as ns>"
-                + "${true}<@ns.impM1>${true}</@>"
-                + "${true}<@incM>${true}</@>"
-                + "${true}");
-        TEMPLATES.putTemplate(INCLUDED_FTL,
-                "[inc:${true}]"
-                + "<#macro incM>[incM:${true}{<#nested>}${true}]</#macro>");
-        TEMPLATES.putTemplate(IMPORTED_FTL,
-                "<#macro impM1>[impM1:${true}{<#nested>}${true}<@impM2>${true}</@>${true}]</#macro>"
-                + "<#macro impM2>[impM2:${true}{<#nested>}${true}]</#macro>"
-                );
-    }
-    
-    @Test
-    public void test() throws IOException, TemplateException {
-        assertOutputs(
-                "M[inc:M]MM[impM1:M{M}M[impM2:M{M}M]M]M[incM:M{M}M]M",
-                "M,m", "INC,inc", "IMP,imp");
-        assertOutputs(
-                "C[inc:C]CC[impM1:C{C}C[impM2:C{C}C]C]C[incM:C{C}C]C",
-                null, "INC,inc", "IMP,imp");
-        assertOutputs(
-                "M[inc:M]MM[impM1:M{M}M[impM2:M{M}M]M]M[incM:M{M}M]M",
-                "M,m", null, "IMP,imp");
-        assertOutputs(
-                "M[inc:M]MM[impM1:M{M}M[impM2:M{M}M]M]M[incM:M{M}M]M",
-                "M,m", "INC,inc", null);
-    }
-
-    private void assertOutputs(
-            String expectedOutput,
-            String mainBoolFmt, String incBoolFmt, String impBoolFtm)
-            throws IOException, TemplateException {
-        assertEquals(
-                expectedOutput,
-                renderWith(Configuration.VERSION_3_0_0, mainBoolFmt, incBoolFmt, impBoolFtm));
-    }
-    
-    private String renderWith(Version version, String mainBoolFmt, String incBoolFmt, String
impBoolFtm)
-            throws IOException, TemplateException {
-        Configuration cfg = new Configuration(version);
-        cfg.setTemplateLoader(TEMPLATES);
-        cfg.setCacheStorage(new StrongCacheStorage());
-        cfg.setBooleanFormat("C,c");
-        
-        if (incBoolFmt != null) {
-            cfg.getTemplate(INCLUDED_FTL).setBooleanFormat(incBoolFmt);
-        }
-        
-        if (impBoolFtm != null) {
-            cfg.getTemplate(IMPORTED_FTL).setBooleanFormat(impBoolFtm);
-        }
-        
-        Template t = cfg.getTemplate(MAIN_FTL);
-        if (mainBoolFmt != null) {
-            t.setBooleanFormat(mainBoolFmt);
-        }
-        
-        StringWriter sw = new StringWriter();
-        t.process(null, sw);
-        return sw.toString();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0356b30b/src/test/java/org/apache/freemarker/core/templateresolver/TemplateConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/freemarker/core/templateresolver/TemplateConfigurationFactoryTest.java
b/src/test/java/org/apache/freemarker/core/templateresolver/TemplateConfigurationFactoryTest.java
index 3a416d9..727faa1 100644
--- a/src/test/java/org/apache/freemarker/core/templateresolver/TemplateConfigurationFactoryTest.java
+++ b/src/test/java/org/apache/freemarker/core/templateresolver/TemplateConfigurationFactoryTest.java
@@ -38,8 +38,7 @@ public class TemplateConfigurationFactoryTest {
         TemplateConfiguration tc = newTemplateConfiguration(1);
         
         TemplateConfigurationFactory tcf = new ConditionalTemplateConfigurationFactory(new
FileNameGlobMatcher("*.ftlx"), tc);
-        tcf.setConfiguration(cfg);
-        
+
         assertNotApplicable(tcf, "x.ftl");
         assertApplicable(tcf, "x.ftlx", tc);
     }
@@ -52,8 +51,7 @@ public class TemplateConfigurationFactoryTest {
                 new FileNameGlobMatcher("*.ftlx"),
                 new ConditionalTemplateConfigurationFactory(
                         new FileNameGlobMatcher("x.*"), tc));
-        tcf.setConfiguration(cfg);
-        
+
         assertNotApplicable(tcf, "x.ftl");
         assertNotApplicable(tcf, "y.ftlx");
         assertApplicable(tcf, "x.ftlx", tc);
@@ -69,8 +67,7 @@ public class TemplateConfigurationFactoryTest {
                 new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*.ftlx"),
tc1),
                 new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*a*.*"),
tc2),
                 new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*b*.*"),
tc3));
-        tcf.setConfiguration(cfg);
-        
+
         assertNotApplicable(tcf, "x.ftl");
         assertApplicable(tcf, "x.ftlx", tc1);
         assertApplicable(tcf, "a.ftl", tc2);
@@ -93,7 +90,6 @@ public class TemplateConfigurationFactoryTest {
                 new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*.ftlx"),
tc1),
                 new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*a*.*"),
tc2),
                 new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*b*.*"),
tc3));
-        tcf.setConfiguration(cfg);
 
         try {
             assertNotApplicable(tcf, "x.ftl");
@@ -145,8 +141,7 @@ public class TemplateConfigurationFactoryTest {
                         new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*.*x"),
tcXml))
                         .allowNoMatch(true),
                 new ConditionalTemplateConfigurationFactory(new FileNameGlobMatcher("*.nws.*"),
tcNWS));
-        tcf.setConfiguration(cfg);
-        
+
         assertNotApplicable(tcf, "x.ftl");
         assertApplicable(tcf, "b/x.ftl", tcBCommon);
         assertApplicable(tcf, "b/x.s.ftl", tcBCommon, tcBSpec);
@@ -157,29 +152,6 @@ public class TemplateConfigurationFactoryTest {
         assertApplicable(tcf, "a.nws.hh", tcHH, tcNWS);
     }
 
-    @Test
-    public void testSetConfiguration() {
-        TemplateConfiguration tc = new TemplateConfiguration.Builder().build();
-        ConditionalTemplateConfigurationFactory tcf = new ConditionalTemplateConfigurationFactory(
-                new FileNameGlobMatcher("*"), tc);
-        assertNull(tcf.getConfiguration());
-        assertNull(tc.getParentConfiguration());
-        
-        tcf.setConfiguration(cfg);
-        assertEquals(cfg, tcf.getConfiguration());
-        assertEquals(cfg, tc.getParentConfiguration());
-        
-        // Ignored:
-        tcf.setConfiguration(cfg);
-        
-        try {
-            tcf.setConfiguration(new Configuration(Configuration.VERSION_3_0_0));
-            fail();
-        } catch (IllegalStateException e) {
-            assertThat(e.getMessage(), containsString("TemplateConfigurationFactory"));
-        }
-    }
-
     @SuppressWarnings("boxing")
     private TemplateConfiguration newTemplateConfiguration(int id) {
         TemplateConfiguration.Builder tcb = new TemplateConfiguration.Builder();
@@ -196,7 +168,6 @@ public class TemplateConfigurationFactoryTest {
     private void assertApplicable(TemplateConfigurationFactory tcf, String sourceName, TemplateConfiguration...
expectedTCs)
             throws IOException, TemplateConfigurationFactoryException {
         TemplateConfiguration mergedTC = tcf.get(sourceName, DummyTemplateLoadingSource.INSTANCE);
-        assertNotNull("TC should have its parents Configuration set", mergedTC.getParentConfiguration());
         List<Object> mergedTCAttNames = new ArrayList<Object>(mergedTC.getCustomAttributes().keySet());
 
         for (TemplateConfiguration expectedTC : expectedTCs) {


Mime
View raw message