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.Element;
24 import org.w3c.dom.Node;
25 import org.w3c.dom.NodeList;
26
27 import javax.xml.transform.stream.StreamSource;
28 import java.io.FileInputStream;
29 import java.io.InputStream;
30
31 public class AnnotationDeepTest extends TestCase {
32
33
34
35
36
37
38
39 public void testAppInfoNoSource() throws Exception {
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 InputStream is = new FileInputStream(Resources.asURI("annotation-appinfo-no-source.xsd"));
66 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
67 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
68
69 XmlSchemaAnnotation annotation = schema.getAnnotation();
70 assertTrue("annotation is retrieved ok", null != annotation);
71 XmlSchemaObjectCollection items = annotation.getItems();
72 assertEquals("Annotation contains an appinfo and yet this fails", 1, items.getCount());
73
74 }
75
76
77
78
79
80
81
82 public void testAppInfoDeep() throws Exception {
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 InputStream is = new FileInputStream(Resources.asURI("annotation-appinfo-deep.xsd"));
109 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
110 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
111
112 XmlSchemaAnnotation annotation = schema.getAnnotation();
113 assertTrue("annotation is retrieved ok", null != annotation);
114 XmlSchemaObjectCollection items = annotation.getItems();
115 assertTrue(items.getItem(0) instanceof XmlSchemaAppInfo);
116 XmlSchemaAppInfo appInfo = (XmlSchemaAppInfo) items.getItem(0);
117 NodeList markup = appInfo.getMarkup();
118 assertTrue("The markup exists", null != markup);
119 Node node = markup.item(1);
120 assertTrue(node instanceof Element);
121 Element el = (Element) node;
122 assertEquals("First level child is retrieved ok",
123 "http://java.sun.com/xml/ns/jaxb", node.getNamespaceURI());
124 assertEquals("First level child is retrieved ok",
125 "schemaBindings", node.getLocalName());
126 assertTrue("schemaBindings should have a child", el.getChildNodes().getLength() > 0);
127 NodeList l = el.getElementsByTagNameNS("http://java.sun.com/xml/ns/jaxb", "package");
128 assertTrue("ok this is actually working",l.getLength() > 0);
129
130 }
131 }