KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > jaxrpchandler > JAXRPCHandlerTestCase


1 package test.wsdl.jaxrpchandler;
2
3 import junit.framework.TestCase;
4 import org.apache.axis.client.AdminClient;
5 import org.apache.axis.utils.Admin;
6 import org.apache.axis.utils.Options;
7
8 import javax.xml.namespace.QName JavaDoc;
9 import javax.xml.rpc.handler.HandlerInfo JavaDoc;
10 import javax.xml.rpc.handler.HandlerRegistry JavaDoc;
11 import java.net.URL JavaDoc;
12
13 /**
14  *
15  */

16 public class JAXRPCHandlerTestCase extends TestCase {
17
18     private static boolean _roundtrip = false;
19     private static int _faultRoundtrip = 0;
20
21     public static void completeRoundtrip() {
22         _roundtrip = true;
23     }
24
25     public static void setFaultRoundtrip(int faultCount) {
26         _faultRoundtrip = faultCount;
27     }
28
29
30     /**
31      * Default constructor for use as service
32      */

33     public JAXRPCHandlerTestCase() {
34         super("JAXRPCHandlerTest");
35     }
36
37     public JAXRPCHandlerTestCase(String JavaDoc name) {
38         super(name);
39     }
40
41     public void testStockQuote() throws Exception JavaDoc {
42         String JavaDoc[] args = {};
43         goStockQuote(args);
44     }
45
46     public void testHandleFail() throws Exception JavaDoc {
47         String JavaDoc[] args = {};
48         goFail(args);
49     }
50
51     public void goStockQuote(String JavaDoc[] args) throws Exception JavaDoc {
52         Options opts = new Options( args );
53         args = opts.getRemainingArgs();
54
55         URL JavaDoc url = new URL JavaDoc(opts.getURL());
56         String JavaDoc user = opts.getUser();
57         String JavaDoc passwd = opts.getPassword();
58         System.out.println("URL is " + url);
59
60         _roundtrip = false;
61         doTestDeploy();
62         float val = getQuote(url,false);
63         assertEquals("Stock price is not the expected 55.25 +/- 0.01", val, 55.25, 0.01);
64         assertTrue("Expected setting for config-based handlers should be true", _roundtrip == true);
65         doTestClientUndeploy();
66         _roundtrip = false;
67         val = getQuote(url,true);
68         assertEquals("Stock price is not the expected 55.25 +/- 0.01", val, 55.25, 0.01);
69         assertTrue("Expected setting for programmatic-based handlers should be true", _roundtrip == true);
70         doTestServerUndeploy();
71
72     }
73
74     public void goFail(String JavaDoc[] args) throws Exception JavaDoc {
75         Options opts = new Options( args );
76         args = opts.getRemainingArgs();
77
78         URL JavaDoc url = new URL JavaDoc(opts.getURL());
79         String JavaDoc user = opts.getUser();
80         String JavaDoc passwd = opts.getPassword();
81         System.out.println("Fail URL is " + url);
82
83         _faultRoundtrip = 0;
84         doTestDeploy();
85         try {
86             float val = getQuoteFail(url, true);
87         } catch (Exception JavaDoc e) {
88             // catch and ignore the exception
89
}
90
91         assertTrue("Expected setting for config-based handlers should be 3"
92               + " (1 Request Client Handler increment, passed in header to Server Handler "
93               + " 1 Fault Server Handler increment, passed back in header to Response Client Handler "
94               + " 1 Response Client Handler increment)",
95               _faultRoundtrip == 3);
96
97         doTestClientUndeploy();
98         doTestServerUndeploy();
99
100     }
101
102     public float getQuote (URL JavaDoc url, boolean runJAXRPCHandler) throws Exception JavaDoc {
103         StockQuoteService service = new StockQuoteServiceLocator();
104         if (runJAXRPCHandler) {
105             HandlerRegistry JavaDoc hr = service.getHandlerRegistry();
106             java.util.List JavaDoc lhi = new java.util.Vector JavaDoc();
107             test.wsdl.jaxrpchandler.ClientHandler mh = new test.wsdl.jaxrpchandler.ClientHandler();
108             Class JavaDoc myhandler = mh.getClass();
109             HandlerInfo JavaDoc hi = new HandlerInfo JavaDoc(myhandler,null,null);
110             lhi.add(hi);
111             hr.setHandlerChain(new QName JavaDoc("","jaxrpchandler"),lhi);
112         }
113
114         float res;
115
116         StockQuote sq = service.getjaxrpchandler(url);
117         res = sq.getQuote("XXX");
118
119         return res;
120     }
121
122     public float getQuoteFail (URL JavaDoc url, boolean runJAXRPCHandler) throws Exception JavaDoc {
123         StockQuoteService service = new StockQuoteServiceLocator();
124         if (runJAXRPCHandler) {
125             HandlerRegistry JavaDoc hr = service.getHandlerRegistry();
126             java.util.List JavaDoc lhi = new java.util.Vector JavaDoc();
127             test.wsdl.jaxrpchandler.ClientHandler mh = new test.wsdl.jaxrpchandler.ClientHandler();
128             Class JavaDoc myhandler = mh.getClass();
129             HandlerInfo JavaDoc hi = new HandlerInfo JavaDoc(myhandler,null,null);
130             lhi.add(hi);
131             hr.setHandlerChain(new QName JavaDoc("","jaxrpchandler"),lhi);
132         }
133
134         float res;
135
136         StockQuote sq = service.getjaxrpchandler(url);
137         res = sq.getQuote("fail");
138
139         return res;
140     }
141
142     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
143         JAXRPCHandlerTestCase test = new JAXRPCHandlerTestCase("test");
144         test.goStockQuote(args);
145         test.goFail(args);
146     }
147
148     public void doTestClientUndeploy() throws Exception JavaDoc {
149         String JavaDoc[] args1 = { "client", "test/wsdl/jaxrpchandler/undeploy.wsdd"};
150         Admin.main(args1);
151     }
152
153     public void doTestServerUndeploy() throws Exception JavaDoc {
154         String JavaDoc[] args = { "test/wsdl/jaxrpchandler/undeploy.wsdd"};
155         AdminClient.main(args);
156     }
157
158     public void doTestDeploy() throws Exception JavaDoc {
159         String JavaDoc[] args = { "test/wsdl/jaxrpchandler/server_deploy.wsdd"};
160         AdminClient.main(args);
161         String JavaDoc[] args1 = { "client", "test/wsdl/jaxrpchandler/client_deploy.wsdd"};
162         Admin.main(args1);
163     }
164
165 }
166
Popular Tags