KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > dom4j > datatype > TestAutoSchema


1 /*
2  * Copyright 2001 (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: TestAutoSchema.java,v 1.1 2003/07/07 10:30:29 per_nyfelt Exp $
8  */

9
10 package test.dom4j.datatype;
11
12 import junit.framework.Test;
13 import junit.framework.TestSuite;
14 import junit.textui.TestRunner;
15 import org.dom4j.DocumentFactory;
16 import org.dom4j.datatype.DatatypeDocumentFactory;
17 import org.dom4j.io.SAXReader;
18
19 import java.math.BigInteger JavaDoc;
20 import java.util.Calendar JavaDoc;
21
22
23 /** Test harness for the XML Schema Data Type integration. These tests
24   * use auto-loading of the XML Schema document
25   *
26   * @author <a HREF="mailto:jstrachan@apache.org">James Strachan</a>
27   * @version $Revision: 1.1 $
28   */

29 public class TestAutoSchema extends AbstractDataTypeTest {
30
31     public static void main( String JavaDoc[] args ) {
32         TestRunner.run( suite() );
33     }
34
35     public static Test suite() {
36         return new TestSuite( TestAutoSchema.class );
37     }
38
39     public TestAutoSchema(String JavaDoc name) {
40         super(name);
41     }
42
43     // Test case(s)
44
//-------------------------------------------------------------------------
45
public void testIntAttribute() throws Exception JavaDoc {
46         testNodes( "//person/@x", Integer JavaDoc.class );
47     }
48
49     public void testIntElement() throws Exception JavaDoc {
50         testNodes( "//person/salary", Integer JavaDoc.class );
51     }
52
53     public void testString() throws Exception JavaDoc {
54         testNodes( "//person/note", String JavaDoc.class );
55     }
56
57     public void testDate() throws Exception JavaDoc {
58         testNodes( "//person/@d", Calendar JavaDoc.class );
59     }
60
61     public void testDateTime() throws Exception JavaDoc {
62         testNodes( "//person/@dt", Calendar JavaDoc.class );
63     }
64
65     public void testInteger() throws Exception JavaDoc {
66         testNodes( "//person/@age", BigInteger JavaDoc.class );
67     }
68
69
70     // Implementation methods
71
//-------------------------------------------------------------------------
72
protected void setUp() throws Exception JavaDoc {
73         DocumentFactory factory = loadDocumentFactory();
74
75         SAXReader reader = new SAXReader( factory );
76         String JavaDoc uri = getDocumentURI();
77
78         log( "Parsing: " + uri );
79
80         document = reader.read( uri );
81     }
82
83     protected String JavaDoc getDocumentURI() {
84         return "xml/test/schema/personal-schema.xml";
85     }
86
87     // todo create an ozone version of the factory
88
protected DocumentFactory loadDocumentFactory() throws Exception JavaDoc {
89         return DatatypeDocumentFactory.getInstance();
90     }
91
92 }
93
94
95
96
97 /*
98  * Redistribution and use of this software and associated documentation
99  * ("Software"), with or without modification, are permitted provided
100  * that the following conditions are met:
101  *
102  * 1. Redistributions of source code must retain copyright
103  * statements and notices. Redistributions must also contain a
104  * copy of this document.
105  *
106  * 2. Redistributions in binary form must reproduce the
107  * above copyright notice, this list of conditions and the
108  * following disclaimer in the documentation and/or other
109  * materials provided with the distribution.
110  *
111  * 3. The name "DOM4J" must not be used to endorse or promote
112  * products derived from this Software without prior written
113  * permission of MetaStuff, Ltd. For written permission,
114  * please contact dom4j-info@metastuff.com.
115  *
116  * 4. Products derived from this Software may not be called "DOM4J"
117  * nor may "DOM4J" appear in their names without prior written
118  * permission of MetaStuff, Ltd. DOM4J is a registered
119  * trademark of MetaStuff, Ltd.
120  *
121  * 5. Due credit should be given to the DOM4J Project
122  * (http://dom4j.org/).
123  *
124  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
125  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
126  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
127  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
128  * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
129  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
130  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
131  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
132  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
133  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
134  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
135  * OF THE POSSIBILITY OF SUCH DAMAGE.
136  *
137  * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
138  *
139  * $Id: TestAutoSchema.java,v 1.1 2003/07/07 10:30:29 per_nyfelt Exp $
140  */

141
Popular Tags