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.group;
020:
021: import junit.framework.TestCase;
022: import group.test.axis2.apache.org.*;
023: import org.apache.axiom.om.OMElement;
024: import org.apache.axiom.om.OMAbstractFactory;
025: import org.apache.axiom.om.util.StAXUtils;
026:
027: import javax.xml.stream.XMLStreamException;
028: import javax.xml.stream.XMLStreamReader;
029: import java.io.ByteArrayInputStream;
030:
031: import group.test.axis2.apache.org.TestAttributeGroupElement;
032: import group.test.axis2.apache.org.TestNestedAttributeGroupElement;
033:
034: public class GroupTest extends TestCase {
035:
036: public void testSequenceGroupElement() {
037:
038: TestSequenceGroupElement testGroupSequenceElement = new TestSequenceGroupElement();
039: testGroupSequenceElement.setParam1("param1");
040: TestSequenceGroup testSequenceGroup = new TestSequenceGroup();
041: testSequenceGroup.setSequenceParam1("sequenceParam1");
042: testSequenceGroup.setSequenceParam2("sequenceParam2");
043: testGroupSequenceElement
044: .setTestSequenceGroup(testSequenceGroup);
045:
046: try {
047: OMElement omElement = testGroupSequenceElement
048: .getOMElement(TestSequenceGroupElement.MY_QNAME,
049: OMAbstractFactory.getOMFactory());
050: String omElementString = omElement.toStringWithConsume();
051: System.out.println("OM String ==> " + omElementString);
052: XMLStreamReader xmlReader = StAXUtils
053: .createXMLStreamReader(new ByteArrayInputStream(
054: omElementString.getBytes()));
055: TestSequenceGroupElement result = TestSequenceGroupElement.Factory
056: .parse(xmlReader);
057: assertEquals(result.getParam1(), "param1");
058: assertEquals(result.getTestSequenceGroup()
059: .getSequenceParam1(), "sequenceParam1");
060: assertEquals(result.getTestSequenceGroup()
061: .getSequenceParam2(), "sequenceParam2");
062: } catch (XMLStreamException e) {
063: fail();
064: } catch (Exception e) {
065: fail();
066: }
067: }
068:
069: public void testNestedSequenceGroupElement() {
070:
071: TestSequenceNestedGroupElement testSequenceNestedGroupElement = new TestSequenceNestedGroupElement();
072: testSequenceNestedGroupElement.setParam1("param1");
073:
074: TestSequenceNestedGroup testSequenceNestedGroup = new TestSequenceNestedGroup();
075: testSequenceNestedGroup
076: .setNestedSequenceParam1("nestedSequenceParam1");
077:
078: TestSequenceGroup testSequenceGroup = new TestSequenceGroup();
079: testSequenceGroup.setSequenceParam1("sequenceParam1");
080: testSequenceGroup.setSequenceParam2("sequenceParam2");
081:
082: testSequenceNestedGroup.setTestSequenceGroup(testSequenceGroup);
083:
084: testSequenceNestedGroupElement
085: .setTestSequenceNestedGroup(testSequenceNestedGroup);
086:
087: try {
088: OMElement omElement = testSequenceNestedGroupElement
089: .getOMElement(
090: TestSequenceNestedGroupElement.MY_QNAME,
091: OMAbstractFactory.getOMFactory());
092:
093: String omElementString = omElement.toStringWithConsume();
094: System.out.println("OM String ==> " + omElementString);
095: XMLStreamReader xmlReader = StAXUtils
096: .createXMLStreamReader(new ByteArrayInputStream(
097: omElementString.getBytes()));
098: TestSequenceNestedGroupElement result = TestSequenceNestedGroupElement.Factory
099: .parse(xmlReader);
100: assertEquals(result.getParam1(), "param1");
101: assertEquals(result.getTestSequenceNestedGroup()
102: .getNestedSequenceParam1(), "nestedSequenceParam1");
103: assertEquals(result.getTestSequenceNestedGroup()
104: .getTestSequenceGroup().getSequenceParam1(),
105: "sequenceParam1");
106: assertEquals(result.getTestSequenceNestedGroup()
107: .getTestSequenceGroup().getSequenceParam2(),
108: "sequenceParam2");
109: } catch (XMLStreamException e) {
110: fail();
111: } catch (Exception e) {
112: fail();
113: }
114: }
115:
116: public void testChoiceGroupElement() {
117:
118: TestChoiceGroupElement testGroupChoiceElement = new TestChoiceGroupElement();
119: testGroupChoiceElement.setParam1("param1");
120: TestChoiceGroup testChoiceGroup = new TestChoiceGroup();
121: testChoiceGroup.setChoiceParam1("choiceParam1");
122: testGroupChoiceElement.setTestChoiceGroup(testChoiceGroup);
123:
124: try {
125: OMElement omElement = testGroupChoiceElement.getOMElement(
126: TestChoiceGroupElement.MY_QNAME, OMAbstractFactory
127: .getOMFactory());
128: String omElementString = omElement.toStringWithConsume();
129: System.out.println("OM String ==> " + omElementString);
130: XMLStreamReader xmlReader = StAXUtils
131: .createXMLStreamReader(new ByteArrayInputStream(
132: omElementString.getBytes()));
133: TestChoiceGroupElement result = TestChoiceGroupElement.Factory
134: .parse(xmlReader);
135: assertEquals(result.getTestChoiceGroup().getChoiceParam1(),
136: "choiceParam1");
137: } catch (XMLStreamException e) {
138: fail();
139: } catch (Exception e) {
140: fail();
141: }
142: }
143:
144: public void testNestedChoiceGroupElement() {
145:
146: TestChoiceNestedGroupElement testChoiceNestedGroupElement = new TestChoiceNestedGroupElement();
147: testChoiceNestedGroupElement.setParam1("param1");
148:
149: TestChoiceNestedGroup testChoiceNestedGroup = new TestChoiceNestedGroup();
150: testChoiceNestedGroup
151: .setNestedChoiceParam1("nestedChoiceParam1");
152:
153: TestChoiceGroup testChoiceGroup = new TestChoiceGroup();
154: testChoiceGroup.setChoiceParam1("choiceParam1");
155:
156: testChoiceNestedGroup.setTestChoiceGroup(testChoiceGroup);
157:
158: testChoiceNestedGroupElement
159: .setTestChoiceNestedGroup(testChoiceNestedGroup);
160:
161: try {
162: OMElement omElement = testChoiceNestedGroupElement
163: .getOMElement(
164: testChoiceNestedGroupElement.MY_QNAME,
165: OMAbstractFactory.getOMFactory());
166: String omElementString = omElement.toStringWithConsume();
167: System.out.println("OM String ==> " + omElementString);
168: XMLStreamReader xmlReader = StAXUtils
169: .createXMLStreamReader(new ByteArrayInputStream(
170: omElementString.getBytes()));
171: TestChoiceNestedGroupElement result = TestChoiceNestedGroupElement.Factory
172: .parse(xmlReader);
173: assertEquals(result.getTestChoiceNestedGroup()
174: .getTestChoiceGroup().getChoiceParam1(),
175: "choiceParam1");
176: } catch (XMLStreamException e) {
177: fail();
178: } catch (Exception e) {
179: fail();
180: }
181: }
182:
183: public void testAttributeGroup() {
184: TestAttributeGroupElement testAttributeGroup = new TestAttributeGroupElement();
185: testAttributeGroup.setAttribute1("Attribute1");
186: testAttributeGroup.setParam1("Param1");
187:
188: try {
189: OMElement omElement = testAttributeGroup.getOMElement(
190: TestAttributeGroupElement.MY_QNAME,
191: OMAbstractFactory.getOMFactory());
192: String omElementString = omElement.toStringWithConsume();
193: System.out.println("OM Element ==> " + omElementString);
194: XMLStreamReader xmlReader = StAXUtils
195: .createXMLStreamReader(new ByteArrayInputStream(
196: omElementString.getBytes()));
197: TestAttributeGroupElement result = TestAttributeGroupElement.Factory
198: .parse(xmlReader);
199: assertEquals(result.getParam1(), "Param1");
200: assertEquals(result.getAttribute1(), "Attribute1");
201: } catch (XMLStreamException e) {
202: fail();
203: } catch (Exception e) {
204: fail();
205: }
206:
207: }
208:
209: public void testNestedAttributeGroup() {
210: TestNestedAttributeGroupElement testNestedAttributeGroupElement = new TestNestedAttributeGroupElement();
211: testNestedAttributeGroupElement.setAttribute1("Attribute1");
212: testNestedAttributeGroupElement.setAttribute2("Attribute2");
213: testNestedAttributeGroupElement.setParam1("Param1");
214:
215: try {
216: OMElement omElement = testNestedAttributeGroupElement
217: .getOMElement(
218: TestNestedAttributeGroupElement.MY_QNAME,
219: OMAbstractFactory.getOMFactory());
220: String omElementString = omElement.toStringWithConsume();
221: System.out.println("OM Element ==> " + omElementString);
222: XMLStreamReader xmlReader = StAXUtils
223: .createXMLStreamReader(new ByteArrayInputStream(
224: omElementString.getBytes()));
225: TestNestedAttributeGroupElement result = TestNestedAttributeGroupElement.Factory
226: .parse(xmlReader);
227: assertEquals(result.getParam1(), "Param1");
228: assertEquals(result.getAttribute1(), "Attribute1");
229: assertEquals(result.getAttribute2(), "Attribute2");
230: } catch (XMLStreamException e) {
231: fail();
232: } catch (Exception e) {
233: fail();
234: }
235:
236: }
237:
238: }
|