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.Ognl;
035: import ognl.OgnlException;
036:
037: public class ConstantTreeTest extends OgnlTestCase {
038: public static int nonFinalStaticVariable = 15;
039:
040: private static Object[][] TESTS = {
041: { "true", Boolean.TRUE },
042: { "55", Boolean.TRUE },
043: { "@java.awt.Color@black", Boolean.TRUE },
044: { "@org.ognl.test.ConstantTreeTest@nonFinalStaticVariable",
045: Boolean.FALSE },
046: {
047: "@org.ognl.test.ConstantTreeTest@nonFinalStaticVariable + 10",
048: Boolean.FALSE },
049: { "55 + 24 + @java.awt.Event@ALT_MASK", Boolean.TRUE },
050: { "name", Boolean.FALSE }, { "name[i]", Boolean.FALSE },
051: { "name[i].property", Boolean.FALSE },
052: { "name.{? foo }", Boolean.FALSE },
053: { "name.{ foo }", Boolean.FALSE },
054: { "name.{ 25 }", Boolean.FALSE } };
055:
056: /*===================================================================
057: Public static methods
058: ===================================================================*/
059: public static TestSuite suite() {
060: TestSuite result = new TestSuite();
061:
062: for (int i = 0; i < TESTS.length; i++) {
063: result.addTest(new ConstantTreeTest((String) TESTS[i][0]
064: + " (" + TESTS[i][1] + ")", null,
065: (String) TESTS[i][0], TESTS[i][1]));
066: }
067: return result;
068: }
069:
070: /*===================================================================
071: Overridden methods
072: ===================================================================*/
073: protected void runTest() throws OgnlException {
074: assertTrue(Ognl.isConstant(getExpression(), context) == ((Boolean) getExpectedResult())
075: .booleanValue());
076: }
077:
078: /*===================================================================
079: Constructors
080: ===================================================================*/
081: public ConstantTreeTest() {
082: super ();
083: }
084:
085: public ConstantTreeTest(String name) {
086: super (name);
087: }
088:
089: public ConstantTreeTest(String name, Object root,
090: String expressionString, Object expectedResult,
091: Object setValue, Object expectedAfterSetResult) {
092: super (name, root, expressionString, expectedResult, setValue,
093: expectedAfterSetResult);
094: }
095:
096: public ConstantTreeTest(String name, Object root,
097: String expressionString, Object expectedResult,
098: Object setValue) {
099: super (name, root, expressionString, expectedResult, setValue);
100: }
101:
102: public ConstantTreeTest(String name, Object root,
103: String expressionString, Object expectedResult) {
104: super(name, root, expressionString, expectedResult);
105: }
106: }
|