001: //--------------------------------------------------------------------------
002: // Copyright (c) 2004, Drew Davidson and Luke Blanshard
003: // All rights reserved.
004: //
005: // Redistribution and use in source and binary forms, with or without
006: // modification, are permitted provided that the following conditions are
007: // met:
008: //
009: // Redistributions of source code must retain the above copyright notice,
010: // this list of conditions and the following disclaimer.
011: // Redistributions in binary form must reproduce the above copyright
012: // notice, this list of conditions and the following disclaimer in the
013: // documentation and/or other materials provided with the distribution.
014: // Neither the name of the Drew Davidson nor the names of its contributors
015: // may be used to endorse or promote products derived from this software
016: // without specific prior written permission.
017: //
018: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
019: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
020: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
021: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
022: // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
023: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
024: // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
025: // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026: // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
027: // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
028: // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
029: // DAMAGE.
030: //--------------------------------------------------------------------------
031: package org.ognl.test;
032:
033: import java.math.*;
034: import java.util.*;
035: import junit.framework.TestSuite;
036: import org.ognl.test.objects.Root;
037:
038: public class ProjectionSelectionTest extends OgnlTestCase {
039: private static Root ROOT = new Root();
040:
041: private static Object[][] TESTS = {
042: // Projection, selection
043: {
044: ROOT,
045: "array.{class}",
046: Arrays
047: .asList(new Class[] { Integer.class,
048: Integer.class, Integer.class,
049: Integer.class }) },
050: {
051: ROOT,
052: "map.array.{? #this > 2 }",
053: Arrays.asList(new Integer[] { new Integer(3),
054: new Integer(4) }) },
055: { ROOT, "map.array.{^ #this > 2 }",
056: Arrays.asList(new Integer[] { new Integer(3) }) },
057: { ROOT, "map.array.{$ #this > 2 }",
058: Arrays.asList(new Integer[] { new Integer(4) }) },
059: {
060: ROOT,
061: "map.array[*].{?true} instanceof java.util.Collection",
062: Boolean.TRUE },
063: {
064: null,
065: "#fact=1, 30H.{? #fact = #fact * (#this+1), false }, #fact",
066: new BigInteger("265252859812191058636308480000000") }, };
067:
068: /*===================================================================
069: Public static methods
070: ===================================================================*/
071: public static TestSuite suite() {
072: TestSuite result = new TestSuite();
073:
074: for (int i = 0; i < TESTS.length; i++) {
075: result.addTest(new ProjectionSelectionTest(
076: (String) TESTS[i][1], TESTS[i][0],
077: (String) TESTS[i][1], TESTS[i][2]));
078: }
079: return result;
080: }
081:
082: /*===================================================================
083: Constructors
084: ===================================================================*/
085: public ProjectionSelectionTest() {
086: super ();
087: }
088:
089: public ProjectionSelectionTest(String name) {
090: super (name);
091: }
092:
093: public ProjectionSelectionTest(String name, Object root,
094: String expressionString, Object expectedResult,
095: Object setValue, Object expectedAfterSetResult) {
096: super (name, root, expressionString, expectedResult, setValue,
097: expectedAfterSetResult);
098: }
099:
100: public ProjectionSelectionTest(String name, Object root,
101: String expressionString, Object expectedResult,
102: Object setValue) {
103: super (name, root, expressionString, expectedResult, setValue);
104: }
105:
106: public ProjectionSelectionTest(String name, Object root,
107: String expressionString, Object expectedResult) {
108: super(name, root, expressionString, expectedResult);
109: }
110: }
|