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