KickJava   Java API By Example, From Geeks To Geeks.

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


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

10 import java.io.ByteArrayInputStream JavaDoc;
11 import java.net.*;
12
13 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
14 import javax.xml.rpc.ServiceException JavaDoc;
15 import javax.xml.soap.SOAPException JavaDoc;
16
17 import org.apache.axis.message.MessageElement;
18 import org.apache.axis.types.URI;
19 import org.enhydra.shark.asap.types.*;
20 import org.enhydra.shark.asap.types.holders.CreateInstanceRsHolder;
21 import org.enhydra.shark.asap.types.holders.ResponseHolder;
22 import org.enhydra.shark.wfxml.*;
23 import org.enhydra.shark.wfxml.types.*;
24 import org.enhydra.shark.wfxml.types.SetPropertiesRq;
25 import org.enhydra.shark.wfxml.types.holders.*;
26 import org.w3c.dom.*;
27 import org.w3c.dom.CharacterData JavaDoc;
28
29 public class CookbookTestCase extends junit.framework.TestCase {
30     private static SharkWebServiceLocator swsl = new SharkWebServiceLocator();
31
32     private static URI ik;
33
34     private static String JavaDoc targetService;
35
36     public static final String JavaDoc TARGET_SERVICE = "asap.test.ts";
37
38     public static final String JavaDoc DEFAULT_SERVICE = "http://vajat:8080/axis/services/wfxmlFactoryBinding";
39
40     public CookbookTestCase(java.lang.String JavaDoc name) {
41         super(name);
42         targetService = System.getProperty(TARGET_SERVICE, DEFAULT_SERVICE);
43         System.err.println(TARGET_SERVICE + ":" + targetService);
44     }
45
46     /**/
47     public void testLevel1CreateProcess() throws Exception JavaDoc {
48         WfXmlFactoryBindingStub binding = getFactoryBinding();
49
50         Request rqHead = new Request();
51         CreateInstanceRq rqBody = new CreateInstanceRq();
52         ResponseHolder rsHead = new ResponseHolder();
53         CreateInstanceRsHolder rsBody = new CreateInstanceRsHolder();
54
55         rqHead.setReceiverKey(new URI(swsl.getwfxmlFactoryBindingAddress()));
56         //rqHead.getReceiverKey().setQueryString("procMgr=test_js%231%23basic");
57
//rqHead.getReceiverKey().setQueryString("procDef=manufacturing&packageId=test_js");
58
//rqHead.getReceiverKey().setQueryString("procDef=Game&packageId=test_js");
59
rqBody.setObserverKey(new URI(swsl.getasapObserverBindingAddress()));
60         rqBody.getObserverKey().setHost(InetAddress.getLocalHost()
61             .getHostName());
62         rqBody.setStartImmediately(true);
63         rqBody.setName("some fine name");
64         MessageElement[] b = new MessageElement[2];
65         b[0] = new MessageElement("", "P1");
66         b[0].setValue("2");
67         b[1] = new MessageElement("", "P2");
68         b[1].setValue("1");
69         rqBody.setContextData(new CreateInstanceRqContextData(b));
70         // Test operation
71
binding.createInstance(rqHead, rqBody, rsHead, rsBody);
72         ik = rsBody.value.getInstanceKey();
73         System.out.println("InstanceKey is " + ik);
74     }
75
76     public void testLevel3factoryGetProperties() throws Exception JavaDoc {
77         WfXmlFactoryBindingStub binding = getFactoryBinding();
78
79         Request rqHead = new Request();
80         String JavaDoc rqBody = ""; // new java.lang.String()
81
ResponseHolder rsHead = new ResponseHolder();
82         org.enhydra.shark.asap.types.holders.GetPropertiesRsHolder rsBody = new org.enhydra.shark.asap.types.holders.GetPropertiesRsHolder();
83         rqHead.setReceiverKey(new URI(targetService));
84         //rqHead.getReceiverKey().setQueryString("procMgr=test_js%231%23basic");
85
rqHead.setSenderKey(new URI("http://interop.i-flow.com/ASAPClient/ObserverService.asmx"));
86
87         // Test operation
88
binding.getProperties(rqHead, rqBody, rsHead, rsBody);
89         // TBD - validate results
90
FactoryPropertiesGroup fpg = rsBody.value.getFactoryPropertiesGroup();
91         System.err.println("Key=" + fpg.getKey());
92         System.err.println("Name=" + fpg.getName());
93         System.err.println("Subj=" + fpg.getSubject());
94         System.err.println("desc=" + fpg.getDescription());
95         System.err.println("cds="
96                            + fpg.getContextDataSchema().get_any()[0].toString());
97         System.err.println("rds="
98                            + fpg.getResultDataSchema().get_any()[0].toString());
99     }
100     /**/
101
102     public void testRegistryNewDefinition() throws Exception JavaDoc {
103         WfXmlRegistryBindingStub binding = getRegistryBinding();
104
105         Request rqHead = new Request();
106         NewDefinitionRq rqBody = new NewDefinitionRq();
107         ResponseHolder rsHead = new ResponseHolder();
108         NewDefinitionRsHolder rsBody = new NewDefinitionRsHolder();
109         rqHead.setReceiverKey(new URI(targetService));
110         //rqHead.getReceiverKey().setQueryString("procMgr=test_js%231%23basic");
111
//rqHead.setSenderKey(new
112
// URI("http://interop.i-flow.com/ASAPClient/ObserverService.asmx"));
113

114         rqBody.setProcessLanguage("XPDL");
115         rqBody.setDefinition(new NewDefinitionRqDefinition());
116         String JavaDoc s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
117                    + "<xpdl:Package Id=\"toTestNewDefinition\""
118                    + " Name=\"Application Repository\""
119                    + " xmlns=\"http://www.wfmc.org/2002/XPDL1.0\""
120                    + " xmlns:xpdl=\"http://www.wfmc.org/2002/XPDL1.0\""
121                    + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
122                    + " xsi:schemaLocation=\"http://www.wfmc.org/2002/XPDL1.0 http://wfmc.org/standards/docs/TC-1025_schema_10_xpdl.xsd\">"
123                    + " <xpdl:PackageHeader>"
124                    + " <xpdl:XPDLVersion>1.0</xpdl:XPDLVersion>"
125                    + " <xpdl:Vendor>Together</xpdl:Vendor>"
126                    + " <xpdl:Created>13-03-2003</xpdl:Created>"
127                    + " <xpdl:Description>Application repository for modified WfMC example of business process</xpdl:Description>"
128                    + " </xpdl:PackageHeader>"
129                    + " <xpdl:RedefinableHeader PublicationStatus=\"RELEASED\"/>"
130                    + " <xpdl:ConformanceClass GraphConformance=\"NON_BLOCKED\"/>"
131                    + " <xpdl:Script Type=\"text/javascript\"/>"
132                    + "</xpdl:Package>";
133         byte[] a = s.getBytes("UTF8");
134         System.err.println("$$" + a.length);
135
136         Document b = DocumentBuilderFactory.newInstance()
137             .newDocumentBuilder()
138             .parse(new ByteArrayInputStream JavaDoc(a));
139         MessageElement main = convertToMessageElement(b.getFirstChild());
140         rqBody.getDefinition().set_any(new MessageElement[] {
141             main
142         });
143         //rqBody.getDefinition().set_any(new MessageElement[] {/*new
144
// MessageElement("Package","","")*/});
145
// Test operation
146
// binding.getProperties(rqHead,"",rsHead, new
147
// GetPropertiesRsHolder());
148
binding.newDefinition(rqHead, rqBody, rsHead, rsBody);
149         // TBD - validate results
150

151     }
152
153     public void testRegistryListDefinitions() throws Exception JavaDoc {
154         WfXmlRegistryBindingStub binding = getRegistryBinding();
155
156         Request rqHead = new Request();
157         ListDefinitionsRq rqBody = new ListDefinitionsRq();
158         ResponseHolder rsHead = new ResponseHolder();
159         ListDefinitionsRsHolder rsBody = new ListDefinitionsRsHolder();
160         rqHead.setReceiverKey(new URI(targetService));
161         //rqHead.getReceiverKey().setQueryString("procMgr=test_js%231%23basic");
162
//rqHead.setSenderKey(new
163
// URI("http://interop.i-flow.com/ASAPClient/ObserverService.asmx"));
164

165         rqBody.setName("basic");
166         rqBody.setStatus("1");
167         // Test operation
168
binding.listDefinitions(rqHead, rqBody, rsHead, rsBody);
169         // TBD - validate results
170
}
171
172     public void testRegistrySetPropeties() throws Exception JavaDoc {
173         WfXmlRegistryBindingStub binding = getRegistryBinding();
174
175         Request rqHead = new Request();
176         org.enhydra.shark.wfxml.types.SetPropertiesRq rqBody = new SetPropertiesRq();
177         ResponseHolder rsHead = new ResponseHolder();
178         SetPropertiesRsHolder rsBody = new SetPropertiesRsHolder();
179         rqHead.setReceiverKey(new URI(targetService));
180         //rqHead.getReceiverKey().setQueryString("procMgr=test_js%231%23basic");
181
//rqHead.setSenderKey(new
182
// URI("http://interop.i-flow.com/ASAPClient/ObserverService.asmx"));
183

184         rqBody.setKey(targetService);
185         // Test operation
186
binding.setProperties(rqHead, rqBody, rsHead, rsBody);
187         // TBD - validate results
188
}
189     
190
191     public void testRegistryGetPropeties() throws Exception JavaDoc {
192         WfXmlRegistryBindingStub binding = getRegistryBinding();
193
194         Request rqHead = new Request();
195         String JavaDoc rqBody = "";
196         ResponseHolder rsHead = new ResponseHolder();
197         GetPropertiesRsHolder rsBody = new GetPropertiesRsHolder();
198         rqHead.setReceiverKey(new URI(targetService));
199         //rqHead.getReceiverKey().setQueryString("procMgr=test_js%231%23basic");
200
//rqHead.setSenderKey(new
201
// URI("http://interop.i-flow.com/ASAPClient/ObserverService.asmx"));
202

203         // Test operation
204
binding.getProperties(rqHead, rqBody, rsHead, rsBody);
205         // TBD - validate results
206
}
207     
208     public void testFactoryGetDefinition() throws Exception JavaDoc {
209         WfXmlFactoryBindingStub binding = getFactoryBinding();
210
211         Request rqHead = new Request();
212         GetDefinitionRq rqBody = new GetDefinitionRq();
213         ResponseHolder rsHead = new ResponseHolder();
214         GetDefinitionRsHolder rsBody = new GetDefinitionRsHolder();
215         rqHead.setReceiverKey(new URI(targetService));
216         //rqHead.getReceiverKey().setQueryString("procMgr=test_js%231%23basic");
217
rqHead.setSenderKey(new URI("http://interop.i-flow.com/ASAPClient/ObserverService.asmx"));
218
219         rqBody.setProcessLanguage("XDPL");
220         // Test operation
221
binding.getDefinition(rqHead, rqBody, rsHead, rsBody);
222         // TBD - validate results
223
}
224     
225     public void testFactorySetDefinition() throws Exception JavaDoc {
226         WfXmlFactoryBindingStub binding = getFactoryBinding();
227
228         Request rqHead = new Request();
229         SetDefinitionRq rqBody = new SetDefinitionRq();
230         ResponseHolder rsHead = new ResponseHolder();
231         SetDefinitionRsHolder rsBody = new SetDefinitionRsHolder();
232         rqHead.setReceiverKey(new URI(targetService));
233         //rqHead.getReceiverKey().setQueryString("procMgr=test_js%231%23basic");
234
rqHead.setSenderKey(new URI("http://interop.i-flow.com/ASAPClient/ObserverService.asmx"));
235
236         rqBody.setProcessLanguage("XPDL");
237         rqBody.setDefinition(new SetDefinitionRqDefinition());
238         String JavaDoc s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
239                    + "<xpdl:Package Id=\"Application_Repository\""
240                    + " Name=\"Application Repository\""
241                    + " xmlns=\"http://www.wfmc.org/2002/XPDL1.0\""
242                    + " xmlns:xpdl=\"http://www.wfmc.org/2002/XPDL1.0\""
243                    + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
244                    + " xsi:schemaLocation=\"http://www.wfmc.org/2002/XPDL1.0 http://wfmc.org/standards/docs/TC-1025_schema_10_xpdl.xsd\">"
245                    + " <xpdl:PackageHeader>"
246                    + " <xpdl:XPDLVersion>1.0</xpdl:XPDLVersion>"
247                    + " <xpdl:Vendor>Together</xpdl:Vendor>"
248                    + " <xpdl:Created>13-03-2003</xpdl:Created>"
249                    + " <xpdl:Description>Application repository for modified WfMC example of business process</xpdl:Description>"
250                    + " </xpdl:PackageHeader>"
251                    + " <xpdl:RedefinableHeader PublicationStatus=\"RELEASED\"/>"
252                    + " <xpdl:ConformanceClass GraphConformance=\"NON_BLOCKED\"/>"
253                    + " <xpdl:Script Type=\"text/javascript\"/>"
254                    + "</xpdl:Package>";
255         byte[] a = s.getBytes("UTF8");
256         System.err.println("$$" + a.length);
257
258         Document b = DocumentBuilderFactory.newInstance()
259             .newDocumentBuilder()
260             .parse(new ByteArrayInputStream JavaDoc(a));
261         MessageElement main = convertToMessageElement(b.getFirstChild());
262         rqBody.getDefinition().set_any(new MessageElement[] {
263             main
264         });
265         // Test operation
266
binding.setDefinition(rqHead, rqBody, rsHead, rsBody);
267         // TBD - validate results
268
}
269     
270     /**
271      * @param node
272      * @return
273      * @throws SOAPException
274      */

275     private MessageElement convertToMessageElement(Node node) throws SOAPException JavaDoc {
276         if (Node.TEXT_NODE == node.getNodeType()) {
277             return new MessageElement((CharacterData JavaDoc) node);
278         }
279         MessageElement ret = new MessageElement(node.getNodeName(), "xpdl", "http://www.wfmc.org/2002/XPDL1.0");
280         // MessageElement ret = new MessageElement("xpdl", node.getNodeName());
281
NamedNodeMap atts = node.getAttributes();
282         if (null != atts) {
283             for (int i = 0; i < atts.getLength(); ++i) {
284                 Node att = atts.item(i);
285                 ret.addAttribute("", att.getNodeName(), att.getNodeValue());
286             }
287         }
288         NodeList children = node.getChildNodes();
289         if (null != children) {
290             for (int i = 0; i < children.getLength(); ++i) {
291                 MessageElement r = convertToMessageElement(children.item(i));
292                 if (null != r) {
293                     ret.addChild(r);
294                 }
295             }
296         }
297         return ret;
298     }
299
300     /*
301      * public void testLevel2Completed() throws Exception {
302      * AsapObserverBindingStub binding; try { binding =
303      * (AsapObserverBindingStub) swsl.getasapObserverBinding(); } catch
304      * (ServiceException jre) { if (jre.getLinkedCause() != null)
305      * jre.getLinkedCause().printStackTrace(); throw new
306      * junit.framework.AssertionFailedError( "JAX-RPC ServiceException
307      * caught: " + jre); } assertNotNull("binding is null", binding); //
308      * Time out after a minute binding.setTimeout(60000); Request rqh =
309      * new Request(); CompletedRq rqb = new CompletedRq();
310      * rqb.setInstanceKey(new
311      * URI(swsl.getasapInstanceBindingAddress())); rqb.setResultData(new
312      * CompletedRqResultData()); ResponseHolder rsh = new
313      * ResponseHolder(); ObjectHolder rsb = new ObjectHolder();
314      * rqh.setReceiverKey(new
315      * URI(swsl.getasapObserverBindingAddress())); // Test operation
316      * binding.completed(rqh, rqb, rsh, rsb); // TBD - validate results }
317      */

318     private WfXmlFactoryBindingStub getFactoryBinding() throws MalformedURLException {
319         WfXmlFactoryBindingStub ret;
320         try {
321             ret = (WfXmlFactoryBindingStub) swsl.getwfxmlFactoryBinding(new URL(targetService));
322         } catch (ServiceException JavaDoc jre) {
323             if (jre.getLinkedCause() != null) jre.getLinkedCause()
324                 .printStackTrace();
325             throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: "
326                                                            + jre);
327         }
328         assertNotNull("binding is null", ret);
329
330         // Time out after a minute
331
ret.setTimeout(60000);
332         return ret;
333     }
334
335     private WfXmlRegistryBindingStub getRegistryBinding() throws MalformedURLException {
336         WfXmlRegistryBindingStub ret;
337         try {
338             ret = (WfXmlRegistryBindingStub) swsl.getwfxmlRegistryBinding(new URL("http://vajat:8080/axis/services/wfxmlRegistryBinding"));
339         } catch (ServiceException JavaDoc jre) {
340             if (jre.getLinkedCause() != null) jre.getLinkedCause()
341                 .printStackTrace();
342             throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: "
343                                                            + jre);
344         }
345         assertNotNull("binding is null", ret);
346
347         // Time out after a minute
348
ret.setTimeout(60000);
349         return ret;
350     }
351 }
352
353
Popular Tags