Clover coverage report -
Coverage timestamp: Sat Jul 7 2007 16:41:13 CEST
file stats: LOC: 153   Methods: 10
NCLOC: 97   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
WsPingTest.java 83.3% 95.8% 100% 94.3%
coverage coverage
 1    /*
 2    * WsPingTest.java
 3    *
 4    * Created on January 2, 2007, 8:38 PM
 5    *
 6    * To change this template, choose Tools | Template Manager
 7    * and open the template in the editor.
 8    */
 9   
 10    package jtr.test.jee.client;
 11   
 12    import java.util.Map;
 13    import java.util.Set;
 14    import java.util.concurrent.ExecutionException;
 15    import java.util.concurrent.Future;
 16   
 17    import javax.xml.bind.JAXBElement;
 18   
 19    import jtr.runners.AbstractWsRunner;
 20    import jtr.test.IOutcome;
 21    import jtr.test.jee.ping.client.IncrementMultResult;
 22    import jtr.test.jee.ping.client.IncrementMultResultResponse;
 23    import jtr.test.jee.ping.client.ObjectFactory;
 24    import jtr.test.jee.ping.client.Ping;
 25    import jtr.test.jee.ping.client.PingResponse;
 26    import jtr.ws.IWsResponse;
 27    import jtr.ws.IWsResponseListener;
 28    import jtr.ws.WsProviderException;
 29   
 30    /**
 31    *
 32    * @author frusso
 33    */
 34    public class WsPingTest extends AbstractWsRunner{
 35   
 36    /**
 37    * Creates a new instance of WsPingTest
 38    */
 39  20 public WsPingTest() {
 40    }
 41   
 42  6000 public void test() throws Throwable {
 43  6000 userMsg = "Using WS-binding "+getBinding().getUniqueName();
 44  6000 if(getBinding().getUniqueName().contains("pingWS")) {
 45  2000 testSynchInvocation();
 46    } else {
 47  4000 if(getBinding().getUniqueName().contains("oneWayWS")) {
 48  2000 testOneWayInvocation();
 49  2000 } else if(getBinding().getUniqueName().contains("inoutWS")) {
 50  2000 testIncrementMultResult();
 51    }
 52    }
 53    }
 54   
 55  2000 private void testSynchInvocation() throws WsProviderException, InterruptedException, ExecutionException {
 56    //**************
 57    // paramter
 58  2000 ObjectFactory of = new ObjectFactory();
 59  2000 Ping ping = new Ping();
 60  2000 ping.setPinger(getName());
 61  2000 JAXBElement<Ping> pingReq = of.createPing(ping);
 62    //**********************
 63    // req-rsp invocation
 64  2000 JAXBElement<PingResponse> pong = (JAXBElement<PingResponse>) invoke(getBinding(), pingReq);
 65  1999 System.out.println("WS Received PONG: "+pong.getValue().getReturn()); //getValue().getResult());
 66   
 67   
 68    //*******************
 69    // 1-way invocation
 70  2000 invokeOneWay(getBinding(), pingReq);
 71    //******************************************
 72    // asynch-invocation with response-listener
 73  2000 Future res = invokeAsync(getBinding(), pingReq, new IWsResponseListener() {
 74  1999 public void handleResponse(IWsResponse rsp) {
 75  1999 try {
 76  1999 if(rsp!=null) {
 77  2000 System.out.println("\nWS Received asynch-listened for PONG: "+((JAXBElement<PingResponse>)rsp.get()).getValue().getReturn());
 78  2000 responseInspection(rsp);
 79    }
 80    } catch (ExecutionException ex) {
 81  0 ex.printStackTrace();
 82    } catch (InterruptedException ex) {
 83  0 ex.printStackTrace();
 84    }
 85    }
 86    });
 87  2000 System.out.print("WS Waiting for a response ");
 88  2000 while(!res.isDone()) {
 89  4834633 System.out.print(".");
 90    }
 91  2000 System.out.println("\nWS Received!");
 92   
 93   
 94    //*********************************
 95    // asynch-invocation with polling
 96  2000 IWsResponse rsp = invokeAsync(getBinding(), pingReq);
 97  2000 System.out.print("WS Waiting for a response ");
 98  2000 while(!rsp.isDone()) {
 99  1611653 System.out.print(".");
 100    }
 101  2000 System.out.println("\nWS Received asynch PONG: "+((JAXBElement<PingResponse>)rsp.get()).getValue().getReturn());
 102  2000 responseInspection(rsp);
 103    }
 104   
 105    // I'm unable to use a String[] as parameter
 106  2000 private void testOneWayInvocation() throws WsProviderException {
 107  2000 userMsg = userMsg + "\nThis invocation should fail.";
 108  2000 invokeOneWay(getBinding(), new String[] {"foo","bar"});
 109    }
 110   
 111    // At deploy time JBoss-4.0.5 complaints for a javax.xml.ws.Holder class not found exception
 112    // so i am unable to use INOUT params
 113    // JBoss-5 ships with the missing jboss-jaxws.jar file: these type of parameters must be tested
 114    // against this new version
 115  2000 private void testIncrementMultResult() throws WsProviderException {
 116  2000 ObjectFactory of = new ObjectFactory();
 117  2000 IncrementMultResult par = of.createIncrementMultResult();
 118  2000 par.setArg0(12.333);
 119  2000 par.setArg1(2.123);
 120  2000 par.setArg2(12.333*2.123);
 121  2000 JAXBElement<IncrementMultResult> parReq = of.createIncrementMultResult(par);
 122   
 123  2000 JAXBElement<IncrementMultResultResponse> rsp = (JAXBElement) invoke(getBinding(), parReq);
 124  2000 System.out.println("WS Received: "+rsp.getValue());
 125    }
 126   
 127    /**
 128    * This method shows how it is possible to inspect the context associated with the
 129    * response by means of the IWsResponse interface. Invocations over its instances
 130    * are actually proxied to instances of 'javax.xml.ws.Response<T>'.
 131    */
 132  4000 private void responseInspection(IWsResponse rsp) {
 133  4000 System.out.println("WS Exploring the context...");
 134  4000 Map<String,Object> ctx = rsp.getContext();
 135  4000 Set<Map.Entry<String,Object>> entrySet = ctx.entrySet();
 136  3999 System.out.println();
 137  4000 for(Map.Entry<String,Object> entry : entrySet) {
 138  52000 System.out.println("WS KEY: "+entry.getKey()+", VALUE: "+entry.getValue());
 139    }
 140    }
 141   
 142  2000 public void receiveFailureNotification(Throwable throwable, String string) {
 143    }
 144   
 145  20 public void cleanupResources() {
 146    }
 147   
 148  6000 public void enrichOutcome(IOutcome outcome) {
 149  6000 outcome.setUserObject(userMsg);
 150    }
 151   
 152    private String userMsg;
 153    }