| 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; |
| 9 |
import javax.xml.rpc.handler.HandlerInfo; |
| 10 |
import javax.xml.rpc.handler.HandlerRegistry; |
| 11 |
import java.net.URL; |
| 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 name) { |
| 38 |
super(name); |
| 39 |
} |
| 40 |
|
| 41 |
public void testStockQuote() throws Exception { |
| 42 |
String[] args = {}; |
| 43 |
goStockQuote(args); |
| 44 |
} |
| 45 |
|
| 46 |
public void testHandleFail() throws Exception { |
| 47 |
String[] args = {}; |
| 48 |
goFail(args); |
| 49 |
} |
| 50 |
|
| 51 |
public void goStockQuote(String[] args) throws Exception { |
| 52 |
Options opts = new Options( args ); |
| 53 |
args = opts.getRemainingArgs(); |
| 54 |
|
| 55 |
URL url = new URL(opts.getURL()); |
| 56 |
String user = opts.getUser(); |
| 57 |
String 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[] args) throws Exception { |
| 75 |
Options opts = new Options( args ); |
| 76 |
args = opts.getRemainingArgs(); |
| 77 |
|
| 78 |
URL url = new URL(opts.getURL()); |
| 79 |
String user = opts.getUser(); |
| 80 |
String 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 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 url, boolean runJAXRPCHandler) throws Exception { |
| 103 |
StockQuoteService service = new StockQuoteServiceLocator(); |
| 104 |
if (runJAXRPCHandler) { |
| 105 |
HandlerRegistry hr = service.getHandlerRegistry(); |
| 106 |
java.util.List lhi = new java.util.Vector(); |
| 107 |
test.wsdl.jaxrpchandler.ClientHandler mh = new test.wsdl.jaxrpchandler.ClientHandler(); |
| 108 |
Class myhandler = mh.getClass(); |
| 109 |
HandlerInfo hi = new HandlerInfo(myhandler,null,null); |
| 110 |
lhi.add(hi); |
| 111 |
hr.setHandlerChain(new QName("","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 url, boolean runJAXRPCHandler) throws Exception { |
| 123 |
StockQuoteService service = new StockQuoteServiceLocator(); |
| 124 |
if (runJAXRPCHandler) { |
| 125 |
HandlerRegistry hr = service.getHandlerRegistry(); |
| 126 |
java.util.List lhi = new java.util.Vector(); |
| 127 |
test.wsdl.jaxrpchandler.ClientHandler mh = new test.wsdl.jaxrpchandler.ClientHandler(); |
| 128 |
Class myhandler = mh.getClass(); |
| 129 |
HandlerInfo hi = new HandlerInfo(myhandler,null,null); |
| 130 |
lhi.add(hi); |
| 131 |
hr.setHandlerChain(new QName("","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[] args) throws Exception { |
| 143 |
JAXRPCHandlerTestCase test = new JAXRPCHandlerTestCase("test"); |
| 144 |
test.goStockQuote(args); |
| 145 |
test.goFail(args); |
| 146 |
} |
| 147 |
|
| 148 |
public void doTestClientUndeploy() throws Exception { |
| 149 |
String[] args1 = { "client", "test/wsdl/jaxrpchandler/undeploy.wsdd"}; |
| 150 |
Admin.main(args1); |
| 151 |
} |
| 152 |
|
| 153 |
public void doTestServerUndeploy() throws Exception { |
| 154 |
String[] args = { "test/wsdl/jaxrpchandler/undeploy.wsdd"}; |
| 155 |
AdminClient.main(args); |
| 156 |
} |
| 157 |
|
| 158 |
public void doTestDeploy() throws Exception { |
| 159 |
String[] args = { "test/wsdl/jaxrpchandler/server_deploy.wsdd"}; |
| 160 |
AdminClient.main(args); |
| 161 |
String[] args1 = { "client", "test/wsdl/jaxrpchandler/client_deploy.wsdd"}; |
| 162 |
Admin.main(args1); |
| 163 |
} |
| 164 |
|
| 165 |
} |