aboutsummaryrefslogtreecommitdiff
path: root/velocity-engine-core/src/test
diff options
context:
space:
mode:
authorClaude Brisson <cbrisson@apache.org>2019-06-05 23:46:02 +0000
committerClaude Brisson <cbrisson@apache.org>2019-06-05 23:46:02 +0000
commite1e494870d13a58cc23a6209aac6e0fe67dae1cc (patch)
tree70e6b539755673095107c43a75dbfa6e1a4f794b /velocity-engine-core/src/test
parent41bd49095236a247202c9411fc1d089a7b61e503 (diff)
downloadapache-velocity-engine-e1e494870d13a58cc23a6209aac6e0fe67dae1cc.tar.gz
[engine][VELOCITY-915] Add new backward compatibility flags to mimic 1.7 behavior for invalid references event handlers
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1860691 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core/src/test')
-rw-r--r--velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java136
1 files changed, 134 insertions, 2 deletions
diff --git a/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java b/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java
index 22d5c38d..ad946418 100644
--- a/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java
+++ b/velocity-engine-core/src/test/java/org/apache/velocity/test/BuiltInEventHandlerTestCase.java
@@ -128,9 +128,10 @@ public class BuiltInEventHandlerTestCase extends BaseTestCase {
context.put("a1","test");
context.put("b1","test");
+ context.put("n1", null);
Writer writer = new StringWriter();
- ve.evaluate(context,writer,"test","$a1 $c1 $a1.length() $a1.foobar()");
+ ve.evaluate(context,writer,"test","$a1 $c1 $a1.length() $a1.foobar() $!c1 $n1 $!n1 #if($c1) nop #end");
List errors = reporter.getInvalidReferences();
assertEquals(2,errors.size());
@@ -143,7 +144,7 @@ public class BuiltInEventHandlerTestCase extends BaseTestCase {
public void testReportInvalidReferences2() throws Exception
{
VelocityEngine ve = new VelocityEngine();
- ve.setProperty("eventhandler.invalidreference.exception","true");
+ ve.setProperty("event_handler.invalid_references.exception","true");
ReportInvalidReferences reporter = new ReportInvalidReferences();
ve.init();
@@ -169,6 +170,137 @@ public class BuiltInEventHandlerTestCase extends BaseTestCase {
}
/**
+ * Test reporting of invalid syntax
+ * @throws Exception
+ */
+ public void testReportQuietInvalidReferences() throws Exception
+ {
+ VelocityEngine ve = new VelocityEngine();
+ ve.setProperty("event_handler.invalid_references.quiet","true");
+ ReportInvalidReferences reporter = new ReportInvalidReferences();
+ ve.init();
+
+ VelocityContext context = new VelocityContext();
+ EventCartridge ec = new EventCartridge();
+ ec.addEventHandler(reporter);
+ ec.attachToContext(context);
+
+ context.put("a1","test");
+ context.put("b1","test");
+ context.put("n1", null);
+ Writer writer = new StringWriter();
+
+ ve.evaluate(context,writer,"test","$a1 $c1 $a1.length() $a1.foobar() $!c1 $n1 $!n1 #if($c1) nop #end");
+
+ List errors = reporter.getInvalidReferences();
+ assertEquals(3,errors.size());
+ assertEquals("$c1",((InvalidReferenceInfo) errors.get(0)).getInvalidReference());
+ assertEquals("$a1.foobar()",((InvalidReferenceInfo) errors.get(1)).getInvalidReference());
+ assertEquals("$c1",((InvalidReferenceInfo) errors.get(2)).getInvalidReference());
+
+ log("Caught invalid references (local configuration).");
+ }
+
+ /**
+ * Test reporting of invalid syntax
+ * @throws Exception
+ */
+ public void testReportNullInvalidReferences() throws Exception
+ {
+ VelocityEngine ve = new VelocityEngine();
+ ve.setProperty("event_handler.invalid_references.null","true");
+ ReportInvalidReferences reporter = new ReportInvalidReferences();
+ ve.init();
+
+ VelocityContext context = new VelocityContext();
+ EventCartridge ec = new EventCartridge();
+ ec.addEventHandler(reporter);
+ ec.attachToContext(context);
+
+ context.put("a1","test");
+ context.put("b1","test");
+ context.put("n1", null);
+ Writer writer = new StringWriter();
+
+ ve.evaluate(context,writer,"test","$a1 $c1 $a1.length() $a1.foobar() $!c1 $n1 $!n1 #if($c1) nop #end");
+
+ List errors = reporter.getInvalidReferences();
+ assertEquals(3,errors.size());
+ assertEquals("$c1",((InvalidReferenceInfo) errors.get(0)).getInvalidReference());
+ assertEquals("$a1.foobar()",((InvalidReferenceInfo) errors.get(1)).getInvalidReference());
+ assertEquals("$n1",((InvalidReferenceInfo) errors.get(2)).getInvalidReference());
+
+ log("Caught invalid references (local configuration).");
+ }
+
+ /**
+ * Test reporting of invalid syntax
+ * @throws Exception
+ */
+ public void testReportNullQuietInvalidReferences() throws Exception
+ {
+ VelocityEngine ve = new VelocityEngine();
+ ve.setProperty("event_handler.invalid_references.quiet","true");
+ ve.setProperty("event_handler.invalid_references.null","true");
+ ReportInvalidReferences reporter = new ReportInvalidReferences();
+ ve.init();
+
+ VelocityContext context = new VelocityContext();
+ EventCartridge ec = new EventCartridge();
+ ec.addEventHandler(reporter);
+ ec.attachToContext(context);
+
+ context.put("a1","test");
+ context.put("b1","test");
+ context.put("n1", null);
+ Writer writer = new StringWriter();
+
+ ve.evaluate(context,writer,"test","$a1 $c1 $a1.length() $a1.foobar() $!c1 $n1 $!n1 #if($c1) nop #end");
+
+ List errors = reporter.getInvalidReferences();
+ assertEquals(5,errors.size());
+ assertEquals("$c1",((InvalidReferenceInfo) errors.get(0)).getInvalidReference());
+ assertEquals("$a1.foobar()",((InvalidReferenceInfo) errors.get(1)).getInvalidReference());
+ assertEquals("$c1",((InvalidReferenceInfo) errors.get(2)).getInvalidReference());
+ assertEquals("$n1",((InvalidReferenceInfo) errors.get(3)).getInvalidReference());
+ assertEquals("$n1",((InvalidReferenceInfo) errors.get(4)).getInvalidReference());
+
+ log("Caught invalid references (local configuration).");
+ }
+
+ /**
+ * Test reporting of invalid syntax
+ * @throws Exception
+ */
+ public void testReportTestedInvalidReferences() throws Exception
+ {
+ VelocityEngine ve = new VelocityEngine();
+ ve.setProperty("event_handler.invalid_references.tested","true");
+ ReportInvalidReferences reporter = new ReportInvalidReferences();
+ ve.init();
+
+ VelocityContext context = new VelocityContext();
+ EventCartridge ec = new EventCartridge();
+ ec.addEventHandler(reporter);
+ ec.attachToContext(context);
+
+ context.put("a1","test");
+ context.put("b1","test");
+ context.put("n1", null);
+ Writer writer = new StringWriter();
+
+ ve.evaluate(context,writer,"test","$a1 $c1 $a1.length() $a1.foobar() $!c1 $n1 $!n1 #if($c1) nop #end");
+
+ List errors = reporter.getInvalidReferences();
+ assertEquals(3,errors.size());
+ assertEquals("$c1",((InvalidReferenceInfo) errors.get(0)).getInvalidReference());
+ assertEquals("$a1.foobar()",((InvalidReferenceInfo) errors.get(1)).getInvalidReference());
+ assertEquals("$c1",((InvalidReferenceInfo) errors.get(2)).getInvalidReference());
+
+ log("Caught invalid references (local configuration).");
+ }
+
+ /**
* Test escaping
* @throws Exception
*/