1 package tests;
2
3 import junit.framework.TestCase;
4 import org.apache.ws.commons.schema.*;
5
6 import javax.xml.namespace.QName;
7 import javax.xml.transform.stream.StreamSource;
8 import java.io.FileInputStream;
9 import java.io.InputStream;
10 import java.util.HashSet;
11 import java.util.Set;
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class AnyTest extends TestCase {
31
32
33
34
35
36
37 public void testAny() throws Exception {
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
60 "department");
61 InputStream is = new FileInputStream(Resources.asURI("any.xsd"));
62 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
63 XmlSchema schema = schemaCol.read(new StreamSource(is), null);
64
65 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
66 assertNotNull(elem);
67 assertEquals("department", elem.getName());
68 assertEquals(new QName("http://soapinterop.org/types", "department"),
69 elem.getQName());
70
71 XmlSchemaComplexType type =
72 (XmlSchemaComplexType)elem.getSchemaType();
73 assertNotNull(type);
74
75 XmlSchemaSequence xss = (XmlSchemaSequence)type.getParticle();
76 assertNotNull(xss);
77
78 XmlSchemaObjectCollection c = xss.getItems();
79 assertEquals(3, c.getCount());
80
81 Set s = new HashSet();
82 s.add("id");
83 s.add("name");
84 Object o = null;
85 for (int i = 0; i < c.getCount(); i++) {
86 o = c.getItem(i);
87 if (o instanceof XmlSchemaElement) {
88 String name = ((XmlSchemaElement)o).getName();
89 if (name.equals("id")) {
90 assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
91 "integer"),
92 ((XmlSchemaElement)o).getSchemaTypeName());
93 } else if (name.equals("name")) {
94 assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
95 "string"),
96 ((XmlSchemaElement)o).getSchemaTypeName());
97 }
98 s.remove(name);
99 } else if (o instanceof XmlSchemaAny) {
100 XmlSchemaContentProcessing xscp =
101 ((XmlSchemaAny)o).getProcessContent();
102 assertEquals("none", xscp.toString());
103 assertEquals(5L, ((XmlSchemaAny)o).getMinOccurs());
104 assertEquals(10L, ((XmlSchemaAny)o).getMaxOccurs());
105 }
106 }
107
108 assertTrue("The set should have been empty, but instead contained: "
109 + s + ".",
110 s.isEmpty());
111
112 }
113
114 }