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 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
92 "test1include");
93 InputStream is = new FileInputStream(Resources.asURI("include.xsd"));
94 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
95 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
96
97 XmlSchemaObjectCollection c = schema.getIncludes();
98 assertEquals(2, c.getCount());
99
100 Set set = new HashSet();
101 set.add(Resources.asURI("include2.xsd"));
102 set.add(Resources.asURI("include3.xsd"));
103 for (int i = 0; i < c.getCount(); i++) {
104 XmlSchemaInclude include = (XmlSchemaInclude)c.getItem(i);
105 assertNotNull(include);
106 XmlSchema s = include.getSchema();
107 assertNotNull(s);
108 String schemaLocation = include.getSchemaLocation();
109 if (schemaLocation.equals(Resources.asURI("include2.xsd"))) {
110 XmlSchemaElement xse =
111 s.getElementByName(new
112 QName("http://soapinterop.org/types", "test1include"));
113 assertEquals("test1include", xse.getName());
114 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "string"),
115 xse.getSchemaTypeName());
116 } else if (schemaLocation.equals(Resources.asURI("include3.xsd"))) {
117 XmlSchemaElement xse =
118 s.getElementByName(new
119 QName("http://soapinterop.org/types", "test2include"));
120 assertEquals("test2include", xse.getName());
121 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
122 xse.getSchemaTypeName());
123 } else {
124 fail("The schemaLocation of \"" + schemaLocation + "\" was"
125 + " not expected.");
126 }
127 set.remove(schemaLocation);
128 }
129
130 assertTrue("The set should have been empty, but instead contained: "
131 + set + ".",
132 set.isEmpty());
133
134 }
135
136
137
138
139
140 public void testImportSchemaWithoutNamespace() throws Exception {
141 InputStream is = new FileInputStream(Resources.asURI("includingWithNamespace.xsd"));
142 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
143 schemaCol.read(new StreamSource(is), null);
144
145 assertNotNull(schemaCol.getTypeByQName(new QName("http://tns.demo.org", "XdwsGroupId")));
146 }
147
148
149
150
151
152 public void testSchemaInclude() throws Exception{
153 String uri = Resources.asURI("WSCOMMONS-87/includeBase.xsd");
154 InputSource isource = new InputSource(new FileInputStream(uri));
155 isource.setSystemId(uri);
156 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
157 XmlSchema schema = schemaCol.read(isource, null);
158 assertNotNull(schema);
159 }
160
161
162
163
164
165 public void testSchemaIncludeNoDefaultNS() throws Exception{
166 String uri = Resources.asURI("WSCOMMONS-87/includeBaseNoDefaultNS.xsd");
167 InputSource isource = new InputSource(new FileInputStream(uri));
168 isource.setSystemId(uri);
169 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
170 XmlSchema schema = schemaCol.read(isource, null);
171 assertNotNull(schema);
172 }
173 }