aboutsummaryrefslogtreecommitdiff
path: root/velocity-engine-core/src/test
diff options
context:
space:
mode:
authorClaude Brisson <cbrisson@apache.org>2019-06-12 00:58:53 +0000
committerClaude Brisson <cbrisson@apache.org>2019-06-12 00:58:53 +0000
commit1bf4b32ffc5f9637285ce7de855460fd00da10b0 (patch)
tree1c4050072d9d831133ea7d39b9a568d2603d33ed /velocity-engine-core/src/test
parent9cc0c4e1f55b06cb587432d06e203f5f7c3d6293 (diff)
parent0c363b9df8654b05c503c6b192e94dfc458482dd (diff)
downloadapache-velocity-engine-1bf4b32ffc5f9637285ce7de855460fd00da10b0.tar.gz
[engine][VELOCITY-917] Merge changes from trunk
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/branches/parser_experiments@1861084 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
*/