⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 roundtriptestservicetestcase.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * Copyright 2001-2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *  *      http://www.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package test.wsdl.roundtrip;import junit.framework.TestCase;import test.wsdl.roundtrip.holders.BondInvestmentHolder;import javax.xml.rpc.ServiceException;import javax.xml.rpc.holders.StringHolder;import java.math.BigDecimal;import java.math.BigInteger;import java.rmi.RemoteException;import java.util.Calendar;import java.util.Date;import java.util.HashMap;import java.util.TimeZone;/** * This class contains the test methods to verify that Java mapping * to XML/WSDL works as specified by the JAX-RPC specification. * * The following items are tested: * - Primitives * - Standard Java Classes * - Arrays * - Multiple Arrays * - JAX-RPC Value Types * - Nillables (when used with literal element declarations)  * * @version   1.00  06 Feb 2002 * @author    Brent Ulbricht */public class RoundtripTestServiceTestCase extends TestCase {    private RoundtripPortType binding = null;    private RoundtripPortType binding2 = null;    private static final double DOUBLE_DELTA = 0.0D;    private static final float FLOAT_DELTA = 0.0F;    /**     *  The Junit framework requires that each class that subclasses     *  TestCase define a constructor accepting a string.  This method     *  can be used to specify a specific testXXXXX method in this     *  class to run.     */    public RoundtripTestServiceTestCase(String name) {        super(name);    } // Constructor    /**     *  The setUp method executes before each test method in this class     *  to get the binding.     */    public void setUp() {        try {            binding = new RoundtripPortTypeServiceLocator().getRoundtripTest();            binding2 = new RoundtripPortTypeServiceLocator().getRoundtripTest2();        } catch (ServiceException jre) {            fail("JAX-RPC ServiceException caught: " + jre);        }        assertTrue("binding is null", binding != null);    } // setUp    /**     *  Test to insure that a JAX-RPC Value Type works correctly.  StockInvestment     *  subclasses Investment and should pass data members in both the Investment      *  and StockInvestment classes across the wire correctly.     */    public void testStockInvestment() throws Exception {        StockInvestment stock = new StockInvestment();        stock.setName("International Business Machines");        stock.setId(1);        stock.setTradeExchange("NYSE");        stock.setLastTradePrice(200.55F);        float lastTradePrice = binding.getRealtimeLastTradePrice(stock);        assertEquals("The expected and actual values did not match.",                201.25F,                lastTradePrice,                FLOAT_DELTA);        // Make sure static field dontMapToWSDL is not mapped.        try {            (StockInvestment.class).                    getDeclaredMethod("getDontMapToWSDL",                            new Class[] {});            fail("Should not map static member dontMapToWSDL");        } catch (NoSuchMethodException e) {            // Cool the method should not be in the class        }        // Make sure private field avgYearlyReturn is not mapped.        try {            (StockInvestment.class).getDeclaredMethod("getAvgYearlyReturn",                    new Class[] {});            fail("Should not map private member avgYearlyReturn");        } catch (NoSuchMethodException e) {            // Cool the method should not be in the class        }    } // testStockInvestment    /**     *  Like the above test, but uses the alternate port.     */    public void testStockInvestmentWithPort2() throws Exception {        StockInvestment stock = new StockInvestment();        stock.setName("International Business Machines");        stock.setId(1);        stock.setTradeExchange("NYSE");        stock.setLastTradePrice(200.55F);        float lastTradePrice = binding2.getRealtimeLastTradePrice(stock);        assertEquals("The expected and actual values did not match.",                201.25F,                lastTradePrice,                FLOAT_DELTA);        // Make sure static field dontMapToWSDL is not mapped.        try {            (StockInvestment.class).getDeclaredMethod("getDontMapToWSDL",                    new Class[] {});            fail("Should not map static member dontMapToWSDL");        } catch (NoSuchMethodException e) {            // Cool the method should not be in the class        }        // Make sure private field avgYearlyReturn is not mapped.        try {            (StockInvestment.class).getDeclaredMethod("getAvgYearlyReturn",                    new Class[] {});            fail("Should not map private member avgYearlyReturn");        } catch (NoSuchMethodException e) {            // Cool the method should not be in the class        }    } // testStockInvestmentWithPort2    /**     *  Test to insure that a JAX-RPC Value Type works correctly.  PreferredStockInvestment     *  subclasses StockInvestment and should pass data members in both the Investment,      *  StockInvestment, and PreferredStockInvestment classes across the wire correctly.     */    public void testPreferredStockInvestment() throws RemoteException {        PreferredStockInvestment oldStock = new PreferredStockInvestment();        oldStock.setName("SOAP Inc.");        oldStock.setId(202);        oldStock.setTradeExchange("NASDAQ");        oldStock.setLastTradePrice(10.50F);        oldStock.setDividendsInArrears(100.44D);        oldStock.setPreferredYield(new BigDecimal("7.00"));        PreferredStockInvestment newStock = binding.getDividends(oldStock);        assertEquals("The expected and actual values did not match.",                newStock.getName(),                "AXIS Inc.");        assertEquals("The expected and actual values did not match.",                203,                newStock.getId());        assertEquals("The expected and actual values did not match.",                "NASDAQ",                newStock.getTradeExchange());        assertEquals("The expected and actual values did not match.",                101.44D,                newStock.getDividendsInArrears(),                DOUBLE_DELTA);        assertEquals("The expected and actual values did not match.",                new BigDecimal("8.00"),                newStock.getPreferredYield());        assertEquals("The expected and actual values did not match.",                11.50F,                newStock.getLastTradePrice(),                FLOAT_DELTA);    } // testPreferredStockInvestment    /**     *  The BondInvestment class contains all the supported data members:     *  primitives, standard Java classes, arrays, and primitive wrapper     *  classes.  This test insures that the data is transmitted across     *  the wire correctly.     */    public void testRoundtripBondInvestment() throws RemoteException {        CallOptions[] callOptions = new CallOptions[2];        callOptions[0] = new CallOptions();        Calendar date = Calendar.getInstance();        TimeZone gmt = TimeZone.getTimeZone("GMT");        date.setTimeZone(gmt);        date.setTime(new Date(1013441507388L));        callOptions[0].setCallDate(date);        callOptions[1] = new CallOptions();        date = Calendar.getInstance();        date.setTimeZone(gmt);        date.setTime(new Date(1013441507390L));        callOptions[1].setCallDate(date);        HashMap map = new HashMap();        map.put("Test", "Test Works");        short[] shortArray = {(short) 30};        byte[] byteArray = {(byte) 1};        Short[] wrapperShortArray = {new Short((short) 23), new Short((short) 56)};        Byte[] wrapperByteArray = {new Byte((byte) 2), new Byte((byte) 15)};        BondInvestment sendValue = new BondInvestment();        sendValue.setMap(map);        sendValue.setOptions(callOptions);        sendValue.setOptions2(callOptions);        sendValue.setOptions3(callOptions[0]);        sendValue.setWrapperShortArray(wrapperShortArray);        sendValue.setWrapperByteArray(wrapperByteArray);        sendValue.setWrapperDouble(new Double(2323.232D));        sendValue.setWrapperFloat(new Float(23.023F));        sendValue.setWrapperInteger(new Integer(2093));        sendValue.setWrapperShort(new Short((short) 203));        sendValue.setWrapperByte(new Byte((byte) 20));        sendValue.setWrapperBoolean(new Boolean(true));        sendValue.setShortArray(shortArray);        sendValue.setByteArray(byteArray);        date = Calendar.getInstance();        date.setTimeZone(gmt);        date.setTime(new Date(1012937861996L));        sendValue.setCallableDate(date);        sendValue.setBondAmount(new BigDecimal("2675.23"));        sendValue.setPortfolioType(new BigInteger("2093"));        sendValue.setTradeExchange("NYSE");        sendValue.setFiftyTwoWeekHigh(45.012D);        sendValue.setLastTradePrice(87895.32F);        sendValue.setYield(5475L);        sendValue.setStockBeta(32);        sendValue.setDocType((short) 35);        sendValue.setTaxIndicator((byte) 3);        BondInvestment actual = binding.methodBondInvestmentInOut(sendValue);        date.setTime(new Date(1013441507308L));        assertEquals("Returned map is not correct.",                actual.getMap().get("Test"), "Test Works");        assertEquals("The expected and actual values did not match.",                date,                actual.getOptions()[0].getCallDate());        date.setTime(new Date(1013441507328L));        assertEquals("The expected and actual values did not match.",                date,                actual.getOptions()[1].getCallDate());        assertEquals("The expected and actual values did not match.",                new Short((short) 33),                actual.getWrapperShortArray()[0]);        assertEquals("The expected and actual values did not match.",                new Short((short) 86),                actual.getWrapperShortArray()[1]);        assertEquals("The expected and actual values did not match.",                new Byte((byte) 4),                actual.getWrapperByteArray()[0]);        assertEquals("The expected and actual values did not match.",                new Byte((byte) 18),                actual.getWrapperByteArray()[1]);        assertEquals("The expected and actual values did not match.",                new Double(33.232D),                actual.getWrapperDouble());        assertEquals("The expected and actual values did not match.",                new Float(2.23F),                actual.getWrapperFloat());        assertEquals("The expected and actual values did not match.",                new Integer(3),                actual.getWrapperInteger());        assertEquals("The expected and actual values did not match.",                new Short((short) 2),                actual.getWrapperShort());        assertEquals("The expected and actual values did not match.",                new Byte((byte) 21),                actual.getWrapperByte());        assertEquals("The expected and actual values did not match.",                new Boolean(false),                actual.getWrapperBoolean());        assertEquals("The expected and actual values did not match.",                (short) 36,                actual.getShortArray()[0]);        assertEquals("The expected and actual values did not match.",                (byte) 7,                actual.getByteArray()[0]);        date.setTime(new Date(1012937862997L));        assertEquals("The expected and actual values did not match.",                date,                actual.getCallableDate());        assertEquals("The expected and actual values did not match.",                new BigDecimal("2735.23"),                actual.getBondAmount());        assertEquals("The expected and actual values did not match.",                new BigInteger("21093"),                actual.getPortfolioType());        assertEquals("The expected and actual values did not match.",                new String("AMEX"),                actual.getTradeExchange());        assertEquals("The expected and actual values did not match.",                415.012D,                actual.getFiftyTwoWeekHigh(),                DOUBLE_DELTA);        assertEquals("The expected and actual values did not match.",                8795.32F,                actual.getLastTradePrice(),                FLOAT_DELTA);        assertEquals("The expected and actual values did not match.",                575L,                actual.getYield());        assertEquals("The expected and actual values did not match.",                3,                actual.getStockBeta());        assertEquals("The expected and actual values did not match.",                (short) 45,                actual.getDocType());        assertEquals("The expected and actual values did not match.",                (byte) 8,                actual.getTaxIndicator());    } // testRoundtripBondInvestment    /**     *  The BondInvestment class contains all the supported data members:     *  primitives, standard Java classes, arrays, and primitive wrapper     *  classes.  This test insures that a BondInvestment class received     *  by a remote method contains the expected values.     */    public void testBondInvestmentOut() throws RemoteException {        BondInvestment actual = binding.methodBondInvestmentOut();        Calendar date = Calendar.getInstance();        TimeZone gmt = TimeZone.getTimeZone("GMT");        date.setTimeZone(gmt);        date.setTime(new Date(1013441507308L));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -