Debian Codegraph @

test/GenericLocalTest.java

raw
1 /*
2 * Copyright 2002-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 package test;
17
18 import junit.framework.TestCase;
19 import org.apache.axis.client.Call;
20 import org.apache.axis.client.Service;
21 import org.apache.axis.configuration.BasicServerConfig;
22 import org.apache.axis.configuration.SimpleProvider;
23 import org.apache.axis.constants.Style;
24 import org.apache.axis.constants.Use;
25 import org.apache.axis.handlers.soap.SOAPService;
26 import org.apache.axis.providers.java.RPCProvider;
27 import org.apache.axis.server.AxisServer;
28 import org.apache.axis.transport.local.LocalTransport;
29 import org.apache.axis.Handler;
30
31 /**
32 * This is a framework class which handles all the basic stuff necessary
33 * to set up a local "roundtrip" test to an AxisServer.
34 *
35 * To use it - extend this class with your own test. Make sure if you
36 * override setUp() that you call super.setUp() so that the engine gets
37 * initialized correctly. The method deploy() needs to be called to deploy
38 * a target service and set up the transport to talk to it - note that this
39 * is done by default in the no-argument setUp(). If you don't want this
40 * behavior, or want to tweak names/classes, just call super.setUp(false)
41 * instead of super.setUp() and the deploy() call won't happen.
42 *
43 * Then you get a Call object by calling getCall() and you're ready to rock.
44 *
45 * @author Glen Daniels ([email protected])
46 */
47 public class GenericLocalTest extends TestCase {
48 protected AxisServer server;
49 protected SimpleProvider config;
50 protected LocalTransport transport;
51 protected SOAPService service = null;
52
53 public GenericLocalTest(String s) {
54 super(s);
55 }
56
57 /**
58 * Default setUp, which automatically deploys the current class
59 * as a service named "service". Override to switch this off.
60 *
61 * @throws Exception
62 */
63 protected void setUp() throws Exception {
64 setUp(true);
65 }
66
67 /**
68 * setUp which allows controlling whether or not deploy() is called.
69 *
70 * @param deploy indicates whether we should call deploy()
71 * @throws Exception
72 */
73 protected void setUp(boolean deploy) throws Exception {
74 super.setUp();
75 config = new BasicServerConfig();
76 server = new AxisServer(config);
77 transport = new LocalTransport(server);
78
79 if (deploy)
80 deploy();
81 }
82
83 /**
84 * Get an initialized Call, ready to invoke us over the local transport.
85 *
86 * @return an initialized Call object.
87 */
88 public Call getCall() {
89 Call call = new Call(new Service());
90 call.setTransport(transport);
91 return call;
92 }
93
94 /**
95 * Convenience method to deploy ourselves as a service
96 */
97 public void deploy() {
98 deploy("service", this.getClass(), Style.RPC);
99 }
100
101 /**
102 * Deploy a service to the local server we've set up, and point the
103 * cached local transport object to the desired service name.
104 *
105 * After calling this method, the "service" field will contain the
106 * deployed service, on which you could set other options if
107 * desired.
108 *
109 * @param serviceName the name under which to deploy the service.
110 * @param target class of the service.
111 */
112 public void deploy(String serviceName, Class target, Style style) {
113 String className = target.getName();
114
115 service = new SOAPService(new RPCProvider());
116 service.setStyle(style);
117
118 service.setOption("className", className);
119 service.setOption("allowedMethods", "*");
120
121 config.deployService(serviceName, service);
122 transport.setRemoteService(serviceName);
123 }
124
125 public void deploy(String serviceName, Class target, Style style, Use use) {
126 String className = target.getName();
127
128 service = new SOAPService(new RPCProvider());
129 service.setStyle(style);
130 service.setUse(use);
131
132 service.setOption("className", className);
133 service.setOption("allowedMethods", "*");
134
135 config.deployService(serviceName, service);
136 transport.setRemoteService(serviceName);
137 }
138 /**
139 * Deploy a service to the local server we've set up, using a
140 * Handler we provide as the pivot.
141 *
142 * @param serviceName
143 * @param handler
144 */
145 public void deploy(String serviceName, Handler handler) {
146 service = new SOAPService(handler);
147
148 config.deployService(serviceName, service);
149 transport.setRemoteService(serviceName);
150 }
151 }