1 16 17 package test.functional; 18 19 import junit.framework.AssertionFailedError; 20 import junit.framework.TestCase; 21 import org.apache.axis.EngineConfiguration; 22 import org.apache.axis.SimpleTargetedChain; 23 import org.apache.axis.client.Call; 24 import org.apache.axis.client.Service; 25 import org.apache.axis.components.logger.LogFactory; 26 import org.apache.axis.configuration.DefaultEngineConfigurationFactory; 27 import org.apache.axis.configuration.SimpleProvider; 28 import org.apache.axis.encoding.XMLType; 29 import org.apache.commons.logging.Log; 30 import samples.transport.tcp.AdminClient; 31 import samples.transport.tcp.GetQuote; 32 import samples.transport.tcp.TCPSender; 33 34 import javax.xml.namespace.QName ; 35 import javax.xml.rpc.ParameterMode ; 36 import java.net.URL ; 37 38 40 public class TestTCPTransportSample extends TestCase { 41 static Log log = 42 LogFactory.getLog(TestTCPTransportSample.class.getName()); 43 44 public TestTCPTransportSample(String name) { 45 super(name); 46 } 47 48 public void doTestDeploy () throws Exception { 49 String [] args = { "-ltcp://localhost:8088", "samples/transport/deploy.wsdd" }; 50 AdminClient.main(args); 51 } 52 53 public void doTestUndeploy () throws Exception { 54 String [] args = { "-ltcp://localhost:8088", "samples/stock/undeploy.wsdd" }; 55 AdminClient.main(args); 56 } 57 58 public void doTestStock() throws Exception { 59 try { 60 log.info("Testing TCP stock service..."); 61 GetQuote tester = new GetQuote(); 62 tester.getQuote(new String [] { "-ltcp://localhost:8088", "XXX" }); 63 String symbol = "XXX"; 65 EngineConfiguration defaultConfig = 66 (new DefaultEngineConfigurationFactory()). 67 getClientEngineConfig(); 68 SimpleProvider config = new SimpleProvider(defaultConfig); 69 SimpleTargetedChain c = new SimpleTargetedChain(new TCPSender()); 70 config.deployTransport("tcp", c); 71 72 Service service = new Service(config); 73 74 Call call = (Call) service.createCall(); 75 76 call.setTargetEndpointAddress( new URL ("tcp://localhost:8088") ); 77 call.setOperationName( new QName ("urn:xmltoday-delayed-quotes", "getQuote") ); 78 call.addParameter( "symbol", XMLType.XSD_STRING, ParameterMode.IN ); 79 call.setReturnType( XMLType.XSD_FLOAT ); 80 81 Object ret = call.invoke( 82 "urn:xmltoday-delayed-quotes", "getQuote", 83 new Object [] {symbol} ); 84 if (ret instanceof Float ) { 85 Float res = (Float ) ret; 86 assertEquals("TestTCPTransportSample: stock price should be 55.25 +/- 0.000001", res.floatValue(), 55.25, 0.000001); 87 } else { 88 throw new AssertionFailedError("Bad return value from TCP stock test: "+ret); 89 } 90 } 91 92 catch( Exception e ) { 94 e.printStackTrace(); 95 throw new AssertionFailedError("Fault returned from TCP stock test: "+e); 96 } 97 } 98 99 public void testTCPTransportSample () throws Exception { 100 try { 101 log.info("Testing TCP transport."); 102 103 log.info("Testing deployment..."); 104 doTestDeploy(); 105 log.info("OK!"); 106 107 log.info("Testing service..."); 108 doTestStock(); 109 log.info("OK!"); 110 111 120 log.info("Test complete."); 121 } 122 catch( Exception e ) { 123 e.printStackTrace(); 124 throw new AssertionFailedError("Fault returned from test: "+e); 125 } 126 } 127 128 public static void main(String [] args) 129 { 130 TestTCPTransportSample tester = new TestTCPTransportSample("TCP test"); 131 try { 132 tester.testTCPTransportSample(); 133 } catch (Exception e) { 134 } 135 } 136 137 } 138 139 | Popular Tags |