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