You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by cb...@apache.org on 2008/08/10 08:00:22 UTC
svn commit: r684410 [14/16] - in /ibatis/trunk/java/ibatis-3: ./
ibatis-3-core/src/main/java/org/apache/ibatis/ognl/
ibatis-3-core/src/test/java/org/apache/ibatis/ognl/
ibatis-3-core/src/test/java/org/apache/ibatis/ognl/objects/
ibatis-3-core/src/test/...
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ObjectIndexedTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ObjectIndexedTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ObjectIndexedTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ObjectIndexedTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,212 @@
+package org.apache.ibatis.ognl;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.Ognl;
+import org.apache.ibatis.ognl.OgnlContext;
+import org.apache.ibatis.ognl.OgnlException;
+import org.apache.ibatis.ognl.OgnlRuntime;
+import org.apache.ibatis.ognl.SimpleNode;
+
+public class ObjectIndexedTest extends TestCase
+{
+ protected OgnlContext context;
+
+ /*===================================================================
+ Public static classes
+ ===================================================================*/
+ public static interface TestInterface
+ {
+ String getSunk(String index);
+ void setSunk(String index, String sunk);
+ }
+
+ public static class Test1 extends Object implements TestInterface
+ {
+ public String getSunk(String index)
+ {
+ return "foo";
+ }
+
+ public void setSunk(String index, String sunk)
+ {
+ /* do nothing */
+ }
+ }
+
+ public static class Test2 extends Test1
+ {
+ public String getSunk(String index)
+ {
+ return "foo";
+ }
+
+ public void setSunk(String index, String sunk)
+ {
+ /* do nothing */
+ }
+ }
+
+ public static class Test3 extends Test1
+ {
+ public String getSunk(String index)
+ {
+ return "foo";
+ }
+
+ public void setSunk(String index, String sunk)
+ {
+ /* do nothing */
+ }
+
+ public String getSunk(Object index)
+ {
+ return null;
+ }
+ }
+
+ public static class Test4 extends Test1
+ {
+ public String getSunk(String index)
+ {
+ return "foo";
+ }
+
+ public void setSunk(String index, String sunk)
+ {
+ /* do nothing */
+ }
+
+ public void setSunk(Object index, String sunk)
+ {
+ /* do nothing */
+ }
+ }
+
+ public static class Test5 extends Test1
+ {
+ public String getSunk(String index)
+ {
+ return "foo";
+ }
+
+ public void setSunk(String index, String sunk)
+ {
+ /* do nothing */
+ }
+
+ public String getSunk(Object index)
+ {
+ return null;
+ }
+
+ public void setSunk(Object index, String sunk)
+ {
+ /* do nothing */
+ }
+ }
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ return new TestSuite(ObjectIndexedTest.class);
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public ObjectIndexedTest()
+ {
+ super();
+ }
+
+ public ObjectIndexedTest(String name)
+ {
+ super(name);
+ }
+
+ /*===================================================================
+ Public methods
+ ===================================================================*/
+ public void testPropertyDescriptorReflection() throws Exception
+ {
+ OgnlRuntime.getPropertyDescriptor(java.util.AbstractList.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.util.AbstractSequentialList.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.lang.reflect.Array.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.util.ArrayList.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.util.BitSet.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.util.Calendar.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.lang.reflect.Field.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.util.LinkedList.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.util.List.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.util.Iterator.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.lang.ThreadLocal.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.net.URL.class, "");
+ OgnlRuntime.getPropertyDescriptor(java.util.Vector.class, "");
+ }
+
+ public void testObjectIndexAccess() throws OgnlException
+ {
+ SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");
+
+ context.put("ka", new Test1());
+ Ognl.getValue(expression, context, "aksdj");
+ }
+
+ public void testObjectIndexInSubclass() throws OgnlException
+ {
+ SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");
+
+ context.put("ka", new Test2());
+ Ognl.getValue(expression, context, "aksdj");
+ }
+
+ public void testMultipleObjectIndexGetters() throws OgnlException
+ {
+ SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");
+
+ context.put("ka", new Test3());
+ try {
+ Ognl.getValue(expression, context, new Test3());
+ fail();
+ } catch (OgnlException ex) {
+ /* Should throw */
+ }
+ }
+
+ public void testMultipleObjectIndexSetters() throws OgnlException
+ {
+ SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");
+
+ context.put("ka", new Test4());
+ try {
+ Ognl.getValue(expression, context, "aksdj");
+ fail();
+ } catch (OgnlException ex) {
+ /* Should throw */
+ }
+ }
+
+ public void testMultipleObjectIndexMethodPairs() throws OgnlException
+ {
+ SimpleNode expression = (SimpleNode)Ognl.parseExpression("#ka.sunk[#root]");
+
+ context.put("ka", new Test5());
+ try {
+ Ognl.getValue(expression, context, "aksdj");
+ fail();
+ } catch (OgnlException ex) {
+ /* Should throw */
+ }
+ }
+
+ /*===================================================================
+ Overridden methods
+ ===================================================================*/
+ protected void setUp()
+ {
+ context = (OgnlContext)Ognl.createDefaultContext(null);
+ }
+}
\ No newline at end of file
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/OgnlTestCase.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/OgnlTestCase.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/OgnlTestCase.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/OgnlTestCase.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,220 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.Array;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.Ognl;
+import org.apache.ibatis.ognl.OgnlContext;
+import org.apache.ibatis.ognl.OgnlException;
+import org.apache.ibatis.ognl.SimpleNode;
+
+public class OgnlTestCase extends TestCase
+{
+ protected OgnlContext context;
+ private String expressionString;
+ private SimpleNode expression;
+ private Object expectedResult;
+ private Object root;
+ private boolean hasSetValue;
+ private Object setValue;
+ private boolean hasExpectedAfterSetResult;
+ private Object expectedAfterSetResult;
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ /**
+ Returns true if object1 is equal to object2 in either the
+ sense that they are the same object or, if both are non-null
+ if they are equal in the <CODE>equals()</CODE> sense.
+ */
+ public static boolean isEqual(Object object1, Object object2)
+ {
+ boolean result = false;
+
+ if (object1 == object2) {
+ result = true;
+ } else {
+ if ((object1 != null) && object1.getClass().isArray()) {
+ if ((object2 != null) && object2.getClass().isArray() && (object2.getClass() == object1.getClass())) {
+ result = (Array.getLength(object1) == Array.getLength(object2));
+ if (result) {
+ for (int i = 0, icount = Array.getLength(object1); result && (i < icount); i++) {
+ result = isEqual(Array.get(object1, i), Array.get(object2, i));
+ }
+ }
+ }
+ } else {
+ result = (object1 != null) && (object2 != null) && object1.equals(object2);
+ }
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public OgnlTestCase()
+ {
+ super();
+ }
+
+ public OgnlTestCase(String name)
+ {
+ super(name);
+ }
+
+ public OgnlTestCase(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ this(name, root, expressionString, expectedResult, setValue);
+ this.hasExpectedAfterSetResult = true;
+ this.expectedAfterSetResult = expectedAfterSetResult;
+ }
+
+ public OgnlTestCase(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ this(name, root, expressionString, expectedResult);
+ this.hasSetValue = true;
+ this.setValue = setValue;
+ }
+
+ public OgnlTestCase(String name, Object root, String expressionString, Object expectedResult)
+ {
+ this(name);
+ this.root = root;
+ this.expressionString = expressionString;
+ this.expectedResult = expectedResult;
+ }
+
+ /*===================================================================
+ Public methods
+ ===================================================================*/
+ public String getExpressionDump(SimpleNode node)
+ {
+ StringWriter writer = new StringWriter();
+
+ node.dump(new PrintWriter(writer), " ");
+ return writer.toString();
+ }
+
+ public String getExpressionString()
+ {
+ return expressionString;
+ }
+
+ public SimpleNode getExpression() throws OgnlException
+ {
+ if (expression == null) {
+ expression = (SimpleNode)Ognl.parseExpression(expressionString);
+ }
+ return expression;
+ }
+
+ public Object getExpectedResult()
+ {
+ return expectedResult;
+ }
+
+ /*===================================================================
+ Overridden methods
+ ===================================================================*/
+ protected void runTest() throws Exception
+ {
+ Object testedResult = null;
+
+ try {
+ SimpleNode expr;
+
+ testedResult = expectedResult;
+ expr = getExpression();
+ /*
+ PrintWriter writer = new PrintWriter(System.err);
+ System.err.println(expr.toString());
+ expr.dump(writer, "");
+ writer.flush();
+ */
+ assertTrue(isEqual(Ognl.getValue(expr, context, root), expectedResult));
+ if (hasSetValue) {
+ testedResult = hasExpectedAfterSetResult ? expectedAfterSetResult : setValue;
+ Ognl.setValue(expr, context, root, setValue);
+ assertTrue(isEqual(Ognl.getValue(expr, context, root), testedResult));
+ }
+ } catch (Exception ex) {
+ if (testedResult instanceof Class) {
+ assertTrue(((Class)testedResult).isAssignableFrom(ex.getClass()));
+ } else {
+ throw ex;
+ }
+ }
+ }
+
+ private static Object[][] TESTS = {
+ // Quoting
+ { null, "`c`", new Character('c') },
+ { null, "'s'", new Character('s') },
+ { null, "'string'", "string" },
+ { null, "\"string\"", "string" },
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ if (TESTS[i].length == 3) {
+ result.addTest(new QuotingTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new QuotingTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3]));
+ } else {
+ if (TESTS[i].length == 5) {
+ result.addTest(new QuotingTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
+ } else {
+ throw new RuntimeException("don't understand TEST format");
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ protected void setUp()
+ {
+ context = (OgnlContext)Ognl.createDefaultContext(null);
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/OperatorTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/OperatorTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/OperatorTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/OperatorTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,107 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import junit.framework.TestSuite;
+
+public class OperatorTest extends OgnlTestCase
+{
+ private static Object[][] TESTS = {
+ { null, "\"one\" > \"two\"", Boolean.FALSE },
+ { null, "\"one\" >= \"two\"", Boolean.FALSE },
+ { null, "\"one\" < \"two\"", Boolean.TRUE },
+ { null, "\"one\" <= \"two\"", Boolean.TRUE },
+ { null, "\"one\" == \"two\"", Boolean.FALSE },
+ { null, "\"o\" > \"o\"", Boolean.FALSE },
+ { null, "\"o\" gt \"o\"", Boolean.FALSE },
+ { null, "\"o\" >= \"o\"", Boolean.TRUE },
+ { null, "\"o\" gte \"o\"", Boolean.TRUE },
+ { null, "\"o\" < \"o\"", Boolean.FALSE },
+ { null, "\"o\" lt \"o\"", Boolean.FALSE },
+ { null, "\"o\" <= \"o\"", Boolean.TRUE },
+ { null, "\"o\" lte \"o\"", Boolean.TRUE },
+ { null, "\"o\" == \"o\"", Boolean.TRUE },
+ { null, "\"o\" eq \"o\"", Boolean.TRUE },
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ if (TESTS[i].length == 3) {
+ result.addTest(new OperatorTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new OperatorTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3]));
+ } else {
+ if (TESTS[i].length == 5) {
+ result.addTest(new OperatorTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
+ } else {
+ throw new RuntimeException("don't understand TEST format");
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public OperatorTest()
+ {
+ super();
+ }
+
+ public OperatorTest(String name)
+ {
+ super(name);
+ }
+
+ public OperatorTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public OperatorTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public OperatorTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/Performance.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/Performance.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/Performance.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/Performance.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,221 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.lang.reflect.*;
+import java.text.*;
+import org.apache.ibatis.ognl.Ognl;
+import org.apache.ibatis.ognl.OgnlContext;
+import org.apache.ibatis.ognl.OgnlException;
+import org.apache.ibatis.ognl.OgnlRuntime;
+import org.apache.ibatis.ognl.SimpleNode;
+import org.apache.ibatis.ognl.objects.Bean1;
+
+public class Performance extends Object
+{
+ private static int MAX_ITERATIONS = -1;
+ private static boolean ITERATIONS_MODE;
+ private static long MAX_TIME = -1L;
+ private static boolean TIME_MODE;
+ private static NumberFormat FACTOR_FORMAT = new DecimalFormat("0.0");
+
+ private String name;
+ private OgnlContext context = (OgnlContext)Ognl.createDefaultContext(null);
+ private Bean1 root = new Bean1();
+ private SimpleNode expression;
+ private Method method;
+ private int iterations;
+ private long t0;
+ private long t1;
+
+ /*===================================================================
+ Private static classes
+ ===================================================================*/
+ private static class Results
+ {
+ int iterations;
+ long time;
+
+ public Results(int iterations, long time)
+ {
+ super();
+ this.iterations = iterations;
+ this.time = time;
+ }
+
+ public float getFactor(Results otherResults)
+ {
+ if (TIME_MODE) {
+ return Math.max((float)otherResults.iterations, (float)iterations) / Math.min((float)otherResults.iterations, (float)iterations);
+ }
+ return Math.max((float)otherResults.time, (float)time) / Math.min((float)otherResults.time, (float)time);
+ }
+ }
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public Performance(String name, String expressionString, String javaMethodName) throws OgnlException
+ {
+ super();
+ this.name = name;
+ expression = (SimpleNode)Ognl.parseExpression(expressionString);
+ try {
+ method = getClass().getMethod(javaMethodName, new Class[] {});
+ } catch (Exception ex) {
+ throw new OgnlException("java method not found", ex);
+ }
+ }
+
+ /*===================================================================
+ Protected methods
+ ===================================================================*/
+ protected void startTest()
+ {
+ iterations = 0;
+ t0 = t1 = System.currentTimeMillis();
+ }
+
+ protected Results endTest()
+ {
+ return new Results(iterations, t1 - t0);
+ }
+
+ protected boolean done()
+ {
+ iterations++;
+ t1 = System.currentTimeMillis();
+ if (TIME_MODE) {
+ return (t1 - t0) >= MAX_TIME;
+ } else {
+ if (ITERATIONS_MODE) {
+ return iterations >= MAX_ITERATIONS;
+ } else {
+ throw new RuntimeException("no maximums specified");
+ }
+ }
+ }
+
+ /*===================================================================
+ Public methods
+ ===================================================================*/
+ public String getName()
+ {
+ return name;
+ }
+
+ public SimpleNode getExpression()
+ {
+ return expression;
+ }
+
+ public Results testExpression(boolean compiled) throws OgnlException
+ {
+ if (compiled) {
+ context.put("_compile", Boolean.TRUE);
+ } else {
+ context.remove("_compile");
+ }
+ Ognl.getValue(expression, context, root);
+ startTest();
+ do {
+ Ognl.getValue(expression, context, root);
+ } while (!done());
+ return endTest();
+ }
+
+ public Results testJava() throws OgnlException
+ {
+ try {
+ return (Results)method.invoke(this, new Object[] {});
+ } catch (Exception ex) {
+ throw new OgnlException("invoking java method '" + method.getName() + "'", ex);
+ }
+ }
+
+ public Results testConstantExpression() throws OgnlException
+ {
+ startTest();
+ do {
+ int result = 100 + 20 * 5;
+ } while (!done());
+ return endTest();
+ }
+
+ public Results testSinglePropertyExpression() throws OgnlException
+ {
+ startTest();
+ do {
+ root.getBean2();
+ } while (!done());
+ return endTest();
+ }
+
+ public Results testPropertyNavigationExpression() throws OgnlException
+ {
+ startTest();
+ do {
+ root.getBean2().getBean3().getValue();
+ } while (!done());
+ return endTest();
+ }
+
+ public Results testPropertyNavigationAndComparisonExpression() throws OgnlException
+ {
+ startTest();
+ do {
+ boolean result = root.getBean2().getBean3().getValue() < 24;
+ } while (!done());
+ return endTest();
+ }
+
+ public Results testIndexedPropertyNavigationExpression() throws OgnlException
+ {
+ startTest();
+ do {
+ root.getBean2().getBean3().getIndexedValue(25);
+ } while (!done());
+ return endTest();
+ }
+
+ public Results testPropertyNavigationWithMapExpression() throws OgnlException
+ {
+ startTest();
+ do {
+ root.getBean2().getBean3().getMap().get("foo");
+ } while (!done());
+ return endTest();
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrimitiveArrayTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrimitiveArrayTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrimitiveArrayTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrimitiveArrayTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,110 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.objects.Root;
+
+public class PrimitiveArrayTest extends OgnlTestCase
+{
+ private static Root ROOT = new Root();
+
+ private static Object[][] TESTS = {
+ // Primitive array creation
+ { ROOT, "new boolean[5]", new boolean[5] },
+ { ROOT, "new boolean[] { true, false }", new boolean[] { true, false } },
+ { ROOT, "new boolean[] { 0, 1, 5.5 }", new boolean[] { false, true, true } },
+ { ROOT, "new char[] { 'a', 'b' }", new char[] { 'a', 'b' } },
+ { ROOT, "new char[] { 10, 11 }", new char[] { (char)10, (char)11 } },
+ { ROOT, "new byte[] { 1, 2 }", new byte[] { 1, 2 } },
+ { ROOT, "new short[] { 1, 2 }", new short[] { 1, 2 } },
+ { ROOT, "new int[six]", new int[ROOT.six] },
+ { ROOT, "new int[#root.six]", new int[ROOT.six] },
+ { ROOT, "new int[6]", new int[6] },
+ { ROOT, "new int[] { 1, 2 }", new int[] { 1, 2 } },
+ { ROOT, "new long[] { 1, 2 }", new long[] { 1, 2 } },
+ { ROOT, "new float[] { 1, 2 }", new float[] { 1, 2 } },
+ { ROOT, "new double[] { 1, 2 }", new double[] { 1, 2 } },
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ if (TESTS[i].length == 3) {
+ result.addTest(new PrimitiveArrayTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new PrimitiveArrayTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3]));
+ } else {
+ if (TESTS[i].length == 5) {
+ result.addTest(new PrimitiveArrayTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
+ } else {
+ throw new RuntimeException("don't understand TEST format");
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public PrimitiveArrayTest()
+ {
+ super();
+ }
+
+ public PrimitiveArrayTest(String name)
+ {
+ super(name);
+ }
+
+ public PrimitiveArrayTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public PrimitiveArrayTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public PrimitiveArrayTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrimitiveNullHandlingTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrimitiveNullHandlingTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrimitiveNullHandlingTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrimitiveNullHandlingTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,106 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.objects.Simple;
+
+public class PrimitiveNullHandlingTest extends OgnlTestCase
+{
+ private static Simple SIMPLE = new Simple();
+
+ static
+ {
+ SIMPLE.setFloatValue(10.56f);
+ SIMPLE.setIntValue(34);
+ }
+
+ private static Object[][] TESTS = {
+ // Primitive null handling
+ { SIMPLE, "floatValue", new Float(10.56f), null, new Float(0f) }, /* set float to null, should yield 0.0f */
+ { SIMPLE, "intValue", new Integer(34), null, new Integer(0) }, /* set int to null, should yield 0 */
+ { SIMPLE, "booleanValue", Boolean.FALSE, Boolean.TRUE, Boolean.TRUE }, /* set boolean to TRUE, should yield true */
+ { SIMPLE, "booleanValue", Boolean.TRUE, null, Boolean.FALSE }, /* set boolean to null, should yield false */
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ if (TESTS[i].length == 3) {
+ result.addTest(new PrimitiveNullHandlingTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new PrimitiveNullHandlingTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3]));
+ } else {
+ if (TESTS[i].length == 5) {
+ result.addTest(new PrimitiveNullHandlingTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
+ } else {
+ throw new RuntimeException("don't understand TEST format");
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public PrimitiveNullHandlingTest()
+ {
+ super();
+ }
+
+ public PrimitiveNullHandlingTest(String name)
+ {
+ super(name);
+ }
+
+ public PrimitiveNullHandlingTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public PrimitiveNullHandlingTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public PrimitiveNullHandlingTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrivateAccessorTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrivateAccessorTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrivateAccessorTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrivateAccessorTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,116 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.DefaultMemberAccess;
+import org.apache.ibatis.ognl.objects.Root;
+
+public class PrivateAccessorTest extends OgnlTestCase
+{
+ private static Root ROOT = new Root();
+
+ private static Object[][] TESTS = {
+ // Using private get/set methods
+ { ROOT, "getPrivateAccessorIntValue()", new Integer(67) }, /* Call private method */
+ { ROOT, "privateAccessorIntValue", new Integer(67) }, /* Implied private method */
+ { ROOT, "privateAccessorIntValue", new Integer(67), new Integer(100) }, /* Implied private method */
+ { ROOT, "privateAccessorIntValue2", new Integer(67) }, /* Implied private method */
+ { ROOT, "privateAccessorIntValue2", new Integer(67), new Integer(100) }, /* Implied private method */
+ { ROOT, "privateAccessorIntValue3", new Integer(67) }, /* Implied private method */
+ { ROOT, "privateAccessorIntValue3", new Integer(67), new Integer(100) }, /* Implied private method */
+ { ROOT, "privateAccessorBooleanValue", Boolean.TRUE }, /* Implied private method */
+ { ROOT, "privateAccessorBooleanValue", Boolean.TRUE, Boolean.FALSE }, /* Implied private method */
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ if (TESTS[i].length == 3) {
+ result.addTest(new PrivateAccessorTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new PrivateAccessorTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3]));
+ } else {
+ if (TESTS[i].length == 5) {
+ result.addTest(new PrivateAccessorTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
+ } else {
+ throw new RuntimeException("don't understand TEST format");
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public PrivateAccessorTest()
+ {
+ super();
+ }
+
+ public PrivateAccessorTest(String name)
+ {
+ super(name);
+ }
+
+ public PrivateAccessorTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public PrivateAccessorTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public PrivateAccessorTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+
+ /*===================================================================
+ Overridden methods
+ ===================================================================*/
+ public void setUp()
+ {
+ super.setUp();
+ context.setMemberAccess(new DefaultMemberAccess(true));
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrivateMemberTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrivateMemberTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrivateMemberTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PrivateMemberTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,97 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.DefaultMemberAccess;
+import org.apache.ibatis.ognl.Ognl;
+import org.apache.ibatis.ognl.OgnlContext;
+import org.apache.ibatis.ognl.OgnlException;
+
+/**
+ * This is a test program for private access in OGNL.
+ * shows the failures and a summary.
+ */
+public class PrivateMemberTest extends TestCase
+{
+ private String _privateProperty = "private value";
+ protected OgnlContext context;
+
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ return new TestSuite(PrivateMemberTest.class);
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public PrivateMemberTest(String name)
+ {
+ super(name);
+ }
+
+ /*===================================================================
+ Public methods
+ ===================================================================*/
+ private String getPrivateProperty()
+ {
+ return _privateProperty;
+ }
+
+ private void setPrivateProperty(String value)
+ {
+ _privateProperty = value;
+ }
+
+ public void testPrivateAccessor() throws OgnlException
+ {
+ assertEquals(Ognl.getValue("privateProperty", context, this), getPrivateProperty());
+ }
+
+ public void testPrivateField() throws OgnlException
+ {
+ assertEquals(Ognl.getValue("_privateProperty", context, this), _privateProperty);
+ }
+
+ /*===================================================================
+ Overridden methods
+ ===================================================================*/
+ public void setUp()
+ {
+ context = (OgnlContext)Ognl.createDefaultContext(null);
+ context.setMemberAccess(new DefaultMemberAccess(true));
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ProjectionSelectionTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ProjectionSelectionTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ProjectionSelectionTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ProjectionSelectionTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,92 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.math.*;
+import java.util.*;
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.objects.Root;
+
+public class ProjectionSelectionTest extends OgnlTestCase
+{
+ private static Root ROOT = new Root();
+
+ private static Object[][] TESTS = {
+ // Projection, selection
+ { ROOT, "array.{class}", Arrays.asList(new Class[]{Integer.class,Integer.class,Integer.class,Integer.class}) },
+ { ROOT, "map.array.{? #this > 2 }", Arrays.asList(new Integer[]{new Integer(3), new Integer(4)}) },
+ { ROOT, "map.array.{^ #this > 2 }", Arrays.asList(new Integer[]{new Integer(3)}) },
+ { ROOT, "map.array.{$ #this > 2 }", Arrays.asList(new Integer[]{new Integer(4)}) },
+ { ROOT, "map.array[*].{?true} instanceof java.util.Collection", Boolean.TRUE },
+ { null, "#fact=1, 30H.{? #fact = #fact * (#this+1), false }, #fact", new BigInteger("265252859812191058636308480000000") },
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ result.addTest(new ProjectionSelectionTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public ProjectionSelectionTest()
+ {
+ super();
+ }
+
+ public ProjectionSelectionTest(String name)
+ {
+ super(name);
+ }
+
+ public ProjectionSelectionTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public ProjectionSelectionTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public ProjectionSelectionTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PropertyNotFoundTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PropertyNotFoundTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PropertyNotFoundTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PropertyNotFoundTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,145 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import java.util.Map;
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.OgnlContext;
+import org.apache.ibatis.ognl.OgnlException;
+import org.apache.ibatis.ognl.OgnlRuntime;
+import org.apache.ibatis.ognl.PropertyAccessor;
+
+public class PropertyNotFoundTest extends OgnlTestCase
+{
+ private static final Blah BLAH = new Blah();
+
+ private static Object[][] TESTS = {
+ { BLAH, "webwork.token.name", OgnlException.class, "W value", OgnlException.class },
+ };
+
+ /*===================================================================
+ Public static classes
+ ===================================================================*/
+ public static class Blah
+ {
+ String x;
+ String y;
+
+ public String getX() {
+ return x;
+ }
+
+ public void setX(String x) {
+ this.x = x;
+ }
+
+ public String getY() {
+ return y;
+ }
+
+ public void setY(String y) {
+ this.y = y;
+ }
+ }
+
+ public static class BlahPropertyAccessor implements PropertyAccessor
+ {
+ public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException
+ {
+ }
+
+ public Object getProperty(Map context, Object target, Object name) throws OgnlException
+ {
+ if ("x".equals(name) || "y".equals(name)) {
+ return OgnlRuntime.getProperty((OgnlContext)context, target, name);
+ }
+ return null;
+ }
+ }
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ if (TESTS[i].length == 3) {
+ result.addTest(new PropertyNotFoundTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new PropertyNotFoundTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3]));
+ } else {
+ if (TESTS[i].length == 5) {
+ result.addTest(new PropertyNotFoundTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
+ } else {
+ throw new RuntimeException("don't understand TEST format");
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public PropertyNotFoundTest()
+ {
+ super();
+ }
+
+ public PropertyNotFoundTest(String name)
+ {
+ super(name);
+ }
+
+ public PropertyNotFoundTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public PropertyNotFoundTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public PropertyNotFoundTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+
+ protected void setUp()
+ {
+ super.setUp();
+ OgnlRuntime.setPropertyAccessor(Blah.class, new BlahPropertyAccessor());
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PropertyTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PropertyTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PropertyTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/PropertyTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,105 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.objects.Root;
+
+public class PropertyTest extends OgnlTestCase
+{
+ private static Root ROOT = new Root();
+
+ private static Object[][] TESTS = {
+ { ROOT, "map", ROOT.getMap() },
+ { ROOT, "map.test", ROOT },
+ { ROOT, "map[\"test\"]", ROOT },
+ { ROOT, "map[\"te\" + \"st\"]", ROOT },
+ { ROOT, "map[(\"s\" + \"i\") + \"ze\"]", ROOT.getMap().get(Root.SIZE_STRING) },
+ { ROOT, "map[\"size\"]", ROOT.getMap().get(Root.SIZE_STRING) },
+ { ROOT, "map[@org.apache.ibatis.ognl.objects.Root@SIZE_STRING]", ROOT.getMap().get(Root.SIZE_STRING) },
+ { ROOT.getMap(), "list", ROOT.getList() },
+ { ROOT, "map.array[0]", new Integer(ROOT.getArray()[0]) },
+ { ROOT, "map.list[1]", ROOT.getList().get(1) },
+ { ROOT, "map[^]", new Integer(99) },
+ { ROOT, "map[$]", null },
+ { ROOT.getMap(), "array[$]", new Integer(ROOT.getArray()[ROOT.getArray().length-1]) },
+ { ROOT, "[\"map\"]", ROOT.getMap() },
+ { ROOT.getArray(), "length", new Integer(ROOT.getArray().length) },
+ { ROOT, "getMap().list[|]", ROOT.getList().get(ROOT.getList().size()/2) },
+ { ROOT, "map.(array[2] + size()).doubleValue()", new Double(ROOT.getArray()[2] + ROOT.getMap().size()) },
+ { ROOT, "map.(#this)", ROOT.getMap() },
+ { ROOT, "map.(#this != null ? #this['size'] : null)", ROOT.getMap().get(Root.SIZE_STRING) },
+ { ROOT, "map[^].(#this == null ? 'empty' : #this)", new Integer(99) },
+ { ROOT, "map[$].(#this == null ? 'empty' : #this)", "empty" },
+ { ROOT, "map[$].(#root == null ? 'empty' : #root)", ROOT }
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ result.addTest(new PropertyTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public PropertyTest()
+ {
+ super();
+ }
+
+ public PropertyTest(String name)
+ {
+ super(name);
+ }
+
+ public PropertyTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public PropertyTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public PropertyTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ProtectedInnerClassTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ProtectedInnerClassTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ProtectedInnerClassTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ProtectedInnerClassTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,86 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.objects.Root;
+
+public class ProtectedInnerClassTest extends OgnlTestCase
+{
+ private static Root ROOT = new Root();
+
+ private static Object[][] TESTS = {
+ // member access of inner class (Arrays.asList() returned protected inner class)
+ { ROOT, "list.size()", new Integer(ROOT.getList().size()) },
+ { ROOT, "list[0]", ROOT.getList().get(0) },
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ result.addTest(new ProtectedInnerClassTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public ProtectedInnerClassTest()
+ {
+ super();
+ }
+
+ public ProtectedInnerClassTest(String name)
+ {
+ super(name);
+ }
+
+ public ProtectedInnerClassTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public ProtectedInnerClassTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public ProtectedInnerClassTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/QuotingTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/QuotingTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/QuotingTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/QuotingTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,97 @@
+//--------------------------------------------------------------------------
+// Copyright (c) 2004, Drew Davidson and Luke Blanshard
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// Neither the name of the Drew Davidson nor the names of its contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+// DAMAGE.
+//--------------------------------------------------------------------------
+package org.apache.ibatis.ognl;
+
+import junit.framework.TestSuite;
+
+public class QuotingTest extends OgnlTestCase
+{
+ private static Object[][] TESTS = {
+ // Quoting
+ { null, "`c`", new Character('c') },
+ { null, "'s'", new Character('s') },
+ { null, "'string'", "string" },
+ { null, "\"string\"", "string" },
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ if (TESTS[i].length == 3) {
+ result.addTest(new QuotingTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new QuotingTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3]));
+ } else {
+ if (TESTS[i].length == 5) {
+ result.addTest(new QuotingTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2], TESTS[i][3], TESTS[i][4]));
+ } else {
+ throw new RuntimeException("don't understand TEST format");
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public QuotingTest()
+ {
+ super();
+ }
+
+ public QuotingTest(String name)
+ {
+ super(name);
+ }
+
+ public QuotingTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public QuotingTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public QuotingTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+}