1 2 3 package org.enhydra.shark.wfxml.test; 4 5 10 import java.io.ByteArrayInputStream ; 11 import java.net.*; 12 13 import javax.xml.parsers.DocumentBuilderFactory ; 14 import javax.xml.rpc.ServiceException ; 15 import javax.xml.soap.SOAPException ; 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 ; 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 targetService; 35 36 public static final String TARGET_SERVICE = "asap.test.ts"; 37 38 public static final String DEFAULT_SERVICE = "http://vajat:8080/axis/services/wfxmlFactoryBinding"; 39 40 public CookbookTestCase(java.lang.String 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 { 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 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 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 { 77 WfXmlFactoryBindingStub binding = getFactoryBinding(); 78 79 Request rqHead = new Request(); 80 String rqBody = ""; 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.setSenderKey(new URI("http://interop.i-flow.com/ASAPClient/ObserverService.asmx")); 86 87 binding.getProperties(rqHead, rqBody, rsHead, rsBody); 89 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 { 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 114 rqBody.setProcessLanguage("XPDL"); 115 rqBody.setDefinition(new NewDefinitionRqDefinition()); 116 String 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 (a)); 139 MessageElement main = convertToMessageElement(b.getFirstChild()); 140 rqBody.getDefinition().set_any(new MessageElement[] { 141 main 142 }); 143 binding.newDefinition(rqHead, rqBody, rsHead, rsBody); 149 151 } 152 153 public void testRegistryListDefinitions() throws Exception { 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 165 rqBody.setName("basic"); 166 rqBody.setStatus("1"); 167 binding.listDefinitions(rqHead, rqBody, rsHead, rsBody); 169 } 171 172 public void testRegistrySetPropeties() throws Exception { 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 184 rqBody.setKey(targetService); 185 binding.setProperties(rqHead, rqBody, rsHead, rsBody); 187 } 189 190 191 public void testRegistryGetPropeties() throws Exception { 192 WfXmlRegistryBindingStub binding = getRegistryBinding(); 193 194 Request rqHead = new Request(); 195 String rqBody = ""; 196 ResponseHolder rsHead = new ResponseHolder(); 197 GetPropertiesRsHolder rsBody = new GetPropertiesRsHolder(); 198 rqHead.setReceiverKey(new URI(targetService)); 199 203 binding.getProperties(rqHead, rqBody, rsHead, rsBody); 205 } 207 208 public void testFactoryGetDefinition() throws Exception { 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.setSenderKey(new URI("http://interop.i-flow.com/ASAPClient/ObserverService.asmx")); 218 219 rqBody.setProcessLanguage("XDPL"); 220 binding.getDefinition(rqHead, rqBody, rsHead, rsBody); 222 } 224 225 public void testFactorySetDefinition() throws Exception { 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.setSenderKey(new URI("http://interop.i-flow.com/ASAPClient/ObserverService.asmx")); 235 236 rqBody.setProcessLanguage("XPDL"); 237 rqBody.setDefinition(new SetDefinitionRqDefinition()); 238 String 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 (a)); 261 MessageElement main = convertToMessageElement(b.getFirstChild()); 262 rqBody.getDefinition().set_any(new MessageElement[] { 263 main 264 }); 265 binding.setDefinition(rqHead, rqBody, rsHead, rsBody); 267 } 269 270 275 private MessageElement convertToMessageElement(Node node) throws SOAPException { 276 if (Node.TEXT_NODE == node.getNodeType()) { 277 return new MessageElement((CharacterData ) node); 278 } 279 MessageElement ret = new MessageElement(node.getNodeName(), "xpdl", "http://www.wfmc.org/2002/XPDL1.0"); 280 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 318 private WfXmlFactoryBindingStub getFactoryBinding() throws MalformedURLException { 319 WfXmlFactoryBindingStub ret; 320 try { 321 ret = (WfXmlFactoryBindingStub) swsl.getwfxmlFactoryBinding(new URL(targetService)); 322 } catch (ServiceException 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 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 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 ret.setTimeout(60000); 349 return ret; 350 } 351 } 352 353 | Popular Tags |