1 package org.objectweb.celtix.bus.ws.rm; 2 3 import java.io.IOException ; 4 import java.io.InputStream ; 5 import java.math.BigInteger ; 6 import java.net.URL ; 7 import java.util.ArrayList ; 8 import java.util.Collection ; 9 10 import javax.wsdl.WSDLException; 11 import javax.xml.datatype.DatatypeFactory ; 12 import javax.xml.datatype.Duration ; 13 import javax.xml.namespace.QName ; 14 15 import junit.framework.TestCase; 16 17 import org.easymock.IMocksControl; 18 import org.easymock.classextension.EasyMock; 19 import org.objectweb.celtix.Bus; 20 import org.objectweb.celtix.BusException; 21 import org.objectweb.celtix.bus.bindings.TestClientTransport; 22 import org.objectweb.celtix.bus.bindings.TestInputStreamContext; 23 import org.objectweb.celtix.bus.configuration.wsrm.SourcePolicyType; 24 import org.objectweb.celtix.bus.ws.addressing.ContextUtils; 25 import org.objectweb.celtix.bus.ws.addressing.VersionTransformer; 26 import org.objectweb.celtix.ws.addressing.EndpointReferenceType; 27 import org.objectweb.celtix.ws.rm.Identifier; 28 import org.objectweb.celtix.ws.rm.policy.RMAssertionType; 29 import org.objectweb.celtix.ws.rm.wsdl.SequenceFault; 30 import org.objectweb.celtix.wsdl.EndpointReferenceUtils; 31 32 import static org.easymock.classextension.EasyMock.*; 33 34 public class RMProxyTest extends TestCase { 35 36 Bus bus; 37 EndpointReferenceType epr; 38 39 public void setUp() throws BusException { 40 bus = Bus.init(); 41 URL wsdlUrl = getClass().getResource("/wsdl/hello_world.wsdl"); 42 QName serviceName = new QName ("http://objectweb.org/hello_world_soap_http", "SOAPService"); 43 epr = EndpointReferenceUtils.getEndpointReference(wsdlUrl, serviceName, "SoapPort"); 44 } 45 46 public void tearDown() throws BusException { 47 bus.shutdown(true); 48 } 49 50 public void testCreateSequenceOnClientNoOfferIncluded() throws Exception { 51 52 TestSoapClientBinding binding = new TestSoapClientBinding(bus, epr); 53 TestClientTransport ct = binding.getClientTransport(); 54 InputStream is = getClass().getResourceAsStream("resources/spec/CreateSequenceResponse.xml"); 55 TestInputStreamContext istreamCtx = new TestInputStreamContext(); 56 istreamCtx.setInputStream(is); 57 ct.setInputStreamMessageContext(istreamCtx); 58 59 IMocksControl control = EasyMock.createNiceControl(); 60 61 RMHandler handler = control.createMock(RMHandler.class); 62 RMProxy proxy = new RMProxy(handler); 63 RMSource source = control.createMock(RMSource.class); 64 SourcePolicyType sp = control.createMock(SourcePolicyType.class); 65 66 Identifier sid = RMUtils.getWSRMFactory().createIdentifier(); 67 sid.setValue("s1"); 68 69 expect(handler.getBinding()).andReturn(binding); 70 expect(handler.getTransport()).andReturn(ct); 71 expect(source.getSourcePolicies()).andReturn(sp); 72 expect(sp.getAcksTo()).andReturn(null); 73 expect(sp.getSequenceExpiration()).andReturn(null); 74 expect(sp.isIncludeOffer()).andReturn(false); 75 expect(handler.getBinding()).andReturn(binding).times(2); 76 82 control.replay(); 83 proxy.createSequence(source, 84 getTo(), 85 RMUtils.createReference(Names.WSA_ANONYMOUS_ADDRESS), 86 ContextUtils.WSA_OBJECT_FACTORY.createRelatesToType()); 87 control.verify(); 88 assertTrue("expected send", binding.isSent()); 89 } 90 91 public void testCreateSequenceOnClientOfferAccepted() throws Exception { 92 TestSoapClientBinding binding = new TestSoapClientBinding(bus, epr); 93 TestClientTransport ct = binding.getClientTransport(); 94 InputStream is = getClass().getResourceAsStream("resources/CreateSequenceResponseOfferAccepted.xml"); 95 TestInputStreamContext istreamCtx = new TestInputStreamContext(); 96 istreamCtx.setInputStream(is); 97 ct.setInputStreamMessageContext(istreamCtx); 98 99 IMocksControl control = EasyMock.createNiceControl(); 100 101 RMHandler handler = control.createMock(RMHandler.class); 102 RMProxy proxy = new RMProxy(handler); 103 RMSource source = control.createMock(RMSource.class); 104 SourcePolicyType sp = control.createMock(SourcePolicyType.class); 105 106 Identifier sid = RMUtils.getWSRMFactory().createIdentifier(); 107 sid.setValue("s1"); 108 Duration osd = DatatypeFactory.newInstance().newDuration("PT24H"); 109 assertNotNull(osd); 110 Identifier offeredSid = RMUtils.getWSRMFactory().createIdentifier(); 111 offeredSid.setValue("s1Offer"); 112 113 expect(handler.getBinding()).andReturn(binding); 114 expect(handler.getTransport()).andReturn(ct); 115 expect(source.getSourcePolicies()).andReturn(sp); 116 expect(sp.getAcksTo()).andReturn(null); 117 expect(sp.getSequenceExpiration()).andReturn(null); 118 expect(sp.isIncludeOffer()).andReturn(true); 119 expect(sp.getOfferedSequenceExpiration()).andReturn(null); 120 expect(source.generateSequenceIdentifier()).andReturn(offeredSid); 121 expect(handler.getBinding()).andReturn(binding).times(2); 122 132 control.replay(); 133 proxy.createSequence(source, 134 getTo(), 135 RMUtils.createReference(Names.WSA_ANONYMOUS_ADDRESS), 136 ContextUtils.WSA_OBJECT_FACTORY.createRelatesToType()); 137 control.verify(); 138 assertTrue("expected send", binding.isSent()); 139 } 140 141 public void testCreateSequenceOnClientOfferRejected() throws Exception { 142 TestSoapClientBinding binding = new TestSoapClientBinding(bus, epr); 143 TestClientTransport ct = binding.getClientTransport(); 144 InputStream is = getClass().getResourceAsStream("resources/CreateSequenceResponseOfferAccepted.xml"); 145 TestInputStreamContext istreamCtx = new TestInputStreamContext(); 146 istreamCtx.setInputStream(is); 147 ct.setInputStreamMessageContext(istreamCtx); 148 149 IMocksControl control = EasyMock.createNiceControl(); 150 151 RMHandler handler = control.createMock(RMHandler.class); 152 RMProxy proxy = new RMProxy(handler); 153 RMSource source = control.createMock(RMSource.class); 154 SourcePolicyType sp = control.createMock(SourcePolicyType.class); 155 157 Identifier sid = RMUtils.getWSRMFactory().createIdentifier(); 158 sid.setValue("s1"); 159 Duration osd = DatatypeFactory.newInstance().newDuration("PT24H"); 160 Identifier offeredSid = RMUtils.getWSRMFactory().createIdentifier(); 161 offeredSid.setValue("s1Offer"); 162 163 expect(handler.getBinding()).andReturn(binding); 164 expect(source.getSourcePolicies()).andReturn(sp); 165 expect(sp.getAcksTo()).andReturn(null); 166 expect(sp.getSequenceExpiration()).andReturn(null); 167 expect(sp.isIncludeOffer()).andReturn(true); 168 expect(sp.getOfferedSequenceExpiration()).andReturn(osd); 169 expect(source.generateSequenceIdentifier()).andReturn(offeredSid); 170 expect(handler.getBinding()).andReturn(binding).times(2); 171 175 control.replay(); 176 proxy.createSequence(source, 177 getTo(), 178 RMUtils.createReference(Names.WSA_ANONYMOUS_ADDRESS), 179 ContextUtils.WSA_OBJECT_FACTORY.createRelatesToType()); 180 control.verify(); 181 assertTrue("expected send", binding.isSent()); 182 } 183 184 185 public void testTerminateSequenceOnClient() throws IOException , WSDLException, SequenceFault { 186 TestSoapClientBinding binding = new TestSoapClientBinding(bus, epr); 187 188 IMocksControl control = EasyMock.createNiceControl(); 189 RMHandler handler = control.createMock(RMHandler.class); 190 191 handler.getBinding(); 192 EasyMock.expectLastCall().andReturn(binding).times(3); 193 handler.getClientBinding(); 196 EasyMock.expectLastCall().andReturn(binding).times(4); 197 198 RMSource source = control.createMock(RMSource.class); 199 handler.getSource(); 200 EasyMock.expectLastCall().andReturn(source); 201 source.removeSequence(EasyMock.isA(SourceSequence.class)); 202 EasyMock.expectLastCall(); 203 204 205 control.replay(); 206 207 RMProxy proxy = new RMProxy(handler); 208 209 Identifier sid = RMUtils.getWSRMFactory().createIdentifier(); 210 sid.setValue("TerminatedSequence"); 211 SourceSequence seq = new SourceSequence(sid, null, null); 212 213 proxy.terminateSequence(seq); 214 215 control.verify(); 216 assertTrue("expected send", binding.isSent()); 217 } 218 219 public void testRequestAcknowledgement() throws IOException , WSDLException, SequenceFault { 220 TestSoapClientBinding binding = new TestSoapClientBinding(bus, epr); 221 222 IMocksControl control = EasyMock.createNiceControl(); 223 RMHandler handler = control.createMock(RMHandler.class); 224 225 handler.getBinding(); 226 EasyMock.expectLastCall().andReturn(binding).times(3); 227 handler.getClientBinding(); 230 EasyMock.expectLastCall().andReturn(binding).times(4); 231 232 control.replay(); 233 234 RMProxy proxy = new RMProxy(handler); 235 236 Identifier sid = RMUtils.getWSRMFactory().createIdentifier(); 237 sid.setValue("AckRequestedSequence"); 238 SourceSequence seq = new SourceSequence(sid, null, null); 239 seq.setTarget(getTo()); 240 241 Collection <SourceSequence> seqs = new ArrayList <SourceSequence>(); 242 seqs.add(seq); 243 244 proxy.requestAcknowledgment(seqs); 245 246 control.verify(); 247 assertTrue("expected send", binding.isSent()); 248 } 249 250 public void testLastMessage() throws IOException , WSDLException, SequenceFault { 251 TestSoapClientBinding binding = new TestSoapClientBinding(bus, epr); 252 253 IMocksControl control = EasyMock.createNiceControl(); 254 RMHandler handler = control.createMock(RMHandler.class); 255 256 handler.getBinding(); 257 EasyMock.expectLastCall().andReturn(binding).times(3); 258 handler.getClientBinding(); 261 EasyMock.expectLastCall().andReturn(binding).times(4); 262 263 control.replay(); 264 265 RMProxy proxy = new RMProxy(handler); 266 267 Identifier sid = RMUtils.getWSRMFactory().createIdentifier(); 268 sid.setValue("LastMessageSequence"); 269 SourceSequence seq = new SourceSequence(sid, null, null); 270 seq.setTarget(getTo()); 271 proxy.lastMessage(seq); 272 273 control.verify(); 274 assertTrue("expected send", binding.isSent()); 275 } 276 277 public void testAcknowledge() throws IOException , WSDLException, SequenceFault { 278 TestSoapClientBinding binding = new TestSoapClientBinding(bus, epr); 279 IMocksControl control = EasyMock.createNiceControl(); 280 RMHandler handler = control.createMock(RMHandler.class); 281 RMDestination dest = control.createMock(RMDestination.class); 282 RMAssertionType rma = control.createMock(RMAssertionType.class); 283 284 dest.getRMAssertion(); 285 expectLastCall().andReturn(rma).times(2); 286 rma.getAcknowledgementInterval(); 287 expectLastCall().andReturn(null).times(2); 288 dest.getAcksPolicy(); 289 expectLastCall().andReturn(null).times(2); 290 291 handler.getBinding(); 292 EasyMock.expectLastCall().andReturn(binding).times(3); 293 handler.getClientBinding(); 296 EasyMock.expectLastCall().andReturn(binding).times(2); 297 298 control.replay(); 299 300 RMProxy proxy = new RMProxy(handler); 301 302 Identifier sid = RMUtils.getWSRMFactory().createIdentifier(); 303 sid.setValue("Acknowledge"); 304 DestinationSequence seq = new DestinationSequence(sid, 305 RMUtils.createReference("http://localhost:9999/decoupled"), dest); 306 seq.acknowledge(BigInteger.ONE); 307 seq.acknowledge(BigInteger.TEN); 308 proxy.acknowledge(seq); 309 310 control.verify(); 311 assertTrue("expected send", binding.isSent()); 312 } 313 314 public void testSequenceInfoOnClient() throws IOException , WSDLException, SequenceFault { 315 316 TestSoapClientBinding binding = new TestSoapClientBinding(bus, epr); 317 TestClientTransport ct = binding.getClientTransport(); 318 InputStream is = getClass().getResourceAsStream("resources/spec/SequenceInfoResponse.xml"); 319 TestInputStreamContext istreamCtx = new TestInputStreamContext(); 320 istreamCtx.setInputStream(is); 321 ct.setInputStreamMessageContext(istreamCtx); 322 323 IMocksControl control = EasyMock.createNiceControl(); 324 RMHandler handler = control.createMock(RMHandler.class); 325 handler.getBinding(); 326 EasyMock.expectLastCall().andReturn(binding).times(3); 327 handler.getClientBinding(); 330 EasyMock.expectLastCall().andReturn(binding).times(4); 331 332 RMSource source = control.createMock(RMSource.class); 333 handler.getSource(); 334 EasyMock.expectLastCall().andReturn(source); 335 source.removeSequence(EasyMock.isA(SourceSequence.class)); 336 EasyMock.expectLastCall(); 337 338 control.replay(); 339 340 RMProxy service = new RMProxy(handler); 341 342 Identifier sid = RMUtils.getWSRMFactory().createIdentifier(); 343 sid.setValue("TerminatedSequence"); 344 SourceSequence seq = new SourceSequence(sid, null, null); 345 346 service.terminateSequence(seq); 347 348 control.verify(); 349 assertTrue("expected send", binding.isSent()); 350 } 351 352 private EndpointReferenceType getTo() { 353 return VersionTransformer.convert( 354 RMUtils.createReference(RMUtils.getAddressingConstants().getAnonymousURI())); 355 } 356 } 357 | Popular Tags |