KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.bpel.xml;
2
3 import javax.wsdl.Definition;
4 import javax.wsdl.PortType;
5 import javax.xml.namespace.QName JavaDoc;
6
7 import org.w3c.dom.Element JavaDoc;
8
9 import org.jbpm.bpel.def.BpelDefinition;
10 import org.jbpm.bpel.def.ImportsDefinition;
11 import org.jbpm.bpel.service.def.PartnerLinkDefinition;
12 import org.jbpm.bpel.wsdl.def.PartnerLinkType.Role;
13 import org.jbpm.bpel.wsdl.util.WsdlUtil;
14
15 /**
16  * @author Juan Cantu
17  * @version $Revision: 1.10 $ $Date: 2005/06/23 02:17:26 $
18  */

19 public class PartnerLinkReaderTest extends AbstractReaderTestCase {
20   BpelReader reader;
21   BpelDefinition pd;
22   PortType partnerPortType;
23   PortType myPortType;
24   
25   private static final String JavaDoc WSDL_TEXT =
26     "<definitions targetNamespace='http://manufacturing.org/wsdl/purchase'" +
27     " xmlns:plnk='http://schemas.xmlsoap.org/ws/2004/03/partner-link/'" +
28     " xmlns:bpws='http://schemas.xmlsoap.org/ws/2004/03/business-process/'" +
29     " xmlns:xsd='http://www.w3.org/2001/XMLSchema'" +
30     " xmlns:tns='http://manufacturing.org/wsdl/purchase'" +
31     " xmlns='http://schemas.xmlsoap.org/wsdl/'>" +
32     " <message name='aQName'/>" +
33     " <portType name='ppt'>" +
34     " <operation name='o'>" +
35     " <input message='tns:aQName'/>" +
36     " </operation>" +
37     " </portType>" +
38     " <portType name='mpt'>" +
39     " <operation name='o'>" +
40     " <input message='tns:aQName'/>" +
41     " </operation>" +
42     " </portType>" +
43     " <plnk:partnerLinkType name='schedulingLT'>" +
44     " <plnk:role name='schedulingRequester' portType='tns:ppt'/>" +
45     " <plnk:role name='schedulingService' portType='tns:mpt'/>" +
46     " </plnk:partnerLinkType>" +
47     " <bpws:property name='p1' type='xsd:string'/>" +
48     " <bpws:property name='p2' type='xsd:string'/>" +
49     " <bpws:property name='p3' type='xsd:string'/>" +
50     "</definitions>";
51   static final String JavaDoc NS_TNS = "http://manufacturing.org/wsdl/purchase";
52   
53   public void setUp() throws Exception JavaDoc {
54     reader = new BpelReader();
55     pd = new BpelDefinition();
56     // read wsdl
57
Definition def = WsdlUtil.readText(WSDL_TEXT);
58     // port types
59
partnerPortType = def.getPortType(new QName JavaDoc(NS_TNS, "ppt"));
60     myPortType = def.getPortType(new QName JavaDoc(NS_TNS, "mpt"));
61     // set up imports
62
ImportsDefinition imports = pd.getImports();
63     imports.addImport(WsdlUtil.createImport(def));
64     
65   }
66   
67   public void testMyRole() throws Exception JavaDoc {
68     String JavaDoc xml =
69       "<partnerLinks xmlns:tns='http://manufacturing.org/wsdl/purchase'>" +
70       " <partnerLink name='pl' partnerLinkType='tns:schedulingLT' " +
71       " myRole='schedulingService' partnerRole='schedulingRequester'/>" +
72       " </partnerLinks>";
73     PartnerLinkDefinition pl = parsePartnerLink( xml );
74     Role myRole = pl.getMyRole();
75     assertNotNull(myRole);
76     assertEquals("schedulingService", myRole.getName());
77     assertSame( myPortType, myRole.getPortType() );
78   }
79
80   public void testPartnerRole() throws Exception JavaDoc {
81     String JavaDoc xml =
82       "<partnerLinks xmlns:tns='http://manufacturing.org/wsdl/purchase'>" +
83       " <partnerLink name='pl' partnerLinkType='tns:schedulingLT' " +
84       " myRole='schedulingService' partnerRole='schedulingRequester'/>" +
85       " </partnerLinks>";
86     PartnerLinkDefinition pl = parsePartnerLink( xml );
87     Role partnerRole = pl.getPartnerRole();
88     assertNotNull(partnerRole);
89     assertEquals("schedulingRequester", partnerRole.getName());
90     assertSame(partnerPortType, partnerRole.getPortType());
91   }
92   
93   private PartnerLinkDefinition parsePartnerLink(String JavaDoc xml) throws Exception JavaDoc {
94     Element JavaDoc element = parseAsBpelElement(xml);
95     return (PartnerLinkDefinition) reader.readPartnerLinks(element, pd.getScope()).get("pl");
96   }
97 }
98
Popular Tags