Debian Codegraph @

test/functional/TestTCPTransportSample.java

raw
1 /*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
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 /** Test the stock sample code.
39 */
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"; // args[0] ;
64
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 // }
93 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 // Commented out for now, because namespaced-based dispatch for the
112 // TCPListener doesn't work yet. Possible solutions:
113 // 1. Deploy the AdminService at the WSDD namespace's name
114 // 2. Build another dispatch mechanism into the TCP transport
115 //
116 // log.info("Testing undeployment...");
117 // doTestUndeploy();
118 // log.info("OK!");
119
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