1   /*
2    * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
3    *
4    * This software is open source.
5    * See the bottom of this file for the licence.
6    */
7   
8   package org.dom4j.datatype;
9   
10  import junit.textui.TestRunner;
11  
12  import java.math.BigDecimal;
13  import java.math.BigInteger;
14  import java.util.Calendar;
15  
16  import org.dom4j.DocumentFactory;
17  import org.dom4j.io.SAXReader;
18  
19  /***
20   * Test harness to test the various data types supported in the XML Schema Data
21   * Type integration.
22   * 
23   * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
24   * @version $Revision: 1.4 $
25   */
26  public class DataTypesTest extends AbstractDataTypeTestCase {
27      public static void main(String[] args) {
28          TestRunner.run(DataTypesTest.class);
29      }
30  
31      // Test case(s)
32      // -------------------------------------------------------------------------
33      public void testgMonthDay() throws Exception {
34          testNodes("//gMonthDayTag", Calendar.class);
35      }
36  
37      public void testgDay() throws Exception {
38          testNodes("//gDayTag", Calendar.class);
39      }
40  
41      public void testgMonth() throws Exception {
42          testNodes("//gMonthTag", Calendar.class);
43      }
44  
45      public void testDate() throws Exception {
46          testNodes("//dateTag", Calendar.class);
47      }
48  
49      public void testTime() throws Exception {
50          testNodes("//timeTag", Calendar.class);
51      }
52  
53      public void testDateTime() throws Exception {
54          testNodes("//dateTimeTag", Calendar.class);
55      }
56  
57      public void testgYearMonth() throws Exception {
58          testNodes("//gYearMonthTag", Calendar.class);
59      }
60  
61      public void testgYear() throws Exception {
62          testNodes("//gYearTag", Calendar.class);
63      }
64  
65      public void testBoolean() throws Exception {
66          testNodes("//booleanTag", Boolean.class);
67      }
68  
69      public void testBase64Binary() throws Exception {
70          testNodes("//base64BinaryTag", byte[].class);
71      }
72  
73      public void testHexBinary() throws Exception {
74          testNodes("//hexBinaryTag", byte[].class);
75      }
76  
77      // Number types
78      public void testFloat() throws Exception {
79          testNodes("//floatTag", Float.class);
80      }
81  
82      public void testDouble() throws Exception {
83          testNodes("//doubleTag", Double.class);
84      }
85  
86      public void testDecimal() throws Exception {
87          testNodes("//decimalTag", BigDecimal.class);
88      }
89  
90      public void testInteger() throws Exception {
91          testNodes("//integerTag", BigInteger.class);
92      }
93  
94      public void testNonPositiveInteger() throws Exception {
95          testNodes("//nonPositiveIntegerTag", BigInteger.class);
96      }
97  
98      public void testNegativeInteger() throws Exception {
99          testNodes("//negativeIntegerTag", BigInteger.class);
100     }
101 
102     public void testLong() throws Exception {
103         testNodes("//longTag", Long.class);
104     }
105 
106     public void testInt() throws Exception {
107         testNodes("//intTag", Integer.class);
108     }
109 
110     public void testShort() throws Exception {
111         testNodes("//shortTag", Short.class);
112     }
113 
114     public void testByte() throws Exception {
115         testNodes("//byteTag", Byte.class);
116     }
117 
118     public void testNonNegativeInteger() throws Exception {
119         testNodes("//nonNegativeIntegerTag", BigInteger.class);
120     }
121 
122     public void testUnsignedLong() throws Exception {
123         testNodes("//unsignedLongTag", BigInteger.class);
124     }
125 
126     public void testUnsignedInt() throws Exception {
127         testNodes("//unsignedIntTag", Long.class);
128     }
129 
130     public void testUnsignedShort() throws Exception {
131         testNodes("//unsignedShortTag", Integer.class);
132     }
133 
134     public void testUnsignedByte() throws Exception {
135         testNodes("//unsignedByteTag", Short.class);
136     }
137 
138     public void testPositiveInteger() throws Exception {
139         testNodes("//positiveIntegerTag", BigInteger.class);
140     }
141 
142     // Implementation methods
143     // -------------------------------------------------------------------------
144     protected void setUp() throws Exception {
145         super.setUp();
146 
147         DocumentFactory factory = DatatypeDocumentFactory.getInstance();
148         SAXReader reader = new SAXReader(factory);
149         document = getDocument("/xml/test/schema/test.xml", reader);
150     }
151 }
152 
153 /*
154  * Redistribution and use of this software and associated documentation
155  * ("Software"), with or without modification, are permitted provided that the
156  * following conditions are met:
157  * 
158  * 1. Redistributions of source code must retain copyright statements and
159  * notices. Redistributions must also contain a copy of this document.
160  * 
161  * 2. Redistributions in binary form must reproduce the above copyright notice,
162  * this list of conditions and the following disclaimer in the documentation
163  * and/or other materials provided with the distribution.
164  * 
165  * 3. The name "DOM4J" must not be used to endorse or promote products derived
166  * from this Software without prior written permission of MetaStuff, Ltd. For
167  * written permission, please contact dom4j-info@metastuff.com.
168  * 
169  * 4. Products derived from this Software may not be called "DOM4J" nor may
170  * "DOM4J" appear in their names without prior written permission of MetaStuff,
171  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
172  * 
173  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
174  * 
175  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
176  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
177  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
178  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
179  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
180  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
181  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
182  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
183  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
184  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
185  * POSSIBILITY OF SUCH DAMAGE.
186  * 
187  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
188  */