aboutsummaryrefslogtreecommitdiff
path: root/velocity-engine-core/src/test/java/org/apache/velocity
diff options
context:
space:
mode:
authorClaude Brisson <cbrisson@apache.org>2020-01-28 10:48:29 +0000
committerClaude Brisson <cbrisson@apache.org>2020-01-28 10:48:29 +0000
commit1cdc4eb1a0d01dfc9d34d5e0b5acc6bf616c2a99 (patch)
treec2e62965bf349db0aef30e3217fc3d68cd9bd84c /velocity-engine-core/src/test/java/org/apache/velocity
parent97ffb37b7c9bbe1b724dea9de57092e0eb655fd8 (diff)
downloadapache-velocity-engine-1cdc4eb1a0d01dfc9d34d5e0b5acc6bf616c2a99.tar.gz
[engine] Review VELOCITY-926 fix:
deprecate velocimacro.arguments.preserve_literals in favor of the new velocimacro.enable_bc_mode flag, which mimics 1.7 velocimacro behavior: - preserve arguments literals: #macro(m $arg) $arg #end m($null) will displays $arg w/o bc mode and $null with bc mode - use global defaults for missing arguments: #macro(m $foo) $foo #end #set($foo='foo') #m() will display $foo w/o bc mode and 'foo' with bc mode The following use cases have been left aside from backward compatibility: - preserving local macro scope values #macro(test) #set($foo = 'foo') $some_tool.change_foo_value_in_global_context_to_bar() $foo #end #test() will always display 'bar', while 1.7 displayed 'foo' - setting a null argument to null, while argument name exists in context, #macro(setnull $foo) #set($foo = $null) #end #set($foo='foo') #setnull($null) $foo Will always display 'foo' (w or w/o bc mode), while 1.7 did display $foo git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1873244 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core/src/test/java/org/apache/velocity')
-rw-r--r--velocity-engine-core/src/test/java/org/apache/velocity/test/PreserveArgumentsLiteralsTestCase.java45
-rw-r--r--velocity-engine-core/src/test/java/org/apache/velocity/test/VelocimacroBCModeTestCase.java99
-rwxr-xr-xvelocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity904TestCase.java1
3 files changed, 100 insertions, 45 deletions
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/PreserveArgumentsLiteralsTestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/PreserveArgumentsLiteralsTestCase.java
deleted file mode 100644
index ff627e18..00000000
--- a/velocity-engine-core/src/test/java/org/apache/velocity/test/PreserveArgumentsLiteralsTestCase.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.apache.velocity.test;
-
-/*
- * 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.
- */
-
-import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.runtime.RuntimeConstants;
-
-/**
- * This class tests the mode where velocimacros do preserve arguments literals
- */
-
-public class PreserveArgumentsLiteralsTestCase extends BaseTestCase
-{
- public PreserveArgumentsLiteralsTestCase(final String name)
- {
- super(name);
- }
-
- protected void setUpEngine(VelocityEngine engine)
- {
- engine.setProperty(RuntimeConstants.VM_PRESERVE_ARGUMENTS_LITERALS, true);
- }
-
- public void testPreserveLiterals()
- {
- assertEvalEquals("$bar","#macro(m $foo)$foo#end#m($bar)");
- }
-}
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/VelocimacroBCModeTestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/VelocimacroBCModeTestCase.java
new file mode 100644
index 00000000..72a27c15
--- /dev/null
+++ b/velocity-engine-core/src/test/java/org/apache/velocity/test/VelocimacroBCModeTestCase.java
@@ -0,0 +1,99 @@
+package org.apache.velocity.test;
+
+/*
+ * 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.
+ */
+
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.RuntimeConstants;
+
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+/**
+ * This class tests the mode where velocimacros do preserve arguments literals
+ */
+
+public class VelocimacroBCModeTestCase extends BaseTestCase
+{
+ private static final String BASE_DIR = TEST_COMPARE_DIR + "/bc_mode";
+ private static final String CMP_DIR = BASE_DIR + "/compare";
+ private static final String RESULTS_DIR = TEST_RESULT_DIR + "/bc_mode";
+
+ public VelocimacroBCModeTestCase(final String name)
+ {
+ super(name);
+ }
+
+ protected void setUpEngine(VelocityEngine engine)
+ {
+ boolean bcMode = !getName().contains("NoPreserve");
+ engine.setProperty(RuntimeConstants.VM_ENABLE_BC_MODE, bcMode);
+ engine.setProperty("file.resource.loader.path", TEST_COMPARE_DIR + "/bc_mode");
+ }
+
+ public void testPreserveLiterals()
+ {
+ assertEvalEquals("$bar","#macro(m $foo)$foo#end#m($bar)");
+ }
+
+ public void testGlobalDefaults()
+ {
+ assertEvalEquals("foo","#macro(m $foo)$foo#end#set($foo='foo')#m()");
+ }
+
+ public void testVariousCasesPreserve() throws Exception
+ {
+ doTestVariousCases("bc_mode_enabled");
+ }
+
+ public void testVariousCasesNoPreserve() throws Exception
+ {
+ doTestVariousCases("bc_mode_disabled");
+ }
+
+ private void doTestVariousCases(String compare_ext) throws Exception
+ {
+ assureResultsDirectoryExists(RESULTS_DIR);
+ String basefilename = "test_bc_mode";
+ Template template = engine.getTemplate( getFileName(null, basefilename, "vtl") );
+ context = new VelocityContext();
+ FileOutputStream fos;
+ Writer fwriter;
+
+ fos = new FileOutputStream (getFileName(RESULTS_DIR, basefilename, RESULT_FILE_EXT));
+
+ fwriter = new BufferedWriter( new OutputStreamWriter(fos) );
+
+ template.merge(context, fwriter);
+ fwriter.flush();
+ fwriter.close();
+
+ if (!isMatch(RESULTS_DIR, CMP_DIR, basefilename, RESULT_FILE_EXT, compare_ext))
+ {
+ String result = getFileContents(RESULTS_DIR, basefilename, RESULT_FILE_EXT);
+ String compare = getFileContents(CMP_DIR, basefilename, compare_ext);
+
+ assertEquals(compare, result);
+ }
+ }
+}
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity904TestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity904TestCase.java
index b22e198b..86caa7cf 100755
--- a/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity904TestCase.java
+++ b/velocity-engine-core/src/test/java/org/apache/velocity/test/issues/Velocity904TestCase.java
@@ -35,6 +35,7 @@ public class Velocity904TestCase extends BaseTestCase
@Override
protected void setUpEngine(VelocityEngine engine)
{
+ // that will also test the deprecation of velocimacro.arguments.preserve_literals towards velocimacro.enable_bc_mode
engine.setProperty("velocimacro.arguments.preserve_literals", getName().contains("NoPreserve") ? "false" : "true");
}