001: //$Id: ProcessMapTypeTest.java 264 2007-01-21 23:09:24Z jg_hamburg $
002: /********************************************************************************
003: * DDTUnit, a Datadriven Approach to Unit- and Moduletesting
004: * Copyright (c) 2004, Joerg and Kai Gellien
005: * All rights reserved.
006: *
007: * The Software is provided under the terms of the Common Public License 1.0
008: * as provided with the distribution of DDTUnit in the file cpl-v10.html.
009: * Redistribution and use in source and binary forms, with or without
010: * modification, are permitted provided that the following conditions
011: * are met:
012: *
013: * + Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * + Redistributions in binary form must reproduce the above
017: * copyright notice, this list of conditions and the following
018: * disclaimer in the documentation and/or other materials provided
019: * with the distribution.
020: *
021: * + Neither the name of the authors or DDTUnit, nor the
022: * names of its contributors may be used to endorse or promote
023: * products derived from this software without specific prior
024: * written permission.
025: *
026: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
027: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
028: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
029: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
030: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
031: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
032: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
033: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
034: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
035: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
036: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037: ********************************************************************************/package junitx.ddtunit.functest;
038:
039: import java.util.HashMap;
040: import java.util.List;
041: import java.util.Map;
042:
043: import junitx.ddtunit.DDTTestCase;
044: import junitx.ddtunit.resources.ComplexVO;
045:
046: /**
047: * Test class for checking read facilities of map type xml resource objects.
048: *
049: * @author jg
050: */
051: public class ProcessMapTypeTest extends DDTTestCase {
052:
053: /*
054: * (non-Javadoc)
055: *
056: * @see junitx.ddtunit.DDTTestCase#initContext()()
057: */
058: protected void initContext() {
059: initTestData("ProcessMapTypeTest", "ProcessMapTypeTest");
060: }
061:
062: /**
063: * Test reading simple <code>java.util.HashMap</code> object from xml
064: * resource as base object.
065: */
066: public void testReadMap() {
067: Map map = (Map) getObject("myMap");
068: assertNotNull("Map should not be null", map);
069: addObjectToAssert("count", new Integer(map.size()));
070: Object key = getObject("key");
071: addObjectToAssert("expected", map.get(key));
072: }
073:
074: public void testReadSpecialMap() {
075: Map map = (HashMap) getObject("myMap");
076: addObjectToAssert("result", map);
077: }
078:
079: /**
080: * Test reading of <code>java.util.Map</code> as field of complex data
081: * type.
082: */
083: public void testReadMapAsField() {
084: ComplexVO complexVO = (ComplexVO) getObject("complexVO");
085: Map mapField = complexVO.getMap();
086: addObjectToAssert("count", new Integer(mapField.size()));
087: Object key = getObject("key");
088: addObjectToAssert("expected", mapField.get(key));
089: }
090:
091: /**
092: * Test reading of <code>java.util.Map</code> as member of
093: * <code>java.util.Collection</code> type.
094: */
095: public void testReadMapAsCollectionMember() {
096: List list = (List) getObject("list");
097: assertNotNull("List should not be null", list);
098: assertEquals("Wrong number of collection entries",
099: getObject("listCount"), new Integer(list.size()));
100: Map mapField = (Map) list.get(0);
101: addObjectToAssert("count", new Integer(mapField.size()));
102: Object key = getObject("key");
103: addObjectToAssert("expected", mapField.get(key));
104: }
105:
106: public void testArrayFromMap() {
107: Map map = (Map) getObject("myMap");
108: addObjectToAssert("count", new Integer(map.size()));
109: addObjectToAssert("result", map.get(getObject("key")));
110: }
111:
112: }
|