KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > systest > basicDOCBare > DOCBareClientServerTest


1 package org.objectweb.celtix.systest.basicDOCBare;
2
3 import java.lang.annotation.Annotation JavaDoc;
4 import java.lang.reflect.Method JavaDoc;
5 import java.net.URL JavaDoc;
6
7 import javax.jws.WebMethod;
8 import javax.jws.WebParam;
9 import javax.xml.namespace.QName JavaDoc;
10 // import javax.xml.ws.AsyncHandler;
11

12 import javax.xml.ws.Holder;
13
14 import junit.framework.Test;
15 import junit.framework.TestSuite;
16
17 import org.objectweb.celtix.systest.common.ClientServerSetupBase;
18 import org.objectweb.celtix.systest.common.ClientServerTestBase;
19
20 import org.objectweb.hello_world_doc_lit_bare.PutLastTradedPricePortType;
21 import org.objectweb.hello_world_doc_lit_bare.SOAPService;
22 import org.objectweb.hello_world_doc_lit_bare.types.TradePriceData;
23
24 public class DOCBareClientServerTest extends ClientServerTestBase {
25
26     private final QName JavaDoc serviceName = new QName JavaDoc("http://objectweb.org/hello_world_doc_lit_bare",
27                                                 "SOAPService");
28     private final QName JavaDoc portName = new QName JavaDoc("http://objectweb.org/hello_world_doc_lit_bare", "SoapPort");
29
30     public static Test suite() throws Exception JavaDoc {
31         TestSuite suite = new TestSuite(DOCBareClientServerTest.class);
32         return new ClientServerSetupBase(suite) {
33             public void startServers() throws Exception JavaDoc {
34                 assertTrue("server did not launch correctly", launchServer(Server.class));
35             }
36         };
37     }
38
39     public void testBasicConnection() throws Exception JavaDoc {
40         URL JavaDoc wsdl = getClass().getResource("/wsdl/doc_lit_bare.wsdl");
41         assertNotNull("WSDL is null", wsdl);
42
43         SOAPService service = new SOAPService(wsdl, serviceName);
44         assertNotNull("Service is ull ", service);
45
46         PutLastTradedPricePortType putLastTradedPrice = service.getPort(portName,
47                                                                         PutLastTradedPricePortType.class);
48         TradePriceData priceData = new TradePriceData();
49         priceData.setTickerPrice(1.0f);
50         priceData.setTickerSymbol("CELTIX");
51
52         Holder<TradePriceData> holder = new Holder<TradePriceData>(priceData);
53
54         for (int i = 0; i < 5; i++) {
55             putLastTradedPrice.sayHi(holder);
56             assertEquals(4.5f, holder.value.getTickerPrice());
57             assertEquals("OBJECTWEB", holder.value.getTickerSymbol());
58             putLastTradedPrice.putLastTradedPrice(priceData);
59         }
60
61     }
62
63     public void testAnnotation() throws Exception JavaDoc {
64         Class JavaDoc claz = PutLastTradedPricePortType.class;
65         TradePriceData priceData = new TradePriceData();
66         Holder<TradePriceData> holder = new Holder<TradePriceData>(priceData);
67         Method JavaDoc method = claz.getMethod("sayHi", holder.getClass());
68         assertNotNull("Can not find SayHi method in generated class ", method);
69         Annotation JavaDoc ann = method.getAnnotation(WebMethod.class);
70         WebMethod webMethod = (WebMethod)ann;
71         assertEquals(webMethod.operationName(), "SayHi");
72         Annotation JavaDoc[][] paraAnns = method.getParameterAnnotations();
73         for (Annotation JavaDoc[] paraType : paraAnns) {
74             for (Annotation JavaDoc an : paraType) {
75                 if (an.annotationType() == WebParam.class) {
76                     WebParam webParam = (WebParam)an;
77                     assertNotSame("", webParam.targetNamespace());
78                 }
79             }
80         }
81     }
82
83     public static void main(String JavaDoc[] args) {
84         junit.textui.TestRunner.run(DOCBareClientServerTest.class);
85     }
86
87     /*
88      * public static void main(String[] args) { ClientServerTest cst = new
89      * ClientServerTest(); if ("client".equals(args[0])) { try {
90      * cst.testAsyncPollingCall(); } catch (Exception ex) {
91      * ex.printStackTrace(); } System.err.println("Exiting...........");
92      * System.exit(0); } else if ("server".equals(args[0])) { try { //
93      * cst.setUp(); cst.onetimeSetUp(); } catch (Exception ex) {
94      * ex.printStackTrace(); } } else { System.out.println("Invaid arg"); } }
95      */

96
97 }
98
Popular Tags