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 org.apache.axiom.om.OMAbstractFactory;
23: import org.apache.axiom.om.OMElement;
24: import org.apache.axiom.om.util.StAXUtils;
25: import org.apache.axis2.databinding.types.Language;
26: import test.axis2.apache.org.FullName;
27: import test.axis2.apache.org.BaseType;
28: import test.axis2.apache.org.SimpleType;
29:
30: import javax.xml.stream.XMLStreamReader;
31: import java.io.ByteArrayInputStream;
32:
33: public class SimpleExtensionTest extends TestCase {
34:
35: public void testSimpleTypeComplexExtension() {
36: FullName fullName = new FullName();
37: fullName.setFirst("amila");
38: fullName.setMiddle("chinthaka");
39: fullName.setLast("suriarachchi");
40: fullName.setLanguage(new Language("singhala"));
41: fullName.setAttribute1(BaseType.Factory.fromString(
42: BaseType._s1, ""));
43:
44: fullName.setAttribute2(SimpleType.Factory.fromString(
45: "ATTRIBUTE", ""));
46:
47: try {
48: OMElement omElement = fullName.getOMElement(
49: FullName.MY_QNAME, OMAbstractFactory
50: .getSOAP11Factory());
51: String omElementString;
52: XMLStreamReader xmlReader;
53: FullName newFullName;
54:
55: omElementString = omElement.toStringWithConsume();
56: System.out.println("OM String ==> " + omElementString);
57: xmlReader = StAXUtils
58: .createXMLStreamReader(new ByteArrayInputStream(
59: omElementString.getBytes()));
60: newFullName = FullName.Factory.parse(xmlReader);
61: assertEquals(newFullName.getFirst(), "amila");
62: assertEquals(newFullName.getMiddle(), "chinthaka");
63: assertEquals(newFullName.getLast(), "suriarachchi");
64: assertEquals(newFullName.getLanguage().toString(),
65: "singhala");
66: assertEquals(newFullName.getAttribute1().toString(),
67: BaseType._s1);
68: assertEquals(newFullName.getAttribute2().toString(),
69: "ATTRIBUTE");
70:
71: omElementString = omElement.toString();
72: System.out.println("OM String ==> " + omElementString);
73: xmlReader = StAXUtils
74: .createXMLStreamReader(new ByteArrayInputStream(
75: omElementString.getBytes()));
76: newFullName = FullName.Factory.parse(xmlReader);
77: assertEquals(newFullName.getFirst(), "amila");
78: assertEquals(newFullName.getMiddle(), "chinthaka");
79: assertEquals(newFullName.getLast(), "suriarachchi");
80: assertEquals(newFullName.getLanguage().toString(),
81: "singhala");
82: assertEquals(newFullName.getAttribute1().toString(),
83: BaseType._s1);
84: assertEquals(newFullName.getAttribute2().toString(),
85: "ATTRIBUTE");
86: } catch (Exception e) {
87: assertFalse(true);
88: }
89: }
90:
91: }
|