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.Map;
034: import junit.framework.TestSuite;
035: import ognl.OgnlContext;
036: import ognl.OgnlException;
037: import ognl.OgnlRuntime;
038: import ognl.PropertyAccessor;
039:
040: public class PropertyNotFoundTest extends OgnlTestCase {
041: private static final Blah BLAH = new Blah();
042:
043: private static Object[][] TESTS = { { BLAH, "webwork.token.name",
044: OgnlException.class, "W value", OgnlException.class }, };
045:
046: /*===================================================================
047: Public static classes
048: ===================================================================*/
049: public static class Blah {
050: String x;
051: String y;
052:
053: public String getX() {
054: return x;
055: }
056:
057: public void setX(String x) {
058: this .x = x;
059: }
060:
061: public String getY() {
062: return y;
063: }
064:
065: public void setY(String y) {
066: this .y = y;
067: }
068: }
069:
070: public static class BlahPropertyAccessor implements
071: PropertyAccessor {
072: public void setProperty(Map context, Object target,
073: Object name, Object value) throws OgnlException {
074: }
075:
076: public Object getProperty(Map context, Object target,
077: Object name) throws OgnlException {
078: if ("x".equals(name) || "y".equals(name)) {
079: return OgnlRuntime.getProperty((OgnlContext) context,
080: target, name);
081: }
082: return null;
083: }
084: }
085:
086: /*===================================================================
087: Public static methods
088: ===================================================================*/
089: public static TestSuite suite() {
090: TestSuite result = new TestSuite();
091:
092: for (int i = 0; i < TESTS.length; i++) {
093: if (TESTS[i].length == 3) {
094: result.addTest(new PropertyNotFoundTest(
095: (String) TESTS[i][1], TESTS[i][0],
096: (String) TESTS[i][1], TESTS[i][2]));
097: } else {
098: if (TESTS[i].length == 4) {
099: result.addTest(new PropertyNotFoundTest(
100: (String) TESTS[i][1], TESTS[i][0],
101: (String) TESTS[i][1], TESTS[i][2],
102: TESTS[i][3]));
103: } else {
104: if (TESTS[i].length == 5) {
105: result.addTest(new PropertyNotFoundTest(
106: (String) TESTS[i][1], TESTS[i][0],
107: (String) TESTS[i][1], TESTS[i][2],
108: TESTS[i][3], TESTS[i][4]));
109: } else {
110: throw new RuntimeException(
111: "don't understand TEST format");
112: }
113: }
114: }
115: }
116: return result;
117: }
118:
119: /*===================================================================
120: Constructors
121: ===================================================================*/
122: public PropertyNotFoundTest() {
123: super ();
124: }
125:
126: public PropertyNotFoundTest(String name) {
127: super (name);
128: }
129:
130: public PropertyNotFoundTest(String name, Object root,
131: String expressionString, Object expectedResult,
132: Object setValue, Object expectedAfterSetResult) {
133: super (name, root, expressionString, expectedResult, setValue,
134: expectedAfterSetResult);
135: }
136:
137: public PropertyNotFoundTest(String name, Object root,
138: String expressionString, Object expectedResult,
139: Object setValue) {
140: super (name, root, expressionString, expectedResult, setValue);
141: }
142:
143: public PropertyNotFoundTest(String name, Object root,
144: String expressionString, Object expectedResult) {
145: super (name, root, expressionString, expectedResult);
146: }
147:
148: protected void setUp() {
149: super .setUp();
150: OgnlRuntime.setPropertyAccessor(Blah.class,
151: new BlahPropertyAccessor());
152: }
153: }
|