1 package org.jbpm.bpel.wsdl.xml; 2 3 import java.io.CharArrayWriter ; 4 5 import javax.wsdl.Definition; 6 import javax.wsdl.factory.WSDLFactory; 7 import javax.xml.namespace.QName ; 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 19 public class PartnerLinkTypeTest extends TestCase { 20 21 private Definition definition; 22 23 private static final String NS_POS = "http://manufacturing.org/wsdl/purchase"; 24 private static final String FILE_NAME = "partnerLinkTypeSample.wsdl"; 25 26 protected void setUp() throws Exception { 27 definition = WsdlUtil.getFactory().newWSDLReader().readWSDL(getClass().getResource(FILE_NAME).toString()); 28 } 29 30 public void testGetPartnerLinkType() { 31 String tns = definition.getTargetNamespace(); 32 PartnerLinkType plinkType = WsdlUtil.getPartnerLinkType(definition, new QName (tns, "purchasingLT")); 33 assertNotNull(plinkType); 34 assertEquals("purchaseService", plinkType.getFirstRole().getName()); 35 36 plinkType = WsdlUtil.getPartnerLinkType(definition, new QName (tns, "shippingLT")); 37 assertNotNull(plinkType); 38 assertEquals("shippingService", plinkType.getFirstRole().getName()); 39 } 40 41 public void testUnmarshall() { 42 String tns = definition.getTargetNamespace(); 43 PartnerLinkType plinkType = WsdlUtil.getPartnerLinkType(definition, new QName (tns, "purchasingLT")); 45 assertNotNull(plinkType); 46 PartnerLinkType.Role role = plinkType.getFirstRole(); 48 assertEquals("purchaseService", role.getName()); 49 assertEquals(new QName (NS_POS, "purchaseOrderPT"), role.getPortType().getQName()); 50 assertNull(plinkType.getSecondRole()); 52 53 plinkType = WsdlUtil.getPartnerLinkType(definition, new QName (tns, "invoicingLT")); 55 assertNotNull(plinkType); 56 role = plinkType.getFirstRole(); 58 assertEquals("invoiceService", role.getName()); 59 assertEquals(new QName (NS_POS, "computePricePT"), role.getPortType().getQName()); 60 role = plinkType.getSecondRole(); 62 assertEquals("invoiceRequester", role.getName()); 63 assertEquals(new QName (NS_POS, "invoiceCallbackPT"), 64 role.getPortType().getQName()); 65 } 66 67 public void testMarshall() throws Exception { 68 CharArrayWriter output = new CharArrayWriter (); 70 WSDLFactory factory = WsdlUtil.getFactory(); 71 factory.newWSDLWriter().writeWSDL(definition, output); 72 output.close(); 73 definition = factory.newWSDLReader().readWSDL( 75 definition.getDocumentBaseURI(), NodeUtil.parseElement(output.toString())); 76 testUnmarshall(); 78 } 79 } 80 | Popular Tags |