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.util.*;
034: import junit.framework.TestSuite;
035: import org.ognl.test.objects.Root;
036:
037: public class CollectionDirectPropertyTest extends OgnlTestCase {
038: private static Root ROOT = new Root();
039:
040: private static Object[][] TESTS = {
041: // Collection direct properties
042: { Arrays.asList(new String[] { "hello", "world" }), "size",
043: new Integer(2) },
044: { Arrays.asList(new String[] { "hello", "world" }),
045: "isEmpty", Boolean.FALSE },
046: { Arrays.asList(new String[] {}), "isEmpty", Boolean.TRUE },
047: { Arrays.asList(new String[] { "hello", "world" }),
048: "iterator.next", "hello" },
049: { Arrays.asList(new String[] { "hello", "world" }),
050: "iterator.hasNext", Boolean.TRUE },
051: { Arrays.asList(new String[] { "hello", "world" }),
052: "#it = iterator, #it.next, #it.next, #it.hasNext",
053: Boolean.FALSE },
054: { Arrays.asList(new String[] { "hello", "world" }),
055: "#it = iterator, #it.next, #it.next", "world" },
056: { Arrays.asList(new String[] { "hello", "world" }), "size",
057: new Integer(2) },
058: { ROOT, "map[\"test\"]", ROOT },
059: { ROOT, "map.size", new Integer(ROOT.getMap().size()) },
060: { ROOT, "map.keys", ROOT.getMap().keySet() },
061: { ROOT, "map.values", ROOT.getMap().values() },
062: { ROOT, "map.keys.size",
063: new Integer(ROOT.getMap().keySet().size()) },
064: { ROOT, "map[\"size\"]", ROOT.getMap().get("size") },
065: {
066: ROOT,
067: "map.isEmpty",
068: ROOT.getMap().isEmpty() ? Boolean.TRUE
069: : Boolean.FALSE },
070: { ROOT, "map[\"isEmpty\"]", null }, };
071:
072: /*===================================================================
073: Public static methods
074: ===================================================================*/
075: public static TestSuite suite() {
076: TestSuite result = new TestSuite();
077:
078: for (int i = 0; i < TESTS.length; i++) {
079: if (TESTS[i].length == 3) {
080: result.addTest(new CollectionDirectPropertyTest(
081: (String) TESTS[i][1], TESTS[i][0],
082: (String) TESTS[i][1], TESTS[i][2]));
083: } else {
084: if (TESTS[i].length == 4) {
085: result.addTest(new CollectionDirectPropertyTest(
086: (String) TESTS[i][1], TESTS[i][0],
087: (String) TESTS[i][1], TESTS[i][2],
088: TESTS[i][3]));
089: } else {
090: if (TESTS[i].length == 5) {
091: result
092: .addTest(new CollectionDirectPropertyTest(
093: (String) TESTS[i][1],
094: TESTS[i][0],
095: (String) TESTS[i][1],
096: TESTS[i][2], TESTS[i][3],
097: TESTS[i][4]));
098: } else {
099: throw new RuntimeException(
100: "don't understand TEST format");
101: }
102: }
103: }
104: }
105: return result;
106: }
107:
108: /*===================================================================
109: Constructors
110: ===================================================================*/
111: public CollectionDirectPropertyTest() {
112: super ();
113: }
114:
115: public CollectionDirectPropertyTest(String name) {
116: super (name);
117: }
118:
119: public CollectionDirectPropertyTest(String name, Object root,
120: String expressionString, Object expectedResult,
121: Object setValue, Object expectedAfterSetResult) {
122: super (name, root, expressionString, expectedResult, setValue,
123: expectedAfterSetResult);
124: }
125:
126: public CollectionDirectPropertyTest(String name, Object root,
127: String expressionString, Object expectedResult,
128: Object setValue) {
129: super (name, root, expressionString, expectedResult, setValue);
130: }
131:
132: public CollectionDirectPropertyTest(String name, Object root,
133: String expressionString, Object expectedResult) {
134: super(name, root, expressionString, expectedResult);
135: }
136: }
|