1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package tests;
21
22 import junit.framework.TestCase;
23 import org.apache.ws.commons.schema.XmlSchema;
24 import org.apache.ws.commons.schema.XmlSchemaCollection;
25 import org.w3c.dom.Document;
26
27 import javax.xml.parsers.DocumentBuilderFactory;
28 import javax.xml.namespace.QName;
29 import java.io.File;
30
31 public class ImportTest extends TestCase {
32
33 public void testSchemaImport() throws Exception{
34
35 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
36 documentBuilderFactory.setNamespaceAware(true);
37 Document doc = documentBuilderFactory.newDocumentBuilder().
38 parse(Resources.asURI("importBase.xsd"));
39
40 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
41 schemaCol.setBaseUri(Resources.TEST_RESOURCES);
42 XmlSchema schema = schemaCol.read(doc,null);
43 assertNotNull(schema);
44
45
46 schemaCol = new XmlSchemaCollection();
47 schemaCol.setBaseUri(Resources.TEST_RESOURCES + "/");
48 schema = schemaCol.read(doc,null);
49 assertNotNull(schema);
50 }
51
52
53
54
55
56 public void testSchemaImport2() throws Exception{
57 File file = new File(Resources.asURI("importBase.xsd"));
58
59 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
60 documentBuilderFactory.setNamespaceAware(true);
61 Document doc = documentBuilderFactory.newDocumentBuilder().
62 parse(file.toURL().toString());
63
64 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
65 XmlSchema schema = schemaCol.read(doc,file.toURL().toString(),null);
66 assertNotNull(schema);
67
68 }
69
70
71
72
73
74 public void testSchemaImport3() throws Exception{
75 File file = new File(Resources.asURI("importBase.xsd"));
76
77 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
78 documentBuilderFactory.setNamespaceAware(true);
79 Document doc = documentBuilderFactory.newDocumentBuilder().
80 parse(file.toURL().toString());
81
82 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
83 XmlSchema schema = schemaCol.read(doc,file.toURL().toString(),null);
84 assertNotNull(schema);
85
86 assertNotNull(schema.getTypeByName(new QName("http://soapinterop.org/xsd2","SOAPStruct")));
87 assertNotNull(schema.getElementByName(new QName("http://soapinterop.org/xsd2","SOAPWrapper")));
88 }
89 }