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 java.io.FileInputStream;
23 import java.io.InputStream;
24
25 import javax.xml.namespace.QName;
26 import javax.xml.transform.stream.StreamSource;
27
28 import junit.framework.TestCase;
29
30 import org.apache.ws.commons.schema.XmlSchemaCollection;
31 import org.apache.ws.commons.schema.XmlSchemaComplexType;
32 import org.apache.ws.commons.schema.XmlSchemaElement;
33 import org.apache.ws.commons.schema.XmlSchemaSequence;
34
35 /*
36 * Copyright 2004,2007 The Apache Software Foundation.
37 * Copyright 2006 International Business Machines Corp.
38 *
39 * Licensed under the Apache License, Version 2.0 (the "License");
40 * you may not use this file except in compliance with the License.
41 * You may obtain a copy of the License at
42 *
43 * http://www.apache.org/licenses/LICENSE-2.0
44 *
45 * Unless required by applicable law or agreed to in writing, software
46 * distributed under the License is distributed on an "AS IS" BASIS,
47 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
48 * See the License for the specific language governing permissions and
49 * limitations under the License.
50 *
51 */
52 public class SequenceTest extends TestCase {
53
54 /**
55 * This method will test the sequence - the min and max occurences.
56 *
57 * @throws Exception Any exception encountered
58 */
59 public void testChoice() throws Exception {
60
61 /*
62 <schema xmlns="http://www.w3.org/2001/XMLSchema"
63 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
64 xmlns:tns="http://soapinterop.org/types"
65 targetNamespace="http://soapinterop.org/types">
66
67 <element name="computer">
68 <complexType>
69 <sequence minOccurs="4" maxOccurs="50">
70 <element name="desktop" type="string"/>
71 <element name="laptop" type="string"/>
72 </sequence>
73 </complexType>
74 </element>
75
76 </schema>
77 */
78
79 QName computerElementQname = new QName("http://soapinterop.org/types",
80 "computer");
81
82
83 InputStream is = new FileInputStream(Resources.asURI("sequence.xsd"));
84 XmlSchemaCollection schemaCol = new XmlSchemaCollection();
85 schemaCol.read(new StreamSource(is), null);
86
87 QName WRONG_QNAME = new QName("http://soapinterop.org/types",
88 "machine");
89 XmlSchemaElement elem = schemaCol.getElementByQName(WRONG_QNAME);
90 assertNull(elem);
91 elem = schemaCol.getElementByQName(computerElementQname);
92 assertEquals("computer", elem.getName());
93 assertEquals(new QName("http://soapinterop.org/types", "computer"),
94 elem.getQName());
95
96 XmlSchemaComplexType cType = (XmlSchemaComplexType)elem.getSchemaType();
97 assertNotNull(cType);
98
99 XmlSchemaSequence sequence = (XmlSchemaSequence)cType.getParticle();
100 assertNotNull(sequence);
101
102 //values from the XML file
103 assertEquals(sequence.getMinOccurs(),4);
104 assertEquals(sequence.getMaxOccurs(),50);
105
106 }
107
108 }