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
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public class ComplexContentRestrictionTest extends TestCase {
50
51
52
53
54
55
56 public void testComplexContentRestriction() throws Exception {
57
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 QName TYPE_QNAME = new QName("http://soapinterop.org/types",
89 "NoAssemblyRequiredProduct");
90 InputStream is = new FileInputStream(Resources.asURI("deriverestriction.xsd"));
91 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
92 schemaCol.read(new StreamSource(is), null);
93
94 XmlSchemaComplexType cType =
95 (XmlSchemaComplexType)schemaCol.getTypeByQName(TYPE_QNAME);
96 assertNotNull(cType);
97
98 XmlSchemaContentModel xscm = cType.getContentModel();
99 assertNotNull(xscm);
100
101 XmlSchemaComplexContentRestriction xsccr =
102 (XmlSchemaComplexContentRestriction)xscm.getContent();
103 assertEquals(new QName("http://soapinterop.org/types",
104 "AssemblyRequiredProduct"),
105 xsccr.getBaseTypeName());
106
107 XmlSchemaSequence xsp = (XmlSchemaSequence)xsccr.getParticle();
108 assertNotNull(xsp);
109
110 XmlSchemaObjectCollection col = xsp.getItems();
111
112 Set s = new HashSet();
113 s.add("Name");
114 s.add("Description");
115 s.add("Parts");
116 for (int i = 0; i < col.getCount(); i++) {
117 XmlSchemaElement xse = (XmlSchemaElement)col.getItem(i);
118 String name = xse.getName();
119 if (name.equals("Name")) {
120 assertEquals(new QName("", "Name"),
121 xse.getQName());
122 assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
123 "string"),
124 xse.getSchemaTypeName());
125 assertTrue(!xse.isAbstract());
126 assertTrue(!xse.isNillable());
127 } else if (name.equals("Description")) {
128 assertEquals(new QName("", "Description"),
129 xse.getQName());
130 assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
131 "string"),
132 xse.getSchemaTypeName());
133 assertTrue(!xse.isAbstract());
134 assertTrue(xse.isNillable());
135 } else if (name.equals("Parts")) {
136 assertEquals(new QName("", "Parts"),
137 xse.getQName());
138 assertEquals(new QName("http://www.w3.org/2001/XMLSchema",
139 "string"),
140 xse.getSchemaTypeName());
141 } else {
142 fail("An invalid name of \"" + name + "\" was found.");
143 }
144 s.remove(name);
145 }
146
147 assertTrue("The set should have been empty, but instead contained: "
148 + s + ".",
149 s.isEmpty());
150
151 }
152
153 }