View Javadoc

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