KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > wsdl > stubheaders > StubHeaderServiceTestCase


1 /**
2  * StubHeaderServiceTestCase.java
3  *
4  * Test case. Add a SOAP header using the Stub APIs and make sure the
5  * service returns a SOAP header that we can read.
6  */

7
8 package test.wsdl.stubheaders;
9
10 import org.apache.axis.message.SOAPHeaderElement;
11
12 public class StubHeaderServiceTestCase extends junit.framework.TestCase {
13     public StubHeaderServiceTestCase(java.lang.String JavaDoc name) {
14         super(name);
15     }
16
17     public void testStubHeaderServiceWSDL() throws Exception JavaDoc {
18         javax.xml.rpc.ServiceFactory JavaDoc serviceFactory = javax.xml.rpc.ServiceFactory.newInstance();
19         java.net.URL JavaDoc url = new java.net.URL JavaDoc(new test.wsdl.stubheaders.StubHeaderServiceLocator().getStubHeaderServiceAddress() + "?WSDL");
20         javax.xml.rpc.Service JavaDoc service = serviceFactory.createService(url, new test.wsdl.stubheaders.StubHeaderServiceLocator().getServiceName());
21         assertTrue(service != null);
22     }
23
24     public void test1StubHeaderServiceEcho() throws Exception JavaDoc {
25         StubHeaderStub binding;
26         try {
27             binding = (test.wsdl.stubheaders.StubHeaderStub)
28                           new StubHeaderServiceLocator().getStubHeaderService();
29         }
30         catch (javax.xml.rpc.ServiceException JavaDoc jre) {
31             if(jre.getLinkedCause()!=null)
32                 jre.getLinkedCause().printStackTrace();
33             throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
34         }
35         assertNotNull("binding is null", binding);
36
37         // Time out after a minute
38
binding.setTimeout(60000);
39
40         // Set header value via the Stub API
41
binding.setHeader("http://test.org/inputheader", "headerin", "inputvalue");
42
43         // Test operation
44
java.lang.String JavaDoc value = null;
45         value = binding.echo(new java.lang.String JavaDoc());
46
47         // validate input header was echoed back
48
assertEquals("Request header did not reach service", "inputvalue", value);
49
50         // Check that getting the list of response headers works
51
SOAPHeaderElement[] hdrs = binding.getResponseHeaders();
52         assertEquals("List of response headers has the wrong number", 1, hdrs.length );
53
54         // Get response header using ONLY the Stub API
55
SOAPHeaderElement hdr = binding.getResponseHeader("http://test.org/outputheader", "headerout");
56         assertNotNull("Cant find header 'headerout' in response", hdr);
57         assertNotNull("Header object value is NULL", hdr.getObjectValue());
58         assertEquals("Response header did not arrive as expected", "outputvalue", hdr.getObjectValue());
59
60         // Everything is OK
61
}
62
63 }
64
Popular Tags