001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.schema.testsuite;
020:
021: import org.apache.axiom.om.OMElement;
022: import org.apache.axiom.om.OMAbstractFactory;
023: import org.apache.axiom.om.OMFactory;
024: import org.apache.axiom.om.util.StAXUtils;
025: import services.echo.types.*;
026:
027: import javax.xml.stream.XMLStreamReader;
028: import java.io.ByteArrayInputStream;
029:
030: public class XsdAnyElementsTest extends AbstractTest {
031:
032: public static final int MIN_EQUALS_ZERO_NILLABLE_TRUE_TEST = 1;
033: public static final int MIN_EQUALS_ZERO_NILLABLE_FALSE_TEST = 2;
034: public static final int MIN_EQUALS_ONE_NILLABLE_TRUE_TEST = 3;
035: public static final int MIN_EQUALS_ONE_NILLABLE_FALSE_TEST = 4;
036:
037: public void testAnyTypeArray() {
038: OMElement[] returnObject;
039: System.out.println("minOccurs = 0 and nillable true");
040: try {
041: returnObject = testAnyTypeArray(null,
042: MIN_EQUALS_ZERO_NILLABLE_TRUE_TEST);
043: assertTrue(assertArrayEqual(returnObject,
044: new OMElement[] { null }));
045: returnObject = testAnyTypeArray(new OMElement[] { null },
046: MIN_EQUALS_ZERO_NILLABLE_TRUE_TEST);
047: assertTrue(assertArrayEqual(returnObject,
048: new OMElement[] { null }));
049: returnObject = testAnyTypeArray(
050: new OMElement[] { getOMElement() },
051: MIN_EQUALS_ZERO_NILLABLE_TRUE_TEST);
052: assertTrue(assertArrayEqual(returnObject,
053: new OMElement[] { getOMElement() }));
054: returnObject = testAnyTypeArray(new OMElement[] {
055: getOMElement(), null },
056: MIN_EQUALS_ZERO_NILLABLE_TRUE_TEST);
057: assertTrue(assertArrayEqual(returnObject, new OMElement[] {
058: getOMElement(), null }));
059: } catch (Exception e) {
060: e.printStackTrace();
061: fail();
062: }
063:
064: System.out.println("minOccurs = 0 and nillable false");
065: try {
066: returnObject = testAnyTypeArray(null,
067: MIN_EQUALS_ZERO_NILLABLE_FALSE_TEST);
068: assertTrue(assertArrayEqual(returnObject, null));
069: returnObject = testAnyTypeArray(new OMElement[] { null },
070: MIN_EQUALS_ZERO_NILLABLE_FALSE_TEST);
071: assertTrue(assertArrayEqual(returnObject, null));
072: returnObject = testAnyTypeArray(
073: new OMElement[] { getOMElement() },
074: MIN_EQUALS_ZERO_NILLABLE_FALSE_TEST);
075: assertTrue(assertArrayEqual(returnObject,
076: new OMElement[] { getOMElement() }));
077: returnObject = testAnyTypeArray(new OMElement[] {
078: getOMElement(), null },
079: MIN_EQUALS_ZERO_NILLABLE_FALSE_TEST);
080: assertTrue(assertArrayEqual(returnObject,
081: new OMElement[] { getOMElement() }));
082: } catch (Exception e) {
083: fail();
084: }
085:
086: System.out.println("minOccurs = 1 and nillable true");
087: try {
088: returnObject = testAnyTypeArray(null,
089: MIN_EQUALS_ONE_NILLABLE_TRUE_TEST);
090: assertTrue(assertArrayEqual(returnObject,
091: new OMElement[] { null }));
092: returnObject = testAnyTypeArray(new OMElement[] { null },
093: MIN_EQUALS_ONE_NILLABLE_TRUE_TEST);
094: assertTrue(assertArrayEqual(returnObject,
095: new OMElement[] { null }));
096: returnObject = testAnyTypeArray(
097: new OMElement[] { getOMElement() },
098: MIN_EQUALS_ONE_NILLABLE_TRUE_TEST);
099: assertTrue(assertArrayEqual(returnObject,
100: new OMElement[] { getOMElement() }));
101: returnObject = testAnyTypeArray(new OMElement[] {
102: getOMElement(), null },
103: MIN_EQUALS_ONE_NILLABLE_TRUE_TEST);
104: assertTrue(assertArrayEqual(returnObject, new OMElement[] {
105: getOMElement(), null }));
106: } catch (Exception e) {
107: fail();
108: }
109:
110: System.out.println("minOccurs = 1 and nillable false");
111: try {
112: returnObject = testAnyTypeArray(null,
113: MIN_EQUALS_ONE_NILLABLE_FALSE_TEST);
114: assertTrue(assertArrayEqual(returnObject, null));
115: fail();
116: } catch (Exception e) {
117: assertTrue(true);
118: }
119:
120: try {
121: returnObject = testAnyTypeArray(new OMElement[] { null },
122: MIN_EQUALS_ONE_NILLABLE_FALSE_TEST);
123: assertTrue(assertArrayEqual(returnObject,
124: new OMElement[] { null }));
125: fail();
126: } catch (Exception e) {
127: assertTrue(true);
128: }
129:
130: try {
131: returnObject = testAnyTypeArray(new OMElement[] {
132: getOMElement(), null },
133: MIN_EQUALS_ONE_NILLABLE_FALSE_TEST);
134: assertTrue(assertArrayEqual(returnObject, new OMElement[] {
135: getOMElement(), null }));
136: fail();
137: } catch (Exception e) {
138: assertTrue(true);
139: }
140:
141: try {
142: returnObject = testAnyTypeArray(
143: new OMElement[] { getOMElement() },
144: MIN_EQUALS_ONE_NILLABLE_FALSE_TEST);
145: assertTrue(assertArrayEqual(returnObject,
146: new OMElement[] { getOMElement() }));
147: } catch (Exception e) {
148: fail();
149: }
150: }
151:
152: public OMElement[] testAnyTypeArray(OMElement[] innerElement,
153: int type) throws Exception {
154: OMElement omElement;
155: OMElement[] returnObject = null;
156: String omElementString;
157: switch (type) {
158: case MIN_EQUALS_ZERO_NILLABLE_TRUE_TEST: {
159: TestAnyType1 testAnyType = new TestAnyType1();
160: testAnyType.setTestValue(innerElement);
161: omElement = testAnyType.getOMElement(TestAnyType1.MY_QNAME,
162: OMAbstractFactory.getSOAP12Factory());
163: omElementString = omElement.toStringWithConsume();
164: System.out.println("OMElement ==> " + omElementString);
165: XMLStreamReader xmlReader = StAXUtils
166: .createXMLStreamReader(new ByteArrayInputStream(
167: omElementString.getBytes()));
168: returnObject = TestAnyType1.Factory.parse(xmlReader)
169: .getTestValue();
170: break;
171: }
172: case MIN_EQUALS_ZERO_NILLABLE_FALSE_TEST: {
173: TestAnyType3 testAnyType = new TestAnyType3();
174: testAnyType.setTestValue(innerElement);
175: omElement = testAnyType.getOMElement(TestAnyType3.MY_QNAME,
176: OMAbstractFactory.getSOAP12Factory());
177: omElementString = omElement.toStringWithConsume();
178: System.out.println("OMElement ==> " + omElementString);
179: XMLStreamReader xmlReader = StAXUtils
180: .createXMLStreamReader(new ByteArrayInputStream(
181: omElementString.getBytes()));
182: returnObject = TestAnyType3.Factory.parse(xmlReader)
183: .getTestValue();
184: break;
185: }
186: case MIN_EQUALS_ONE_NILLABLE_TRUE_TEST: {
187: TestAnyType5 testAnyType = new TestAnyType5();
188: testAnyType.setTestValue(innerElement);
189: omElement = testAnyType.getOMElement(TestAnyType5.MY_QNAME,
190: OMAbstractFactory.getSOAP12Factory());
191: omElementString = omElement.toStringWithConsume();
192: System.out.println("OMElement ==> " + omElementString);
193: XMLStreamReader xmlReader = StAXUtils
194: .createXMLStreamReader(new ByteArrayInputStream(
195: omElementString.getBytes()));
196: returnObject = TestAnyType5.Factory.parse(xmlReader)
197: .getTestValue();
198: break;
199: }
200: case MIN_EQUALS_ONE_NILLABLE_FALSE_TEST: {
201: TestAnyType7 testAnyType = new TestAnyType7();
202: testAnyType.setTestValue(innerElement);
203: omElement = testAnyType.getOMElement(TestAnyType7.MY_QNAME,
204: OMAbstractFactory.getSOAP12Factory());
205: omElementString = omElement.toStringWithConsume();
206: System.out.println("OMElement ==> " + omElementString);
207: XMLStreamReader xmlReader = StAXUtils
208: .createXMLStreamReader(new ByteArrayInputStream(
209: omElementString.getBytes()));
210: returnObject = TestAnyType7.Factory.parse(xmlReader)
211: .getTestValue();
212: break;
213: }
214: }
215: return returnObject;
216: }
217:
218: public void testAnyType() {
219:
220: OMElement returnObject;
221: System.out.println("minOccurs = 0 nillable true");
222: try {
223: returnObject = testAnyType(null,
224: MIN_EQUALS_ZERO_NILLABLE_TRUE_TEST);
225: assertTrue(isOMElementsEqual(returnObject, null));
226: returnObject = testAnyType(getOMElement(),
227: MIN_EQUALS_ZERO_NILLABLE_TRUE_TEST);
228: assertTrue(isOMElementsEqual(returnObject, getOMElement()));
229: } catch (Exception e) {
230: fail();
231: }
232: System.out.println("minOccurs = 0 nillable false");
233: try {
234: returnObject = testAnyType(null,
235: MIN_EQUALS_ZERO_NILLABLE_FALSE_TEST);
236: assertTrue(isOMElementsEqual(returnObject, null));
237: returnObject = testAnyType(getOMElement(),
238: MIN_EQUALS_ZERO_NILLABLE_FALSE_TEST);
239: assertTrue(isOMElementsEqual(returnObject, getOMElement()));
240: } catch (Exception e) {
241: fail();
242: }
243: System.out.println("minOccurs = 1 nillable true");
244: try {
245: returnObject = testAnyType(null,
246: MIN_EQUALS_ONE_NILLABLE_TRUE_TEST);
247: assertTrue(isOMElementsEqual(returnObject, null));
248: returnObject = testAnyType(getOMElement(),
249: MIN_EQUALS_ONE_NILLABLE_TRUE_TEST);
250: assertTrue(isOMElementsEqual(returnObject, getOMElement()));
251: } catch (Exception e) {
252: fail();
253: }
254: System.out.println("minOccurs = 1 nillable false");
255: try {
256: returnObject = testAnyType(null,
257: MIN_EQUALS_ONE_NILLABLE_FALSE_TEST);
258: fail();
259: } catch (Exception e) {
260: assertTrue(true);
261: }
262:
263: try {
264: returnObject = testAnyType(getOMElement(),
265: MIN_EQUALS_ONE_NILLABLE_FALSE_TEST);
266: assertTrue(isOMElementsEqual(returnObject, getOMElement()));
267: } catch (Exception e) {
268: fail();
269: }
270:
271: }
272:
273: public OMElement testAnyType(OMElement innerElement, int type)
274: throws Exception {
275: OMElement omElement;
276: OMElement returnObject = null;
277: String omElementString;
278: switch (type) {
279: case MIN_EQUALS_ZERO_NILLABLE_TRUE_TEST: {
280: TestAnyType2 testAnyType = new TestAnyType2();
281: testAnyType.setTestValue(innerElement);
282: omElement = testAnyType.getOMElement(TestAnyType2.MY_QNAME,
283: OMAbstractFactory.getSOAP12Factory());
284: omElementString = omElement.toStringWithConsume();
285: System.out.println("OMElement ==> " + omElementString);
286: XMLStreamReader xmlReader = StAXUtils
287: .createXMLStreamReader(new ByteArrayInputStream(
288: omElementString.getBytes()));
289: returnObject = TestAnyType2.Factory.parse(xmlReader)
290: .getTestValue();
291: break;
292: }
293: case MIN_EQUALS_ZERO_NILLABLE_FALSE_TEST: {
294: TestAnyType4 testAnyType = new TestAnyType4();
295: testAnyType.setTestValue(innerElement);
296: omElement = testAnyType.getOMElement(TestAnyType4.MY_QNAME,
297: OMAbstractFactory.getSOAP12Factory());
298: omElementString = omElement.toStringWithConsume();
299: System.out.println("OMElement ==> " + omElementString);
300: XMLStreamReader xmlReader = StAXUtils
301: .createXMLStreamReader(new ByteArrayInputStream(
302: omElementString.getBytes()));
303: returnObject = TestAnyType4.Factory.parse(xmlReader)
304: .getTestValue();
305: break;
306: }
307: case MIN_EQUALS_ONE_NILLABLE_TRUE_TEST: {
308: TestAnyType6 testAnyType = new TestAnyType6();
309: testAnyType.setTestValue(innerElement);
310: omElement = testAnyType.getOMElement(TestAnyType6.MY_QNAME,
311: OMAbstractFactory.getSOAP12Factory());
312: omElementString = omElement.toStringWithConsume();
313: System.out.println("OMElement ==> " + omElementString);
314: XMLStreamReader xmlReader = StAXUtils
315: .createXMLStreamReader(new ByteArrayInputStream(
316: omElementString.getBytes()));
317: returnObject = TestAnyType6.Factory.parse(xmlReader)
318: .getTestValue();
319: break;
320: }
321: case MIN_EQUALS_ONE_NILLABLE_FALSE_TEST: {
322: TestAnyType8 testAnyType = new TestAnyType8();
323: testAnyType.setTestValue(innerElement);
324: omElement = testAnyType.getOMElement(TestAnyType8.MY_QNAME,
325: OMAbstractFactory.getSOAP12Factory());
326: omElementString = omElement.toStringWithConsume();
327: System.out.println("OMElement ==> " + omElementString);
328: XMLStreamReader xmlReader = StAXUtils
329: .createXMLStreamReader(new ByteArrayInputStream(
330: omElementString.getBytes()));
331: returnObject = TestAnyType8.Factory.parse(xmlReader)
332: .getTestValue();
333: break;
334: }
335: }
336: return returnObject;
337: }
338:
339: }
|