1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package tests;
21
22 import junit.framework.TestCase;
23 import org.apache.ws.commons.schema.*;
24
25 import javax.xml.namespace.QName;
26 import javax.xml.transform.stream.StreamSource;
27 import java.io.FileInputStream;
28 import java.io.InputStream;
29 import java.util.HashSet;
30 import java.util.Set;
31
32 /*
33 * Copyright 2004,2007 The Apache Software Foundation.
34 * Copyright 2006 International Business Machines Corp.
35 *
36 * Licensed under the Apache License, Version 2.0 (the "License");
37 * you may not use this file except in compliance with the License.
38 * You may obtain a copy of the License at
39 *
40 * http://www.apache.org/licenses/LICENSE-2.0
41 *
42 * Unless required by applicable law or agreed to in writing, software
43 * distributed under the License is distributed on an "AS IS" BASIS,
44 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45 * See the License for the specific language governing permissions and
46 * limitations under the License.
47 *
48 */
49 public class UnionTest extends TestCase {
50
51 /**
52 * This method will test the union.
53 *
54 * @throws Exception Any exception encountered
55 */
56 public void testUnion() throws Exception {
57
58 /*
59 <schema xmlns="http://www.w3.org/2001/XMLSchema"
60 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
61 xmlns:tns="http://soapinterop.org/types"
62 targetNamespace="http://soapinterop.org/types">
63
64 <element name="unionTest">
65 <simpleType>
66 <union memberTypes="float decimal"/>
67 </simpleType>
68 </element>
69
70 </schema>
71 */
72
73 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
74 "unionTest");
75 InputStream is = new FileInputStream(Resources.asURI("union.xsd"));
76 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
77 schemaCol.read(new StreamSource(is), null);
78
79
80 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
81 assertNotNull(elem);
82 assertEquals("unionTest", elem.getName());
83 assertEquals(new QName("http://soapinterop.org/types", "unionTest"),
84 elem.getQName());
85
86 XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
87 assertNotNull(simpleType);
88
89 XmlSchemaSimpleTypeUnion xsstu =
90 (XmlSchemaSimpleTypeUnion)simpleType.getContent();
91 assertNotNull(xsstu);
92
93 QName[] qname = xsstu.getMemberTypesQNames();
94 Set s = new HashSet();
95 s.add(new QName("http://www.w3.org/2001/XMLSchema", "float"));
96 s.add(new QName("http://www.w3.org/2001/XMLSchema", "decimal"));
97 for (int i = 0; i < qname.length; i++) {
98 assertTrue(s.remove(qname[i]));
99 }
100 assertTrue("The set should have been empty, but instead contained: "
101 + s + ".",
102 s.isEmpty());
103
104 assertEquals("float decimal", xsstu.getMemberTypesSource());
105
106 }
107
108 }