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.*;
20  
21  import javax.xml.namespace.QName;
22  import javax.xml.transform.stream.StreamSource;
23  import java.io.FileInputStream;
24  import java.io.InputStream;
25  
26  /**
27   * TestElementForm
28   */
29  public class TestElementForm extends TestCase {
30      String NS = "http://unqualified-elements.example.com";
31      QName UNQUAL = new QName(NS, "unQualifiedLocals");
32      private XmlSchemaCollection schema;
33  
34      protected void setUp() throws Exception {
35          InputStream is = new FileInputStream(Resources.asURI("elementForm.xsd"));
36          schema = new XmlSchemaCollection();
37          schema.read(new StreamSource(is), null);
38      }
39  
40      public void testLocalElements() throws Exception {
41          XmlSchemaElement element = schema.getElementByQName(UNQUAL);
42          assertNotNull("Couldn't find unQualifiedLocals element", element);
43          XmlSchemaComplexType type = (XmlSchemaComplexType)element.getSchemaType();
44          XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle();
45          XmlSchemaObjectCollection items = seq.getItems();
46          XmlSchemaElement subElement;
47          subElement = (XmlSchemaElement)items.getItem(0);
48          QName qname = subElement.getQName();
49          assertEquals("Namespace on unqualified element", "", qname.getNamespaceURI());
50          subElement = (XmlSchemaElement)items.getItem(1);
51          qname = subElement.getQName();
52          assertEquals("Bad namespace on qualified element", NS, qname.getNamespaceURI());
53      }
54  }