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 org.apache.ws.commons.schema.*;
23 import org.apache.ws.commons.schema.constants.Constants;
24 import org.w3c.dom.Attr;
25
26 import java.io.FileInputStream;
27 import java.io.InputStream;
28 import java.util.Map;
29
30 import javax.xml.namespace.QName;
31 import javax.xml.transform.stream.StreamSource;
32
33 import junit.framework.TestCase;
34
35
36
37
38
39
40
41 public class WSCommons378Test extends TestCase {
42
43
44
45
46
47
48
49
50 public void test() throws Exception {
51 InputStream is = new FileInputStream(Resources
52 .asURI("wscommons-378.xsd"));
53 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
54 schemaCol.read(new StreamSource(is), null);
55
56 XmlSchemaSimpleType type = (XmlSchemaSimpleType) schemaCol
57 .getTypeByQName(new QName("foo"));
58 XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction) type
59 .getContent();
60 XmlSchemaObjectCollection facets = restriction.getFacets();
61
62 assertEquals(2, facets.getCount());
63
64 XmlSchemaEnumerationFacet facet1 = (XmlSchemaEnumerationFacet) facets
65 .getItem(0);
66 XmlSchemaEnumerationFacet facet2 = (XmlSchemaEnumerationFacet) facets
67 .getItem(1);
68
69 final Map externalAttributes1 = (Map) facet1.getMetaInfoMap().get(
70 Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
71 final Map externalAttributes2 = (Map) facet2.getMetaInfoMap().get(
72 Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
73
74 assertNotNull(externalAttributes1);
75 assertNotNull(externalAttributes2);
76
77 assertEquals(1, externalAttributes1.size());
78 assertEquals(1, externalAttributes2.size());
79
80 Attr attr1 = (Attr) externalAttributes1.values().iterator().next();
81 Attr attr2 = (Attr) externalAttributes2.values().iterator().next();
82
83 assertNotNull(attr1);
84 assertNotNull(attr2);
85
86 assertEquals("http://testuri.org/", attr1.getNamespaceURI());
87 assertEquals("http://testuri.org/", attr2.getNamespaceURI());
88
89 assertEquals("test", attr1.getPrefix());
90 assertEquals("test", attr2.getPrefix());
91
92 assertEquals("attr1", attr1.getLocalName());
93 assertEquals("attr2", attr2.getLocalName());
94
95 assertEquals("attr1-value", attr1.getValue());
96 assertEquals("attr2-value", attr2.getValue());
97 }
98 }