KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > xml > AbstractReaderTestCase


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 JavaDoc;
7
8 import junit.framework.TestCase;
9
10 import org.w3c.dom.Element JavaDoc;
11 import org.xml.sax.SAXException JavaDoc;
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 /**
25  * @author Juan Cantú
26  * @version $Revision: 1.11 $ $Date: 2005/06/23 02:17:26 $
27  */

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 JavaDoc 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 JavaDoc NS_TNS = "http://manufacturing.org/wsdl/purchase";
72    
73   public void setUp() throws Exception JavaDoc {
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 JavaDoc {
82     // read wsdl
83
Definition def = WsdlUtil.readText(WSDL_TEXT);
84     // set up imports
85
ImportsDefinition imports = pd.getImports();
86     imports.addImport(WsdlUtil.createImport(def));
87     // port types
88
partnerPortType = imports.getPortType(new QName JavaDoc(NS_TNS, "ppt"));
89     myPortType = imports.getPortType(new QName JavaDoc(NS_TNS, "mpt"));
90     operation = partnerPortType.getOperation("o", null, null);
91     // message properties
92
p1 = imports.getProperty(new QName JavaDoc(NS_TNS, "p1"));
93     p2 = imports.getProperty(new QName JavaDoc(NS_TNS, "p2"));
94     p3 = imports.getProperty(new QName JavaDoc(NS_TNS, "p3"));
95     // message variable
96
messageVariable = new VariableDefinition();
97     messageVariable.setName("iv");
98     messageVariable.setTypeInfo(imports.getMessageTypeInfo(new QName JavaDoc(NS_TNS, "aQName")));
99     // partner link
100
PartnerLinkType plinkType = imports.getPartnerLinkType(new QName JavaDoc(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 JavaDoc parseAsBpelElement(String JavaDoc text) throws SAXException JavaDoc {
110     String JavaDoc textToParse =
111       "<parent xmlns='" + BpelConstants.NS_BPWS + "'>" + text + "</parent>";
112     return (Element JavaDoc) NodeUtil.parseElement(textToParse).getChildNodes().item(0);
113   }
114   
115   protected Activity readActivity(String JavaDoc xml) throws SAXException JavaDoc {
116     Element JavaDoc element = parseAsBpelElement(xml);
117     return readActivity(element, scope);
118   }
119
120   protected Activity readActivity(Element JavaDoc 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