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.*;
24 import org.xml.sax.InputSource;
25
26 import javax.xml.namespace.QName;
27 import javax.xml.transform.stream.StreamSource;
28 import java.io.FileInputStream;
29 import java.io.InputStream;
30 import java.util.HashSet;
31 import java.util.Set;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class IncludeTest extends TestCase {
51
52
53
54
55
56
57 public void testInclude() throws Exception {
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91 InputStream is = new FileInputStream(Resources.asURI("include.xsd"));
92 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
93 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
94
95 XmlSchemaObjectCollection c = schema.getIncludes();
96 assertEquals(2, c.getCount());
97
98 Set set = new HashSet();
99 set.add(Resources.asURI("include2.xsd"));
100 set.add(Resources.asURI("include3.xsd"));
101 for (int i = 0; i < c.getCount(); i++) {
102 XmlSchemaInclude include = (XmlSchemaInclude)c.getItem(i);
103 assertNotNull(include);
104 XmlSchema s = include.getSchema();
105 assertNotNull(s);
106 String schemaLocation = include.getSchemaLocation();
107 if (schemaLocation.equals(Resources.asURI("include2.xsd"))) {
108 XmlSchemaElement xse =
109 s.getElementByName(new
110 QName("http://soapinterop.org/types", "test1include"));
111 assertEquals("test1include", xse.getName());
112 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
113 xse.getSchemaTypeName());
114 } else if (schemaLocation.equals(Resources.asURI("include3.xsd"))) {
115 XmlSchemaElement xse =
116 s.getElementByName(new
117 QName("http://soapinterop.org/types", "test2include"));
118 assertEquals("test2include", xse.getName());
119 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
120 xse.getSchemaTypeName());
121 } else {
122 fail("The schemaLocation of \"" + schemaLocation + "\" was"
123 + " not expected.");
124 }
125 set.remove(schemaLocation);
126 }
127
128 assertTrue("The set should have been empty, but instead contained: "
129 + set + ".",
130 set.isEmpty());
131
132 }
133
134
135
136
137
138 public void testImportSchemaWithoutNamespace() throws Exception {
139 InputStream is = new FileInputStream(Resources.asURI("includingWithNamespace.xsd"));
140 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
141 schemaCol.read(new StreamSource(is), null);
142
143 assertNotNull(schemaCol.getTypeByQName(new QName("http://tns.demo.org", "XdwsGroupId")));
144 }
145
146
147
148
149
150
151 public void testIncludeSchemaWithoutNamespace() throws Exception {
152 String uri = Resources.asURI("woden.xsd");
153 InputSource is = new InputSource(new FileInputStream(uri));
154 is.setSystemId(uri);
155 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
156 XmlSchema schema = schemaCol.read(is, null);
157
158 XmlSchemaObjectCollection c = schema.getIncludes();
159 assertEquals(1, c.getCount());
160
161 XmlSchemaInclude schemaInclude = (XmlSchemaInclude)c.getItem(0);
162 assertNotNull(schemaInclude);
163
164 XmlSchema schema2 = schemaInclude.getSchema();
165 assertNull(schema2.getTargetNamespace());
166 }
167
168
169
170
171
172 public void testSchemaInclude() throws Exception{
173 String uri = Resources.asURI("WSCOMMONS-87/includeBase.xsd");
174 InputSource isource = new InputSource(new FileInputStream(uri));
175 isource.setSystemId(uri);
176 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
177 XmlSchema schema = schemaCol.read(isource, null);
178 assertNotNull(schema);
179 }
180
181
182
183
184
185 public void testSchemaIncludeNoDefaultNS() throws Exception{
186 String uri = Resources.asURI("WSCOMMONS-87/includeBaseNoDefaultNS.xsd");
187 InputSource isource = new InputSource(new FileInputStream(uri));
188 isource.setSystemId(uri);
189 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
190 XmlSchema schema = schemaCol.read(isource, null);
191 assertNotNull(schema);
192 }
193 }