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.ExpressionSyntaxException;
035: import org.ognl.test.objects.Root;
036: import org.ognl.test.objects.Simple;
037:
038: public class ArrayCreationTest extends OgnlTestCase {
039: private static Root ROOT = new Root();
040:
041: private static Object[][] TESTS = {
042: // Array creation
043: { ROOT, "new String[] { \"one\", \"two\" }",
044: new String[] { "one", "two" } },
045: { ROOT, "new String[] { 1, 2 }", new String[] { "1", "2" } },
046: {
047: ROOT,
048: "new Integer[] { \"1\", 2, \"3\" }",
049: new Integer[] { new Integer(1), new Integer(2),
050: new Integer(3) } },
051: { ROOT, "new String[10]", new String[10] },
052: { ROOT, "new Object[4] { #root, #this }",
053: ExpressionSyntaxException.class },
054: { ROOT, "new Object[4]", new Object[4] },
055: { ROOT, "new Object[] { #root, #this }",
056: new Object[] { ROOT, ROOT } },
057: {
058: ROOT,
059: "new org.ognl.test.objects.Simple[] { new org.ognl.test.objects.Simple(), new org.ognl.test.objects.Simple(\"foo\", 1.0, 2) }",
060: new Simple[] { new Simple(),
061: new Simple("foo", 1.0f, 2) } },
062: { ROOT, "new org.ognl.test.objects.Simple[5]",
063: new Simple[5] },
064: { ROOT, "new org.ognl.test.objects.Simple(new Object[5])",
065: new Simple(new Object[5]) },
066: { ROOT, "new org.ognl.test.objects.Simple(new String[5])",
067: new Simple(new String[5]) }, };
068:
069: /*===================================================================
070: Public static methods
071: ===================================================================*/
072: public static TestSuite suite() {
073: TestSuite result = new TestSuite();
074:
075: for (int i = 0; i < TESTS.length; i++) {
076: if (TESTS[i].length == 3) {
077: result.addTest(new ArrayCreationTest(
078: (String) TESTS[i][1], TESTS[i][0],
079: (String) TESTS[i][1], TESTS[i][2]));
080: } else {
081: if (TESTS[i].length == 4) {
082: result.addTest(new ArrayCreationTest(
083: (String) TESTS[i][1], TESTS[i][0],
084: (String) TESTS[i][1], TESTS[i][2],
085: TESTS[i][3]));
086: } else {
087: if (TESTS[i].length == 5) {
088: result.addTest(new ArrayCreationTest(
089: (String) TESTS[i][1], TESTS[i][0],
090: (String) TESTS[i][1], TESTS[i][2],
091: TESTS[i][3], TESTS[i][4]));
092: } else {
093: throw new RuntimeException(
094: "don't understand TEST format");
095: }
096: }
097: }
098: }
099: return result;
100: }
101:
102: /*===================================================================
103: Constructors
104: ===================================================================*/
105: public ArrayCreationTest() {
106: super ();
107: }
108:
109: public ArrayCreationTest(String name) {
110: super (name);
111: }
112:
113: public ArrayCreationTest(String name, Object root,
114: String expressionString, Object expectedResult,
115: Object setValue, Object expectedAfterSetResult) {
116: super (name, root, expressionString, expectedResult, setValue,
117: expectedAfterSetResult);
118: }
119:
120: public ArrayCreationTest(String name, Object root,
121: String expressionString, Object expectedResult,
122: Object setValue) {
123: super (name, root, expressionString, expectedResult, setValue);
124: }
125:
126: public ArrayCreationTest(String name, Object root,
127: String expressionString, Object expectedResult) {
128: super(name, root, expressionString, expectedResult);
129: }
130: }
|