1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package tests;
20
21 import junit.framework.TestCase;
22 import org.apache.ws.commons.schema.*;
23 import org.w3c.dom.Node;
24 import org.w3c.dom.NodeList;
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 public class AnnotationTest extends TestCase {
35
36
37
38
39
40
41
42
43
44 public void testEmptyAppInfo() throws Exception {
45
46
47
48
49
50
51
52
53
54
55
56
57
58 QName TYPE_QNAME = new QName("http://soapinterop.org/types",
59 "emptyAppinfo");
60 InputStream is = new FileInputStream(Resources.asURI("annotation.xsd"));
61 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
62 schemaCol.read(new StreamSource(is), null);
63
64 XmlSchemaSimpleType simpleType =
65 (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
66 assertNotNull(simpleType);
67
68 XmlSchemaAnnotation xsa = simpleType.getAnnotation();
69 assertNotNull(xsa);
70
71 XmlSchemaObjectCollection col = xsa.getItems();
72 assertEquals(1, col.getCount());
73
74 Set s = new HashSet();
75 s.add(XmlSchemaDocumentation.class.getName());
76 for (int i = 0; i < col.getCount(); i++) {
77 XmlSchemaObject o = col.getItem(i);
78 if (o instanceof XmlSchemaAppInfo) {
79 fail("The appinfo element did not contain a source"
80 + " attribute or any content, so this element"
81 + " was not exptected to be found.");
82 } else if (o instanceof XmlSchemaDocumentation) {
83 assertEquals("en",
84 ((XmlSchemaDocumentation)o).getLanguage());
85 assertEquals("http://test/source/doc",
86 ((XmlSchemaDocumentation)o).getSource());
87 NodeList nl = ((XmlSchemaDocumentation)o).getMarkup();
88 for (int j = 0; j < nl.getLength(); j++) {
89 Node n = nl.item(j);
90 if (n.getNodeType() == Node.TEXT_NODE) {
91 assertEquals("testing987", n.getNodeValue());
92 }
93 }
94 }
95 assertTrue(s.remove(o.getClass().getName()));
96 }
97 assertTrue("The set should have been empty, but instead contained: "
98 + s + ".",
99 s.isEmpty());
100 }
101
102
103
104
105
106
107
108
109
110 public void testEmptyDocumentation() throws Exception {
111
112
113
114
115
116
117
118
119
120
121
122
123
124 QName TYPE_QNAME = new QName("http://soapinterop.org/types",
125 "emptyDocumentation");
126 InputStream is = new FileInputStream(Resources.asURI("annotation.xsd"));
127 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
128 schemaCol.read(new StreamSource(is), null);
129
130 XmlSchemaSimpleType simpleType =
131 (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
132 assertNotNull(simpleType);
133
134 XmlSchemaAnnotation xsa = simpleType.getAnnotation();
135 assertNotNull(xsa);
136
137 XmlSchemaObjectCollection col = xsa.getItems();
138 assertEquals(1, col.getCount());
139
140 Set s = new HashSet();
141 s.add(XmlSchemaAppInfo.class.getName());
142 for (int i = 0; i < col.getCount(); i++) {
143 XmlSchemaObject o = col.getItem(i);
144 if (o instanceof XmlSchemaAppInfo) {
145 assertEquals("http://test/source/appinfo",
146 ((XmlSchemaAppInfo)o).getSource());
147 NodeList nl = ((XmlSchemaAppInfo)o).getMarkup();
148 for (int j = 0; j < nl.getLength(); j++) {
149 Node n = nl.item(j);
150 if (n.getNodeType() == Node.TEXT_NODE) {
151 assertEquals("testing123", n.getNodeValue());
152 }
153 }
154 } else if (o instanceof XmlSchemaDocumentation) {
155 fail("The documentation element did not contain a source"
156 + " attribute or any content, so this element"
157 + " was not exptected to be found.");
158 }
159 assertTrue(s.remove(o.getClass().getName()));
160 }
161 assertTrue("The set should have been empty, but instead contained: "
162 + s + ".",
163 s.isEmpty());
164 }
165
166
167
168
169
170
171
172
173
174 public void testEmptyAppinfoDocumentation() throws Exception {
175
176
177
178
179
180
181
182
183
184
185
186
187
188 QName TYPE_QNAME = new QName("http://soapinterop.org/types",
189 "emptyAppinfoDocumentation");
190 InputStream is = new FileInputStream(Resources.asURI("annotation.xsd"));
191 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
192 schemaCol.read(new StreamSource(is), null);
193
194 XmlSchemaSimpleType simpleType =
195 (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
196 assertNotNull(simpleType);
197
198 XmlSchemaAnnotation xsa = simpleType.getAnnotation();
199 assertNotNull(xsa);
200
201 XmlSchemaObjectCollection col = xsa.getItems();
202 assertEquals(0, col.getCount());
203
204 }
205
206
207
208
209
210
211
212 public void testFullDocumentationAppinfo() throws Exception {
213
214
215
216
217
218
219
220
221
222
223
224
225
226 QName TYPE_QNAME = new QName("http://soapinterop.org/types",
227 "annotationTest");
228 InputStream is = new FileInputStream(Resources.asURI("annotation.xsd"));
229 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
230 schemaCol.read(new StreamSource(is), null);
231
232 XmlSchemaSimpleType simpleType =
233 (XmlSchemaSimpleType)schemaCol.getTypeByQName(TYPE_QNAME);
234 assertNotNull(simpleType);
235
236 XmlSchemaAnnotation xsa = simpleType.getAnnotation();
237 assertNotNull(xsa);
238
239 XmlSchemaObjectCollection col = xsa.getItems();
240 assertEquals(2, col.getCount());
241
242 Set s = new HashSet();
243 s.add(XmlSchemaAppInfo.class.getName());
244 s.add(XmlSchemaDocumentation.class.getName());
245 for (int i = 0; i < col.getCount(); i++) {
246 XmlSchemaObject o = col.getItem(i);
247 if (o instanceof XmlSchemaAppInfo) {
248 assertEquals("http://test/source/appinfo",
249 ((XmlSchemaAppInfo)o).getSource());
250 NodeList nl = ((XmlSchemaAppInfo)o).getMarkup();
251 for (int j = 0; j < nl.getLength(); j++) {
252 Node n = nl.item(j);
253 if (n.getNodeType() == Node.TEXT_NODE) {
254 assertEquals("testing123", n.getNodeValue());
255 }
256 }
257 } else if (o instanceof XmlSchemaDocumentation) {
258 assertEquals("en",
259 ((XmlSchemaDocumentation)o).getLanguage());
260 assertEquals("http://test/source/doc",
261 ((XmlSchemaDocumentation)o).getSource());
262 NodeList nl = ((XmlSchemaDocumentation)o).getMarkup();
263 for (int j = 0; j < nl.getLength(); j++) {
264 Node n = nl.item(j);
265 if (n.getNodeType() == Node.TEXT_NODE) {
266 assertEquals("testing987", n.getNodeValue());
267 }
268 }
269 }
270 assertTrue(s.remove(o.getClass().getName()));
271 }
272 assertTrue("The set should have been empty, but instead contained: "
273 + s + ".",
274 s.isEmpty());
275 }
276
277
278
279
280
281
282
283 public void testXmlSchemaElementAnnotation() throws Exception {
284
285
286
287
288
289
290
291
292 InputStream is = new FileInputStream(Resources.asURI("annotation.xsd"));
293 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
294 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
295
296 XmlSchemaAnnotation xsa = schema.getAnnotation();
297 XmlSchemaObjectCollection col = xsa.getItems();
298 assertEquals(2, col.getCount());
299
300 Set s = new HashSet();
301 s.add(XmlSchemaAppInfo.class.getName());
302 s.add(XmlSchemaDocumentation.class.getName());
303 for (int i = 0; i < col.getCount(); i++) {
304 XmlSchemaObject o = col.getItem(i);
305 if (o instanceof XmlSchemaAppInfo) {
306 assertEquals("http://test101/source/appinfo",
307 ((XmlSchemaAppInfo)o).getSource());
308 NodeList nl = ((XmlSchemaAppInfo)o).getMarkup();
309 for (int j = 0; j < nl.getLength(); j++) {
310 Node n = nl.item(j);
311 if (n.getNodeType() == Node.TEXT_NODE) {
312 assertEquals("testing101", n.getNodeValue());
313 }
314 }
315 } else if (o instanceof XmlSchemaDocumentation) {
316 assertEquals("en",
317 ((XmlSchemaDocumentation)o).getLanguage());
318 assertEquals("http://test101/source/doc",
319 ((XmlSchemaDocumentation)o).getSource());
320 NodeList nl = ((XmlSchemaDocumentation)o).getMarkup();
321 for (int j = 0; j < nl.getLength(); j++) {
322 Node n = nl.item(j);
323 if (n.getNodeType() == Node.TEXT_NODE) {
324 assertEquals("testing101", n.getNodeValue());
325 }
326 }
327 }
328 assertTrue(s.remove(o.getClass().getName()));
329 }
330 assertTrue("The set should have been empty, but instead contained: "
331 + s + ".",
332 s.isEmpty());
333
334 }
335
336 }