View Javadoc

1   //$Id: ProcessSetTypeTest.java 240 2006-05-03 22:45:16Z jg_hamburg $
2   /********************************************************************************
3    * DDTUnit, a Datadriven Approach to Unit- and Moduletesting
4    * Copyright (c) 2004, Joerg and Kai Gellien
5    * All rights reserved.
6    *
7    * The Software is provided under the terms of the Common Public License 1.0
8    * as provided with the distribution of DDTUnit in the file cpl-v10.html.
9    * Redistribution and use in source and binary forms, with or without
10   * modification, are permitted provided that the following conditions
11   * are met:
12   *
13   *     + Redistributions of source code must retain the above copyright
14   *       notice, this list of conditions and the following disclaimer.
15   *
16   *     + Redistributions in binary form must reproduce the above
17   *       copyright notice, this list of conditions and the following
18   *       disclaimer in the documentation and/or other materials provided
19   *       with the distribution.
20   *
21   *     + Neither the name of the authors or DDTUnit, nor the
22   *       names of its contributors may be used to endorse or promote
23   *       products derived from this software without specific prior
24   *       written permission.
25   *
26   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
30   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37   ********************************************************************************/
38  package junitx.ddtunit.functest;
39  
40  import java.util.Collection;
41  import java.util.Set;
42  
43  import junitx.ddtunit.DDTTestCase;
44  
45  /**
46   * Test class for checking read facilities of collection type xml resource
47   * objects.
48   * 
49   * @author jg
50   */
51  public class ProcessSetTypeTest extends DDTTestCase {
52  
53      /*
54       * (non-Javadoc)
55       * 
56       * @see junitx.ddtunit.DDTTestCase#initContext()()
57       */
58      protected void initContext() {
59          initTestData("ProcessSetTypeTest", "ProcessSetTypeTest");
60      }
61  
62      /**
63       * Test reading simple <code>java.util.Vector</code> object from xml
64       * resource.
65       * 
66       */
67      public void testReadSet() {
68          Set set = (Set) getObject("mySet");
69          assertNotNull("Set should not be null", set);
70          addObjectToAssert("count", new Integer(set.size()));
71          if (set.size() > 0) {
72              addObjectToAssert("expected", set.toArray()[0]);
73          } else {
74              addObjectToAssert("expected", null);
75          }
76      }
77  
78      public void testReadNullSet() {
79          Set set = (Set) getObject("mySet");
80          addObjectToAssert("result", set);
81      }
82  
83      /**
84       * Test reading of nested collections.
85       * 
86       */
87      public void testReadNestedSet() {
88          Set set = (Set) getObject("mySet");
89          assertNotNull("Set should not be null", set);
90          assertObject("count", new Integer(set.size()), false);
91          Object[] setElements = set.toArray();
92          Collection first = (Collection) setElements[0];
93          Collection second = (Collection) setElements[1];
94          assertObject("count", new Integer(first.size()), false);
95          assertObject("count", new Integer(second.size()));
96      }
97  
98      /**
99       * Test reading of nested collections.
100      * 
101      */
102     public void testReadNestedMixedType() {
103         Set set = (Set) getObject("mySet");
104         assertNotNull("Set should not be null", set);
105         assertObject("count", new Integer(set.size()), false);
106         Object[] setElements = set.toArray();
107         Collection first = (Collection) setElements[0];
108         addObjectToAssert("count", new Integer(first.size()));
109         Object[] firstElements = first.toArray();
110         addObjectToAssert("firstEntry", firstElements[0]);
111         addObjectToAssert("secondEntry", firstElements[1]);
112     }
113 
114     public void testArrayFromSet() {
115         Set set = (Set) getObject("mySet");
116         addObjectToAssert("count", new Integer(set.size()));
117         addObjectToAssert("result", set.toArray()[0]);
118     }
119 
120 }