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