01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
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: package org.apache.axis2.schema.extension;
20:
21: import junit.framework.TestCase;
22: import test.axis2.apache.org.TestComplexElement;
23: import test.axis2.apache.org.ExtendedComplexType;
24: import test.axis2.apache.org.FullName;
25: import test.axis2.apache.org.BaseType;
26: import org.apache.axiom.om.OMElement;
27: import org.apache.axiom.om.OMAbstractFactory;
28: import org.apache.axiom.om.util.StAXUtils;
29:
30: import javax.xml.stream.XMLStreamReader;
31: import java.io.ByteArrayInputStream;
32:
33: public class ComplexExtenstionTest extends TestCase {
34:
35: public void testComplexExtension() {
36:
37: TestComplexElement testComplexElement = new TestComplexElement();
38: ExtendedComplexType extendedComplexType = new ExtendedComplexType();
39: testComplexElement.setTestComplexElement(extendedComplexType);
40: extendedComplexType.setFirst("Amila");
41: extendedComplexType.setMiddle("Chinthaka");
42: extendedComplexType.setLast("Suriarachchi");
43: extendedComplexType.setParentElement1("test1");
44: extendedComplexType.setParentElement2("test2");
45:
46: try {
47: OMElement omElement = testComplexElement.getOMElement(
48: TestComplexElement.MY_QNAME, OMAbstractFactory
49: .getSOAP11Factory());
50: String omElementString;
51: XMLStreamReader xmlReader;
52: TestComplexElement result;
53:
54: omElementString = omElement.toStringWithConsume();
55: System.out.println("OM String ==> " + omElementString);
56: xmlReader = StAXUtils
57: .createXMLStreamReader(new ByteArrayInputStream(
58: omElementString.getBytes()));
59: result = TestComplexElement.Factory.parse(xmlReader);
60: assertEquals(result.getTestComplexElement().getFirst(),
61: "Amila");
62: assertEquals(result.getTestComplexElement().getMiddle(),
63: "Chinthaka");
64: assertEquals(result.getTestComplexElement().getLast(),
65: "Suriarachchi");
66: assertEquals(result.getTestComplexElement()
67: .getParentElement1(), "test1");
68: assertEquals(result.getTestComplexElement()
69: .getParentElement2(), "test2");
70:
71: omElementString = omElement.toString();
72: System.out.println("OM String ==> " + omElementString);
73: xmlReader = StAXUtils
74: .createXMLStreamReader(new ByteArrayInputStream(
75: omElementString.getBytes()));
76: result = TestComplexElement.Factory.parse(xmlReader);
77: assertEquals(result.getTestComplexElement().getFirst(),
78: "Amila");
79: assertEquals(result.getTestComplexElement().getMiddle(),
80: "Chinthaka");
81: assertEquals(result.getTestComplexElement().getLast(),
82: "Suriarachchi");
83: assertEquals(result.getTestComplexElement()
84: .getParentElement1(), "test1");
85: assertEquals(result.getTestComplexElement()
86: .getParentElement2(), "test2");
87:
88: } catch (Exception e) {
89: assertFalse(true);
90: }
91:
92: }
93: }
|