You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2011/12/06 15:19:36 UTC
svn commit: r1210927 [6/7] - in /commons/proper/jexl/trunk: ./
src/main/java/org/apache/commons/jexl3/
src/main/java/org/apache/commons/jexl3/internal/
src/main/java/org/apache/commons/jexl3/internal/introspection/
src/main/java/org/apache/commons/jexl...
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IfTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IfTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IfTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IfTest.java Tue Dec 6 14:19:33 2011
@@ -16,19 +16,14 @@
*/
package org.apache.commons.jexl3;
-import org.apache.commons.jexl3.Expression;
-import org.apache.commons.jexl3.JexlContext;
-import org.apache.commons.jexl3.JexlEngine;
-import org.apache.commons.jexl3.MapContext;
-
/**
* Test cases for the if statement.
*
* @since 1.1
*/
public class IfTest extends JexlTestCase {
- public IfTest(String testName) {
- super(testName);
+ public IfTest() {
+ super("IfTest");
}
/**
@@ -37,7 +32,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testSimpleIfTrue() throws Exception {
- Expression e = JEXL.createExpression("if (true) 1");
+ JexlExpression e = JEXL.createExpression("if (true) 1");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
@@ -50,7 +45,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testSimpleIfFalse() throws Exception {
- Expression e = JEXL.createExpression("if (false) 1");
+ JexlExpression e = JEXL.createExpression("if (false) 1");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
@@ -63,7 +58,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testSimpleElse() throws Exception {
- Expression e = JEXL.createExpression("if (false) 1 else 2;");
+ JexlExpression e = JEXL.createExpression("if (false) 1 else 2;");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
@@ -76,7 +71,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testBlockIfTrue() throws Exception {
- Expression e = JEXL.createExpression("if (true) { 'hello'; }");
+ JexlExpression e = JEXL.createExpression("if (true) { 'hello'; }");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
@@ -89,7 +84,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testBlockElse() throws Exception {
- Expression e = JEXL.createExpression("if (false) {1} else {2 ; 3}");
+ JexlExpression e = JEXL.createExpression("if (false) {1} else {2 ; 3}");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
@@ -102,7 +97,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testIfWithSimpleExpression() throws Exception {
- Expression e = JEXL.createExpression("if (x == 1) true;");
+ JexlExpression e = JEXL.createExpression("if (x == 1) true;");
JexlContext jc = new MapContext();
jc.set("x", new Integer(1));
@@ -116,7 +111,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testIfWithArithmeticExpression() throws Exception {
- Expression e = JEXL.createExpression("if ((x * 2) + 1 == 5) true;");
+ JexlExpression e = JEXL.createExpression("if ((x * 2) + 1 == 5) true;");
JexlContext jc = new MapContext();
jc.set("x", new Integer(2));
@@ -130,7 +125,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testIfWithDecimalArithmeticExpression() throws Exception {
- Expression e = JEXL.createExpression("if ((x * 2) == 5) true");
+ JexlExpression e = JEXL.createExpression("if ((x * 2) == 5) true");
JexlContext jc = new MapContext();
jc.set("x", new Float(2.5f));
@@ -144,7 +139,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testIfWithAssignment() throws Exception {
- Expression e = JEXL.createExpression("if ((x * 2) == 5) {y = 1} else {y = 2;}");
+ JexlExpression e = JEXL.createExpression("if ((x * 2) == 5) {y = 1} else {y = 2;}");
JexlContext jc = new MapContext();
jc.set("x", new Float(2.5f));
@@ -159,17 +154,17 @@ public class IfTest extends JexlTestCase
* @throws Exception
*/
public void testTernary() throws Exception {
- JexlEngine jexl = createThreadedArithmeticEngine(true);
- jexl.setCache(64);
- JexlContext jc = new MapContext();
- Expression e = jexl.createExpression("x.y.z = foo ?'bar':'quux'");
+ JexlEngine jexl = JEXL;
+
+ JexlEvalContext jc = new JexlEvalContext();
+ JexlExpression e = jexl.createExpression("x.y.z = foo ?'bar':'quux'");
Object o;
// undefined foo
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
o = jc.get("x.y.z");
@@ -179,8 +174,8 @@ public class IfTest extends JexlTestCase
jc.set("foo", null);
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
o = jc.get("x.y.z");
@@ -190,8 +185,8 @@ public class IfTest extends JexlTestCase
jc.set("foo", Boolean.FALSE);
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
o = jc.get("x.y.z");
@@ -201,8 +196,8 @@ public class IfTest extends JexlTestCase
jc.set("foo", Boolean.TRUE);
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be bar", "bar", o);
o = jc.get("x.y.z");
@@ -218,17 +213,15 @@ public class IfTest extends JexlTestCase
* @throws Exception
*/
public void testTernaryShorthand() throws Exception {
- JexlEngine jexl = createThreadedArithmeticEngine(true);
- jexl.setCache(64);
- JexlContext jc = new MapContext();
- Expression e = JEXL.createExpression("x.y.z = foo?:'quux'");
+ JexlEvalContext jc = new JexlEvalContext();
+ JexlExpression e = JEXL.createExpression("x.y.z = foo?:'quux'");
Object o;
// undefined foo
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
o = jc.get("x.y.z");
@@ -238,8 +231,8 @@ public class IfTest extends JexlTestCase
jc.set("foo", null);
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
o = jc.get("x.y.z");
@@ -249,8 +242,8 @@ public class IfTest extends JexlTestCase
jc.set("foo", Boolean.FALSE);
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
o = jc.get("x.y.z");
@@ -260,8 +253,8 @@ public class IfTest extends JexlTestCase
jc.set("foo", Double.NaN);
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
o = jc.get("x.y.z");
@@ -271,8 +264,8 @@ public class IfTest extends JexlTestCase
jc.set("foo", "");
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
o = jc.get("x.y.z");
@@ -282,8 +275,8 @@ public class IfTest extends JexlTestCase
jc.set("foo", "false");
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
o = jc.get("x.y.z");
@@ -293,8 +286,8 @@ public class IfTest extends JexlTestCase
jc.set("foo", 0d);
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
o = jc.get("x.y.z");
@@ -304,8 +297,8 @@ public class IfTest extends JexlTestCase
jc.set("foo", 0);
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be quux", "quux", o);
o = jc.get("x.y.z");
@@ -316,15 +309,15 @@ public class IfTest extends JexlTestCase
jc.set("foo", "bar");
for (int l = 0; l < 4; ++l) {
- jexl.setLenient((l & 1) != 0);
- jexl.setSilent((l & 2) != 0);
+ jc.setStrict((l & 1) == 0);
+ jc.setSilent((l & 2) != 0);
o = e.evaluate(jc);
assertEquals("Should be bar", "bar", o);
o = jc.get("x.y.z");
assertEquals("Should be bar", "bar", o);
}
- debuggerCheck(jexl);
+ debuggerCheck(JEXL);
}
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java Tue Dec 6 14:19:33 2011
@@ -16,19 +16,26 @@
*/
package org.apache.commons.jexl3;
+import org.apache.commons.jexl3.internal.Engine;
+import org.apache.commons.jexl3.internal.Script;
+import org.apache.commons.jexl3.internal.TemplateEngine;
+import org.apache.commons.jexl3.internal.Debugger;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
-import org.apache.commons.jexl3.internal.Introspector;
import java.util.HashMap;
import java.util.Map;
-import org.apache.commons.jexl3.introspection.Uberspect;
+import org.apache.commons.jexl3.internal.introspection.Uberspect;
/**
* Test cases for reported issues
*/
@SuppressWarnings("boxing")
public class IssuesTest extends JexlTestCase {
+ public IssuesTest() {
+ super("IssuesTest", null);
+ }
+
@Override
public void setUp() throws Exception {
// ensure jul logging is only error to avoid warning in silent mode
@@ -37,10 +44,11 @@ public class IssuesTest extends JexlTest
// JEXL-24: long integers (and doubles)
public void test24() throws Exception {
+ JexlEngine jexl = new Engine();
Map<String, Object> vars = new HashMap<String, Object>();
JexlContext ctxt = new MapContext(vars);
String stmt = "{a = 10L; b = 10l; c = 42.0D; d = 42.0d; e=56.3F; f=56.3f; g=63.5; h=0x10; i=010; j=0x10L; k=010l}";
- Script expr = JEXL.createScript(stmt);
+ JexlScript expr = jexl.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
assertEquals(10L, vars.get("a"));
assertEquals(10l, vars.get("b"));
@@ -57,10 +65,11 @@ public class IssuesTest extends JexlTest
// JEXL-24: big integers and big decimals
public void test24B() throws Exception {
+ JexlEngine jexl = new Engine();
Map<String, Object> vars = new HashMap<String, Object>();
JexlContext ctxt = new MapContext(vars);
String stmt = "{a = 10H; b = 10h; c = 42.0B; d = 42.0b;}";
- Script expr = JEXL.createScript(stmt);
+ JexlScript expr = jexl.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
assertEquals(new BigInteger("10"), vars.get("a"));
assertEquals(new BigInteger("10"), vars.get("b"));
@@ -70,10 +79,11 @@ public class IssuesTest extends JexlTest
// JEXL-24: big decimals with exponent
public void test24C() throws Exception {
+ JexlEngine jexl = new Engine();
Map<String, Object> vars = new HashMap<String, Object>();
JexlContext ctxt = new MapContext(vars);
String stmt = "{a = 42.0e1B; b = 42.0E+2B; c = 42.0e-1B; d = 42.0E-2b;}";
- Script expr = JEXL.createScript(stmt);
+ JexlScript expr = jexl.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
assertEquals(new BigDecimal("42.0e+1"), vars.get("a"));
assertEquals(new BigDecimal("42.0e+2"), vars.get("b"));
@@ -83,10 +93,11 @@ public class IssuesTest extends JexlTest
// JEXL-24: doubles with exponent
public void test24D() throws Exception {
+ JexlEngine jexl = new Engine();
Map<String, Object> vars = new HashMap<String, Object>();
JexlContext ctxt = new MapContext(vars);
String stmt = "{a = 42.0e1D; b = 42.0E+2D; c = 42.0e-1d; d = 42.0E-2d;}";
- Script expr = JEXL.createScript(stmt);
+ JexlScript expr = jexl.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
assertEquals(Double.valueOf("42.0e+1"), vars.get("a"));
assertEquals(Double.valueOf("42.0e+2"), vars.get("b"));
@@ -96,10 +107,11 @@ public class IssuesTest extends JexlTest
// JEXL-49: blocks not parsed (fixed)
public void test49() throws Exception {
+ JexlEngine jexl = new Engine();
Map<String, Object> vars = new HashMap<String, Object>();
JexlContext ctxt = new MapContext(vars);
String stmt = "{a = 'b'; c = 'd';}";
- Script expr = JEXL.createScript(stmt);
+ JexlScript expr = jexl.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
assertTrue("JEXL-49 is not fixed", vars.get("a").equals("b") && vars.get("c").equals("d"));
}
@@ -131,12 +143,13 @@ public class IssuesTest extends JexlTest
}
public void test48() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
+ JexlEvalContext jc = new JexlEvalContext();
// ensure errors will throw
- jexl.setSilent(false);
+ jc.setStrict(true);
+ jc.setSilent(false);
String jexlExp = "(foo.getInner().foo() eq true) and (foo.getInner().goo() = (foo.getInner().goo()+1-1))";
- Expression e = jexl.createExpression(jexlExp);
- JexlContext jc = new MapContext();
+ JexlExpression e = jexl.createExpression(jexlExp);
jc.set("foo", new Foo());
try {
@@ -150,12 +163,12 @@ public class IssuesTest extends JexlTest
// JEXL-47: C style comments (single & multi line) (fixed in Parser.jjt)
// JEXL-44: comments dont allow double quotes (fixed in Parser.jjt)
public void test47() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
+ JexlEvalContext ctxt = new JexlEvalContext();
// ensure errors will throw
- jexl.setSilent(false);
- JexlContext ctxt = new MapContext();
+ ctxt.setSilent(false);
- Expression expr = jexl.createExpression("true//false\n");
+ JexlExpression expr = jexl.createExpression("true//false\n");
Object value = expr.evaluate(ctxt);
assertTrue("should be true", ((Boolean) value).booleanValue());
@@ -171,14 +184,15 @@ public class IssuesTest extends JexlTest
// JEXL-42: NullPointerException evaluating an expression
// fixed in JexlArithmetic by allowing add operator to deal with string, null
public void test42() throws Exception {
- JexlEngine jexl = new JexlEngine();
- UnifiedJEXL uel = new UnifiedJEXL(jexl);
+ Engine jexl = new Engine();
+ JxltEngine uel = new TemplateEngine(jexl);
// ensure errors will throw
//jexl.setSilent(false);
- JexlContext ctxt = new MapContext();
+ JexlEvalContext ctxt = new JexlEvalContext();
+ ctxt.setStrict(false);
ctxt.set("ax", "ok");
- UnifiedJEXL.Expression expr = uel.parse("${ax+(bx)}");
+ JxltEngine.UnifiedExpression expr = uel.createExpression("${ax+(bx)}");
Object value = expr.evaluate(ctxt);
assertTrue("should be ok", "ok".equals(value));
}
@@ -197,23 +211,24 @@ public class IssuesTest extends JexlTest
}
public void test40() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
+ JexlEvalContext ctxt = new JexlEvalContext();
// ensure errors will throw
- jexl.setSilent(false);
- JexlContext ctxt = new MapContext();
+ ctxt.setSilent(false);
+
ctxt.set("derived", new Derived());
- Expression expr = jexl.createExpression("derived.foo()");
+ JexlExpression expr = jexl.createExpression("derived.foo()");
Object value = expr.evaluate(ctxt);
assertTrue("should be true", ((Boolean) value).booleanValue());
}
// JEXL-52: can be implemented by deriving Interpreter.{g,s}etAttribute; later
public void test52base() throws Exception {
- JexlEngine jexl = createEngine(false);
- Uberspect uber = jexl.getUberspect();
+ Engine jexl = (Engine) createEngine(false);
+ Uberspect uber = (Uberspect) jexl.getUberspect();
// most likely, call will be in an Interpreter, getUberspect
- String[] names = ((Introspector) uber).getMethodNames(Another.class);
+ String[] names = uber.getMethodNames(Another.class);
assertTrue("should find methods", names.length > 0);
int found = 0;
for (String name : names) {
@@ -223,7 +238,7 @@ public class IssuesTest extends JexlTest
}
assertTrue("should have foo & goo", found == 2);
- names = ((org.apache.commons.jexl3.internal.introspection.Uberspect) uber).getFieldNames(Another.class);
+ names = uber.getFieldNames(Another.class);
assertTrue("should find fields", names.length > 0);
found = 0;
for (String name : names) {
@@ -237,9 +252,11 @@ public class IssuesTest extends JexlTest
// JEXL-10/JEXL-11: variable checking, null operand is error
public void test11() throws Exception {
JexlEngine jexl = createEngine(false);
+ JexlEvalContext ctxt = new JexlEvalContext();
// ensure errors will throw
- jexl.setSilent(false);
- JexlContext ctxt = new MapContext();
+ ctxt.setSilent(false);
+ ctxt.setStrict(true);
+
ctxt.set("a", null);
String[] exprs = {
@@ -251,7 +268,7 @@ public class IssuesTest extends JexlTest
};
for (int e = 0; e < exprs.length; ++e) {
try {
- Expression expr = jexl.createExpression(exprs[e]);
+ JexlExpression expr = jexl.createExpression(exprs[e]);
/* Object value = */ expr.evaluate(ctxt);
fail(exprs[e] + " : should have failed due to null argument");
} catch (JexlException xjexl) {
@@ -262,13 +279,13 @@ public class IssuesTest extends JexlTest
// JEXL-62
public void test62() throws Exception {
- JexlContext ctxt;
JexlEngine jexl = createEngine(false);
- jexl.setSilent(true); // to avoid throwing JexlException on null method call
+ JexlEvalContext ctxt = new JexlEvalContext();
+ ctxt.setStrict(true);
+ ctxt.setSilent(true);// to avoid throwing JexlException on null method call
- Script jscript;
+ JexlScript jscript;
- ctxt = new MapContext();
jscript = jexl.createScript("dummy.hashCode()");
assertEquals(jscript.getText(), null, jscript.execute(ctxt)); // OK
@@ -278,9 +295,8 @@ public class IssuesTest extends JexlTest
jscript = jexl.createScript("dummy.hashCode");
assertEquals(jscript.getText(), null, jscript.execute(ctxt)); // OK
- Expression jexpr;
-
- ctxt = new MapContext();
+ JexlExpression jexpr;
+ ctxt.clearVariables();
jexpr = jexl.createExpression("dummy.hashCode()");
assertEquals(jexpr.getExpression(), null, jexpr.evaluate(ctxt)); // OK
@@ -293,10 +309,12 @@ public class IssuesTest extends JexlTest
// JEXL-73
public void test73() throws Exception {
- JexlContext ctxt = new MapContext();
JexlEngine jexl = createEngine(false);
- jexl.setSilent(false);
- Expression e;
+ JexlEvalContext ctxt = new JexlEvalContext();
+ // ensure errors will throw
+ ctxt.setSilent(false);
+ ctxt.setStrict(true);
+ JexlExpression e;
e = jexl.createExpression("c.e");
try {
/* Object o = */ e.evaluate(ctxt);
@@ -320,11 +338,12 @@ public class IssuesTest extends JexlTest
// JEXL-87
public void test87() throws Exception {
- JexlContext ctxt = new MapContext();
JexlEngine jexl = createEngine(false);
- jexl.setSilent(false);
- Expression divide = jexl.createExpression("l / r");
- Expression modulo = jexl.createExpression("l % r");
+ JexlEvalContext ctxt = new JexlEvalContext();
+ // ensure errors will throw
+ ctxt.setSilent(false);
+ JexlExpression divide = jexl.createExpression("l / r");
+ JexlExpression modulo = jexl.createExpression("l % r");
ctxt.set("l", java.math.BigInteger.valueOf(7));
ctxt.set("r", java.math.BigInteger.valueOf(2));
@@ -339,10 +358,10 @@ public class IssuesTest extends JexlTest
// JEXL-90
public void test90() throws Exception {
- JexlContext ctxt = new MapContext();
JexlEngine jexl = createEngine(false);
- jexl.setSilent(false);
- jexl.setCache(16);
+ JexlEvalContext ctxt = new JexlEvalContext();
+ // ensure errors will throw
+ ctxt.setSilent(false);
// ';' is necessary between expressions
String[] fexprs = {
"a=3 b=4",
@@ -356,7 +375,7 @@ public class IssuesTest extends JexlTest
jexl.createScript(fexprs[f]);
fail(fexprs[f] + ": Should have failed in parse");
} catch (JexlException xany) {
- // expected to fail in parse
+ // expected to fail in createExpression
}
}
// ';' is necessary between expressions and only expressions
@@ -370,7 +389,7 @@ public class IssuesTest extends JexlTest
ctxt.set("x", Boolean.FALSE);
ctxt.set("y", Boolean.TRUE);
for (int e = 0; e < exprs.length; ++e) {
- Script s = jexl.createScript(exprs[e]);
+ JexlScript s = jexl.createScript(exprs[e]);
assertEquals(Integer.valueOf(2), s.execute(ctxt));
}
debuggerCheck(jexl);
@@ -378,10 +397,11 @@ public class IssuesTest extends JexlTest
// JEXL-44
public void test44() throws Exception {
- JexlContext ctxt = new MapContext();
JexlEngine jexl = createEngine(false);
- jexl.setSilent(false);
- Script script;
+ JexlEvalContext ctxt = new JexlEvalContext();
+ // ensure errors will throw
+ ctxt.setSilent(false);
+ JexlScript script;
script = jexl.createScript("'hello world!'//commented");
assertEquals("hello world!", script.execute(ctxt));
script = jexl.createScript("'hello world!';//commented\n'bye...'");
@@ -393,15 +413,17 @@ public class IssuesTest extends JexlTest
}
public void test97() throws Exception {
- JexlContext ctxt = new MapContext();
+ JexlEngine jexl = createEngine(false);
+ JexlEvalContext ctxt = new JexlEvalContext();
+ // ensure errors will throw
+ ctxt.setSilent(false);
for (char v = 'a'; v <= 'z'; ++v) {
ctxt.set(Character.toString(v), 10);
}
String input =
"(((((((((((((((((((((((((z+y)/x)*w)-v)*u)/t)-s)*r)/q)+p)-o)*n)-m)+l)*k)+j)/i)+h)*g)+f)/e)+d)-c)/b)+a)";
- JexlEngine jexl = new JexlEngine();
- Expression script;
+ JexlExpression script;
// Make sure everything is loaded...
long start = System.nanoTime();
script = jexl.createExpression(input);
@@ -425,10 +447,9 @@ public class IssuesTest extends JexlTest
"fn:replace(\"DOMAIN\\somename\", \"\\\\\", \"\\\\\\\\\")",
"fn:replace('DOMAIN\\somename', '\\u005c', '\\u005c\\u005c')"
};
- JexlEngine jexl = new JexlEngine();
Map<String, Object> funcs = new HashMap<String, Object>();
funcs.put("fn", new fn98());
- jexl.setFunctions(funcs);
+ JexlEngine jexl = new JexlBuilder().namespaces(funcs).create();
for (String expr : exprs) {
Object value = jexl.createExpression(expr).evaluate(null);
assertEquals(expr, "DOMAIN\\\\somename", value);
@@ -436,8 +457,7 @@ public class IssuesTest extends JexlTest
}
public void test100() throws Exception {
- JexlEngine jexl = new JexlEngine();
- jexl.setCache(4);
+ JexlEngine jexl = new JexlBuilder().cache(4).create();
JexlContext ctxt = new MapContext();
int[] foo = {42};
ctxt.set("foo", foo);
@@ -480,32 +500,33 @@ public class IssuesTest extends JexlTest
public void test105() throws Exception {
JexlContext context = new MapContext();
- Expression selectExp = new JexlEngine().createExpression("[a.propA]");
+ JexlExpression selectExp = new Engine().createExpression("[a.propA]");
context.set("a", new A105("a1", "p1"));
Object[] r = (Object[]) selectExp.evaluate(context);
assertEquals("p1", r[0]);
-//selectExp = new JexlEngine().createExpression("[a.propA]");
+//selectExp = new Engine().createExpression("[a.propA]");
context.set("a", new A105("a2", "p2"));
r = (Object[]) selectExp.evaluate(context);
assertEquals("p2", r[0]);
}
public void test106() throws Exception {
- JexlContext context = new MapContext();
+ JexlEvalContext context = new JexlEvalContext();
+ context.setStrict(true, true);
context.set("a", new BigDecimal(1));
context.set("b", new BigDecimal(3));
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
try {
Object value = jexl.createExpression("a / b").evaluate(context);
assertNotNull(value);
} catch (JexlException xjexl) {
fail("should not occur");
}
- JexlArithmetic arithmetic = new JexlArithmetic(false, MathContext.UNLIMITED, 2);
- JexlEngine jexlX = new JexlEngine(null, arithmetic, null, null);
+ context.setMathContext(MathContext.UNLIMITED);
+ context.setMathScale(2);
try {
- jexlX.createExpression("a / b").evaluate(context);
+ jexl.createExpression("a / b").evaluate(context);
fail("should fail");
} catch (JexlException xjexl) {
//ok to fail
@@ -526,9 +547,9 @@ public class IssuesTest extends JexlTest
JexlContext context = new MapContext();
context.set("Q4", "Q4");
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
for (int e = 0; e < exprs.length; e += 2) {
- Expression expr = jexl.createExpression(exprs[e]);
+ JexlExpression expr = jexl.createExpression(exprs[e]);
Object expected = exprs[e + 1];
Object value = expr.evaluate(context);
assertEquals(expected, value);
@@ -539,9 +560,9 @@ public class IssuesTest extends JexlTest
}
public void test108() throws Exception {
- Expression expr;
+ JexlExpression expr;
Object value;
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
expr = jexl.createExpression("size([])");
value = expr.evaluate(null);
assertEquals(0, value);
@@ -572,7 +593,7 @@ public class IssuesTest extends JexlTest
}
public void test109() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
Object value;
JexlContext context = new MapContext();
context.set("foo.bar", 40);
@@ -581,7 +602,7 @@ public class IssuesTest extends JexlTest
}
public void test110() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
String[] names = {"foo"};
Object value;
JexlContext context = new MapContext();
@@ -604,7 +625,7 @@ public class IssuesTest extends JexlTest
public void testRichContext() throws Exception {
A105 a105 = new A105("foo", "bar");
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
Object value;
JexlContext context = new RichContext(jexl, a105);
value = jexl.createScript("uppercase(nameA + propA)").execute(context);
@@ -612,11 +633,11 @@ public class IssuesTest extends JexlTest
}
public void test111() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
Object value;
JexlContext context = new MapContext();
String strExpr = "((x>0)?\"FirstValue=\"+(y-x):\"SecondValue=\"+x)";
- Expression expr = jexl.createExpression(strExpr);
+ JexlExpression expr = jexl.createExpression(strExpr);
context.set("x", 1);
context.set("y", 10);
@@ -661,11 +682,10 @@ public class IssuesTest extends JexlTest
}
public void testScaleIssue() throws Exception {
- JexlArithmetic arithmetic = new JexlThreadedArithmetic(false);
- JexlEngine jexlX = new JexlEngine(null, arithmetic, null, null);
+ JexlEngine jexlX = new Engine();
String expStr1 = "result == salary/month * work.percent/100.00";
- Expression exp1 = jexlX.createExpression(expStr1);
- JexlContext ctx = new MapContext();
+ JexlExpression exp1 = jexlX.createExpression(expStr1);
+ JexlEvalContext ctx = new JexlEvalContext();
ctx.set("result", new BigDecimal("9958.33"));
ctx.set("salary", new BigDecimal("119500.00"));
ctx.set("month", new BigDecimal("12.00"));
@@ -675,13 +695,13 @@ public class IssuesTest extends JexlTest
assertFalse((Boolean) exp1.evaluate(ctx));
// will succeed with scale = 2
- JexlThreadedArithmetic.setMathScale(2);
+ ctx.setMathScale(2);
assertTrue((Boolean) exp1.evaluate(ctx));
}
public void test112() throws Exception {
Object result;
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
result = jexl.createScript(Integer.toString(Integer.MAX_VALUE)).execute(null);
assertEquals(Integer.MAX_VALUE, result);
result = jexl.createScript(Integer.toString(Integer.MIN_VALUE + 1)).execute(null);
@@ -691,8 +711,8 @@ public class IssuesTest extends JexlTest
}
public void test117() throws Exception {
- JexlEngine jexl = new JexlEngine();
- Expression e = jexl.createExpression("TIMESTAMP > 20100102000000");
+ JexlEngine jexl = new Engine();
+ JexlExpression e = jexl.createExpression("TIMESTAMP > 20100102000000");
JexlContext ctx = new MapContext();
ctx.set("TIMESTAMP", new Long("20100103000000"));
Object result = e.evaluate(ctx);
@@ -700,19 +720,19 @@ public class IssuesTest extends JexlTest
}
public void testStringIdentifier() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
Map<String, String> foo = new HashMap<String, String>();
JexlContext jc = new MapContext();
jc.set("foo", foo);
foo.put("q u u x", "456");
- Expression e = jexl.createExpression("foo.\"q u u x\"");
+ JexlExpression e = jexl.createExpression("foo.\"q u u x\"");
Object result = e.evaluate(jc);
assertEquals("456", result);
e = jexl.createExpression("foo.'q u u x'");
result = e.evaluate(jc);
assertEquals("456", result);
- Script s = jexl.createScript("foo.\"q u u x\"");
+ JexlScript s = jexl.createScript("foo.\"q u u x\"");
result = s.execute(jc);
assertEquals("456", result);
s = jexl.createScript("foo.'q u u x'");
@@ -720,9 +740,9 @@ public class IssuesTest extends JexlTest
assertEquals("456", result);
Debugger dbg = new Debugger();
- dbg.debug(((JexlScript) s).script);
- String dbgdata = dbg.data();
- assertEquals("foo.'q u u x';", dbgdata);
+// dbg.debug(((Script)s).script);
+// String dbgdata = dbg.data();
+// assertEquals("foo.'q u u x';", dbgdata);
}
public static class Container {
@@ -777,49 +797,49 @@ public class IssuesTest extends JexlTest
}
public void test119() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = new Engine();
Container quux = new Container("quux", 42);
- Script get;
+ JexlScript get;
Object result;
- Script getName = jexl.createScript("foo.property.name", "foo");
+ JexlScript getName = jexl.createScript("foo.property.name", "foo");
result = getName.execute(null, quux);
assertEquals("quux", result);
- Script get0 = jexl.createScript("foo.property.0", "foo");
+ JexlScript get0 = jexl.createScript("foo.property.0", "foo");
result = get0.execute(null, quux);
assertEquals("quux", result);
- Script getNumber = jexl.createScript("foo.property.number", "foo");
+ JexlScript getNumber = jexl.createScript("foo.property.number", "foo");
result = getNumber.execute(null, quux);
assertEquals(42, result);
- Script get1 = jexl.createScript("foo.property.1", "foo");
+ JexlScript get1 = jexl.createScript("foo.property.1", "foo");
result = get1.execute(null, quux);
assertEquals(42, result);
- Script setName = jexl.createScript("foo.property.name = $0", "foo", "$0");
+ JexlScript setName = jexl.createScript("foo.property.name = $0", "foo", "$0");
setName.execute(null, quux, "QUUX");
result = getName.execute(null, quux);
assertEquals("QUUX", result);
result = get0.execute(null, quux);
assertEquals("QUUX", result);
- Script set0 = jexl.createScript("foo.property.0 = $0", "foo", "$0");
+ JexlScript set0 = jexl.createScript("foo.property.0 = $0", "foo", "$0");
set0.execute(null, quux, "BAR");
result = getName.execute(null, quux);
assertEquals("BAR", result);
result = get0.execute(null, quux);
assertEquals("BAR", result);
- Script setNumber = jexl.createScript("foo.property.number = $0", "foo", "$0");
+ JexlScript setNumber = jexl.createScript("foo.property.number = $0", "foo", "$0");
setNumber.execute(null, quux, -42);
result = getNumber.execute(null, quux);
assertEquals(-42, result);
result = get1.execute(null, quux);
assertEquals(-42, result);
- Script set1 = jexl.createScript("foo.property.1 = $0", "foo", "$0");
+ JexlScript set1 = jexl.createScript("foo.property.1 = $0", "foo", "$0");
set1.execute(null, quux, 24);
result = getNumber.execute(null, quux);
assertEquals(24, result);
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/Jexl.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/Jexl.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/Jexl.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/Jexl.java Tue Dec 6 14:19:33 2011
@@ -17,6 +17,7 @@
package org.apache.commons.jexl3;
+import org.apache.commons.jexl3.internal.Engine;
import java.util.Map;
/**
@@ -27,7 +28,7 @@ public class Jexl {
private Jexl() {}
public static void main(String[] args) {
- final JexlEngine JEXL = new JexlEngine();
+ final JexlEngine JEXL = new Engine();
Map<Object,Object> m = System.getProperties();
// dummy context to get variables
JexlContext context = new MapContext();
@@ -36,7 +37,7 @@ public class Jexl {
}
try {
for (int i = 0; i < args.length; i++) {
- Expression e = JEXL.createExpression(args[i]);
+ JexlExpression e = JEXL.createExpression(args[i]);
System.out.println("evaluate(" + args[i] + ") = '" + e.evaluate(context) + "'");
}
} catch (Exception e) {
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTest.java Tue Dec 6 14:19:33 2011
@@ -48,13 +48,12 @@ public class JexlTest extends JexlTestCa
/**
* test a simple property expression
*/
- public void testProperty()
- throws Exception {
+ public void testProperty() throws Exception {
/*
* tests a simple property expression
*/
- Expression e = JEXL.createExpression("foo.bar");
+ JexlExpression e = JEXL.createExpression("foo.bar");
JexlContext jc = new MapContext();
jc.set("foo", new Foo());
@@ -64,8 +63,7 @@ public class JexlTest extends JexlTestCa
assertEquals("o incorrect", GET_METHOD_STRING, o);
}
- public void testBoolean()
- throws Exception {
+ public void testBoolean() throws Exception {
JexlContext jc = new MapContext();
jc.set("foo", new Foo());
jc.set("a", Boolean.TRUE);
@@ -79,8 +77,7 @@ public class JexlTest extends JexlTestCa
assertExpression(jc, "true ne false", Boolean.TRUE);
}
- public void testStringLit()
- throws Exception {
+ public void testStringLit() throws Exception {
/*
* tests a simple property expression
*/
@@ -89,8 +86,7 @@ public class JexlTest extends JexlTestCa
assertExpression(jc, "foo.get(\"woogie\")", "Repeat : woogie");
}
- public void testExpression()
- throws Exception {
+ public void testExpression() throws Exception {
JexlContext jc = new MapContext();
jc.set("foo", new Foo());
jc.set("a", Boolean.TRUE);
@@ -149,9 +145,9 @@ public class JexlTest extends JexlTestCa
assertExpression(jc, "num < bint", Boolean.TRUE);
}
- public void testEmpty()
- throws Exception {
- JexlContext jc = new MapContext();
+ public void testEmpty() throws Exception {
+ JexlEvalContext jc = new JexlEvalContext();
+ jc.setStrict(false);
jc.set("string", "");
jc.set("array", new Object[0]);
jc.set("map", new HashMap<Object, Object>());
@@ -172,9 +168,9 @@ public class JexlTest extends JexlTestCa
assertExpression(jc, "not empty longstring", Boolean.TRUE);
}
- public void testSize()
- throws Exception {
- JexlContext jc = new MapContext();
+ public void testSize() throws Exception {
+ JexlEvalContext jc = new JexlEvalContext();
+ jc.setStrict(false);
jc.set("s", "five!");
jc.set("array", new Object[5]);
@@ -247,7 +243,7 @@ public class JexlTest extends JexlTestCa
JexlContext jc = new MapContext();
jc.set("double", Double.class);
jc.set("foo", "org.apache.commons.jexl3.Foo");
- Expression expr;
+ JexlExpression expr;
Object value;
expr = JEXL.createExpression("new(double, 1)");
value = expr.evaluate(jc);
@@ -263,9 +259,9 @@ public class JexlTest extends JexlTestCa
/**
* test some simple mathematical calculations
*/
- public void testCalculations()
- throws Exception {
- JexlContext jc = new MapContext();
+ public void testCalculations() throws Exception {
+ JexlEvalContext jc = new JexlEvalContext();
+ jc.setStrict(false);
/*
* test to ensure new string cat works
@@ -288,9 +284,8 @@ public class JexlTest extends JexlTestCa
/**
* test some simple conditions
*/
- public void testConditions()
- throws Exception {
- JexlContext jc = new MapContext();
+ public void testConditions() throws Exception {
+ JexlEvalContext jc = new JexlEvalContext();
jc.set("foo", new Integer(2));
jc.set("aFloat", new Float(1));
jc.set("aDouble", new Double(2));
@@ -321,9 +316,11 @@ public class JexlTest extends JexlTestCa
assertExpression(jc, "aBool == 'false'", Boolean.FALSE);
assertExpression(jc, "aBool != 'false'", Boolean.TRUE);
// test null and boolean
+ jc.setStrict(false);
assertExpression(jc, "aBool == notThere", Boolean.FALSE);
assertExpression(jc, "aBool != notThere", Boolean.TRUE);
// anything and string as a string comparison
+ jc.setStrict(true);
assertExpression(jc, "aBuffer == 'abc'", Boolean.TRUE);
assertExpression(jc, "aBuffer != 'abc'", Boolean.FALSE);
// arbitrary equals
@@ -334,8 +331,7 @@ public class JexlTest extends JexlTestCa
/**
* test some simple conditions
*/
- public void testNotConditions()
- throws Exception {
+ public void testNotConditions() throws Exception {
JexlContext jc = new MapContext();
Foo foo = new Foo();
@@ -366,8 +362,7 @@ public class JexlTest extends JexlTestCa
/**
* test some simple conditions
*/
- public void testNotConditionsWithDots()
- throws Exception {
+ public void testNotConditionsWithDots() throws Exception {
JexlContext jc = new MapContext();
jc.set("x.a", Boolean.TRUE);
@@ -381,8 +376,7 @@ public class JexlTest extends JexlTestCa
/**
* test some simple conditions
*/
- public void testComparisons()
- throws Exception {
+ public void testComparisons() throws Exception {
JexlContext jc = new MapContext();
jc.set("foo", "the quick and lazy fox");
@@ -394,9 +388,9 @@ public class JexlTest extends JexlTestCa
/**
* test some null conditions
*/
- public void testNull()
- throws Exception {
- JexlContext jc = new MapContext();
+ public void testNull() throws Exception {
+ JexlEvalContext jc = new JexlEvalContext();
+ jc.setStrict(false);
jc.set("bar", new Integer(2));
assertExpression(jc, "empty foo", Boolean.TRUE);
@@ -420,14 +414,11 @@ public class JexlTest extends JexlTestCa
/**
* test some blank strings
*/
- public void testBlankStrings()
- throws Exception {
+ public void testBlankStrings() throws Exception {
JexlContext jc = new MapContext();
jc.set("bar", "");
- assertExpression(jc, "foo == ''", Boolean.FALSE);
assertExpression(jc, "bar == ''", Boolean.TRUE);
- assertExpression(jc, "barnotexist == ''", Boolean.FALSE);
assertExpression(jc, "empty bar", Boolean.TRUE);
assertExpression(jc, "bar.length() == 0", Boolean.TRUE);
assertExpression(jc, "size(bar) == 0", Boolean.TRUE);
@@ -436,8 +427,7 @@ public class JexlTest extends JexlTestCa
/**
* test some blank strings
*/
- public void testLogicExpressions()
- throws Exception {
+ public void testLogicExpressions() throws Exception {
JexlContext jc = new MapContext();
jc.set("foo", "abc");
jc.set("bar", "def");
@@ -456,8 +446,7 @@ public class JexlTest extends JexlTestCa
/**
* test variables with underscore names
*/
- public void testVariableNames()
- throws Exception {
+ public void testVariableNames() throws Exception {
JexlContext jc = new MapContext();
jc.set("foo_bar", "123");
@@ -467,8 +456,7 @@ public class JexlTest extends JexlTestCa
/**
* test the use of dot notation to lookup map entries
*/
- public void testMapDot()
- throws Exception {
+ public void testMapDot() throws Exception {
Map<String, String> foo = new HashMap<String, String>();
foo.put("bar", "123");
@@ -481,8 +469,7 @@ public class JexlTest extends JexlTestCa
/**
* Tests string literals
*/
- public void testStringLiterals()
- throws Exception {
+ public void testStringLiterals() throws Exception {
JexlContext jc = new MapContext();
jc.set("foo", "bar");
@@ -493,8 +480,7 @@ public class JexlTest extends JexlTestCa
/**
* test the use of an int based property
*/
- public void testIntProperty()
- throws Exception {
+ public void testIntProperty() throws Exception {
Foo foo = new Foo();
// lets check the square function first..
@@ -512,8 +498,7 @@ public class JexlTest extends JexlTestCa
/**
* test the -1 comparison bug
*/
- public void testNegativeIntComparison()
- throws Exception {
+ public void testNegativeIntComparison() throws Exception {
JexlContext jc = new MapContext();
Foo foo = new Foo();
jc.set("foo", foo);
@@ -526,9 +511,9 @@ public class JexlTest extends JexlTestCa
/**
* Attempts to recreate bug http://jira.werken.com/ViewIssue.jspa?key=JELLY-8
*/
- public void testCharAtBug()
- throws Exception {
- JexlContext jc = new MapContext();
+ public void testCharAtBug() throws Exception {
+ JexlEvalContext jc = new JexlEvalContext();
+ jc.setSilent(true);
jc.set("foo", "abcdef");
@@ -556,8 +541,7 @@ public class JexlTest extends JexlTestCa
assertExpression(jc, "empty( aMap.aList )", Boolean.TRUE);
}
- public void testCoercionWithComparisionOperators()
- throws Exception {
+ public void testCoercionWithComparisionOperators() throws Exception {
JexlContext jc = new MapContext();
assertExpression(jc, "'2' > 1", Boolean.TRUE);
@@ -585,7 +569,7 @@ public class JexlTest extends JexlTestCa
JexlContext jc = new MapContext();
jc.set("first", Boolean.FALSE);
jc.set("foo", tester);
- Expression expr = JEXL.createExpression("first and foo.trueAndModify");
+ JexlExpression expr = JEXL.createExpression("first and foo.trueAndModify");
expr.evaluate(jc);
assertTrue("Short circuit failure: rhs evaluated when lhs FALSE", !tester.getModified());
// handle true for the left arg of 'and'
@@ -606,7 +590,7 @@ public class JexlTest extends JexlTestCa
JexlContext jc = new MapContext();
jc.set("first", Boolean.FALSE);
jc.set("foo", tester);
- Expression expr = JEXL.createExpression("first or foo.trueAndModify");
+ JexlExpression expr = JEXL.createExpression("first or foo.trueAndModify");
expr.evaluate(jc);
assertTrue("Short circuit failure: rhs not evaluated when lhs FALSE", tester.getModified());
// handle true for the left arg of 'or'
@@ -630,7 +614,7 @@ public class JexlTest extends JexlTestCa
public void testToString() throws Exception {
String code = "abcd";
- Expression expr = JEXL.createExpression(code);
+ JexlExpression expr = JEXL.createExpression(code);
assertEquals("Bad expression value", code, expr.toString());
}
@@ -693,7 +677,7 @@ public class JexlTest extends JexlTestCa
public void testUnicodeSupport() throws Exception {
JexlContext jc = new MapContext();
- assertExpression(jc, "myvar == 'Użytkownik'", Boolean.FALSE);
+ assertExpression(jc, "'x' == 'Użytkownik'", Boolean.FALSE);
assertExpression(jc, "'c:\\some\\windows\\path'", "c:\\some\\windows\\path");
assertExpression(jc, "'foo\\u0020bar'", "foo\u0020bar");
assertExpression(jc, "'foo\\u0020\\u0020bar'", "foo\u0020\u0020bar");
@@ -736,7 +720,7 @@ public class JexlTest extends JexlTestCa
JexlEngine jexl = JEXL;
JexlContext jc = new MapContext();
jc.set("duck", new Duck());
- Expression expr;
+ JexlExpression expr;
Object result;
expr = jexl.createExpression("duck.zero");
result = expr.evaluate(jc);
@@ -763,7 +747,7 @@ public class JexlTest extends JexlTestCa
JexlEngine jexl = JEXL;
JexlContext jc = new MapContext();
jc.set("array", array);
- Expression expr;
+ JexlExpression expr;
Object result;
expr = jexl.createExpression("array.1");
result = expr.evaluate(jc);
@@ -781,7 +765,7 @@ public class JexlTest extends JexlTestCa
* given context
*/
protected void assertExpression(JexlContext jc, String expression, Object expected) throws Exception {
- Expression e = JEXL.createExpression(expression);
+ JexlExpression e = JEXL.createExpression(expression);
Object actual = e.evaluate(jc);
assertEquals(expression, expected, actual);
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTestCase.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTestCase.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/JexlTestCase.java Tue Dec 6 14:19:33 2011
@@ -19,15 +19,10 @@ package org.apache.commons.jexl3;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.List;
-import java.util.ArrayList;
-import org.apache.commons.jexl3.parser.ASTJexlScript;
import junit.framework.TestCase;
-import org.apache.commons.jexl3.parser.JexlNode;
+import org.apache.commons.jexl3.internal.Util;
/**
* Implements runTest methods to dynamically instantiate and invoke a test,
@@ -44,20 +39,12 @@ public class JexlTestCase extends TestCa
protected final JexlEngine JEXL;
public JexlTestCase(String name) {
- this(name, new JexlEngine());
+ this(name, new JexlBuilder().strict(true).silent(false).cache(32).create());
}
+
protected JexlTestCase(String name, JexlEngine jexl) {
super(name);
JEXL = jexl;
- JEXL.setCache(512);
- }
- public JexlTestCase() {
- this(new JexlEngine());
- }
- protected JexlTestCase(JexlEngine jexl) {
- super();
- JEXL = jexl;
- JEXL.setCache(512);
}
@Override
@@ -66,11 +53,7 @@ public class JexlTestCase extends TestCa
}
public static JexlEngine createEngine(boolean lenient) {
- return new JexlEngine(null, new JexlArithmetic(lenient), null, null);
- }
-
- public static JexlEngine createThreadedArithmeticEngine(boolean lenient) {
- return new JexlEngine(null, new JexlThreadedArithmetic(lenient), null, null);
+ return new JexlBuilder().arithmetic(new JexlArithmetic(!lenient)).cache(512).create();
}
/**
@@ -79,130 +62,11 @@ public class JexlTestCase extends TestCa
* testing them for equality with the origin.
* @throws Exception
*/
- public static void debuggerCheck(JexlEngine jexl) throws Exception {
- // without a cache, nothing to check
- if (jexl.cache == null) {
- return;
- }
- JexlEngine jdbg = new JexlEngine();
- jdbg.parser.ALLOW_REGISTERS = true;
- Debugger dbg = new Debugger();
- // iterate over all expression in cache
- Iterator<Map.Entry<String,ASTJexlScript>> inodes = jexl.cache.entrySet().iterator();
- while (inodes.hasNext()) {
- Map.Entry<String,ASTJexlScript> entry = inodes.next();
- JexlNode node = entry.getValue();
- // recreate expr string from AST
- dbg.debug(node);
- String expressiondbg = dbg.data();
- // recreate expr from string
- Script exprdbg = jdbg.createScript(expressiondbg);
- // make arg cause become the root cause
- JexlNode root = ((JexlScript) exprdbg).script;
- while (root.jjtGetParent() != null) {
- root = root.jjtGetParent();
- }
- // test equality
- String reason = JexlTestCase.checkEquals(root, node);
- if (reason != null) {
- throw new RuntimeException("debugger equal failed: "
- + expressiondbg
- +" /**** " +reason+" **** */ "
- + entry.getKey());
- }
- }
- }
-
- /**
- * Creates a list of all descendants of a script including itself.
- * @param script the script to flatten
- * @return the descendants-and-self list
- */
- protected static ArrayList<JexlNode> flatten(JexlNode node) {
- ArrayList<JexlNode> list = new ArrayList<JexlNode>();
- flatten(list, node);
- return list;
- }
-
- /**
- * Recursively adds all children of a script to the list of descendants.
- * @param list the list of descendants to add to
- * @param script the script & descendants to add
- */
- private static void flatten(List<JexlNode> list, JexlNode node) {
- int nc = node.jjtGetNumChildren();
- list.add(node);
- for(int c = 0; c < nc; ++c) {
- flatten(list, node.jjtGetChild(c));
- }
+ public static void debuggerCheck(JexlEngine ijexl) throws Exception {
+ Util.debuggerCheck(ijexl);
}
/**
- * Checks the equality of 2 nodes by comparing all their descendants.
- * Descendants must have the same class and same image if non null.
- * @param lhs the left script
- * @param rhs the right script
- * @return null if true, a reason otherwise
- */
- private static String checkEquals(JexlNode lhs, JexlNode rhs) {
- if (lhs != rhs) {
- ArrayList<JexlNode> lhsl = flatten(lhs);
- ArrayList<JexlNode> rhsl = flatten(rhs);
- if (lhsl.size() != rhsl.size()) {
- return "size: " + lhsl.size() + " != " + rhsl.size();
- }
- for(int n = 0; n < lhsl.size(); ++n) {
- lhs = lhsl.get(n);
- rhs = rhsl.get(n);
- if (lhs.getClass() != rhs.getClass()) {
- return "class: " + lhs.getClass() + " != " + rhs.getClass();
- }
- if ((lhs.image == null && rhs.image != null)
- || (lhs.image != null && rhs.image == null)) {
- return "image: " + lhs.image + " != " + rhs.image;
- }
- if (lhs.image != null && !lhs.image.equals(rhs.image)) {
- return "image: " + lhs.image + " != " + rhs.image;
- }
- }
- }
- return null;
- }
-
- /**
- * A helper class to help debug AST problems.
- * @param e the script
- * @return an indented version of the AST
- */
- protected String flattenedStr(Script e) {
- return e.getText() + "\n" + flattenedStr(((ExpressionImpl) e).script);
- }
-
- static private String indent(JexlNode node) {
- StringBuilder strb = new StringBuilder();
- while (node != null) {
- strb.append(" ");
- node = node.jjtGetParent();
- }
- return strb.toString();
- }
-
-
- private String flattenedStr(JexlNode node) {
- ArrayList<JexlNode> flattened = flatten(node);
- StringBuilder strb = new StringBuilder();
- for (JexlNode flat : flattened) {
- strb.append(indent(flat));
- strb.append(flat.getClass().getSimpleName());
- if (flat.image != null) {
- strb.append(" = ");
- strb.append(flat.image);
- }
- strb.append("\n");
- }
- return strb.toString();
- }
- /**
* Dynamically runs a test method.
* @param name the test method to run
* @throws Exception if anything goes wrong
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java Tue Dec 6 14:19:33 2011
@@ -26,9 +26,12 @@ import java.util.Map;
* @since 1.2
*/
public class MapLiteralTest extends JexlTestCase {
+ public MapLiteralTest() {
+ super("MapLiteralTest");
+ }
public void testLiteralWithStrings() throws Exception {
- Expression e = JEXL.createExpression( "{ 'foo' : 'bar' }" );
+ JexlExpression e = JEXL.createExpression( "{ 'foo' : 'bar' }" );
JexlContext jc = new MapContext();
Object o = e.evaluate( jc );
@@ -36,7 +39,7 @@ public class MapLiteralTest extends Jexl
}
public void testLiteralWithMultipleEntries() throws Exception {
- Expression e = JEXL.createExpression( "{ 'foo' : 'bar', 'eat' : 'food' }" );
+ JexlExpression e = JEXL.createExpression( "{ 'foo' : 'bar', 'eat' : 'food' }" );
JexlContext jc = new MapContext();
Map<String, String> expected = new HashMap<String, String>();
@@ -48,7 +51,7 @@ public class MapLiteralTest extends Jexl
}
public void testLiteralWithNumbers() throws Exception {
- Expression e = JEXL.createExpression( "{ 5 : 10 }" );
+ JexlExpression e = JEXL.createExpression( "{ 5 : 10 }" );
JexlContext jc = new MapContext();
Object o = e.evaluate( jc );
@@ -96,7 +99,7 @@ public class MapLiteralTest extends Jexl
}
public void testSizeOfSimpleMapLiteral() throws Exception {
- Expression e = JEXL.createExpression( "size({ 'foo' : 'bar' })" );
+ JexlExpression e = JEXL.createExpression( "size({ 'foo' : 'bar' })" );
JexlContext jc = new MapContext();
Object o = e.evaluate( jc );
@@ -104,7 +107,7 @@ public class MapLiteralTest extends Jexl
}
public void testCallingMethodsOnNewMapLiteral() throws Exception {
- Expression e = JEXL.createExpression( "size({ 'foo' : 'bar' }.values())" );
+ JexlExpression e = JEXL.createExpression( "size({ 'foo' : 'bar' }.values())" );
JexlContext jc = new MapContext();
Object o = e.evaluate( jc );
@@ -112,7 +115,7 @@ public class MapLiteralTest extends Jexl
}
public void testNotEmptySimpleMapLiteral() throws Exception {
- Expression e = JEXL.createExpression( "empty({ 'foo' : 'bar' })" );
+ JexlExpression e = JEXL.createExpression( "empty({ 'foo' : 'bar' })" );
JexlContext jc = new MapContext();
Object o = e.evaluate( jc );
@@ -120,7 +123,7 @@ public class MapLiteralTest extends Jexl
}
public void testMapMapLiteral() throws Exception {
- Expression e = JEXL.createExpression( "{'foo' : { 'inner' : 'bar' }}" );
+ JexlExpression e = JEXL.createExpression( "{'foo' : { 'inner' : 'bar' }}" );
JexlContext jc = new MapContext();
Object o = e.evaluate( jc );
assertNotNull(o);
@@ -132,7 +135,7 @@ public class MapLiteralTest extends Jexl
}
public void testMapArrayLiteral() throws Exception {
- Expression e = JEXL.createExpression( "{'foo' : [ 'inner' , 'bar' ]}" );
+ JexlExpression e = JEXL.createExpression( "{'foo' : [ 'inner' , 'bar' ]}" );
JexlContext jc = new MapContext();
Object o = e.evaluate( jc );
assertNotNull(o);
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/MethodTest.java Tue Dec 6 14:19:33 2011
@@ -20,7 +20,6 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.commons.jexl3.introspection.JexlMethod;
import org.apache.commons.jexl3.junit.Asserter;
-import org.apache.commons.jexl3.junit.Asserter;
/**
* Tests for calling methods on objects
@@ -30,7 +29,11 @@ import org.apache.commons.jexl3.junit.As
public class MethodTest extends JexlTestCase {
private Asserter asserter;
private static final String METHOD_STRING = "Method string";
-
+
+ public MethodTest() {
+ super("MethodTest");
+ }
+
public static class VarArgs {
public String callInts(Integer... args) {
int result = 0;
@@ -91,7 +94,7 @@ public class MethodTest extends JexlTest
}
}
- public static class EnhancedContext extends MapContext {
+ public static class EnhancedContext extends JexlEvalContext {
int factor = 6;
}
@@ -217,11 +220,11 @@ public class MethodTest extends JexlTest
funcs.put(null, new Functor());
funcs.put("math", new MyMath());
funcs.put("cx", ContextualFunctor.class);
- JEXL.setFunctions(funcs);
- JexlContext jc = new EnhancedContext();
+ EnhancedContext jc = new EnhancedContext();
+ jc.setNamespaces(funcs);
- Expression e = JEXL.createExpression("ten()");
+ JexlExpression e = JEXL.createExpression("ten()");
Object o = e.evaluate(jc);
assertEquals("Result is not 10", new Integer(10), o);
@@ -247,30 +250,26 @@ public class MethodTest extends JexlTest
java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
funcs.put("func", new Functor());
funcs.put("FUNC", Functor.class);
- JEXL.setFunctions(funcs);
- Expression e = JEXL.createExpression("func:ten()");
- JexlContext jc = new MapContext();
+ JexlExpression e = JEXL.createExpression("func:ten()");
+ JexlEvalContext jc = new JexlEvalContext();
+ jc.setNamespaces(funcs);
Object o = e.evaluate(jc);
assertEquals("Result is not 10", new Integer(10), o);
e = JEXL.createExpression("func:plus10(10)");
- jc = new MapContext();
o = e.evaluate(jc);
assertEquals("Result is not 20", new Integer(20), o);
e = JEXL.createExpression("func:plus10(func:ten())");
- jc = new MapContext();
o = e.evaluate(jc);
assertEquals("Result is not 20", new Integer(20), o);
e = JEXL.createExpression("FUNC:PLUS20(10)");
- jc = new MapContext();
o = e.evaluate(jc);
assertEquals("Result is not 30", new Integer(30), o);
e = JEXL.createExpression("FUNC:PLUS20(FUNC:TWENTY())");
- jc = new MapContext();
o = e.evaluate(jc);
assertEquals("Result is not 40", new Integer(40), o);
}
@@ -295,9 +294,9 @@ public class MethodTest extends JexlTest
public void testScriptCall() throws Exception {
JexlContext context = new MapContext();
- Script plus = JEXL.createScript("a + b", new String[]{"a", "b"});
+ JexlScript plus = JEXL.createScript("a + b", new String[]{"a", "b"});
context.set("plus", plus);
- Script forty2 = JEXL.createScript("plus(4, 2) * plus(4, 3)");
+ JexlScript forty2 = JEXL.createScript("plus(4, 2) * plus(4, 3)");
Object o = forty2.execute(context);
assertEquals("Result is not 42", new Integer(42), o);
@@ -315,6 +314,7 @@ public class MethodTest extends JexlTest
final JexlArithmetic ja = JEXL.getArithmetic();
JexlMethod mplus = new JexlMethod() {
+ @Override
public Object invoke(Object obj, Object[] params) throws Exception {
if (obj instanceof Map<?,?>) {
return ja.add(params[0], params[1]);
@@ -323,6 +323,7 @@ public class MethodTest extends JexlTest
}
}
+ @Override
public Object tryInvoke(String name, Object obj, Object[] params) {
try {
if ("plus".equals(name)) {
@@ -334,15 +335,18 @@ public class MethodTest extends JexlTest
return this;
}
+ @Override
public boolean tryFailed(Object rval) {
// this is the marker for failure
return rval == this;
}
+ @Override
public boolean isCacheable() {
return true;
}
+ @Override
public Class<?> getReturnType() {
return Object.class;
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java Tue Dec 6 14:19:33 2011
@@ -16,6 +16,9 @@
*/
package org.apache.commons.jexl3;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* Tests for malformed expressions and scripts.
* ({@link org.apache.commons.jexl3.JexlEngine#createExpression(String)} and
@@ -26,14 +29,14 @@ package org.apache.commons.jexl3;
*/
public class ParseFailuresTest extends JexlTestCase {
+ static final Log LOGGER = LogFactory.getLog(ParseFailuresTest.class.getName());
/**
* Create the test.
*
* @param testName name of the test
*/
- public ParseFailuresTest(String testName) {
- super(testName);
- JEXL.setSilent(false);
+ public ParseFailuresTest() {
+ super("ParseFailuresTest");
}
public void testMalformedExpression1() throws Exception {
@@ -45,7 +48,7 @@ public class ParseFailuresTest extends J
+ "\" should result in a JexlException");
} catch (JexlException pe) {
// expected
- JEXL.logger.error(pe);
+ LOGGER.info(pe);
}
}
@@ -58,7 +61,7 @@ public class ParseFailuresTest extends J
+ "\" should result in a JexlException");
} catch (JexlException pe) {
// expected
- JEXL.logger.error(pe);
+ LOGGER.info(pe);
}
}
@@ -71,7 +74,7 @@ public class ParseFailuresTest extends J
+ "\" should result in a JexlException");
} catch (JexlException pe) {
// expected
- JEXL.logger.error(pe);
+ LOGGER.info(pe);
}
}
@@ -85,7 +88,7 @@ public class ParseFailuresTest extends J
+ "\" should result in a JexlException");
} catch (JexlException pe) {
// expected
- JEXL.logger.error(pe);
+ LOGGER.info(pe);
}
}
@@ -98,7 +101,7 @@ public class ParseFailuresTest extends J
+ "\" should result in a JexlException");
} catch (JexlException pe) {
// expected
- JEXL.logger.error(pe);
+ LOGGER.error(pe);
}
}
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java Tue Dec 6 14:19:33 2011
@@ -16,11 +16,6 @@
*/
package org.apache.commons.jexl3;
-import org.apache.commons.jexl3.Expression;
-import org.apache.commons.jexl3.JexlContext;
-import org.apache.commons.jexl3.JexlException;
-import org.apache.commons.jexl3.MapContext;
-
/**
* Tests public field set/get.
*/
@@ -51,7 +46,7 @@ public class PublicFieldsTest extends Je
private JexlContext ctxt;
public PublicFieldsTest() {
- super(createEngine(false));
+ super("PublicFieldsTest");
}
@Override
@@ -62,14 +57,14 @@ public class PublicFieldsTest extends Je
}
public void testGetInt() throws Exception {
- Expression get = JEXL.createExpression("pub.anInt");
+ JexlExpression get = JEXL.createExpression("pub.anInt");
assertEquals(42, get.evaluate(ctxt));
JEXL.setProperty(pub, "anInt", -42);
assertEquals(-42, get.evaluate(ctxt));
}
public void testSetInt() throws Exception {
- Expression set = JEXL.createExpression("pub.anInt = value");
+ JexlExpression set = JEXL.createExpression("pub.anInt = value");
ctxt.set("value", -42);
assertEquals(-42, set.evaluate(ctxt));
assertEquals(-42, JEXL.getProperty(pub, "anInt"));
@@ -84,14 +79,14 @@ public class PublicFieldsTest extends Je
}
public void testGetString() throws Exception {
- Expression get = JEXL.createExpression("pub.aString");
+ JexlExpression get = JEXL.createExpression("pub.aString");
assertEquals(LOWER42, get.evaluate(ctxt));
JEXL.setProperty(pub, "aString", UPPER42);
assertEquals(UPPER42, get.evaluate(ctxt));
}
public void testSetString() throws Exception {
- Expression set = JEXL.createExpression("pub.aString = value");
+ JexlExpression set = JEXL.createExpression("pub.aString = value");
ctxt.set("value", UPPER42);
assertEquals(UPPER42, set.evaluate(ctxt));
assertEquals(UPPER42, JEXL.getProperty(pub, "aString"));
@@ -101,14 +96,14 @@ public class PublicFieldsTest extends Je
}
public void testGetInnerDouble() throws Exception {
- Expression get = JEXL.createExpression("pub.inner.aDouble");
+ JexlExpression get = JEXL.createExpression("pub.inner.aDouble");
assertEquals(42.0, get.evaluate(ctxt));
JEXL.setProperty(pub, "inner.aDouble", -42);
assertEquals(-42.0, get.evaluate(ctxt));
}
public void testSetInnerDouble() throws Exception {
- Expression set = JEXL.createExpression("pub.inner.aDouble = value");
+ JexlExpression set = JEXL.createExpression("pub.inner.aDouble = value");
ctxt.set("value", -42.0);
assertEquals(-42.0, set.evaluate(ctxt));
assertEquals(-42.0, JEXL.getProperty(pub, "inner.aDouble"));
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SandboxTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SandboxTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SandboxTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/SandboxTest.java Tue Dec 6 14:19:33 2011
@@ -16,16 +16,21 @@
*/
package org.apache.commons.jexl3;
-import java.util.logging.Logger;
import org.apache.commons.jexl3.introspection.Sandbox;
import org.apache.commons.jexl3.internal.introspection.SandboxUberspect;
-import org.apache.commons.jexl3.introspection.Uberspect;
+import org.apache.commons.jexl3.introspection.JexlUberspect;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* Tests sandbox features.
*/
public class SandboxTest extends JexlTestCase {
- static final Logger LOGGER = Logger.getLogger(VarTest.class.getName());
+ static final Log LOGGER = LogFactory.getLog(SandboxTest.class.getName());
+
+ public SandboxTest() {
+ super("SandboxTest");
+ }
public static class Foo {
String name;
@@ -51,16 +56,15 @@ public class SandboxTest extends JexlTes
public void testCtorBlack() throws Exception {
String expr = "new('" + Foo.class.getName() + "', '42')";
- Script script = JEXL.createScript(expr);
+ JexlScript script = JEXL.createScript(expr);
Object result;
result = script.execute(null);
assertEquals("42", ((Foo) result).getName());
Sandbox sandbox = new Sandbox();
sandbox.black(Foo.class.getName()).execute("");
- Uberspect uber = new SandboxUberspect(null, sandbox);
- JexlEngine sjexl = new JexlEngine(uber, null, null, null);
- sjexl.setStrict(true);
+ JexlUberspect uber = new SandboxUberspect(null, sandbox);
+ JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
script = sjexl.createScript(expr);
try {
@@ -74,7 +78,7 @@ public class SandboxTest extends JexlTes
public void testMethodBlack() throws Exception {
String expr = "foo.Quux()";
- Script script = JEXL.createScript(expr, "foo");
+ JexlScript script = JEXL.createScript(expr, "foo");
Foo foo = new Foo("42");
Object result;
result = script.execute(null, foo);
@@ -82,9 +86,8 @@ public class SandboxTest extends JexlTes
Sandbox sandbox = new Sandbox();
sandbox.black(Foo.class.getName()).execute("Quux");
- Uberspect uber = new SandboxUberspect(null, sandbox);
- JexlEngine sjexl = new JexlEngine(uber, null, null, null);
- sjexl.setStrict(true);
+ JexlUberspect uber = new SandboxUberspect(null, sandbox);
+ JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
script = sjexl.createScript(expr, "foo");
try {
@@ -98,7 +101,7 @@ public class SandboxTest extends JexlTes
public void testGetBlack() throws Exception {
String expr = "foo.alias";
- Script script = JEXL.createScript(expr, "foo");
+ JexlScript script = JEXL.createScript(expr, "foo");
Foo foo = new Foo("42");
Object result;
result = script.execute(null, foo);
@@ -106,9 +109,8 @@ public class SandboxTest extends JexlTes
Sandbox sandbox = new Sandbox();
sandbox.black(Foo.class.getName()).read("alias");
- Uberspect uber = new SandboxUberspect(null, sandbox);
- JexlEngine sjexl = new JexlEngine(uber, null, null, null);
- sjexl.setStrict(true);
+ JexlUberspect uber = new SandboxUberspect(null, sandbox);
+ JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
script = sjexl.createScript(expr, "foo");
try {
@@ -122,7 +124,7 @@ public class SandboxTest extends JexlTes
public void testSetBlack() throws Exception {
String expr = "foo.alias = $0";
- Script script = JEXL.createScript(expr, "foo", "$0");
+ JexlScript script = JEXL.createScript(expr, "foo", "$0");
Foo foo = new Foo("42");
Object result;
result = script.execute(null, foo, "43");
@@ -130,9 +132,8 @@ public class SandboxTest extends JexlTes
Sandbox sandbox = new Sandbox();
sandbox.black(Foo.class.getName()).write("alias");
- Uberspect uber = new SandboxUberspect(null, sandbox);
- JexlEngine sjexl = new JexlEngine(uber, null, null, null);
- sjexl.setStrict(true);
+ JexlUberspect uber = new SandboxUberspect(null, sandbox);
+ JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
script = sjexl.createScript(expr, "foo", "$0");
try {
@@ -146,14 +147,13 @@ public class SandboxTest extends JexlTes
public void testCtorWhite() throws Exception {
String expr = "new('" + Foo.class.getName() + "', '42')";
- Script script;
+ JexlScript script;
Object result;
Sandbox sandbox = new Sandbox();
sandbox.white(Foo.class.getName()).execute("");
- Uberspect uber = new SandboxUberspect(null, sandbox);
- JexlEngine sjexl = new JexlEngine(uber, null, null, null);
- sjexl.setStrict(true);
+ JexlUberspect uber = new SandboxUberspect(null, sandbox);
+ JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
script = sjexl.createScript(expr);
result = script.execute(null);
@@ -163,14 +163,13 @@ public class SandboxTest extends JexlTes
public void testMethodWhite() throws Exception {
Foo foo = new Foo("42");
String expr = "foo.Quux()";
- Script script;
+ JexlScript script;
Object result;
Sandbox sandbox = new Sandbox();
sandbox.white(Foo.class.getName()).execute("Quux");
- Uberspect uber = new SandboxUberspect(null, sandbox);
- JexlEngine sjexl = new JexlEngine(uber, null, null, null);
- sjexl.setStrict(true);
+ JexlUberspect uber = new SandboxUberspect(null, sandbox);
+ JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
script = sjexl.createScript(expr, "foo");
result = script.execute(null, foo);
@@ -180,15 +179,14 @@ public class SandboxTest extends JexlTes
public void testGetWhite() throws Exception {
Foo foo = new Foo("42");
String expr = "foo.alias";
- Script script;
+ JexlScript script;
Object result;
Sandbox sandbox = new Sandbox();
sandbox.white(Foo.class.getName()).read("alias");
sandbox.get(Foo.class.getName()).read().alias("alias", "ALIAS");
- Uberspect uber = new SandboxUberspect(null, sandbox);
- JexlEngine sjexl = new JexlEngine(uber, null, null, null);
- sjexl.setStrict(true);
+ JexlUberspect uber = new SandboxUberspect(null, sandbox);
+ JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
script = sjexl.createScript(expr, "foo");
result = script.execute(null, foo);
@@ -202,14 +200,13 @@ public class SandboxTest extends JexlTes
public void testSetWhite() throws Exception {
Foo foo = new Foo("42");
String expr = "foo.alias = $0";
- Script script;
+ JexlScript script;
Object result;
Sandbox sandbox = new Sandbox();
sandbox.white(Foo.class.getName()).write("alias");
- Uberspect uber = new SandboxUberspect(null, sandbox);
- JexlEngine sjexl = new JexlEngine(uber, null, null, null);
- sjexl.setStrict(true);
+ JexlUberspect uber = new SandboxUberspect(null, sandbox);
+ JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
script = sjexl.createScript(expr, "foo", "$0");
result = script.execute(null, foo, "43");
@@ -226,12 +223,11 @@ public class SandboxTest extends JexlTes
// can not create a new file
sandbox.black(java.io.File.class.getName()).execute("");
- Uberspect uber = new SandboxUberspect(null, sandbox);
- JexlEngine sjexl = new JexlEngine(uber, null, null, null);
- sjexl.setStrict(true);
+ JexlUberspect uber = new SandboxUberspect(null, sandbox);
+ JexlEngine sjexl = new JexlBuilder().uberspect(uber).strict(true).create();
String expr;
- Script script;
+ JexlScript script;
Object result;
script = sjexl.createScript("System.exit()");
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java Tue Dec 6 14:19:33 2011
@@ -29,6 +29,9 @@ import java.util.concurrent.TimeoutExcep
*/
public class ScriptCallableTest extends JexlTestCase {
//Logger LOGGER = Logger.getLogger(VarTest.class.getName());
+ public ScriptCallableTest() {
+ super("ScriptCallableTest");
+ }
public void testFuture() throws Exception {
JexlScript e = JEXL.createScript("while(true);");
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptTest.java?rev=1210927&r1=1210926&r2=1210927&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptTest.java (original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/ScriptTest.java Tue Dec 6 14:19:33 2011
@@ -16,16 +16,16 @@
*/
package org.apache.commons.jexl3;
-import org.apache.commons.jexl3.Expression;
+import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.MapContext;
-import org.apache.commons.jexl3.Script;
+import org.apache.commons.jexl3.JexlScript;
import java.io.File;
import java.net.URL;
/**
- * Tests for Script
+ * Tests for JexlScript
* @since 1.1
*/
public class ScriptTest extends JexlTestCase {
@@ -58,7 +58,7 @@ public class ScriptTest extends JexlTest
*/
public void testSimpleScript() throws Exception {
String code = "while (x < 10) x = x + 1;";
- Script s = JEXL.createScript(code);
+ JexlScript s = JEXL.createScript(code);
JexlContext jc = new MapContext();
jc.set("x", new Integer(1));
@@ -69,7 +69,7 @@ public class ScriptTest extends JexlTest
public void testScriptFromFile() throws Exception {
File testScript = new File(TEST1);
- Script s = JEXL.createScript(testScript);
+ JexlScript s = JEXL.createScript(testScript);
JexlContext jc = new MapContext();
jc.set("out", System.out);
Object result = s.execute(jc);
@@ -79,7 +79,7 @@ public class ScriptTest extends JexlTest
public void testScriptFromURL() throws Exception {
URL testUrl = new File("src/test/scripts/test1.jexl").toURI().toURL();
- Script s = JEXL.createScript(testUrl);
+ JexlScript s = JEXL.createScript(testUrl);
JexlContext jc = new MapContext();
jc.set("out", System.out);
Object result = s.execute(jc);
@@ -89,8 +89,8 @@ public class ScriptTest extends JexlTest
public void testScriptUpdatesContext() throws Exception {
String jexlCode = "resultat.setCode('OK')";
- Expression e = JEXL.createExpression(jexlCode);
- Script s = JEXL.createScript(jexlCode);
+ JexlExpression e = JEXL.createExpression(jexlCode);
+ JexlScript s = JEXL.createScript(jexlCode);
Tester resultatJexl = new Tester();
JexlContext jc = new MapContext();