KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > outparams > TestOutParams


1 package test.outparams;
2
3 import junit.framework.TestCase;
4 import org.apache.axis.Constants;
5 import org.apache.axis.Handler;
6 import org.apache.axis.Message;
7 import org.apache.axis.MessageContext;
8 import org.apache.axis.client.Call;
9 import org.apache.axis.client.Service;
10 import org.apache.axis.configuration.SimpleProvider;
11 import org.apache.axis.encoding.XMLType;
12 import org.apache.axis.handlers.soap.SOAPService;
13 import org.apache.axis.message.SOAPEnvelope;
14 import org.apache.axis.server.AxisServer;
15 import org.apache.axis.transport.local.LocalTransport;
16
17 import javax.xml.namespace.QName JavaDoc;
18 import java.util.Map JavaDoc;
19
20 /**
21  * Test org.apache.axis.handlers.RPCDispatcher
22  *
23  * @author Sam Ruby <rubys@us.ibm.com>
24  */

25 public class TestOutParams extends TestCase {
26     private final String JavaDoc serviceURN = "urn:X-test-outparams";
27
28
29     /** A fixed message, since the return is hardcoded */
30     private final String JavaDoc message =
31         "<?xml version=\"1.0\"?>\n" +
32         "<soap:Envelope " +
33              "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
34              "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
35              "xmlns:xsi=\"" + Constants.URI_DEFAULT_SCHEMA_XSI + "\" " +
36              "xmlns:xsd=\"" + Constants.URI_DEFAULT_SCHEMA_XSD + "\">\n" +
37              "<soap:Body>\n" +
38              "<ns:someMethod xmlns:ns=\"" + serviceURN + "\"/>\n" +
39              "</soap:Body>\n" +
40         "</soap:Envelope>\n";
41
42     private Service s_service = null ;
43     private Call client = null ;
44     private SimpleProvider provider = new SimpleProvider();
45     private AxisServer server = new AxisServer(provider);
46
47     public TestOutParams(String JavaDoc name) {
48         super(name);
49         server.init();
50     }
51
52     /**
53      * Test returning output params
54      */

55     public void testOutputParams() throws Exception JavaDoc {
56         // Register the service
57
Handler h = new ServiceHandler();
58         s_service = new Service();
59         client = (Call) s_service.createCall();
60
61         // ??? Do we need to register the handler?
62

63         SOAPService service = new SOAPService(h);
64         provider.deployService(serviceURN, service);
65
66         // Make sure the local transport uses the server we just configured
67
client.setTransport(new LocalTransport(server));
68
69         // Create the message context
70
MessageContext msgContext = new MessageContext(server);
71
72         // Construct the soap request
73
SOAPEnvelope envelope = new SOAPEnvelope();
74         msgContext.setRequestMessage(new Message(envelope));
75
76         client.addParameter(
77                 new QName JavaDoc("", "string"),
78                 XMLType.XSD_STRING,
79                 javax.xml.rpc.ParameterMode.IN);
80         client.addParameter(
81                 new QName JavaDoc("", "out1"),
82                 XMLType.XSD_STRING,
83                 javax.xml.rpc.ParameterMode.OUT);
84         client.addParameter(
85                 new QName JavaDoc("", "out2"),
86                 XMLType.XSD_FLOAT,
87                 javax.xml.rpc.ParameterMode.OUT);
88         client.setReturnType(XMLType.XSD_INT);
89         // Invoke the Axis server
90
Object JavaDoc ret = client.invoke(serviceURN, "method",
91                                 new Object JavaDoc [] { "test" });
92
93         Map JavaDoc outParams = client.getOutputParams();
94         assertNotNull("No output Params returned!", outParams);
95
96         Object JavaDoc param = outParams.get(new QName JavaDoc(null, "out1"));
97         assertEquals("Param out1 does not equal expected value", ServiceHandler.OUTPARAM1, param);
98
99         param = outParams.get(new QName JavaDoc(null, "out2"));
100         assertEquals("Param out2 does not equal expected value", ServiceHandler.OUTPARAM2, param);
101
102         assertEquals("Return value does not equal expected value", ((Integer JavaDoc)ret).intValue(), ServiceHandler.RESPONSE.intValue());
103     }
104
105     public static void main(String JavaDoc args[])
106     {
107       try {
108         TestOutParams tester = new TestOutParams("RPC test");
109         tester.testOutputParams();
110       } catch (Exception JavaDoc e) {
111         e.printStackTrace();
112       }
113     }
114 }
115
Popular Tags