1 package tests;
2
3 import junit.framework.TestCase;
4 import org.apache.ws.commons.schema.XmlSchema;
5 import org.apache.ws.commons.schema.XmlSchemaCollection;
6 import org.w3c.dom.Document;
7
8 import javax.xml.parsers.DocumentBuilderFactory;
9 import java.io.File;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class ImportTest extends TestCase {
27
28 public void testSchemaImport() throws Exception{
29
30 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
31 documentBuilderFactory.setNamespaceAware(true);
32 Document doc = documentBuilderFactory.newDocumentBuilder().
33 parse(Resources.asURI("importBase.xsd"));
34
35 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
36 schemaCol.setBaseUri(Resources.TEST_RESOURCES);
37 XmlSchema schema = schemaCol.read(doc,null);
38 assertNotNull(schema);
39
40
41 schemaCol = new XmlSchemaCollection();
42 schemaCol.setBaseUri(Resources.TEST_RESOURCES + "/");
43 schema = schemaCol.read(doc,null);
44 assertNotNull(schema);
45 }
46
47
48
49
50
51 public void testSchemaImport2() throws Exception{
52 File file = new File(Resources.asURI("importBase.xsd"));
53
54 DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
55 documentBuilderFactory.setNamespaceAware(true);
56 Document doc = documentBuilderFactory.newDocumentBuilder().
57 parse(file.toURL().toString());
58
59 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
60 XmlSchema schema = schemaCol.read(doc,file.toURL().toString(),null);
61 assertNotNull(schema);
62
63 }
64 }