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
15
16
17
18
19
20
21
22
23
24
25
26
27
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 }