001: //$Id: ProcessSetTypeTest.java 240 2006-05-03 22:45:16Z 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.Collection;
040: import java.util.Set;
041:
042: import junitx.ddtunit.DDTTestCase;
043:
044: /**
045: * Test class for checking read facilities of collection type xml resource
046: * objects.
047: *
048: * @author jg
049: */
050: public class ProcessSetTypeTest extends DDTTestCase {
051:
052: /*
053: * (non-Javadoc)
054: *
055: * @see junitx.ddtunit.DDTTestCase#initContext()()
056: */
057: protected void initContext() {
058: initTestData("ProcessSetTypeTest", "ProcessSetTypeTest");
059: }
060:
061: /**
062: * Test reading simple <code>java.util.Vector</code> object from xml
063: * resource.
064: *
065: */
066: public void testReadSet() {
067: Set set = (Set) getObject("mySet");
068: assertNotNull("Set should not be null", set);
069: addObjectToAssert("count", new Integer(set.size()));
070: if (set.size() > 0) {
071: addObjectToAssert("expected", set.toArray()[0]);
072: } else {
073: addObjectToAssert("expected", null);
074: }
075: }
076:
077: public void testReadNullSet() {
078: Set set = (Set) getObject("mySet");
079: addObjectToAssert("result", set);
080: }
081:
082: /**
083: * Test reading of nested collections.
084: *
085: */
086: public void testReadNestedSet() {
087: Set set = (Set) getObject("mySet");
088: assertNotNull("Set should not be null", set);
089: assertObject("count", new Integer(set.size()), false);
090: Object[] setElements = set.toArray();
091: Collection first = (Collection) setElements[0];
092: Collection second = (Collection) setElements[1];
093: assertObject("count", new Integer(first.size()), false);
094: assertObject("count", new Integer(second.size()));
095: }
096:
097: /**
098: * Test reading of nested collections.
099: *
100: */
101: public void testReadNestedMixedType() {
102: Set set = (Set) getObject("mySet");
103: assertNotNull("Set should not be null", set);
104: assertObject("count", new Integer(set.size()), false);
105: Object[] setElements = set.toArray();
106: Collection first = (Collection) setElements[0];
107: addObjectToAssert("count", new Integer(first.size()));
108: Object[] firstElements = first.toArray();
109: addObjectToAssert("firstEntry", firstElements[0]);
110: addObjectToAssert("secondEntry", firstElements[1]);
111: }
112:
113: public void testArrayFromSet() {
114: Set set = (Set) getObject("mySet");
115: addObjectToAssert("count", new Integer(set.size()));
116: addObjectToAssert("result", set.toArray()[0]);
117: }
118:
119: }
|