KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > bpel > wsdl > xml > PartnerLinkTypeTest


1 package org.jbpm.bpel.wsdl.xml;
2
3 import java.io.CharArrayWriter JavaDoc;
4
5 import javax.wsdl.Definition;
6 import javax.wsdl.factory.WSDLFactory;
7 import javax.xml.namespace.QName JavaDoc;
8
9 import junit.framework.TestCase;
10
11 import org.jbpm.bpel.wsdl.def.PartnerLinkType;
12 import org.jbpm.bpel.wsdl.util.WsdlUtil;
13 import org.jbpm.bpel.xml.util.NodeUtil;
14
15 /**
16  * @author Alejandro Guízar
17  * @version $Revision: 1.4 $ $Date: 2005/06/23 02:17:27 $
18  */

19 public class PartnerLinkTypeTest extends TestCase {
20   
21   private Definition definition;
22   
23   private static final String JavaDoc NS_POS = "http://manufacturing.org/wsdl/purchase";
24   private static final String JavaDoc FILE_NAME = "partnerLinkTypeSample.wsdl";
25
26   protected void setUp() throws Exception JavaDoc {
27     definition = WsdlUtil.getFactory().newWSDLReader().readWSDL(getClass().getResource(FILE_NAME).toString());
28   }
29
30   public void testGetPartnerLinkType() {
31     String JavaDoc tns = definition.getTargetNamespace();
32     PartnerLinkType plinkType = WsdlUtil.getPartnerLinkType(definition, new QName JavaDoc(tns, "purchasingLT"));
33     assertNotNull(plinkType);
34     assertEquals("purchaseService", plinkType.getFirstRole().getName());
35
36     plinkType = WsdlUtil.getPartnerLinkType(definition, new QName JavaDoc(tns, "shippingLT"));
37     assertNotNull(plinkType);
38     assertEquals("shippingService", plinkType.getFirstRole().getName());
39   }
40
41   public void testUnmarshall() {
42     String JavaDoc tns = definition.getTargetNamespace();
43     // purchasing partner link
44
PartnerLinkType plinkType = WsdlUtil.getPartnerLinkType(definition, new QName JavaDoc(tns, "purchasingLT"));
45     assertNotNull(plinkType);
46     // First role
47
PartnerLinkType.Role role = plinkType.getFirstRole();
48     assertEquals("purchaseService", role.getName());
49     assertEquals(new QName JavaDoc(NS_POS, "purchaseOrderPT"), role.getPortType().getQName());
50     // Second role
51
assertNull(plinkType.getSecondRole());
52
53     // invoicing partner link
54
plinkType = WsdlUtil.getPartnerLinkType(definition, new QName JavaDoc(tns, "invoicingLT"));
55     assertNotNull(plinkType);
56     // First role
57
role = plinkType.getFirstRole();
58     assertEquals("invoiceService", role.getName());
59     assertEquals(new QName JavaDoc(NS_POS, "computePricePT"), role.getPortType().getQName());
60     // Second role
61
role = plinkType.getSecondRole();
62     assertEquals("invoiceRequester", role.getName());
63     assertEquals(new QName JavaDoc(NS_POS, "invoiceCallbackPT"),
64       role.getPortType().getQName());
65   }
66
67   public void testMarshall() throws Exception JavaDoc {
68     // write the definition to a stream
69
CharArrayWriter JavaDoc output = new CharArrayWriter JavaDoc();
70     WSDLFactory factory = WsdlUtil.getFactory();
71     factory.newWSDLWriter().writeWSDL(definition, output);
72     output.close();
73     // read the definition back from the stream
74
definition = factory.newWSDLReader().readWSDL(
75         definition.getDocumentBaseURI(), NodeUtil.parseElement(output.toString()));
76     // test the definition works the same
77
testUnmarshall();
78   }
79 }
80
Popular Tags