1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }