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.Indexed;
035:
036: public class IndexedPropertyTest extends OgnlTestCase {
037: private static Indexed INDEXED = new Indexed();
038:
039: private static Object[][] TESTS = {
040: // Indexed properties
041: { INDEXED, "values", INDEXED.getValues() }, /* gets String[] */
042: { INDEXED, "[\"values\"]", INDEXED.getValues() }, /* String[] */
043: { INDEXED.getValues(), "[0]", INDEXED.getValues()[0] }, /* "foo" */
044: { INDEXED, "getValues()[0]", INDEXED.getValues()[0] }, /* "foo" directly from array */
045: { INDEXED, "values[0]", INDEXED.getValues(0) }, /* "foo" + "xxx" */
046: { INDEXED, "values[^]", INDEXED.getValues(0) }, /* "foo" + "xxx" */
047: { INDEXED, "values[|]", INDEXED.getValues(1) }, /* "bar" + "xxx" */
048: { INDEXED, "values[$]", INDEXED.getValues(2) }, /* "baz" + "xxx" */
049: { INDEXED, "values[1]", "bar" + "xxx", "xxxx" + "xxx",
050: "xxxx" + "xxx" }, /* set through setValues(int, String) */
051: { INDEXED, "values[1]", "xxxx" + "xxx" }, /* getValues(int) again to check if setValues(int, String) was called */
052: { INDEXED, "setValues(2, \"xxxx\")", null }, /* was "baz" -> "xxxx" */
053: };
054:
055: /*===================================================================
056: Public static methods
057: ===================================================================*/
058: public static TestSuite suite() {
059: TestSuite result = new TestSuite();
060:
061: for (int i = 0; i < TESTS.length; i++) {
062: if (TESTS[i].length == 3) {
063: result.addTest(new IndexedPropertyTest(
064: (String) TESTS[i][1], TESTS[i][0],
065: (String) TESTS[i][1], TESTS[i][2]));
066: } else {
067: if (TESTS[i].length == 4) {
068: result.addTest(new IndexedPropertyTest(
069: (String) TESTS[i][1], TESTS[i][0],
070: (String) TESTS[i][1], TESTS[i][2],
071: TESTS[i][3]));
072: } else {
073: if (TESTS[i].length == 5) {
074: result.addTest(new IndexedPropertyTest(
075: (String) TESTS[i][1], TESTS[i][0],
076: (String) TESTS[i][1], TESTS[i][2],
077: TESTS[i][3], TESTS[i][4]));
078: } else {
079: throw new RuntimeException(
080: "don't understand TEST format");
081: }
082: }
083: }
084: }
085: return result;
086: }
087:
088: /*===================================================================
089: Constructors
090: ===================================================================*/
091: public IndexedPropertyTest() {
092: super ();
093: }
094:
095: public IndexedPropertyTest(String name) {
096: super (name);
097: }
098:
099: public IndexedPropertyTest(String name, Object root,
100: String expressionString, Object expectedResult,
101: Object setValue, Object expectedAfterSetResult) {
102: super (name, root, expressionString, expectedResult, setValue,
103: expectedAfterSetResult);
104: }
105:
106: public IndexedPropertyTest(String name, Object root,
107: String expressionString, Object expectedResult,
108: Object setValue) {
109: super (name, root, expressionString, expectedResult, setValue);
110: }
111:
112: public IndexedPropertyTest(String name, Object root,
113: String expressionString, Object expectedResult) {
114: super(name, root, expressionString, expectedResult);
115: }
116: }
|