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:
020: package org.apache.axis2.jaxws.jaxb.wrapper;
021:
022: import java.util.ArrayList;
023: import java.util.Map;
024: import java.util.WeakHashMap;
025:
026: import junit.framework.TestCase;
027: import org.apache.axis2.jaxws.wrapper.JAXBWrapperTool;
028: import org.apache.axis2.jaxws.wrapper.impl.JAXBWrapperException;
029: import org.apache.axis2.jaxws.wrapper.impl.JAXBWrapperToolImpl;
030: import org.apache.axis2.jaxws.TestLogger;
031:
032: public class WrapperToolTest extends TestCase {
033: public void testWrapStockQuote() {
034: try {
035: JAXBWrapperTool wrapper = new JAXBWrapperToolImpl();
036:
037: String jaxbClassName = "org.test.stock2.GetPrice";
038: Class jaxbClass;
039: try {
040: jaxbClass = Class.forName(jaxbClassName, false,
041: ClassLoader.getSystemClassLoader());
042: } catch (Exception e) {
043: jaxbClass = Class.forName(jaxbClassName, false, this
044: .getClass().getClassLoader());
045: }
046: ArrayList<String> childNames = new ArrayList<String>();
047: String childName = "symbol";
048: childNames.add(childName);
049: String symbolObj = new String("IBM");
050: Map<String, Object> childObjects = new WeakHashMap<String, Object>();
051: childObjects.put(childName, symbolObj);
052: Object jaxbObject = wrapper.wrap(jaxbClass, childNames,
053: childObjects);
054: org.test.stock2.GetPrice getPrice = (org.test.stock2.GetPrice) jaxbObject;
055:
056: } catch (JAXBWrapperException e) {
057: e.printStackTrace();
058: } catch (ClassNotFoundException e) {
059: e.printStackTrace();
060: }
061: }
062:
063: public void testUnwrapStockQuote() {
064: try {
065: JAXBWrapperTool wrapper = new JAXBWrapperToolImpl();
066: org.test.stock2.GetPrice price = new org.test.stock2.GetPrice();
067: price.setSymbol("IBM");
068:
069: ArrayList<String> childNames = new ArrayList<String>();
070: String childName = "symbol";
071: childNames.add(childName);
072:
073: Object[] jaxbObjects = wrapper.unWrap(price, childNames);
074:
075: } catch (JAXBWrapperException e) {
076: e.printStackTrace();
077: }
078: }
079:
080: public void testWrapMFQuote() {
081: try {
082: JAXBWrapperTool wrapper = new JAXBWrapperToolImpl();
083:
084: String jaxbClassName = "org.test.stock1.GetPrice";
085: Class jaxbClass;
086: try {
087: jaxbClass = Class.forName(jaxbClassName, false,
088: ClassLoader.getSystemClassLoader());
089: } catch (Exception e) {
090: jaxbClass = Class.forName(jaxbClassName, false, this
091: .getClass().getClassLoader());
092: }
093: ArrayList<String> childNames = new ArrayList<String>();
094: String fund = "fund";
095: String fundName = new String("PRGFX");
096: String holding = "holdings.";
097: String topHolding = new String("GE");
098: String nav = "nav";
099: String navInMillion = new String("700");
100:
101: childNames.add(fund);
102: childNames.add(holding);
103: childNames.add(nav);
104:
105: Map<String, Object> childObjects = new WeakHashMap<String, Object>();
106:
107: childObjects.put(fund, fundName);
108: childObjects.put(holding, topHolding);
109: childObjects.put(nav, navInMillion);
110:
111: Object jaxbObject = wrapper.wrap(jaxbClass, childNames,
112: childObjects);
113: org.test.stock1.GetPrice getPrice = (org.test.stock1.GetPrice) jaxbObject;
114:
115: } catch (JAXBWrapperException e) {
116: e.printStackTrace();
117: } catch (ClassNotFoundException e) {
118: e.printStackTrace();
119: }
120: }
121:
122: public void testUnwrapMFQuote() {
123: try {
124: JAXBWrapperTool wrapper = new JAXBWrapperToolImpl();
125: org.test.stock1.GetPrice price = new org.test.stock1.GetPrice();
126: price.setFund("PRGFX");
127: price.setHoldings("GE");
128: price.setNav("700");
129:
130: ArrayList<String> childNames = new ArrayList<String>();
131: String fund = "fund";
132: childNames.add(fund);
133: String holding = "holdings.";
134: childNames.add(holding);
135: String nav = "nav";
136: childNames.add(nav);
137:
138: Object[] jaxbObjects = wrapper.unWrap(price, childNames);
139: } catch (JAXBWrapperException e) {
140: e.printStackTrace();
141: }
142: }
143: }
|