1   /*
2    * Copyright 2004,2007 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }