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.XmlSchemaCollection;
23 import org.apache.ws.commons.schema.XmlSchemaElement;
24 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
25 import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
26 import org.apache.ws.commons.schema.XmlSchemaType;
27
28 import javax.xml.namespace.QName;
29 import javax.xml.transform.stream.StreamSource;
30 import java.io.FileInputStream;
31 import java.io.InputStream;
32
33 public class TestSimpleRestriction extends TestCase {
34 public void testSimpleRestriction() throws Exception {
35 QName TYPE_QNAME = new QName("http://soapinterop.org/types",
36 "layoutComponentType");
37 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
38 "foo");
39
40 InputStream is = new FileInputStream(Resources.asURI("SimpleContentRestriction.xsd"));
41 XmlSchemaCollection schema = new XmlSchemaCollection();
42 schema.read(new StreamSource(is), null);
43
44 XmlSchemaType simpleType = schema.getTypeByQName(TYPE_QNAME);
45 assertNotNull(simpleType);
46
47 XmlSchemaElement elem = schema.getElementByQName(ELEMENT_QNAME);
48 assertNotNull(elem);
49
50 XmlSchemaType type = elem.getSchemaType();
51 assertNotNull(type);
52 }
53
54 public void testSimpleTypeRestrictionWithoutNamespace() throws Exception {
55 InputStream is = new FileInputStream(Resources.asURI("includedWithoutNamespace.xsd"));
56 XmlSchemaCollection schema = new XmlSchemaCollection();
57 schema.read(new StreamSource(is), null);
58 XmlSchemaType principalId = schema.getTypeByQName(new QName("", "XdwsPrincipalId"));
59 assertNotNull(principalId);
60 XmlSchemaSimpleType groupId = (XmlSchemaSimpleType)schema.getTypeByQName(new QName("", "XdwsGroupId"));
61 assertNotNull(groupId);
62 QName baseName = ((XmlSchemaSimpleTypeRestriction)groupId.getContent()).getBaseTypeName();
63
64 assertEquals(principalId.getQName(), baseName);
65 }
66 }