1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package tests;
20
21 import junit.framework.TestCase;
22 import org.apache.ws.commons.schema.*;
23
24 import javax.xml.namespace.QName;
25 import javax.xml.transform.stream.StreamSource;
26 import java.io.FileInputStream;
27 import java.io.InputStream;
28
29
30
31
32 public class TestElementForm extends TestCase {
33 String NS = "http://unqualified-elements.example.com";
34 QName UNQUAL = new QName(NS, "unQualifiedLocals");
35 private XmlSchemaCollection schema;
36
37 protected void setUp() throws Exception {
38 InputStream is = new FileInputStream(Resources.asURI("elementForm.xsd"));
39 schema = new XmlSchemaCollection();
40 schema.read(new StreamSource(is), null);
41 }
42
43 public void testLocalElements() throws Exception {
44 XmlSchemaElement element = schema.getElementByQName(UNQUAL);
45 assertNotNull("Couldn't find unQualifiedLocals element", element);
46 XmlSchemaComplexType type = (XmlSchemaComplexType)element.getSchemaType();
47 XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle();
48 XmlSchemaObjectCollection items = seq.getItems();
49 XmlSchemaElement subElement;
50 subElement = (XmlSchemaElement)items.getItem(0);
51 QName qname = subElement.getQName();
52 assertEquals("Namespace on unqualified element", "", qname.getNamespaceURI());
53 subElement = (XmlSchemaElement)items.getItem(1);
54 qname = subElement.getQName();
55 assertEquals("Bad namespace on qualified element", NS, qname.getNamespaceURI());
56 }
57 }