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 ognl.OgnlException;
035: import org.ognl.test.objects.ObjectIndexed;
036:
037: public class ObjectIndexedPropertyTest extends OgnlTestCase {
038: private static ObjectIndexed OBJECT_INDEXED = new ObjectIndexed();
039:
040: private static Object[][] TESTS = {
041: // Arbitrary indexed properties
042: { OBJECT_INDEXED, "attributes[\"bar\"]", "baz" }, /* get non-indexed property through attributes Map */
043: { OBJECT_INDEXED, "attribute[\"foo\"]", "bar" }, /* get indexed property */
044: { OBJECT_INDEXED, "attribute[\"bar\"]", "baz", "newValue",
045: "newValue" }, /* set indexed property */
046: { OBJECT_INDEXED, "attribute[\"bar\"]", "newValue" }, /* get indexed property back to confirm */
047: { OBJECT_INDEXED, "attributes[\"bar\"]", "newValue" }, /* get property back through Map to confirm */
048: { OBJECT_INDEXED,
049: "attribute[\"other\"].attribute[\"bar\"]", "baz" }, /* get indexed property from indexed, then through other */
050: { OBJECT_INDEXED,
051: "attribute[\"other\"].attributes[\"bar\"]", "baz" }, /* get property back through Map to confirm */
052: { OBJECT_INDEXED, "attribute[$]", OgnlException.class }, /* illegal DynamicSubscript access to object indexed property */
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 ObjectIndexedPropertyTest(
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 ObjectIndexedPropertyTest(
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 ObjectIndexedPropertyTest(
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 ObjectIndexedPropertyTest() {
092: super ();
093: }
094:
095: public ObjectIndexedPropertyTest(String name) {
096: super (name);
097: }
098:
099: public ObjectIndexedPropertyTest(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 ObjectIndexedPropertyTest(String name, Object root,
107: String expressionString, Object expectedResult,
108: Object setValue) {
109: super (name, root, expressionString, expectedResult, setValue);
110: }
111:
112: public ObjectIndexedPropertyTest(String name, Object root,
113: String expressionString, Object expectedResult) {
114: super(name, root, expressionString, expectedResult);
115: }
116: }
|