1 package org.objectweb.celtix.bus.ws.rm; 2 3 import java.math.BigInteger ; 4 import java.net.URL ; 5 6 import javax.wsdl.WSDLException; 7 import javax.xml.bind.JAXBException; 8 import javax.xml.namespace.QName ; 9 10 import junit.framework.TestCase; 11 12 import org.easymock.classextension.EasyMock; 13 import org.objectweb.celtix.Bus; 14 import org.objectweb.celtix.BusException; 15 import org.objectweb.celtix.bus.wsdl.WSDLManagerImpl; 16 import org.objectweb.celtix.ws.addressing.EndpointReferenceType; 17 import org.objectweb.celtix.ws.rm.policy.RMAssertionType; 18 import org.objectweb.celtix.wsdl.EndpointReferenceUtils; 19 import org.objectweb.celtix.wsdl.WSDLManager; 20 21 public class RMPolicyProviderTest extends TestCase { 22 23 public void testNoPolicy() throws BusException, WSDLException { 24 URL url = getClass().getResource("/wsdl/hello_world.wsdl"); 25 QName serviceName = new QName ("http://objectweb.org/hello_world_soap_http", "SOAPService"); 26 String portName = "SoapPort"; 27 28 EndpointReferenceType epr = EndpointReferenceUtils.getEndpointReference(url, serviceName, portName); 29 WSDLManager wsdlManager = new WSDLManagerImpl(null); 30 31 Bus bus = EasyMock.createMock(Bus.class); 32 bus.getWSDLManager(); 33 EasyMock.expectLastCall().andReturn(wsdlManager).times(2); 34 EasyMock.replay(bus); 35 36 RMPolicyProvider provider = new RMPolicyProvider(bus, epr); 37 assertNull(provider.getObject("rmPolicy")); 38 assertNull(provider.getObject("rmAssertion")); 39 40 EasyMock.verify(bus); 41 } 42 43 public void testReferenced() throws BusException, WSDLException, JAXBException { 44 URL url = getClass().getResource("resources/ReliableOneWay.wsdl"); 45 assertNotNull("Could not find WSDL", url); 46 QName serviceName = new QName ("http://tempuri.org/", "PingService"); 47 String portName = "WSHttpBinding_IPing"; 48 49 EndpointReferenceType epr = EndpointReferenceUtils.getEndpointReference(url, serviceName, portName); 50 WSDLManager wsdlManager = new WSDLManagerImpl(null); 51 52 Bus bus = EasyMock.createMock(Bus.class); 53 bus.getWSDLManager(); 54 EasyMock.expectLastCall().andReturn(wsdlManager).times(2); 55 EasyMock.replay(bus); 56 57 RMPolicyProvider provider = new RMPolicyProvider(bus, epr); 58 RMAssertionType rma = (RMAssertionType)provider.getObject("rmAssertion"); 59 assertNotNull(rma); 60 assertEquals(new BigInteger ("600000"), rma.getInactivityTimeout().getMilliseconds()); 61 assertEquals(new BigInteger ("200"), rma.getAcknowledgementInterval().getMilliseconds()); 62 assertNull(rma.getBaseRetransmissionInterval()); 63 64 EasyMock.verify(bus); 65 } 66 67 public void testPolicyOnBinding() throws BusException, WSDLException, JAXBException { 68 URL url = getClass().getResource("resources/hello_world_rmassertion.wsdl"); 69 QName serviceName = new QName ("http://objectweb.org/hello_world_soap_http", "SOAPService1"); 70 String portName = "SoapPort"; 71 72 EndpointReferenceType epr = EndpointReferenceUtils.getEndpointReference(url, serviceName, portName); 73 WSDLManager wsdlManager = new WSDLManagerImpl(null); 74 75 Bus bus = EasyMock.createMock(Bus.class); 76 bus.getWSDLManager(); 77 EasyMock.expectLastCall().andReturn(wsdlManager).times(2); 78 EasyMock.replay(bus); 79 80 RMPolicyProvider provider = new RMPolicyProvider(bus, epr); 81 assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr)); 82 assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr).getBinding()); 83 RMAssertionType rma = (RMAssertionType)provider.getObject("rmAssertion"); 84 assertNotNull(rma); 85 assertEquals(new BigInteger ("600000"), rma.getInactivityTimeout().getMilliseconds()); 86 assertEquals(new BigInteger ("200"), rma.getAcknowledgementInterval().getMilliseconds()); 87 assertNull(rma.getBaseRetransmissionInterval()); 88 89 EasyMock.verify(bus); 90 } 91 92 public void testPolicyOnPort() throws BusException, WSDLException, JAXBException { 93 URL url = getClass().getResource("resources/hello_world_rmassertion.wsdl"); 94 QName serviceName = new QName ("http://objectweb.org/hello_world_soap_http", "SOAPService2"); 95 String portName = "SoapPort"; 96 97 EndpointReferenceType epr = EndpointReferenceUtils.getEndpointReference(url, serviceName, portName); 98 WSDLManager wsdlManager = new WSDLManagerImpl(null); 99 100 Bus bus = EasyMock.createMock(Bus.class); 101 bus.getWSDLManager(); 102 EasyMock.expectLastCall().andReturn(wsdlManager).times(2); 103 EasyMock.replay(bus); 104 105 RMPolicyProvider provider = new RMPolicyProvider(bus, epr); 106 assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr)); 107 assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr).getBinding()); 108 RMAssertionType rma = (RMAssertionType)provider.getObject("rmAssertion"); 109 assertNotNull(rma); 110 assertEquals(new BigInteger ("900000"), rma.getInactivityTimeout().getMilliseconds()); 111 assertEquals(new BigInteger ("400"), rma.getAcknowledgementInterval().getMilliseconds()); 112 assertNull(rma.getBaseRetransmissionInterval()); 113 114 EasyMock.verify(bus); 115 } 116 117 public void testUnresolvedReference() throws BusException, WSDLException, JAXBException { 118 URL url = getClass().getResource("resources/hello_world_rmassertion.wsdl"); 119 QName serviceName = new QName ("http://objectweb.org/hello_world_soap_http", "SOAPService3"); 120 String portName = "SoapPort"; 121 122 EndpointReferenceType epr = EndpointReferenceUtils.getEndpointReference(url, serviceName, portName); 123 WSDLManager wsdlManager = new WSDLManagerImpl(null); 124 125 Bus bus = EasyMock.createMock(Bus.class); 126 bus.getWSDLManager(); 127 EasyMock.expectLastCall().andReturn(wsdlManager).times(2); 128 EasyMock.replay(bus); 129 130 RMPolicyProvider provider = new RMPolicyProvider(bus, epr); 131 assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr)); 132 assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr).getBinding()); 133 RMAssertionType rma = (RMAssertionType)provider.getObject("rmAssertion"); 134 assertNull(rma); 135 136 EasyMock.verify(bus); 137 } 138 139 140 141 } 142 | Popular Tags |