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