KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > faults > FaultServiceTestCase


1 /**
2  * FaultServiceTestCase.java
3  *
4  * This file was auto-generated from WSDL
5  * by the Apache Axis Wsdl2java emitter.
6  */

7
8 package test.wsdl.faults;
9
10
11
12
13 public class FaultServiceTestCase extends junit.framework.TestCase {
14     public FaultServiceTestCase(String JavaDoc name) {
15         super(name);
16     }
17
18     /* FIXME: RUNTIME WSDL broken.
19     public void testFaultServiceWSDL() throws Exception {
20         javax.xml.rpc.ServiceFactory serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();
21         java.net.URL url = new java.net.URL(new test.wsdl.faults.FaultServiceLocator().getFaultServiceAddress() + "?WSDL");
22         javax.xml.rpc.Service service = serviceFactory.createService(url, new test.wsdl.faults.FaultServiceLocator().getServiceName());
23         assertTrue(service != null);
24     }
25     */

26
27     public void testFaultServiceGetQuote() {
28         test.wsdl.faults.FaultServicePortType binding;
29         try {
30             binding = new FaultServiceLocator().getFaultService();
31         }
32         catch (javax.xml.rpc.ServiceException JavaDoc jre) {
33             throw new junit.framework.
34
                    AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
35         }
36         assertTrue("binding is null", binding != null);
37         String JavaDoc symbol = new String JavaDoc("MACR");
38         try {
39             float value = 0;
40             value = binding.getQuote(symbol);
41             fail("Should raise an InvalidTickerFault");
42         }
43         catch (InvalidTickerFaultMessage tickerFault) {
44             assertEquals("Ticker Symbol in Fault doesn't match original argument",
45                     symbol, tickerFault.getTickerSymbol());
46         }
47         catch (org.apache.axis.AxisFault e) {
48             throw new junit.framework.
49
                    AssertionFailedError("AxisFault caught: " + e);
50         }
51         catch (java.rmi.RemoteException JavaDoc re) {
52             throw new junit.framework.
53
                    AssertionFailedError("Remote Exception caught: " + re );
54         }
55     }
56
57     public void testFaultServiceThrowFault() throws Exception JavaDoc {
58         test.wsdl.faults.FaultServicePortType binding;
59         try {
60             binding = new FaultServiceLocator().getFaultService();
61         }
62         catch (javax.xml.rpc.ServiceException JavaDoc jre) {
63             throw new junit.framework.
64
                    AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
65         }
66         assertTrue("binding is null", binding != null);
67         int a = 7;
68         String JavaDoc b = "test";
69         float c = 3.14F;
70             
71         try {
72             float value = 0;
73             value = binding.throwFault(a,b,c);
74             fail("Should raise a DerivedFault");
75         }
76         // We are expecting DerivedFault2 (the operation indicates
77
// that it throws a DerivedFault, but we know the impl actually
78
// throws DerivedFault2 which extends DerivedFault)
79
catch (DerivedFault2 e) {
80             assertEquals("Param A in DerivedFault2 doesn't match original",
81                     a, e.getA());
82             assertEquals("Param B in DerivedFault2 doesn't match original",
83                     b, e.getB());
84             assertEquals("Param C in DerivedFault2 doesn't match original",
85                     c, e.getC(), 0.01F);
86         }
87         catch (DerivedFault e) {
88             throw new junit.framework.
89
                    AssertionFailedError("DerivedFault caught: " + e);
90         }
91         catch (BaseFault e) {
92             throw new junit.framework.
93
                    AssertionFailedError("BaseFault caught: " + e);
94         }
95     }
96
97     public void testFaultServiceThrowExtensionFault() {
98         test.wsdl.faults.FaultServicePortType binding;
99         try {
100             binding = new FaultServiceLocator().getFaultService();
101         }
102         catch (javax.xml.rpc.ServiceException JavaDoc jre) {
103             throw new junit.framework.
104
                    AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
105         }
106         assertTrue("binding is null", binding != null);
107         String JavaDoc description = "test";
108             
109         try {
110             int value = 0;
111             value = binding.throwExtensionFault(description);
112             fail("Should raise an ExtensionFault");
113         }
114         catch (ExtensionFault e) {
115             try {
116                 assertEquals("ExtensionFault extension element does not match original",
117                         description, e.getExtension().get_any()[0].getAsDOM().getTagName());
118             } catch (Exception JavaDoc domError) {
119                 throw new junit.framework.
120
                    AssertionFailedError("DOM Exception caught: " + domError);
121             }
122         }
123         catch (org.apache.axis.AxisFault e) {
124             throw new junit.framework.
125
                    AssertionFailedError("AxisFault caught: " + e);
126         }
127         catch (java.rmi.RemoteException JavaDoc re) {
128             throw new junit.framework.
129
                    AssertionFailedError("Remote Exception caught: " + re );
130         }
131     }
132
133 }
134
135
Popular Tags