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
30 /*
31 * Copyright 2004,2007 The Apache Software Foundation.
32 * Copyright 2006 International Business Machines Corp.
33 *
34 * Licensed under the Apache License, Version 2.0 (the "License");
35 * you may not use this file except in compliance with the License.
36 * You may obtain a copy of the License at
37 *
38 * http://www.apache.org/licenses/LICENSE-2.0
39 *
40 * Unless required by applicable law or agreed to in writing, software
41 * distributed under the License is distributed on an "AS IS" BASIS,
42 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43 * See the License for the specific language governing permissions and
44 * limitations under the License.
45 *
46 */
47 public class ListTest extends TestCase {
48
49 /**
50 * This method will test the list.
51 *
52 * @throws Exception Any exception encountered
53 */
54 public void testList() throws Exception {
55
56 /*
57 <schema xmlns="http://www.w3.org/2001/XMLSchema"
58 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
59 xmlns:tns="http://soapinterop.org/types"
60 targetNamespace="http://soapinterop.org/types">
61
62 <element name="workDays">
63 <simpleType>
64 <restriction base="tns:daysInWeek">
65 <length value="5"/>
66 </restriction>
67 </simpleType>
68 </element>
69
70 <simpleType name="daysInWeek">
71 <list itemType="xsd:integer"/>
72 </simpleType>
73
74 </schema>
75 */
76
77 QName ELEMENT_QNAME = new QName("http://soapinterop.org/types",
78 "workDays");
79 InputStream is = new FileInputStream(Resources.asURI("list.xsd"));
80 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
81 schemaCol.read(new StreamSource(is), null);
82
83 XmlSchemaElement elem = schemaCol.getElementByQName(ELEMENT_QNAME);
84 assertNotNull(elem);
85 assertEquals("workDays", elem.getName());
86 assertEquals(new QName("http://soapinterop.org/types", "workDays"),
87 elem.getQName());
88
89 XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)elem.getSchemaType();
90 assertNotNull(simpleType);
91
92 XmlSchemaSimpleTypeRestriction r =
93 (XmlSchemaSimpleTypeRestriction)simpleType.getContent();
94 assertNotNull(r);
95
96 QName baseTypeName = r.getBaseTypeName();
97 assertEquals(new QName("http://soapinterop.org/types", "daysInWeek"),
98 baseTypeName);
99 XmlSchemaType type = schemaCol.getTypeByQName(baseTypeName);
100
101 XmlSchemaSimpleTypeContent content = ((XmlSchemaSimpleType)type).getContent();
102 assertEquals(new QName("http://www.w3.org/2001/XMLSchema", "integer"),
103 ((XmlSchemaSimpleTypeList)content).getItemTypeName());
104
105 }
106
107 }