001: package org.objectweb.celtix.bus.ws.rm;
002:
003: import java.math.BigInteger;
004: import java.net.URL;
005:
006: import javax.wsdl.WSDLException;
007: import javax.xml.bind.JAXBException;
008: import javax.xml.namespace.QName;
009:
010: import junit.framework.TestCase;
011:
012: import org.easymock.classextension.EasyMock;
013: import org.objectweb.celtix.Bus;
014: import org.objectweb.celtix.BusException;
015: import org.objectweb.celtix.bus.wsdl.WSDLManagerImpl;
016: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
017: import org.objectweb.celtix.ws.rm.policy.RMAssertionType;
018: import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
019: import org.objectweb.celtix.wsdl.WSDLManager;
020:
021: public class RMPolicyProviderTest extends TestCase {
022:
023: public void testNoPolicy() throws BusException, WSDLException {
024: URL url = getClass().getResource("/wsdl/hello_world.wsdl");
025: QName serviceName = new QName(
026: "http://objectweb.org/hello_world_soap_http",
027: "SOAPService");
028: String portName = "SoapPort";
029:
030: EndpointReferenceType epr = EndpointReferenceUtils
031: .getEndpointReference(url, serviceName, portName);
032: WSDLManager wsdlManager = new WSDLManagerImpl(null);
033:
034: Bus bus = EasyMock.createMock(Bus.class);
035: bus.getWSDLManager();
036: EasyMock.expectLastCall().andReturn(wsdlManager).times(2);
037: EasyMock.replay(bus);
038:
039: RMPolicyProvider provider = new RMPolicyProvider(bus, epr);
040: assertNull(provider.getObject("rmPolicy"));
041: assertNull(provider.getObject("rmAssertion"));
042:
043: EasyMock.verify(bus);
044: }
045:
046: public void testReferenced() throws BusException, WSDLException,
047: JAXBException {
048: URL url = getClass().getResource(
049: "resources/ReliableOneWay.wsdl");
050: assertNotNull("Could not find WSDL", url);
051: QName serviceName = new QName("http://tempuri.org/",
052: "PingService");
053: String portName = "WSHttpBinding_IPing";
054:
055: EndpointReferenceType epr = EndpointReferenceUtils
056: .getEndpointReference(url, serviceName, portName);
057: WSDLManager wsdlManager = new WSDLManagerImpl(null);
058:
059: Bus bus = EasyMock.createMock(Bus.class);
060: bus.getWSDLManager();
061: EasyMock.expectLastCall().andReturn(wsdlManager).times(2);
062: EasyMock.replay(bus);
063:
064: RMPolicyProvider provider = new RMPolicyProvider(bus, epr);
065: RMAssertionType rma = (RMAssertionType) provider
066: .getObject("rmAssertion");
067: assertNotNull(rma);
068: assertEquals(new BigInteger("600000"), rma
069: .getInactivityTimeout().getMilliseconds());
070: assertEquals(new BigInteger("200"), rma
071: .getAcknowledgementInterval().getMilliseconds());
072: assertNull(rma.getBaseRetransmissionInterval());
073:
074: EasyMock.verify(bus);
075: }
076:
077: public void testPolicyOnBinding() throws BusException,
078: WSDLException, JAXBException {
079: URL url = getClass().getResource(
080: "resources/hello_world_rmassertion.wsdl");
081: QName serviceName = new QName(
082: "http://objectweb.org/hello_world_soap_http",
083: "SOAPService1");
084: String portName = "SoapPort";
085:
086: EndpointReferenceType epr = EndpointReferenceUtils
087: .getEndpointReference(url, serviceName, portName);
088: WSDLManager wsdlManager = new WSDLManagerImpl(null);
089:
090: Bus bus = EasyMock.createMock(Bus.class);
091: bus.getWSDLManager();
092: EasyMock.expectLastCall().andReturn(wsdlManager).times(2);
093: EasyMock.replay(bus);
094:
095: RMPolicyProvider provider = new RMPolicyProvider(bus, epr);
096: assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr));
097: assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr)
098: .getBinding());
099: RMAssertionType rma = (RMAssertionType) provider
100: .getObject("rmAssertion");
101: assertNotNull(rma);
102: assertEquals(new BigInteger("600000"), rma
103: .getInactivityTimeout().getMilliseconds());
104: assertEquals(new BigInteger("200"), rma
105: .getAcknowledgementInterval().getMilliseconds());
106: assertNull(rma.getBaseRetransmissionInterval());
107:
108: EasyMock.verify(bus);
109: }
110:
111: public void testPolicyOnPort() throws BusException, WSDLException,
112: JAXBException {
113: URL url = getClass().getResource(
114: "resources/hello_world_rmassertion.wsdl");
115: QName serviceName = new QName(
116: "http://objectweb.org/hello_world_soap_http",
117: "SOAPService2");
118: String portName = "SoapPort";
119:
120: EndpointReferenceType epr = EndpointReferenceUtils
121: .getEndpointReference(url, serviceName, portName);
122: WSDLManager wsdlManager = new WSDLManagerImpl(null);
123:
124: Bus bus = EasyMock.createMock(Bus.class);
125: bus.getWSDLManager();
126: EasyMock.expectLastCall().andReturn(wsdlManager).times(2);
127: EasyMock.replay(bus);
128:
129: RMPolicyProvider provider = new RMPolicyProvider(bus, epr);
130: assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr));
131: assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr)
132: .getBinding());
133: RMAssertionType rma = (RMAssertionType) provider
134: .getObject("rmAssertion");
135: assertNotNull(rma);
136: assertEquals(new BigInteger("900000"), rma
137: .getInactivityTimeout().getMilliseconds());
138: assertEquals(new BigInteger("400"), rma
139: .getAcknowledgementInterval().getMilliseconds());
140: assertNull(rma.getBaseRetransmissionInterval());
141:
142: EasyMock.verify(bus);
143: }
144:
145: public void testUnresolvedReference() throws BusException,
146: WSDLException, JAXBException {
147: URL url = getClass().getResource(
148: "resources/hello_world_rmassertion.wsdl");
149: QName serviceName = new QName(
150: "http://objectweb.org/hello_world_soap_http",
151: "SOAPService3");
152: String portName = "SoapPort";
153:
154: EndpointReferenceType epr = EndpointReferenceUtils
155: .getEndpointReference(url, serviceName, portName);
156: WSDLManager wsdlManager = new WSDLManagerImpl(null);
157:
158: Bus bus = EasyMock.createMock(Bus.class);
159: bus.getWSDLManager();
160: EasyMock.expectLastCall().andReturn(wsdlManager).times(2);
161: EasyMock.replay(bus);
162:
163: RMPolicyProvider provider = new RMPolicyProvider(bus, epr);
164: assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr));
165: assertNotNull(EndpointReferenceUtils.getPort(wsdlManager, epr)
166: .getBinding());
167: RMAssertionType rma = (RMAssertionType) provider
168: .getObject("rmAssertion");
169: assertNull(rma);
170:
171: EasyMock.verify(bus);
172: }
173:
174: }
|