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.OMAbstractFactory;
022: import org.apache.axiom.om.OMElement;
023: import org.apache.axiom.om.util.StAXUtils;
024: import services.echo.types.*;
025:
026: import javax.xml.stream.XMLStreamReader;
027: import java.io.ByteArrayInputStream;
028:
029: public class OuterElementsTest extends AbstractTest {
030:
031: public static final int NILLABLE_TRUE = 0;
032: public static final int NILLABLE_FALSE = 1;
033:
034: public void testString() {
035: String returnString;
036: try {
037: returnString = testString(null, NILLABLE_TRUE);
038: assertEquals(returnString, null);
039: returnString = testString("Test String", NILLABLE_TRUE);
040: assertEquals(returnString, "Test String");
041: } catch (Exception e) {
042: fail();
043: }
044:
045: try {
046: returnString = testString(null, NILLABLE_FALSE);
047: fail();
048: } catch (Exception e) {
049: assertTrue(true);
050: }
051:
052: try {
053: returnString = testString("Test String", NILLABLE_FALSE);
054: assertEquals(returnString, "Test String");
055: } catch (Exception e) {
056: fail();
057: }
058: }
059:
060: private String testString(String innerElement, int type)
061: throws Exception {
062: OMElement omElement;
063: String returnString = null;
064: String omElementString;
065:
066: switch (type) {
067: case NILLABLE_TRUE: {
068: OuterTestString1 outerTestString = new OuterTestString1();
069: outerTestString.setOuterTestString1(innerElement);
070: omElement = outerTestString.getOMElement(
071: OuterTestString1.MY_QNAME, OMAbstractFactory
072: .getSOAP12Factory());
073: omElementString = omElement.toStringWithConsume();
074: System.out.println("OMElement ==> " + omElementString);
075: XMLStreamReader xmlReader = StAXUtils
076: .createXMLStreamReader(new ByteArrayInputStream(
077: omElementString.getBytes()));
078: returnString = OuterTestString1.Factory.parse(xmlReader)
079: .getOuterTestString1();
080: break;
081: }
082:
083: case NILLABLE_FALSE: {
084: OuterTestString2 outerTestString = new OuterTestString2();
085: outerTestString.setOuterTestString2(innerElement);
086: omElement = outerTestString.getOMElement(
087: OuterTestString2.MY_QNAME, OMAbstractFactory
088: .getSOAP12Factory());
089: omElementString = omElement.toStringWithConsume();
090: System.out.println("OMElement ==> " + omElementString);
091: XMLStreamReader xmlReader = StAXUtils
092: .createXMLStreamReader(new ByteArrayInputStream(
093: omElementString.getBytes()));
094: returnString = OuterTestString2.Factory.parse(xmlReader)
095: .getOuterTestString2();
096: break;
097:
098: }
099: }
100: return returnString;
101: }
102:
103: public void testInt() {
104:
105: try {
106: assertEquals(testInt(5, NILLABLE_TRUE), 5);
107: assertEquals(testInt(Integer.MIN_VALUE, NILLABLE_TRUE),
108: Integer.MIN_VALUE);
109: } catch (Exception e) {
110: fail();
111: }
112:
113: try {
114: assertEquals(testInt(5, NILLABLE_FALSE), 5);
115: } catch (Exception e) {
116: fail();
117: }
118:
119: try {
120: assertEquals(testInt(Integer.MIN_VALUE, NILLABLE_FALSE),
121: Integer.MIN_VALUE);
122: fail();
123: } catch (Exception e) {
124: assertTrue(true);
125: }
126: }
127:
128: private int testInt(int innerElement, int type) throws Exception {
129: OMElement omElement;
130: int returnInt = 0;
131: String omElementString;
132: switch (type) {
133: case NILLABLE_TRUE: {
134: OuterTestInt1 outerTestInt = new OuterTestInt1();
135: outerTestInt.setOuterTestInt1(innerElement);
136: omElement = outerTestInt.getOMElement(
137: OuterTestInt1.MY_QNAME, OMAbstractFactory
138: .getSOAP12Factory());
139: omElementString = omElement.toStringWithConsume();
140: System.out.println("OMElement ==> " + omElementString);
141: XMLStreamReader xmlReader = StAXUtils
142: .createXMLStreamReader(new ByteArrayInputStream(
143: omElementString.getBytes()));
144: returnInt = OuterTestInt1.Factory.parse(xmlReader)
145: .getOuterTestInt1();
146: break;
147: }
148: case NILLABLE_FALSE: {
149: OuterTestInt2 outerTestInt = new OuterTestInt2();
150: outerTestInt.setOuterTestInt2(innerElement);
151: omElement = outerTestInt.getOMElement(
152: OuterTestInt2.MY_QNAME, OMAbstractFactory
153: .getSOAP12Factory());
154: omElementString = omElement.toStringWithConsume();
155: System.out.println("OMElement ==> " + omElementString);
156: XMLStreamReader xmlReader = StAXUtils
157: .createXMLStreamReader(new ByteArrayInputStream(
158: omElementString.getBytes()));
159: returnInt = OuterTestInt2.Factory.parse(xmlReader)
160: .getOuterTestInt2();
161: break;
162: }
163: }
164: return returnInt;
165: }
166:
167: public void testAnyType() {
168: OMElement returnObject;
169: try {
170: returnObject = testAnyType(null, NILLABLE_TRUE);
171: assertTrue(isOMElementsEqual(returnObject, null));
172: returnObject = testAnyType(getOMElement(), NILLABLE_TRUE);
173: assertTrue(isOMElementsEqual(returnObject, getOMElement()));
174: } catch (Exception e) {
175: fail();
176: }
177:
178: try {
179: returnObject = testAnyType(null, NILLABLE_FALSE);
180: fail();
181: } catch (Exception e) {
182: assertTrue(true);
183: }
184:
185: try {
186: returnObject = testAnyType(getOMElement(), NILLABLE_FALSE);
187: assertTrue(isOMElementsEqual(returnObject, getOMElement()));
188: } catch (Exception e) {
189: fail();
190: }
191: }
192:
193: private OMElement testAnyType(OMElement innerElement, int type)
194: throws Exception {
195: OMElement omElement;
196: OMElement returnString = null;
197: String omElementString;
198:
199: switch (type) {
200: case NILLABLE_TRUE: {
201: OuterTestAnyType1 outerTestAnyType = new OuterTestAnyType1();
202: outerTestAnyType.setOuterTestAnyType1(innerElement);
203: omElement = outerTestAnyType.getOMElement(
204: OuterTestAnyType1.MY_QNAME, OMAbstractFactory
205: .getSOAP12Factory());
206: omElementString = omElement.toStringWithConsume();
207: System.out.println("OMElement ==> " + omElementString);
208: XMLStreamReader xmlReader = StAXUtils
209: .createXMLStreamReader(new ByteArrayInputStream(
210: omElementString.getBytes()));
211: returnString = OuterTestAnyType1.Factory.parse(xmlReader)
212: .getOuterTestAnyType1();
213: break;
214: }
215:
216: case NILLABLE_FALSE: {
217: OuterTestAnyType2 outerTestAnyType = new OuterTestAnyType2();
218: outerTestAnyType.setOuterTestAnyType2(innerElement);
219: omElement = outerTestAnyType.getOMElement(
220: OuterTestAnyType2.MY_QNAME, OMAbstractFactory
221: .getSOAP12Factory());
222: omElementString = omElement.toStringWithConsume();
223: System.out.println("OMElement ==> " + omElementString);
224: XMLStreamReader xmlReader = StAXUtils
225: .createXMLStreamReader(new ByteArrayInputStream(
226: omElementString.getBytes()));
227: returnString = OuterTestAnyType2.Factory.parse(xmlReader)
228: .getOuterTestAnyType2();
229: break;
230: }
231: }
232: return returnString;
233: }
234:
235: public void testBookInformation() {
236: BookInformation returnObject;
237: try {
238: returnObject = testBookInformation(null, NILLABLE_TRUE);
239: assertTrue(isBookInformationObjectsEquals(returnObject,
240: null));
241: returnObject = testBookInformation(getBookInformation(),
242: NILLABLE_TRUE);
243: assertTrue(isBookInformationObjectsEquals(returnObject,
244: getBookInformation()));
245: } catch (Exception e) {
246: fail();
247: }
248:
249: try {
250: returnObject = testBookInformation(null, NILLABLE_FALSE);
251: fail();
252: } catch (Exception e) {
253: assertTrue(true);
254: }
255:
256: try {
257: returnObject = testBookInformation(getBookInformation(),
258: NILLABLE_FALSE);
259: assertTrue(isBookInformationObjectsEquals(returnObject,
260: getBookInformation()));
261: } catch (Exception e) {
262: fail();
263: }
264: }
265:
266: private BookInformation testBookInformation(
267: BookInformation innerElement, int type) throws Exception {
268: OMElement omElement;
269: BookInformation returnObject = null;
270: String omElementString;
271:
272: switch (type) {
273: case NILLABLE_TRUE: {
274: OuterTestBookInformation1 outerTestBookInformation = new OuterTestBookInformation1();
275: outerTestBookInformation
276: .setOuterTestBookInformation1(innerElement);
277: omElement = outerTestBookInformation.getOMElement(
278: OuterTestBookInformation1.MY_QNAME,
279: OMAbstractFactory.getSOAP12Factory());
280: omElementString = omElement.toStringWithConsume();
281: System.out.println("OMElement ==> " + omElementString);
282: XMLStreamReader xmlReader = StAXUtils
283: .createXMLStreamReader(new ByteArrayInputStream(
284: omElementString.getBytes()));
285: returnObject = OuterTestBookInformation1.Factory.parse(
286: xmlReader).getOuterTestBookInformation1();
287: break;
288: }
289:
290: case NILLABLE_FALSE: {
291: OuterTestBookInformation2 outerTestBookInformation = new OuterTestBookInformation2();
292: outerTestBookInformation
293: .setOuterTestBookInformation2(innerElement);
294: omElement = outerTestBookInformation.getOMElement(
295: OuterTestBookInformation2.MY_QNAME,
296: OMAbstractFactory.getSOAP12Factory());
297: omElementString = omElement.toStringWithConsume();
298: System.out.println("OMElement ==> " + omElementString);
299: XMLStreamReader xmlReader = StAXUtils
300: .createXMLStreamReader(new ByteArrayInputStream(
301: omElementString.getBytes()));
302: returnObject = OuterTestBookInformation2.Factory.parse(
303: xmlReader).getOuterTestBookInformation2();
304: break;
305: }
306: }
307: return returnObject;
308: }
309:
310: }
|