001: //$Id: ProcessCollectionTypeTest.java 342 2008-02-20 22:38: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.List;
041: import java.util.Vector;
042:
043: import junitx.ddtunit.DDTTestCase;
044:
045: /**
046: * Test class for checking read facilities of collection type xml resource
047: * objects.
048: *
049: * @author jg
050: */
051: public class ProcessCollectionTypeTest extends DDTTestCase {
052:
053: /*
054: * (non-Javadoc)
055: *
056: * @see junitx.ddtunit.DDTTestCase#initContext()()
057: */
058: protected void initContext() {
059: initTestData("ProcessCollectionTypeTest",
060: "ProcessCollectionTypeTest");
061: }
062:
063: /**
064: * Test reading simple <code>java.util.Vector</code> object from xml
065: * resource.
066: *
067: */
068: public void testReadVector() {
069: Vector vector = (Vector) getObject("myVector");
070: assertNotNull("Vector should not be null", vector);
071: addObjectToAssert("count", new Integer(vector.size()));
072: if (vector.size() > 0) {
073: addObjectToAssert("expected", vector.get(1));
074: } else {
075: addObjectToAssert("expected", null);
076: }
077: }
078:
079: public void testReadNullVector() {
080: Vector vector = (Vector) getObject("myVector");
081: addObjectToAssert("result", vector);
082: }
083:
084: /**
085: * Test reading of nested collections.
086: *
087: */
088: public void testReadNestedCollection() {
089: Vector vector = (Vector) getObject("myVector");
090: assertNotNull("Vector should not be null", vector);
091: assertObject("count", new Integer(vector.size()), false);
092: List first = (List) vector.get(0);
093: List second = (List) vector.get(1);
094: assertObject("count", new Integer(first.size()), false);
095: assertObject("count", new Integer(second.size()));
096: }
097:
098: /**
099: * Test reading of nested collections.
100: *
101: */
102: public void testReadNestedMixedType() {
103: Vector vector = (Vector) getObject("myVector");
104: assertNotNull("Vector should not be null", vector);
105: assertObject("count", new Integer(vector.size()), false);
106: List first = (List) vector.get(0);
107: addObjectToAssert("count", new Integer(first.size()));
108: addObjectToAssert("firstEntry", first.get(0));
109: addObjectToAssert("secondEntry", vector.get(1));
110: }
111:
112: public void testArrayFromCollection() {
113: List list = (List) getObject("myList");
114: addObjectToAssert("count", new Integer(list.size()));
115: addObjectToAssert("result", list.get(1));
116: }
117:
118: /**
119: * Test assert behavior with empty nested collection as reported by bug
120: * 1773974
121: */
122: public void testDoubleNestedCollectionInAssert() throws Exception {
123: Collection container = (Collection) getObject("object1");
124: addObjectToAssert("result", container);
125: }
126:
127: public void testIdentifyCollection() throws Exception {
128: Object obj = getObject("myObj");
129: addObjectToAssert("result", obj);
130: }
131:
132: /**
133: * Test verifies parsing behavior of Bug 1898143 on sourceforge
134: * @throws Exception
135: */
136: public void testNestedVoWithCollection() throws Exception {
137: Object obj = getObject("myObj");
138: addObjectToAssert("result", obj);
139: }
140: }
|