1 package org.jbpm.bpel.xml; 2 3 import javax.wsdl.Definition; 4 import javax.wsdl.Operation; 5 import javax.wsdl.PortType; 6 import javax.xml.namespace.QName ; 7 8 import junit.framework.TestCase; 9 10 import org.w3c.dom.Element ; 11 import org.xml.sax.SAXException ; 12 13 import org.jbpm.bpel.data.def.VariableDefinition; 14 import org.jbpm.bpel.def.Activity; 15 import org.jbpm.bpel.def.BpelDefinition; 16 import org.jbpm.bpel.def.CompositeActivity; 17 import org.jbpm.bpel.def.ImportsDefinition; 18 import org.jbpm.bpel.service.def.PartnerLinkDefinition; 19 import org.jbpm.bpel.wsdl.def.PartnerLinkType; 20 import org.jbpm.bpel.wsdl.def.Property; 21 import org.jbpm.bpel.wsdl.util.WsdlUtil; 22 import org.jbpm.bpel.xml.util.NodeUtil; 23 24 28 public abstract class AbstractReaderTestCase extends TestCase { 29 30 protected BpelReader reader; 31 protected BpelDefinition pd; 32 protected TestScope scope; 33 protected PartnerLinkDefinition pLink; 34 protected Operation operation; 35 protected PortType partnerPortType; 36 protected PortType myPortType; 37 protected VariableDefinition messageVariable; 38 protected Property p1, p2, p3; 39 40 private static final String WSDL_TEXT = 41 "<definitions targetNamespace='http://manufacturing.org/wsdl/purchase'" + 42 " xmlns:plnk='http://schemas.xmlsoap.org/ws/2004/03/partner-link/'" + 43 " xmlns:bpws='http://schemas.xmlsoap.org/ws/2004/03/business-process/'" + 44 " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" + 45 " xmlns:tns='http://manufacturing.org/wsdl/purchase'" + 46 " xmlns='http://schemas.xmlsoap.org/wsdl/'>" + 47 " <message name='aQName'/>" + 48 " <portType name='ppt'>" + 49 " <operation name='o'>" + 50 " <input message='tns:aQName'/>" + 51 " </operation>" + 52 " <operation name='o2'>" + 53 " <input message='tns:aQName'/>" + 54 " <output message='tns:aQName'/>" + 55 " </operation>" + 56 " </portType>" + 57 " <portType name='mpt'>" + 58 " <operation name='o'>" + 59 " <input message='tns:aQName'/>" + 60 " <output message='tns:aQName'/>" + 61 " </operation>" + 62 " </portType>" + 63 " <plnk:partnerLinkType name='aPartnerLinkType'>" + 64 " <plnk:role name='role1' portType='tns:ppt'/>" + 65 " <plnk:role name='role2' portType='tns:mpt'/>" + 66 " </plnk:partnerLinkType>" + 67 " <bpws:property name='p1' type='xsd:string'/>" + 68 " <bpws:property name='p2' type='xsd:string'/>" + 69 " <bpws:property name='p3' type='xsd:string'/>" + 70 "</definitions>"; 71 static protected final String NS_TNS = "http://manufacturing.org/wsdl/purchase"; 72 73 public void setUp() throws Exception { 74 reader = new BpelReader(); 75 pd = new BpelDefinition("testPD"); 76 pd.getNodes().clear(); 77 scope = new TestScope(); 78 pd.addNode(scope); 79 } 80 81 protected void initMessageProperties() throws Exception { 82 Definition def = WsdlUtil.readText(WSDL_TEXT); 84 ImportsDefinition imports = pd.getImports(); 86 imports.addImport(WsdlUtil.createImport(def)); 87 partnerPortType = imports.getPortType(new QName (NS_TNS, "ppt")); 89 myPortType = imports.getPortType(new QName (NS_TNS, "mpt")); 90 operation = partnerPortType.getOperation("o", null, null); 91 p1 = imports.getProperty(new QName (NS_TNS, "p1")); 93 p2 = imports.getProperty(new QName (NS_TNS, "p2")); 94 p3 = imports.getProperty(new QName (NS_TNS, "p3")); 95 messageVariable = new VariableDefinition(); 97 messageVariable.setName("iv"); 98 messageVariable.setTypeInfo(imports.getMessageTypeInfo(new QName (NS_TNS, "aQName"))); 99 PartnerLinkType plinkType = imports.getPartnerLinkType(new QName (NS_TNS, "aPartnerLinkType")); 101 pLink = new PartnerLinkDefinition(); 102 pLink.setName("aPartner"); 103 pLink.setPartnerLinkType(plinkType); 104 pLink.setMyRole(plinkType.getSecondRole()); 105 scope.addPartnerLink(pLink); 106 scope.addVariable(messageVariable); 107 } 108 109 protected Element parseAsBpelElement(String text) throws SAXException { 110 String textToParse = 111 "<parent xmlns='" + BpelConstants.NS_BPWS + "'>" + text + "</parent>"; 112 return (Element ) NodeUtil.parseElement(textToParse).getChildNodes().item(0); 113 } 114 115 protected Activity readActivity(String xml) throws SAXException { 116 Element element = parseAsBpelElement(xml); 117 return readActivity(element, scope); 118 } 119 120 protected Activity readActivity(Element element, CompositeActivity parent) { 121 ActivityReader activityReader = reader.getActivityReader(element.getTagName()); 122 Activity activity = activityReader.read(element, parent); 123 return activity; 124 } 125 126 protected static class TestScope extends BpelDefinition.RootScope { 127 public boolean initial = false; 128 129 public boolean isChildInitial(Activity activity) { 130 return initial; 131 } 132 } 133 } 134 | Popular Tags |