1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package tests;
17
18 import junit.framework.TestCase;
19 import org.apache.ws.commons.schema.XmlSchema;
20 import org.apache.ws.commons.schema.XmlSchemaCollection;
21 import org.apache.ws.commons.schema.XmlSchemaElement;
22 import org.apache.ws.commons.schema.XmlSchemaType;
23
24 import javax.xml.namespace.QName;
25 import javax.xml.transform.stream.StreamSource;
26 import java.io.FileInputStream;
27 import java.io.InputStream;
28
29 public class TestSimpleRestriction extends TestCase {
30 public void testSimpleRestriction() throws Exception {
31 QName TYPE_QNAME = new QName("http://soapinterop.org/types",
32 "layoutComponentType");
33 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
34 "foo");
35
36 InputStream is = new FileInputStream(Resources.asURI("SimpleContentRestriction.xsd"));
37 XmlSchemaCollection schema = new XmlSchemaCollection();
38 XmlSchema s = schema.read(new StreamSource(is), null);
39
40 XmlSchemaType simpleType = schema.getTypeByQName(TYPE_QNAME);
41 assertNotNull(simpleType);
42
43 XmlSchemaElement elem = schema.getElementByQName(ELEMENT_QNAME);
44 assertNotNull(elem);
45
46 XmlSchemaType type = elem.getSchemaType();
47 assertNotNull(type);
48 }
49
50 public void testSimpleTypeRestrictionWithoutNamespace() throws Exception {
51 InputStream is = new FileInputStream(Resources.asURI("includedWithoutNamespace.xsd"));
52 XmlSchemaCollection schema = new XmlSchemaCollection();
53 XmlSchema s = schema.read(new StreamSource(is), null);
54 XmlSchemaType principalId = schema.getTypeByQName(new QName("", "XdwsPrincipalId"));
55 assertNotNull(principalId);
56 XmlSchemaType groupId = schema.getTypeByQName(new QName("", "XdwsGroupId"));
57 assertNotNull(groupId);
58 assertEquals(groupId.getBaseSchemaType(), principalId);
59 }
60 }