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