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 [13/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/IndexedPropertyTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/IndexedPropertyTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/IndexedPropertyTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/IndexedPropertyTest.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;
+import org.apache.ibatis.ognl.objects.Indexed;
+
+public class IndexedPropertyTest extends OgnlTestCase
+{
+ private static Indexed INDEXED = new Indexed();
+
+ private static Object[][] TESTS = {
+ // Indexed properties
+ { INDEXED, "values", INDEXED.getValues() }, /* gets String[] */
+ { INDEXED, "[\"values\"]", INDEXED.getValues() }, /* String[] */
+ { INDEXED.getValues(), "[0]", INDEXED.getValues()[0] }, /* "foo" */
+ { INDEXED, "getValues()[0]", INDEXED.getValues()[0] }, /* "foo" directly from array */
+ { INDEXED, "values[0]", INDEXED.getValues(0) }, /* "foo" + "xxx" */
+ { INDEXED, "values[^]", INDEXED.getValues(0) }, /* "foo" + "xxx" */
+ { INDEXED, "values[|]", INDEXED.getValues(1) }, /* "bar" + "xxx" */
+ { INDEXED, "values[$]", INDEXED.getValues(2) }, /* "baz" + "xxx" */
+ { INDEXED, "values[1]", "bar" + "xxx", "xxxx" + "xxx", "xxxx" + "xxx" }, /* set through setValues(int, String) */
+ { INDEXED, "values[1]", "xxxx" + "xxx" }, /* getValues(int) again to check if setValues(int, String) was called */
+ { INDEXED, "setValues(2, \"xxxx\")", null }, /* was "baz" -> "xxxx" */
+ };
+
+ /*===================================================================
+ 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 IndexedPropertyTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new IndexedPropertyTest((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 IndexedPropertyTest((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 IndexedPropertyTest()
+ {
+ super();
+ }
+
+ public IndexedPropertyTest(String name)
+ {
+ super(name);
+ }
+
+ public IndexedPropertyTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public IndexedPropertyTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public IndexedPropertyTest(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/InterfaceInheritanceTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/InterfaceInheritanceTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/InterfaceInheritanceTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/InterfaceInheritanceTest.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 InterfaceInheritanceTest extends OgnlTestCase
+{
+ private static Root ROOT = new Root();
+
+ private static Object[][] TESTS = {
+ // Interface inheritence test
+ { ROOT, "myMap", ROOT.getMyMap() },
+ { ROOT, "myMap.test", ROOT },
+ { ROOT.getMyMap(), "list", ROOT.getList() },
+ { ROOT, "myMap.array[0]", new Integer(ROOT.getArray()[0]) },
+ { ROOT, "myMap.list[1]", ROOT.getList().get(1) },
+ { ROOT, "myMap[^]", new Integer(99) },
+ { ROOT, "myMap[$]", null },
+ { ROOT.getMyMap(), "array[$]", new Integer(ROOT.getArray()[ROOT.getArray().length-1]) },
+ { ROOT, "[\"myMap\"]", ROOT.getMyMap() },
+ { ROOT, "myMap[null]", null },
+ { ROOT, "myMap[#x = null]", null },
+ { ROOT, "myMap.(null,test)", ROOT },
+ { ROOT, "myMap[null] = 25", new Integer(25) },
+ { ROOT, "myMap[null]", new Integer(25), new Integer(50), new Integer(50) },
+ };
+
+ /*===================================================================
+ 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 InterfaceInheritanceTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new InterfaceInheritanceTest((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 InterfaceInheritanceTest((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 InterfaceInheritanceTest()
+ {
+ super();
+ }
+
+ public InterfaceInheritanceTest(String name)
+ {
+ super(name);
+ }
+
+ public InterfaceInheritanceTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public InterfaceInheritanceTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public InterfaceInheritanceTest(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/LambdaExpressionTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/LambdaExpressionTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/LambdaExpressionTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/LambdaExpressionTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,90 @@
+//--------------------------------------------------------------------------
+// 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.BigInteger;
+import java.util.ArrayList;
+import java.util.Arrays;
+import junit.framework.TestSuite;
+
+public class LambdaExpressionTest extends OgnlTestCase
+{
+ private static Object[][] TESTS = {
+ // Lambda expressions
+ { null, "#a=:[33](20).longValue().{0}.toArray().length", new Integer(33) },
+ { null, "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30)", new Integer(1409286144) },
+ { null, "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30L)", new Long(-8764578968847253504L) },
+ { null, "#fact=:[#this<=1? 1 : #fact(#this-1) * #this], #fact(30h)", new BigInteger("265252859812191058636308480000000") },
+ { null, "#bump = :[ #this.{ #this + 1 } ], (#bump)({ 1, 2, 3 })", new ArrayList(Arrays.asList(new Integer[] { new Integer(2), new Integer(3), new Integer(4) })) },
+ { null, "#call = :[ \"calling \" + [0] + \" on \" + [1] ], (#call)({ \"x\", \"y\" })", "calling x on y" },
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ result.addTest(new LambdaExpressionTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public LambdaExpressionTest()
+ {
+ super();
+ }
+
+ public LambdaExpressionTest(String name)
+ {
+ super(name);
+ }
+
+ public LambdaExpressionTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public LambdaExpressionTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public LambdaExpressionTest(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/MapCreationTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MapCreationTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MapCreationTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MapCreationTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,125 @@
+//--------------------------------------------------------------------------
+// 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.*;
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.objects.Root;
+
+public class MapCreationTest extends OgnlTestCase
+{
+ private static Root ROOT = new Root();
+ private static Map fooBarMap1;
+ private static Map fooBarMap2;
+ private static Map fooBarMap3;
+ private static Map fooBarMap4;
+ private static Map fooBarMap5;
+
+ static
+ {
+ fooBarMap1 = new HashMap();
+ fooBarMap1.put("foo", "bar");
+ fooBarMap2 = new HashMap();
+ fooBarMap2.put("foo", "bar");
+ fooBarMap2.put("bar", "baz");
+ fooBarMap3 = new HashMap();
+ fooBarMap3.put("foo", null);
+ fooBarMap3.put("bar", "baz");
+ fooBarMap4 = new LinkedHashMap();
+ fooBarMap4.put("foo", "bar");
+ fooBarMap4.put("bar", "baz");
+ fooBarMap5 = new TreeMap();
+ fooBarMap5.put("foo", "bar");
+ fooBarMap5.put("bar", "baz");
+ }
+
+ private static Object[][] TESTS = {
+ // Map creation
+ { ROOT, "#{ \"foo\" : \"bar\" }", fooBarMap1 },
+ { ROOT, "#{ \"foo\" : \"bar\", \"bar\" : \"baz\" }", fooBarMap2 },
+ { ROOT, "#{ \"foo\", \"bar\" : \"baz\" }", fooBarMap3 },
+ { ROOT, "#@java.util.LinkedHashMap@{ \"foo\" : \"bar\", \"bar\" : \"baz\" }", fooBarMap4 },
+ { ROOT, "#@java.util.TreeMap@{ \"foo\" : \"bar\", \"bar\" : \"baz\" }", fooBarMap5 },
+ };
+
+ /*===================================================================
+ 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 MapCreationTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new MapCreationTest((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 MapCreationTest((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 MapCreationTest()
+ {
+ super();
+ }
+
+ public MapCreationTest(String name)
+ {
+ super(name);
+ }
+
+ public MapCreationTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public MapCreationTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public MapCreationTest(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/MemberAccessTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MemberAccessTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MemberAccessTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MemberAccessTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,123 @@
+//--------------------------------------------------------------------------
+// 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.util.*;
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.OgnlException;
+import org.apache.ibatis.ognl.DefaultMemberAccess;
+import org.apache.ibatis.ognl.objects.Simple;
+
+public class MemberAccessTest extends OgnlTestCase
+{
+ private static Simple ROOT = new Simple();
+ private static Object[][] TESTS = {
+ { "@Runtime@getRuntime()", OgnlException.class },
+ { "@System@getProperty('java.specification.version')", System.getProperty("java.specification.version") },
+ { "bigIntValue", OgnlException.class },
+ { "bigIntValue", OgnlException.class, new Integer(25), OgnlException.class },
+ { "getBigIntValue()", OgnlException.class },
+ { "stringValue", ROOT.getStringValue() },
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ result.addTest(new MemberAccessTest((String)TESTS[i][0] + " (" + TESTS[i][1] + ")", ROOT, (String)TESTS[i][0], TESTS[i][1]));
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public MemberAccessTest()
+ {
+ super();
+ }
+
+ public MemberAccessTest(String name)
+ {
+ super(name);
+ }
+
+ public MemberAccessTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public MemberAccessTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public MemberAccessTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+
+ /*===================================================================
+ Overridden methods
+ ===================================================================*/
+ public void setUp()
+ {
+ super.setUp();
+ /* Should allow access at all to the Simple class except for the bigIntValue property */
+ context.setMemberAccess(new DefaultMemberAccess(false)
+ {
+ public boolean isAccessible(Map context, Object target, Member member, String propertyName)
+ {
+ if (target == Runtime.class) {
+ return false;
+ }
+ if (target instanceof Simple) {
+ if (propertyName != null) {
+ return !propertyName.equals("bigIntValue") &&
+ super.isAccessible(context, target, member, propertyName);
+ } else {
+ if (member instanceof Method) {
+ return !member.getName().equals("getBigIntValue") &&
+ !member.getName().equals("setBigIntValue") &&
+ super.isAccessible(context, target, member, propertyName);
+ }
+ }
+ }
+ return super.isAccessible(context, target, member, propertyName);
+ }
+ });
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MethodTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MethodTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MethodTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MethodTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,83 @@
+//--------------------------------------------------------------------------
+// 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 MethodTest extends OgnlTestCase
+{
+ private static Object ROOT = new Simple();
+ private static Object[][] TESTS = {
+ { "hashCode().doubleValue()", new Double(ROOT.hashCode()) }
+ };
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ result.addTest(new MethodTest((String)TESTS[i][0] + " (" + TESTS[i][1] + ")", ROOT, (String)TESTS[i][0], TESTS[i][1]));
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public MethodTest()
+ {
+ super();
+ }
+
+ public MethodTest(String name)
+ {
+ super(name);
+ }
+
+ public MethodTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public MethodTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public MethodTest(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/MethodWithConversionTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MethodWithConversionTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MethodWithConversionTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/MethodWithConversionTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,101 @@
+//--------------------------------------------------------------------------
+// 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 MethodWithConversionTest extends OgnlTestCase
+{
+ private static Simple SIMPLE = new Simple();
+
+ private static Object[][] TESTS = {
+ // Method call with conversion
+ { SIMPLE, "setValues(new Integer(10), \"10.56\", new Double(34.225))", null },
+ { SIMPLE, "stringValue", "10" },
+ { SIMPLE, "stringValue", "10", new Character('x'), "x" }, /* set through setValue() */
+ { SIMPLE, "setStringValue('x')", null }, /* set by calling setStringValue() directly */
+ { SIMPLE, "floatValue", new Float(10.56) },
+ };
+
+ /*===================================================================
+ 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 MethodWithConversionTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new MethodWithConversionTest((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 MethodWithConversionTest((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 MethodWithConversionTest()
+ {
+ super();
+ }
+
+ public MethodWithConversionTest(String name)
+ {
+ super(name);
+ }
+
+ public MethodWithConversionTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public MethodWithConversionTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public MethodWithConversionTest(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/NestedMethodTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NestedMethodTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NestedMethodTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NestedMethodTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,98 @@
+//--------------------------------------------------------------------------
+// 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.Component;
+
+public class NestedMethodTest extends OgnlTestCase
+{
+ private static Component COMPONENT = new Component();
+
+ private static Object[][] TESTS = {
+ // Expression in a method call argument
+ { COMPONENT, "toDisplay.pictureUrl", COMPONENT.getToDisplay().getPictureUrl() },
+ { COMPONENT, "page.createRelativeAsset(toDisplay.pictureUrl)", COMPONENT.getPage().createRelativeAsset(COMPONENT.getToDisplay().getPictureUrl()) },
+ };
+
+ /*===================================================================
+ 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 NestedMethodTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new NestedMethodTest((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 NestedMethodTest((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 NestedMethodTest()
+ {
+ super();
+ }
+
+ public NestedMethodTest(String name)
+ {
+ super(name);
+ }
+
+ public NestedMethodTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public NestedMethodTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public NestedMethodTest(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/NullHandlerTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NullHandlerTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NullHandlerTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NullHandlerTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,111 @@
+//--------------------------------------------------------------------------
+// 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.OgnlRuntime;
+import org.apache.ibatis.ognl.objects.CorrectedObject;
+
+public class NullHandlerTest extends OgnlTestCase
+{
+ private static CorrectedObject CORRECTED = new CorrectedObject();
+
+ private static Object[][] TESTS = {
+ // NullHandler
+ { CORRECTED, "stringValue", "corrected" },
+ { CORRECTED, "getStringValue()", "corrected" },
+ { CORRECTED, "#root.stringValue", "corrected" },
+ { CORRECTED, "#root.getStringValue()", "corrected" },
+ };
+
+ /*===================================================================
+ 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 NullHandlerTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new NullHandlerTest((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 NullHandlerTest((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 NullHandlerTest()
+ {
+ super();
+ }
+
+ public NullHandlerTest(String name)
+ {
+ super(name);
+ }
+
+ public NullHandlerTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public NullHandlerTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public NullHandlerTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+
+ /*===================================================================
+ Overridden methods
+ ===================================================================*/
+ public void setUp()
+ {
+ super.setUp();
+ OgnlRuntime.setNullHandler(CorrectedObject.class, new CorrectedObjectNullHandler("corrected"));
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NullStringCatenationTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NullStringCatenationTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NullStringCatenationTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NullStringCatenationTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,99 @@
+//--------------------------------------------------------------------------
+// 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 NullStringCatenationTest extends OgnlTestCase
+{
+ private static Root ROOT = new Root();
+
+ private static Object[][] TESTS = {
+ // Null string catenation
+ { ROOT, "\"bar\" + null", "barnull" }, /* Catenate null to a string */
+ { ROOT, "\"bar\" + nullObject", "barnull" }, /* Catenate null to a string */
+ { ROOT, "20.56 + nullObject", NullPointerException.class }, /* Catenate null to a number */
+ };
+
+ /*===================================================================
+ 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 NullStringCatenationTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new NullStringCatenationTest((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 NullStringCatenationTest((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 NullStringCatenationTest()
+ {
+ super();
+ }
+
+ public NullStringCatenationTest(String name)
+ {
+ super(name);
+ }
+
+ public NullStringCatenationTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public NullStringCatenationTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public NullStringCatenationTest(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/NumberFormatExceptionTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NumberFormatExceptionTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NumberFormatExceptionTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NumberFormatExceptionTest.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 java.math.*;
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.OgnlException;
+import org.apache.ibatis.ognl.objects.Simple;
+
+public class NumberFormatExceptionTest extends OgnlTestCase
+{
+ private static Simple SIMPLE = new Simple();
+
+ private static Object[][] TESTS = {
+ // NumberFormatException handling (default is to throw NumberFormatException on bad string conversions)
+ { SIMPLE, "floatValue", new Float(0f), new Float(10f), new Float(10f) }, /* set float to 10.0f */
+ { SIMPLE, "floatValue", new Float(10f), "x10x", OgnlException.class }, /* set float to invalid format string, should yield OgnlException */
+
+ { SIMPLE, "intValue", new Integer(0), new Integer(34), new Integer(34) }, /* set int to 34 */
+ { SIMPLE, "intValue", new Integer(34), "foobar", OgnlException.class }, /* set int to invalid format string, should yield OgnlException */
+ { SIMPLE, "intValue", new Integer(34), "", OgnlException.class }, /* set int to empty string, should yield 0gnlException */
+ { SIMPLE, "intValue", new Integer(34), " \t", OgnlException.class }, /* set int to whitespace-only string, should yield 0gnlException */
+ { SIMPLE, "intValue", new Integer(34), " \t1234\t\t", new Integer(1234) }, /* set int to whitespace-laden valid string, should yield 1234 */
+
+ { SIMPLE, "bigIntValue", BigInteger.valueOf(0), BigInteger.valueOf(34), BigInteger.valueOf(34) }, /* set bigint to 34 */
+ { SIMPLE, "bigIntValue", BigInteger.valueOf(34), null, null }, /* set bigint to null string, should yield 0 */
+ { SIMPLE, "bigIntValue", null, "", OgnlException.class }, /* set bigint to empty string, should yield 0gnlException */
+ { SIMPLE, "bigIntValue", null, "foobar", OgnlException.class }, /* set bigint to invalid format string, should yield OgnlException */
+
+ { SIMPLE, "bigDecValue", new BigDecimal(0.0), new BigDecimal(34.55), new BigDecimal(34.55) }, /* set bigdec to 34.55 */
+ { SIMPLE, "bigDecValue", new BigDecimal(34.55), null, null }, /* set bigdec to null string, should yield 0.0 */
+ { SIMPLE, "bigDecValue", null, "", OgnlException.class }, /* set bigdec to empty string, should yield 0gnlException */
+ { SIMPLE, "bigDecValue", null, "foobar", OgnlException.class }, /* set bigdec to invalid format string, should yield OgnlException */
+ };
+
+ /*===================================================================
+ 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 NumberFormatExceptionTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new NumberFormatExceptionTest((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 NumberFormatExceptionTest((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 NumberFormatExceptionTest()
+ {
+ super();
+ }
+
+ public NumberFormatExceptionTest(String name)
+ {
+ super(name);
+ }
+
+ public NumberFormatExceptionTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public NumberFormatExceptionTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public NumberFormatExceptionTest(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/NumericConversionTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NumericConversionTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NumericConversionTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/NumericConversionTest.java Sat Aug 9 23:00:18 2008
@@ -0,0 +1,226 @@
+//--------------------------------------------------------------------------
+// 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.BigDecimal;
+import java.math.BigInteger;
+import junit.framework.TestSuite;
+import org.apache.ibatis.ognl.OgnlException;
+import org.apache.ibatis.ognl.OgnlOps;
+
+public class NumericConversionTest extends OgnlTestCase
+{
+ private static Object[][] TESTS = {
+ /* To Integer.class */
+ { "55", Integer.class, new Integer(55) },
+ { new Integer(55), Integer.class, new Integer(55) },
+ { new Double(55), Integer.class, new Integer(55) },
+ { Boolean.TRUE, Integer.class, new Integer(1) },
+ { new Byte((byte)55), Integer.class, new Integer(55) },
+ { new Character((char)55), Integer.class, new Integer(55) },
+ { new Short((short)55), Integer.class, new Integer(55) },
+ { new Long(55), Integer.class, new Integer(55) },
+ { new Float(55), Integer.class, new Integer(55) },
+ { new BigInteger("55"), Integer.class, new Integer(55) },
+ { new BigDecimal("55"), Integer.class, new Integer(55) },
+
+ /* To Double.class */
+ { "55.1234", Double.class, new Double(55.1234) },
+ { new Integer(55), Double.class, new Double(55) },
+ { new Double(55.1234), Double.class, new Double(55.1234) },
+ { Boolean.TRUE, Double.class, new Double(1) },
+ { new Byte((byte)55), Double.class, new Double(55) },
+ { new Character((char)55), Double.class, new Double(55) },
+ { new Short((short)55), Double.class, new Double(55) },
+ { new Long(55), Double.class, new Double(55) },
+ { new Float(55.1234), Double.class, new Double(55.1234), new Integer(4) },
+ { new BigInteger("55"), Double.class, new Double(55) },
+ { new BigDecimal("55.1234"), Double.class, new Double(55.1234) },
+
+ /* To Boolean.class */
+ { "true", Boolean.class, Boolean.TRUE },
+ { new Integer(55), Boolean.class, Boolean.TRUE },
+ { new Double(55), Boolean.class, Boolean.TRUE },
+ { Boolean.TRUE, Boolean.class, Boolean.TRUE },
+ { new Byte((byte)55), Boolean.class, Boolean.TRUE },
+ { new Character((char)55), Boolean.class, Boolean.TRUE },
+ { new Short((short)55), Boolean.class, Boolean.TRUE },
+ { new Long(55), Boolean.class, Boolean.TRUE },
+ { new Float(55), Boolean.class, Boolean.TRUE },
+ { new BigInteger("55"), Boolean.class, Boolean.TRUE },
+ { new BigDecimal("55"), Boolean.class, Boolean.TRUE },
+
+ /* To Byte.class */
+ { "55", Byte.class, new Byte((byte)55) },
+ { new Integer(55), Byte.class, new Byte((byte)55) },
+ { new Double(55), Byte.class, new Byte((byte)55) },
+ { Boolean.TRUE, Byte.class, new Byte((byte)1) },
+ { new Byte((byte)55), Byte.class, new Byte((byte)55) },
+ { new Character((char)55), Byte.class, new Byte((byte)55) },
+ { new Short((short)55), Byte.class, new Byte((byte)55) },
+ { new Long(55), Byte.class, new Byte((byte)55) },
+ { new Float(55), Byte.class, new Byte((byte)55) },
+ { new BigInteger("55"), Byte.class, new Byte((byte)55) },
+ { new BigDecimal("55"), Byte.class, new Byte((byte)55) },
+
+ /* To Character.class */
+ { "55", Character.class, new Character((char)55) },
+ { new Integer(55), Character.class, new Character((char)55) },
+ { new Double(55), Character.class, new Character((char)55) },
+ { Boolean.TRUE, Character.class, new Character((char)1) },
+ { new Byte((byte)55), Character.class, new Character((char)55) },
+ { new Character((char)55), Character.class, new Character((char)55) },
+ { new Short((short)55), Character.class, new Character((char)55) },
+ { new Long(55), Character.class, new Character((char)55) },
+ { new Float(55), Character.class, new Character((char)55) },
+ { new BigInteger("55"), Character.class, new Character((char)55) },
+ { new BigDecimal("55"), Character.class, new Character((char)55) },
+
+ /* To Short.class */
+ { "55", Short.class, new Short((short)55) },
+ { new Integer(55), Short.class, new Short((short)55) },
+ { new Double(55), Short.class, new Short((short)55) },
+ { Boolean.TRUE, Short.class, new Short((short)1) },
+ { new Byte((byte)55), Short.class, new Short((short)55) },
+ { new Character((char)55), Short.class, new Short((short)55) },
+ { new Short((short)55), Short.class, new Short((short)55) },
+ { new Long(55), Short.class, new Short((short)55) },
+ { new Float(55), Short.class, new Short((short)55) },
+ { new BigInteger("55"), Short.class, new Short((short)55) },
+ { new BigDecimal("55"), Short.class, new Short((short)55) },
+
+ /* To Long.class */
+ { "55", Long.class, new Long(55) },
+ { new Integer(55), Long.class, new Long(55) },
+ { new Double(55), Long.class, new Long(55) },
+ { Boolean.TRUE, Long.class, new Long(1) },
+ { new Byte((byte)55), Long.class, new Long(55) },
+ { new Character((char)55), Long.class, new Long(55) },
+ { new Short((short)55), Long.class, new Long(55) },
+ { new Long(55), Long.class, new Long(55) },
+ { new Float(55), Long.class, new Long(55) },
+ { new BigInteger("55"), Long.class, new Long(55) },
+ { new BigDecimal("55"), Long.class, new Long(55) },
+
+ /* To Float.class */
+ { "55.1234", Float.class, new Float(55.1234) },
+ { new Integer(55), Float.class, new Float(55) },
+ { new Double(55.1234), Float.class, new Float(55.1234) },
+ { Boolean.TRUE, Float.class, new Float(1) },
+ { new Byte((byte)55), Float.class, new Float(55) },
+ { new Character((char)55), Float.class, new Float(55) },
+ { new Short((short)55), Float.class, new Float(55) },
+ { new Long(55), Float.class, new Float(55) },
+ { new Float(55.1234), Float.class, new Float(55.1234) },
+ { new BigInteger("55"), Float.class, new Float(55) },
+ { new BigDecimal("55.1234"), Float.class, new Float(55.1234) },
+
+ /* To BigInteger.class */
+ { "55", BigInteger.class, new BigInteger("55") },
+ { new Integer(55), BigInteger.class, new BigInteger("55") },
+ { new Double(55), BigInteger.class, new BigInteger("55") },
+ { Boolean.TRUE, BigInteger.class, new BigInteger("1") },
+ { new Byte((byte)55), BigInteger.class, new BigInteger("55") },
+ { new Character((char)55), BigInteger.class, new BigInteger("55") },
+ { new Short((short)55), BigInteger.class, new BigInteger("55") },
+ { new Long(55), BigInteger.class, new BigInteger("55") },
+ { new Float(55), BigInteger.class, new BigInteger("55") },
+ { new BigInteger("55"), BigInteger.class, new BigInteger("55") },
+ { new BigDecimal("55"), BigInteger.class, new BigInteger("55") },
+
+ /* To BigDecimal.class */
+ { "55.1234", BigDecimal.class, new BigDecimal("55.1234") },
+ { new Integer(55), BigDecimal.class, new BigDecimal("55") },
+ { new Double(55.1234), BigDecimal.class, new BigDecimal("55.1234"), new Integer(4) },
+ { Boolean.TRUE, BigDecimal.class, new BigDecimal("1") },
+ { new Byte((byte)55), BigDecimal.class, new BigDecimal("55") },
+ { new Character((char)55), BigDecimal.class, new BigDecimal("55") },
+ { new Short((short)55), BigDecimal.class, new BigDecimal("55") },
+ { new Long(55), BigDecimal.class, new BigDecimal("55") },
+ { new Float(55.1234), BigDecimal.class, new BigDecimal("55.1234"), new Integer(4) },
+ { new BigInteger("55"), BigDecimal.class, new BigDecimal("55") },
+ { new BigDecimal("55.1234"), BigDecimal.class, new BigDecimal("55.1234") },
+ };
+
+ private Object value;
+ private Class toClass;
+ private Object expectedValue;
+ private int scale;
+
+ /*===================================================================
+ Public static methods
+ ===================================================================*/
+ public static TestSuite suite()
+ {
+ TestSuite result = new TestSuite();
+
+ for (int i = 0; i < TESTS.length; i++) {
+ result.addTest(new NumericConversionTest(TESTS[i][0],
+ (Class)TESTS[i][1],
+ TESTS[i][2],
+ (TESTS[i].length > 3) ? ((Integer)TESTS[i][3]).intValue() : -1));
+ }
+ return result;
+ }
+
+ /*===================================================================
+ Constructors
+ ===================================================================*/
+ public NumericConversionTest(Object value, Class toClass, Object expectedValue, int scale)
+ {
+ super(value + " [" + value.getClass().getName() + "] -> " + toClass.getName() + " == " + expectedValue + " [" + expectedValue.getClass().getName() + "]" + ((scale >= 0) ? (" (to within " + scale + " decimal places)") : ""));
+ this.value = value;
+ this.toClass = toClass;
+ this.expectedValue = expectedValue;
+ this.scale = scale;
+ }
+
+ /*===================================================================
+ Overridden methods
+ ===================================================================*/
+ protected void runTest() throws OgnlException
+ {
+ Object result;
+
+ result = OgnlOps.convertValue(value, toClass);
+ if (!isEqual(result, expectedValue)) {
+ if (scale >= 0) {
+ double scalingFactor = Math.pow(10, scale),
+ v1 = ((Number)value).doubleValue() * scalingFactor,
+ v2 = ((Number)expectedValue).doubleValue() * scalingFactor;
+
+ assertTrue((int)v1 == (int)v2);
+ } else {
+ fail();
+ }
+ }
+ }
+}
Added: ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ObjectIndexedPropertyTest.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ObjectIndexedPropertyTest.java?rev=684410&view=auto
==============================================================================
--- ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ObjectIndexedPropertyTest.java (added)
+++ ibatis/trunk/java/ibatis-3/ibatis-3-core/src/test/java/org/apache/ibatis/ognl/ObjectIndexedPropertyTest.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.OgnlException;
+import org.apache.ibatis.ognl.objects.ObjectIndexed;
+
+public class ObjectIndexedPropertyTest extends OgnlTestCase
+{
+ private static ObjectIndexed OBJECT_INDEXED = new ObjectIndexed();
+
+ private static Object[][] TESTS = {
+ // Arbitrary indexed properties
+ { OBJECT_INDEXED, "attributes[\"bar\"]", "baz" }, /* get non-indexed property through attributes Map */
+ { OBJECT_INDEXED, "attribute[\"foo\"]", "bar" }, /* get indexed property */
+ { OBJECT_INDEXED, "attribute[\"bar\"]", "baz", "newValue", "newValue" }, /* set indexed property */
+ { OBJECT_INDEXED, "attribute[\"bar\"]", "newValue" }, /* get indexed property back to confirm */
+ { OBJECT_INDEXED, "attributes[\"bar\"]", "newValue" }, /* get property back through Map to confirm */
+ { OBJECT_INDEXED, "attribute[\"other\"].attribute[\"bar\"]", "baz" }, /* get indexed property from indexed, then through other */
+ { OBJECT_INDEXED, "attribute[\"other\"].attributes[\"bar\"]", "baz" }, /* get property back through Map to confirm */
+ { OBJECT_INDEXED, "attribute[$]", OgnlException.class }, /* illegal DynamicSubscript access to object indexed property */
+ };
+
+ /*===================================================================
+ 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 ObjectIndexedPropertyTest((String)TESTS[i][1], TESTS[i][0], (String)TESTS[i][1], TESTS[i][2]));
+ } else {
+ if (TESTS[i].length == 4) {
+ result.addTest(new ObjectIndexedPropertyTest((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 ObjectIndexedPropertyTest((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 ObjectIndexedPropertyTest()
+ {
+ super();
+ }
+
+ public ObjectIndexedPropertyTest(String name)
+ {
+ super(name);
+ }
+
+ public ObjectIndexedPropertyTest(String name, Object root, String expressionString, Object expectedResult, Object setValue, Object expectedAfterSetResult)
+ {
+ super(name, root, expressionString, expectedResult, setValue, expectedAfterSetResult);
+ }
+
+ public ObjectIndexedPropertyTest(String name, Object root, String expressionString, Object expectedResult, Object setValue)
+ {
+ super(name, root, expressionString, expectedResult, setValue);
+ }
+
+ public ObjectIndexedPropertyTest(String name, Object root, String expressionString, Object expectedResult)
+ {
+ super(name, root, expressionString, expectedResult);
+ }
+}