View Javadoc

1   package tests;
2   
3   import junit.framework.TestCase;
4   
5   import javax.xml.namespace.QName;
6   import javax.xml.transform.stream.StreamSource;
7   import java.io.InputStream;
8   import java.io.FileInputStream;
9   import java.util.Iterator;
10  
11  import org.apache.ws.commons.schema.*;
12  
13  /*
14  * Copyright 2004,2007 The Apache Software Foundation.
15  * Copyright 2006 International Business Machines Corp.
16  *
17  * Licensed under the Apache License, Version 2.0 (the "License");
18  * you may not use this file except in compliance with the License.
19  * You may obtain a copy of the License at
20  *
21  *      http://www.apache.org/licenses/LICENSE-2.0
22  *
23  * Unless required by applicable law or agreed to in writing, software
24  * distributed under the License is distributed on an "AS IS" BASIS,
25  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26  * See the License for the specific language governing permissions and
27  * limitations under the License.
28  *
29  */
30  public class AttributeRefTest extends TestCase {
31  
32      public void testAttRefsWithNS() throws Exception{
33          QName TYPE_QNAME = new QName("http://tempuri.org/attribute",
34                                          "TestAttributeReferenceType");
35  
36  
37          InputStream is = new FileInputStream(Resources.asURI("attributref.xsd"));
38          XmlSchemaCollection schema = new XmlSchemaCollection();
39          XmlSchema s = schema.read(new StreamSource(is), null);
40  
41          XmlSchemaComplexType typeByName = (XmlSchemaComplexType)s.getTypeByName(TYPE_QNAME);
42          assertNotNull(typeByName);
43  
44          XmlSchemaAttribute item = (XmlSchemaAttribute)typeByName.getAttributes().getItem(0);
45          QName qName = item.getRefName();
46          assertNotNull(qName);
47  
48          String namspace = qName.getNamespaceURI();
49          assertEquals("http://tempuri.org/attribute",namspace);
50  
51          for (Iterator toplevelAttributes = s.getAttributes().getValues();toplevelAttributes.hasNext();){
52              XmlSchemaAttribute attribute = (XmlSchemaAttribute) toplevelAttributes.next();
53              assertEquals("http://tempuri.org/attribute",attribute.getQName().getNamespaceURI());
54          }
55  
56  
57      }
58  
59  
60  }