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.references;
020:
021: import com.americanexpress.www.wsdl.ctn.utilities.atb.AtbRequestCheckEligibility_type0;
022: import com.americanexpress.www.wsdl.ctn.utilities.atb.CheckEligibility1;
023: import com.americanexpress.www.wsdl.ctn.utilities.atb.CheckEligibility2;
024: import junit.framework.TestCase;
025: import org.apache.axiom.om.OMAbstractFactory;
026: import org.apache.axiom.om.OMElement;
027: import org.apache.axiom.om.util.StAXUtils;
028:
029: import javax.xml.stream.XMLStreamReader;
030: import java.io.ByteArrayInputStream;
031:
032: public class ElementReferenceTest extends TestCase {
033:
034: public void testSingleElementReference() {
035: CheckEligibility1 echCheckEligibility1 = new CheckEligibility1();
036: AtbRequestCheckEligibility_type0 atbRequestCheckEligibility = new AtbRequestCheckEligibility_type0();
037: echCheckEligibility1
038: .setAtbRequestCheckEligibility(atbRequestCheckEligibility);
039: atbRequestCheckEligibility.setCardNumber("carnumber");
040: atbRequestCheckEligibility.setClientId("clientid");
041: atbRequestCheckEligibility.setExpirationDate("date");
042: atbRequestCheckEligibility.setNameAsOnCard("cardname");
043: atbRequestCheckEligibility.setYearOfRedemption(2);
044:
045: try {
046: OMElement omElement = echCheckEligibility1.getOMElement(
047: CheckEligibility1.MY_QNAME, OMAbstractFactory
048: .getSOAP12Factory());
049: String omElementString = omElement.toStringWithConsume();
050: XMLStreamReader xmlReader = StAXUtils
051: .createXMLStreamReader(new ByteArrayInputStream(
052: omElementString.getBytes()));
053: CheckEligibility1 result = CheckEligibility1.Factory
054: .parse(xmlReader);
055: assertEquals(result.getAtbRequestCheckEligibility()
056: .getCardNumber(), "carnumber");
057: assertEquals(result.getAtbRequestCheckEligibility()
058: .getClientId(), "clientid");
059: assertEquals(result.getAtbRequestCheckEligibility()
060: .getExpirationDate(), "date");
061: assertEquals(result.getAtbRequestCheckEligibility()
062: .getNameAsOnCard(), "cardname");
063: assertEquals(result.getAtbRequestCheckEligibility()
064: .getYearOfRedemption(), 2);
065: } catch (Exception e) {
066: fail();
067: }
068: }
069:
070: public void testMultipleElementReference() {
071: CheckEligibility2 echCheckEligibility2 = new CheckEligibility2();
072: AtbRequestCheckEligibility_type0[] atbRequestCheckEligibility = new AtbRequestCheckEligibility_type0[2];
073: echCheckEligibility2
074: .setAtbRequestCheckEligibility(atbRequestCheckEligibility);
075:
076: atbRequestCheckEligibility[0] = new AtbRequestCheckEligibility_type0();
077: atbRequestCheckEligibility[0].setCardNumber("carnumber");
078: atbRequestCheckEligibility[0].setClientId("clientid");
079: atbRequestCheckEligibility[0].setExpirationDate("date");
080: atbRequestCheckEligibility[0].setNameAsOnCard("cardname");
081: atbRequestCheckEligibility[0].setYearOfRedemption(2);
082:
083: atbRequestCheckEligibility[1] = new AtbRequestCheckEligibility_type0();
084: atbRequestCheckEligibility[1].setCardNumber("carnumber");
085: atbRequestCheckEligibility[1].setClientId("clientid");
086: atbRequestCheckEligibility[1].setExpirationDate("date");
087: atbRequestCheckEligibility[1].setNameAsOnCard("cardname");
088: atbRequestCheckEligibility[1].setYearOfRedemption(2);
089:
090: try {
091: OMElement omElement = echCheckEligibility2.getOMElement(
092: CheckEligibility2.MY_QNAME, OMAbstractFactory
093: .getSOAP12Factory());
094: String omElementString = omElement.toStringWithConsume();
095: XMLStreamReader xmlReader = StAXUtils
096: .createXMLStreamReader(new ByteArrayInputStream(
097: omElementString.getBytes()));
098: CheckEligibility2 result = CheckEligibility2.Factory
099: .parse(xmlReader);
100: assertEquals(result.getAtbRequestCheckEligibility()[0]
101: .getCardNumber(), "carnumber");
102: assertEquals(result.getAtbRequestCheckEligibility()[0]
103: .getClientId(), "clientid");
104: assertEquals(result.getAtbRequestCheckEligibility()[0]
105: .getExpirationDate(), "date");
106: assertEquals(result.getAtbRequestCheckEligibility()[0]
107: .getNameAsOnCard(), "cardname");
108: assertEquals(result.getAtbRequestCheckEligibility()[0]
109: .getYearOfRedemption(), 2);
110:
111: assertEquals(result.getAtbRequestCheckEligibility()[1]
112: .getCardNumber(), "carnumber");
113: assertEquals(result.getAtbRequestCheckEligibility()[1]
114: .getClientId(), "clientid");
115: assertEquals(result.getAtbRequestCheckEligibility()[1]
116: .getExpirationDate(), "date");
117: assertEquals(result.getAtbRequestCheckEligibility()[1]
118: .getNameAsOnCard(), "cardname");
119: assertEquals(result.getAtbRequestCheckEligibility()[1]
120: .getYearOfRedemption(), 2);
121: } catch (Exception e) {
122: fail();
123: }
124: }
125: }
|