commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1209880 - in /commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2: JexlTestCase.java ScriptTest.java UnifiedJEXLTest.java
Date Sat, 03 Dec 2011 10:17:55 GMT
Author: sebb
Date: Sat Dec  3 10:17:54 2011
New Revision: 1209880

URL: http://svn.apache.org/viewvc?rev=1209880&view=rev
Log:
Allow test to work with both versions of Jexl

Modified:
    commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
    commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/ScriptTest.java
    commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java

Modified: commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/JexlTestCase.java?rev=1209880&r1=1209879&r2=1209880&view=diff
==============================================================================
--- commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
(original)
+++ commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
Sat Dec  3 10:17:54 2011
@@ -24,8 +24,11 @@ import java.util.Map;
 import java.util.List;
 import java.util.ArrayList;
 
+import javax.script.ScriptEngine;
+
 import org.apache.commons.jexl2.parser.JexlNode;
 import org.apache.commons.jexl2.parser.ASTJexlScript;
+import org.apache.commons.jexl2.scripting.JexlScriptEngineFactory;
 
 import junit.framework.TestCase;
 
@@ -40,6 +43,18 @@ public class JexlTestCase extends TestCa
     /** String parameter signature for test run. */
     private static final Class<?>[] stringParm = {String.class};
 
+    protected static final boolean testing21; // are we testing 2.1?
+
+    static {
+        JexlScriptEngineFactory factory = new JexlScriptEngineFactory();
+        Object parameter = factory.getParameter(ScriptEngine.ENGINE_VERSION);
+        if ("2.0".equals(parameter)) {
+            testing21 = true;
+        } else {
+            testing21 = false;
+        }
+    }
+
     /** A default Jexl engine instance. */
     protected final JexlEngine JEXL;
 

Modified: commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/ScriptTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/ScriptTest.java?rev=1209880&r1=1209879&r2=1209880&view=diff
==============================================================================
--- commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/ScriptTest.java
(original)
+++ commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/ScriptTest.java
Sat Dec  3 10:17:54 2011
@@ -17,6 +17,7 @@
 package org.apache.commons.jexl2;
 
 import java.io.File;
+import java.lang.reflect.Method;
 import java.net.URL;
 
 /**
@@ -99,4 +100,28 @@ public class ScriptTest extends JexlTest
         assertEquals("OK", resultatJexl.getCode());
     }
 
+    public void testScriptInterfaceBinaryCompat() {
+        Script impl = new Script() {
+
+            public Object execute(JexlContext context) {
+                return context != null ? context : Boolean.FALSE;
+            }
+
+            public String getText() {
+                return "Text";
+            }
+            
+        };
+        assertNotNull(impl);
+        assertEquals(Boolean.FALSE, impl.execute(null));
+        assertEquals("Text", impl.getText());
+        Method[] methods = impl.getClass().getDeclaredMethods();
+        assertEquals("We implemented 2 methods", 2, methods.length);
+        methods = Script.class.getDeclaredMethods();
+        if (testing21) {
+            assertEquals("There are now more", 8, methods.length);
+        } else {
+            assertEquals("There are only 2", 2, methods.length);
+        }
+    }
 }

Modified: commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java?rev=1209880&r1=1209879&r2=1209880&view=diff
==============================================================================
--- commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java
(original)
+++ commons/proper/jexl/branches/COMMONS_JEXL_2_0_1_TEST/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java
Sat Dec  3 10:17:54 2011
@@ -105,7 +105,11 @@ public class UnifiedJEXLTest extends Jex
         vars.put("name", "Doe");
         UnifiedJEXL.Expression  phase1 = expr.prepare(context);
         String as = phase1.asString();
-        assertEquals("Dear ${p} Doe;", as); // 2.1 deferred expressions are resolved in prepare
phase
+        if (testing21) {
+            assertEquals("Dear ${p} Doe;", as); // 2.1 deferred expressions are resolved
in prepare phase
+        } else {
+            assertEquals("Dear #{p} Doe;", as);
+        }
         vars.put("p", "Mr");
         vars.put("name", "Should not be used in 2nd phase");
         Object o = phase1.evaluate(context);
@@ -125,7 +129,11 @@ public class UnifiedJEXLTest extends Jex
     public void testImmediate() throws Exception {
         JexlContext none = null;
         UnifiedJEXL.Expression expr = EL.parse("${'Hello ' + 'World!'}");
-        assertEquals("prepare should return immediate expression", "Hello World!", expr.prepare(none).asString());
+        if (testing21){
+            assertEquals("prepare should return immediate expression", "Hello World!", expr.prepare(none).asString());
+        } else {
+            assertEquals("prepare should return same expression", expr, expr.prepare(none));
+        }
         Object o = expr.evaluate(none);
         assertTrue("expression should be immediate", expr.isImmediate());
         assertEquals("Hello World!", o);
@@ -143,7 +151,11 @@ public class UnifiedJEXLTest extends Jex
     public void testDeferred() throws Exception {
         JexlContext none = null;
         UnifiedJEXL.Expression expr = EL.parse("#{'world'}");
-        assertEquals("prepare should return immediate expression", "${'world'}", expr.prepare(none).asString());
+        if (testing21) {
+            assertEquals("prepare should return immediate expression", "${'world'}", expr.prepare(none).asString());
+        } else {
+            assertEquals("prepare should return same expression", expr, expr.prepare(none));
+        }
         Object o = expr.evaluate(none);
         assertTrue("expression should be deferred", expr.isDeferred());
         assertEquals("world", o);



Mime
View raw message