KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > asap > test > CookbookTestCase


1 /* AsapCookbookTestCase.java */
2
3 package org.enhydra.shark.asap.test;
4
5 /**
6  * JUnit test case for shark web service wrapper.
7  *
8  * @author V.Puskas
9  */

10 import org.enhydra.shark.asap.types.*;
11
12 import java.net.InetAddress JavaDoc;
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
15 import javax.xml.rpc.ServiceException JavaDoc;
16 import org.apache.axis.message.MessageElement;
17 import org.apache.axis.types.URI;
18 import org.enhydra.shark.asap.*;
19 import org.enhydra.shark.asap.AsapFactoryBindingStub;
20 import org.enhydra.shark.asap.SharkWebServiceLocator;
21 import org.enhydra.shark.asap.types.holders.CreateInstanceRsHolder;
22 import org.enhydra.shark.asap.types.holders.GetPropertiesRsHolder;
23 import org.enhydra.shark.asap.types.holders.ResponseHolder;
24
25 public class CookbookTestCase extends junit.framework.TestCase {
26    private static SharkWebServiceLocator swsl = new SharkWebServiceLocator();
27
28    private static URI ik;
29
30    private static String JavaDoc targetService;
31
32    public static final String JavaDoc TARGET_SERVICE = "asap.test.ts";
33
34    public static final String JavaDoc DEFAULT_SERVICE = "http://vajat.prozone.co.yu:8080/axis/services/wfxmlFactoryBinding";
35
36    public CookbookTestCase(java.lang.String JavaDoc name) {
37       super(name);
38       targetService = System.getProperty(TARGET_SERVICE, DEFAULT_SERVICE);
39       System.err.println(TARGET_SERVICE + ":" + targetService);
40    }
41
42    public void testLevel1CreateProcess() throws Exception JavaDoc {
43       AsapFactoryBindingStub binding = getFactroyBinding();
44
45       Request rqHead = new Request();
46       CreateInstanceRq rqBody = new CreateInstanceRq();
47       ResponseHolder rsHead = new ResponseHolder();
48       CreateInstanceRsHolder rsBody = new CreateInstanceRsHolder();
49
50       rqHead.setReceiverKey(new URI(swsl.getasapFactoryBindingAddress()));
51       //rqHead.getReceiverKey().setQueryString("procMgr=test_js%231%23basic");
52
//rqHead.getReceiverKey().setQueryString("procDef=manufacturing&packageId=test_js");
53
//rqHead.getReceiverKey().setQueryString("procDef=Game&packageId=test_js");
54
rqHead.getReceiverKey().setQueryString("procDef=181&packageId=181");
55       //rqHead.getReceiverKey().setQueryString("procDef=manufacturer&packageId=shark_manufacturer");
56
rqBody.setObserverKey(new URI(swsl.getasapObserverBindingAddress()));
57       rqBody.getObserverKey().setHost(InetAddress.getLocalHost()
58          .getHostName());
59       rqBody.setStartImmediately(true);
60       MessageElement[] b = new MessageElement[2];
61       b[0] = new MessageElement("", "product_code");
62       b[0].setValue("52");
63       b[1] = new MessageElement("", "product_quantity");
64       b[1].setValue("69");
65       rqBody.setContextData(new CreateInstanceRqContextData(b));
66       // Test operation
67
binding.createInstance(rqHead, rqBody, rsHead, rsBody);
68       ik = rsBody.value.getInstanceKey();
69       System.out.println("InstanceKey is " + ik);
70    }
71
72    public void testLevel1GetPropsOfProcess() throws Exception JavaDoc {
73       Thread.sleep(10000);
74       AsapInstanceBindingStub binding = getInstanceBinding(ik.toString());
75
76       Request rqHead = new Request(null, ik, YesNoIfError.Yes, "");
77       CreateInstanceRq rqBody = new CreateInstanceRq();
78       ResponseHolder rsHead = new ResponseHolder();
79       GetPropertiesRsHolder rsBody = new GetPropertiesRsHolder();
80       binding.getProperties(rqHead, "", rsHead, rsBody);
81       InstancePropertiesGroup props = rsBody.value.getInstancePropertiesGroup();
82       System.err.println(props.getName());
83       for (int i = 0; i < props.getResultData().get_any().length; i++) {
84          System.err.println(props.getResultData().get_any()[i].getName()
85                             + " = "
86                             + props.getResultData().get_any()[i].getValue());
87       }
88    }
89
90    /*
91     * public void testLevel3factoryGetProperties() throws Exception {
92     * AsapFactoryBindingStub binding = getFactroyBinding(); Request
93     * rqHead = new Request(); String rqBody = ""; // new
94     * java.lang.String() ResponseHolder rsHead = new ResponseHolder();
95     * GetPropertiesRsHolder rsBody = new GetPropertiesRsHolder();
96     * rqHead.setReceiverKey(new URI(targetService));
97     * //rqHead.getReceiverKey().setQueryString("procMgr=test_js%231%23basic");
98     * rqHead.setSenderKey(new
99     * URI("http://interop.i-flow.com/ASAPClient/ObserverService.asmx")); //
100     * Test operation binding.getProperties(rqHead, rqBody, rsHead,
101     * rsBody); // TBD - validate results FactoryPropertiesGroup
102     * fpg=rsBody.value.getFactoryPropertiesGroup();
103     * System.err.println("Key="+fpg.getKey());
104     * System.err.println("Name="+fpg.getName());
105     * System.err.println("Subj="+fpg.getSubject());
106     * System.err.println("desc="+fpg.getDescription());
107     * System.err.println("cds="+fpg.getContextDataSchema().get_any()[0].toString());
108     * System.err.println("rds="+fpg.getResultDataSchema().get_any()[0].toString()); } / *
109     * public void testLevel2Completed() throws Exception {
110     * AsapObserverBindingStub binding; try { binding =
111     * (AsapObserverBindingStub) swsl.getasapObserverBinding(); } catch
112     * (ServiceException jre) { if (jre.getLinkedCause() != null)
113     * jre.getLinkedCause().printStackTrace(); throw new
114     * junit.framework.AssertionFailedError( "JAX-RPC ServiceException
115     * caught: " + jre); } assertNotNull("binding is null", binding); //
116     * Time out after a minute binding.setTimeout(60000); Request rqh =
117     * new Request(); CompletedRq rqb = new CompletedRq();
118     * rqb.setInstanceKey(new URI(swsl.getasapInstanceBindingAddress()));
119     * rqb.setResultData(new CompletedRqResultData()); ResponseHolder rsh =
120     * new ResponseHolder(); ObjectHolder rsb = new ObjectHolder();
121     * rqh.setReceiverKey(new URI(swsl.getasapObserverBindingAddress())); //
122     * Test operation binding.completed(rqh, rqb, rsh, rsb); // TBD -
123     * validate results }
124     */

125    private AsapFactoryBindingStub getFactroyBinding() throws MalformedURLException JavaDoc {
126       AsapFactoryBindingStub ret;
127       try {
128          ret = (AsapFactoryBindingStub) swsl.getasapFactoryBinding(new URL JavaDoc(targetService));
129       } catch (ServiceException JavaDoc jre) {
130          if (jre.getLinkedCause() != null) jre.getLinkedCause()
131             .printStackTrace();
132          throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: "
133                                                         + jre);
134       }
135       assertNotNull("binding is null", ret);
136
137       // Time out after a minute
138
ret.setTimeout(60000);
139       return ret;
140    }
141
142    private AsapInstanceBindingStub getInstanceBinding(String JavaDoc s) throws MalformedURLException JavaDoc {
143       AsapInstanceBindingStub ret;
144       try {
145          ret = (AsapInstanceBindingStub) swsl.getasapInstanceBinding(new URL JavaDoc(s));
146       } catch (ServiceException JavaDoc jre) {
147          if (jre.getLinkedCause() != null) jre.getLinkedCause()
148             .printStackTrace();
149          throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: "
150                                                         + jre);
151       }
152       assertNotNull("binding is null", ret);
153
154       // Time out after a minute
155
ret.setTimeout(60000);
156       return ret;
157    }
158 }
159
160
Popular Tags