1 package tests;
2
3 import junit.framework.TestCase;
4 import org.apache.ws.commons.schema.*;
5 import org.xml.sax.InputSource;
6
7 import javax.xml.namespace.QName;
8 import javax.xml.transform.stream.StreamSource;
9 import java.io.FileInputStream;
10 import java.io.InputStream;
11 import java.util.HashSet;
12 import java.util.Set;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public class IncludeTest extends TestCase {
32
33
34
35
36
37
38 public void testInclude() throws Exception {
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
73 "test1include");
74 InputStream is = new FileInputStream(Resources.asURI("include.xsd"));
75 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
76 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
77
78 XmlSchemaObjectCollection c = schema.getIncludes();
79 assertEquals(2, c.getCount());
80
81 Set set = new HashSet();
82 set.add(Resources.asURI("include2.xsd"));
83 set.add(Resources.asURI("include3.xsd"));
84 for (int i = 0; i < c.getCount(); i++) {
85 XmlSchemaInclude include = (XmlSchemaInclude)c.getItem(i);
86 assertNotNull(include);
87 XmlSchema s = include.getSchema();
88 assertNotNull(s);
89 String schemaLocation = include.getSchemaLocation();
90 if (schemaLocation.equals(Resources.asURI("include2.xsd"))) {
91 XmlSchemaElement xse =
92 s.getElementByName(new
93 QName("http://soapinterop.org/types", "test1include"));
94 assertEquals("test1include", xse.getName());
95 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
96 xse.getSchemaTypeName());
97 } else if (schemaLocation.equals(Resources.asURI("include3.xsd"))) {
98 XmlSchemaElement xse =
99 s.getElementByName(new
100 QName("http://soapinterop.org/types", "test2include"));
101 assertEquals("test2include", xse.getName());
102 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
103 xse.getSchemaTypeName());
104 } else {
105 fail("The schemaLocation of \"" + schemaLocation + "\" was"
106 + " not expected.");
107 }
108 set.remove(schemaLocation);
109 }
110
111 assertTrue("The set should have been empty, but instead contained: "
112 + set + ".",
113 set.isEmpty());
114
115 }
116
117
118
119
120
121 public void testImportSchemaWithoutNamespace() throws Exception {
122 InputStream is = new FileInputStream(Resources.asURI("includingWithNamespace.xsd"));
123 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
124 schemaCol.read(new StreamSource(is), null);
125
126 assertNotNull(schemaCol.getTypeByQName(new QName("http://tns.demo.org", "XdwsGroupId")));
127 }
128
129
130
131
132
133 public void testSchemaInclude() throws Exception{
134 String uri = Resources.asURI("WSCOMMONS-87/includeBase.xsd");
135 InputSource isource = new InputSource(new FileInputStream(uri));
136 isource.setSystemId(uri);
137 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
138 XmlSchema schema = schemaCol.read(isource, null);
139 assertNotNull(schema);
140 }
141
142
143
144
145
146 public void testSchemaIncludeNoDefaultNS() throws Exception{
147 String uri = Resources.asURI("WSCOMMONS-87/includeBaseNoDefaultNS.xsd");
148 InputSource isource = new InputSource(new FileInputStream(uri));
149 isource.setSystemId(uri);
150 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
151 XmlSchema schema = schemaCol.read(isource, null);
152 assertNotNull(schema);
153 }
154 }