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 junit.framework.TestSuite;
034: import org.ognl.test.objects.Root;
035:
036: public class PropertyTest extends OgnlTestCase {
037: private static Root ROOT = new Root();
038:
039: private static Object[][] TESTS = {
040: { ROOT, "map", ROOT.getMap() },
041: { ROOT, "map.test", ROOT },
042: { ROOT, "map[\"test\"]", ROOT },
043: { ROOT, "map[\"te\" + \"st\"]", ROOT },
044: { ROOT, "map[(\"s\" + \"i\") + \"ze\"]",
045: ROOT.getMap().get(Root.SIZE_STRING) },
046: { ROOT, "map[\"size\"]",
047: ROOT.getMap().get(Root.SIZE_STRING) },
048: { ROOT, "map[@org.ognl.test.objects.Root@SIZE_STRING]",
049: ROOT.getMap().get(Root.SIZE_STRING) },
050: { ROOT.getMap(), "list", ROOT.getList() },
051: { ROOT, "map.array[0]", new Integer(ROOT.getArray()[0]) },
052: { ROOT, "map.list[1]", ROOT.getList().get(1) },
053: { ROOT, "map[^]", new Integer(99) },
054: { ROOT, "map[$]", null },
055: {
056: ROOT.getMap(),
057: "array[$]",
058: new Integer(
059: ROOT.getArray()[ROOT.getArray().length - 1]) },
060: { ROOT, "[\"map\"]", ROOT.getMap() },
061: { ROOT.getArray(), "length",
062: new Integer(ROOT.getArray().length) },
063: { ROOT, "getMap().list[|]",
064: ROOT.getList().get(ROOT.getList().size() / 2) },
065: {
066: ROOT,
067: "map.(array[2] + size()).doubleValue()",
068: new Double(ROOT.getArray()[2]
069: + ROOT.getMap().size()) },
070: { ROOT, "map.(#this)", ROOT.getMap() },
071: { ROOT, "map.(#this != null ? #this['size'] : null)",
072: ROOT.getMap().get(Root.SIZE_STRING) },
073: { ROOT, "map[^].(#this == null ? 'empty' : #this)",
074: new Integer(99) },
075: { ROOT, "map[$].(#this == null ? 'empty' : #this)", "empty" },
076: { ROOT, "map[$].(#root == null ? 'empty' : #root)", ROOT } };
077:
078: /*===================================================================
079: Public static methods
080: ===================================================================*/
081: public static TestSuite suite() {
082: TestSuite result = new TestSuite();
083:
084: for (int i = 0; i < TESTS.length; i++) {
085: result.addTest(new PropertyTest((String) TESTS[i][1],
086: TESTS[i][0], (String) TESTS[i][1], TESTS[i][2]));
087: }
088: return result;
089: }
090:
091: /*===================================================================
092: Constructors
093: ===================================================================*/
094: public PropertyTest() {
095: super ();
096: }
097:
098: public PropertyTest(String name) {
099: super (name);
100: }
101:
102: public PropertyTest(String name, Object root,
103: String expressionString, Object expectedResult,
104: Object setValue, Object expectedAfterSetResult) {
105: super (name, root, expressionString, expectedResult, setValue,
106: expectedAfterSetResult);
107: }
108:
109: public PropertyTest(String name, Object root,
110: String expressionString, Object expectedResult,
111: Object setValue) {
112: super (name, root, expressionString, expectedResult, setValue);
113: }
114:
115: public PropertyTest(String name, Object root,
116: String expressionString, Object expectedResult) {
117: super(name, root, expressionString, expectedResult);
118: }
119: }
|