001: package org.objectweb.celtix.bus.ws.rm;
002:
003: import java.io.IOException;
004: import java.io.InputStream;
005: import java.math.BigInteger;
006: import java.net.URL;
007: import java.util.ArrayList;
008: import java.util.Collection;
009:
010: import javax.wsdl.WSDLException;
011: import javax.xml.datatype.DatatypeFactory;
012: import javax.xml.datatype.Duration;
013: import javax.xml.namespace.QName;
014:
015: import junit.framework.TestCase;
016:
017: import org.easymock.IMocksControl;
018: import org.easymock.classextension.EasyMock;
019: import org.objectweb.celtix.Bus;
020: import org.objectweb.celtix.BusException;
021: import org.objectweb.celtix.bus.bindings.TestClientTransport;
022: import org.objectweb.celtix.bus.bindings.TestInputStreamContext;
023: import org.objectweb.celtix.bus.configuration.wsrm.SourcePolicyType;
024: import org.objectweb.celtix.bus.ws.addressing.ContextUtils;
025: import org.objectweb.celtix.bus.ws.addressing.VersionTransformer;
026: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
027: import org.objectweb.celtix.ws.rm.Identifier;
028: import org.objectweb.celtix.ws.rm.policy.RMAssertionType;
029: import org.objectweb.celtix.ws.rm.wsdl.SequenceFault;
030: import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
031:
032: import static org.easymock.classextension.EasyMock.*;
033:
034: public class RMProxyTest extends TestCase {
035:
036: Bus bus;
037: EndpointReferenceType epr;
038:
039: public void setUp() throws BusException {
040: bus = Bus.init();
041: URL wsdlUrl = getClass().getResource("/wsdl/hello_world.wsdl");
042: QName serviceName = new QName(
043: "http://objectweb.org/hello_world_soap_http",
044: "SOAPService");
045: epr = EndpointReferenceUtils.getEndpointReference(wsdlUrl,
046: serviceName, "SoapPort");
047: }
048:
049: public void tearDown() throws BusException {
050: bus.shutdown(true);
051: }
052:
053: public void testCreateSequenceOnClientNoOfferIncluded()
054: throws Exception {
055:
056: TestSoapClientBinding binding = new TestSoapClientBinding(bus,
057: epr);
058: TestClientTransport ct = binding.getClientTransport();
059: InputStream is = getClass().getResourceAsStream(
060: "resources/spec/CreateSequenceResponse.xml");
061: TestInputStreamContext istreamCtx = new TestInputStreamContext();
062: istreamCtx.setInputStream(is);
063: ct.setInputStreamMessageContext(istreamCtx);
064:
065: IMocksControl control = EasyMock.createNiceControl();
066:
067: RMHandler handler = control.createMock(RMHandler.class);
068: RMProxy proxy = new RMProxy(handler);
069: RMSource source = control.createMock(RMSource.class);
070: SourcePolicyType sp = control
071: .createMock(SourcePolicyType.class);
072:
073: Identifier sid = RMUtils.getWSRMFactory().createIdentifier();
074: sid.setValue("s1");
075:
076: expect(handler.getBinding()).andReturn(binding);
077: expect(handler.getTransport()).andReturn(ct);
078: expect(source.getSourcePolicies()).andReturn(sp);
079: expect(sp.getAcksTo()).andReturn(null);
080: expect(sp.getSequenceExpiration()).andReturn(null);
081: expect(sp.isIncludeOffer()).andReturn(false);
082: expect(handler.getBinding()).andReturn(binding).times(2);
083: // Moved to CreateSequenceResponse handling on RMServant
084: //source.addSequence(EasyMock.isA(SourceSequence.class));
085: //expectLastCall();
086: //source.setCurrent((Identifier)EasyMock.isNull(), EasyMock.isA(SourceSequence.class));
087: //expectLastCall();
088:
089: control.replay();
090: proxy.createSequence(source, getTo(), RMUtils
091: .createReference(Names.WSA_ANONYMOUS_ADDRESS),
092: ContextUtils.WSA_OBJECT_FACTORY.createRelatesToType());
093: control.verify();
094: assertTrue("expected send", binding.isSent());
095: }
096:
097: public void testCreateSequenceOnClientOfferAccepted()
098: throws Exception {
099: TestSoapClientBinding binding = new TestSoapClientBinding(bus,
100: epr);
101: TestClientTransport ct = binding.getClientTransport();
102: InputStream is = getClass().getResourceAsStream(
103: "resources/CreateSequenceResponseOfferAccepted.xml");
104: TestInputStreamContext istreamCtx = new TestInputStreamContext();
105: istreamCtx.setInputStream(is);
106: ct.setInputStreamMessageContext(istreamCtx);
107:
108: IMocksControl control = EasyMock.createNiceControl();
109:
110: RMHandler handler = control.createMock(RMHandler.class);
111: RMProxy proxy = new RMProxy(handler);
112: RMSource source = control.createMock(RMSource.class);
113: SourcePolicyType sp = control
114: .createMock(SourcePolicyType.class);
115:
116: Identifier sid = RMUtils.getWSRMFactory().createIdentifier();
117: sid.setValue("s1");
118: Duration osd = DatatypeFactory.newInstance().newDuration(
119: "PT24H");
120: assertNotNull(osd);
121: Identifier offeredSid = RMUtils.getWSRMFactory()
122: .createIdentifier();
123: offeredSid.setValue("s1Offer");
124:
125: expect(handler.getBinding()).andReturn(binding);
126: expect(handler.getTransport()).andReturn(ct);
127: expect(source.getSourcePolicies()).andReturn(sp);
128: expect(sp.getAcksTo()).andReturn(null);
129: expect(sp.getSequenceExpiration()).andReturn(null);
130: expect(sp.isIncludeOffer()).andReturn(true);
131: expect(sp.getOfferedSequenceExpiration()).andReturn(null);
132: expect(source.generateSequenceIdentifier()).andReturn(
133: offeredSid);
134: expect(handler.getBinding()).andReturn(binding).times(2);
135: // Moved to CreateSequenceResponse handling on RMServant
136: //source.addSequence(EasyMock.isA(SourceSequence.class));
137: //expectLastCall();
138: //source.setCurrent((Identifier)EasyMock.isNull(), EasyMock.isA(SourceSequence.class));
139: //expectLastCall();
140: // Moved to CreateSequenceResponse handling on RMServant
141: //expect(source.getHandler()).andReturn(handler);
142: //expect(handler.getDestination()).andReturn(dest);
143: //dest.addSequence(isA(DestinationSequence.class));
144:
145: control.replay();
146: proxy.createSequence(source, getTo(), RMUtils
147: .createReference(Names.WSA_ANONYMOUS_ADDRESS),
148: ContextUtils.WSA_OBJECT_FACTORY.createRelatesToType());
149: control.verify();
150: assertTrue("expected send", binding.isSent());
151: }
152:
153: public void testCreateSequenceOnClientOfferRejected()
154: throws Exception {
155: TestSoapClientBinding binding = new TestSoapClientBinding(bus,
156: epr);
157: TestClientTransport ct = binding.getClientTransport();
158: InputStream is = getClass().getResourceAsStream(
159: "resources/CreateSequenceResponseOfferAccepted.xml");
160: TestInputStreamContext istreamCtx = new TestInputStreamContext();
161: istreamCtx.setInputStream(is);
162: ct.setInputStreamMessageContext(istreamCtx);
163:
164: IMocksControl control = EasyMock.createNiceControl();
165:
166: RMHandler handler = control.createMock(RMHandler.class);
167: RMProxy proxy = new RMProxy(handler);
168: RMSource source = control.createMock(RMSource.class);
169: SourcePolicyType sp = control
170: .createMock(SourcePolicyType.class);
171: //RMDestination dest = control.createMock(RMDestination.class);
172:
173: Identifier sid = RMUtils.getWSRMFactory().createIdentifier();
174: sid.setValue("s1");
175: Duration osd = DatatypeFactory.newInstance().newDuration(
176: "PT24H");
177: Identifier offeredSid = RMUtils.getWSRMFactory()
178: .createIdentifier();
179: offeredSid.setValue("s1Offer");
180:
181: expect(handler.getBinding()).andReturn(binding);
182: expect(source.getSourcePolicies()).andReturn(sp);
183: expect(sp.getAcksTo()).andReturn(null);
184: expect(sp.getSequenceExpiration()).andReturn(null);
185: expect(sp.isIncludeOffer()).andReturn(true);
186: expect(sp.getOfferedSequenceExpiration()).andReturn(osd);
187: expect(source.generateSequenceIdentifier()).andReturn(
188: offeredSid);
189: expect(handler.getBinding()).andReturn(binding).times(2);
190: // Moved to CreateSequenceResponse handling on RMServant
191: //expect(source.getHandler()).andReturn(handler);
192: //expect(handler.getDestination()).andReturn(dest);
193:
194: control.replay();
195: proxy.createSequence(source, getTo(), RMUtils
196: .createReference(Names.WSA_ANONYMOUS_ADDRESS),
197: ContextUtils.WSA_OBJECT_FACTORY.createRelatesToType());
198: control.verify();
199: assertTrue("expected send", binding.isSent());
200: }
201:
202: public void testTerminateSequenceOnClient() throws IOException,
203: WSDLException, SequenceFault {
204: TestSoapClientBinding binding = new TestSoapClientBinding(bus,
205: epr);
206:
207: IMocksControl control = EasyMock.createNiceControl();
208: RMHandler handler = control.createMock(RMHandler.class);
209:
210: handler.getBinding();
211: EasyMock.expectLastCall().andReturn(binding).times(3);
212: //handler.getTransport();
213: //expectLastCall().andReturn(binding.getClientTransport());
214: handler.getClientBinding();
215: EasyMock.expectLastCall().andReturn(binding).times(4);
216:
217: RMSource source = control.createMock(RMSource.class);
218: handler.getSource();
219: EasyMock.expectLastCall().andReturn(source);
220: source.removeSequence(EasyMock.isA(SourceSequence.class));
221: EasyMock.expectLastCall();
222:
223: control.replay();
224:
225: RMProxy proxy = new RMProxy(handler);
226:
227: Identifier sid = RMUtils.getWSRMFactory().createIdentifier();
228: sid.setValue("TerminatedSequence");
229: SourceSequence seq = new SourceSequence(sid, null, null);
230:
231: proxy.terminateSequence(seq);
232:
233: control.verify();
234: assertTrue("expected send", binding.isSent());
235: }
236:
237: public void testRequestAcknowledgement() throws IOException,
238: WSDLException, SequenceFault {
239: TestSoapClientBinding binding = new TestSoapClientBinding(bus,
240: epr);
241:
242: IMocksControl control = EasyMock.createNiceControl();
243: RMHandler handler = control.createMock(RMHandler.class);
244:
245: handler.getBinding();
246: EasyMock.expectLastCall().andReturn(binding).times(3);
247: //handler.getTransport();
248: //expectLastCall().andReturn(binding.getClientTransport());
249: handler.getClientBinding();
250: EasyMock.expectLastCall().andReturn(binding).times(4);
251:
252: control.replay();
253:
254: RMProxy proxy = new RMProxy(handler);
255:
256: Identifier sid = RMUtils.getWSRMFactory().createIdentifier();
257: sid.setValue("AckRequestedSequence");
258: SourceSequence seq = new SourceSequence(sid, null, null);
259: seq.setTarget(getTo());
260:
261: Collection<SourceSequence> seqs = new ArrayList<SourceSequence>();
262: seqs.add(seq);
263:
264: proxy.requestAcknowledgment(seqs);
265:
266: control.verify();
267: assertTrue("expected send", binding.isSent());
268: }
269:
270: public void testLastMessage() throws IOException, WSDLException,
271: SequenceFault {
272: TestSoapClientBinding binding = new TestSoapClientBinding(bus,
273: epr);
274:
275: IMocksControl control = EasyMock.createNiceControl();
276: RMHandler handler = control.createMock(RMHandler.class);
277:
278: handler.getBinding();
279: EasyMock.expectLastCall().andReturn(binding).times(3);
280: //handler.getTransport();
281: //expectLastCall().andReturn(binding.getClientTransport());
282: handler.getClientBinding();
283: EasyMock.expectLastCall().andReturn(binding).times(4);
284:
285: control.replay();
286:
287: RMProxy proxy = new RMProxy(handler);
288:
289: Identifier sid = RMUtils.getWSRMFactory().createIdentifier();
290: sid.setValue("LastMessageSequence");
291: SourceSequence seq = new SourceSequence(sid, null, null);
292: seq.setTarget(getTo());
293: proxy.lastMessage(seq);
294:
295: control.verify();
296: assertTrue("expected send", binding.isSent());
297: }
298:
299: public void testAcknowledge() throws IOException, WSDLException,
300: SequenceFault {
301: TestSoapClientBinding binding = new TestSoapClientBinding(bus,
302: epr);
303: IMocksControl control = EasyMock.createNiceControl();
304: RMHandler handler = control.createMock(RMHandler.class);
305: RMDestination dest = control.createMock(RMDestination.class);
306: RMAssertionType rma = control.createMock(RMAssertionType.class);
307:
308: dest.getRMAssertion();
309: expectLastCall().andReturn(rma).times(2);
310: rma.getAcknowledgementInterval();
311: expectLastCall().andReturn(null).times(2);
312: dest.getAcksPolicy();
313: expectLastCall().andReturn(null).times(2);
314:
315: handler.getBinding();
316: EasyMock.expectLastCall().andReturn(binding).times(3);
317: //handler.getTransport();
318: //expectLastCall().andReturn(transport);
319: handler.getClientBinding();
320: EasyMock.expectLastCall().andReturn(binding).times(2);
321:
322: control.replay();
323:
324: RMProxy proxy = new RMProxy(handler);
325:
326: Identifier sid = RMUtils.getWSRMFactory().createIdentifier();
327: sid.setValue("Acknowledge");
328: DestinationSequence seq = new DestinationSequence(sid, RMUtils
329: .createReference("http://localhost:9999/decoupled"),
330: dest);
331: seq.acknowledge(BigInteger.ONE);
332: seq.acknowledge(BigInteger.TEN);
333: proxy.acknowledge(seq);
334:
335: control.verify();
336: assertTrue("expected send", binding.isSent());
337: }
338:
339: public void testSequenceInfoOnClient() throws IOException,
340: WSDLException, SequenceFault {
341:
342: TestSoapClientBinding binding = new TestSoapClientBinding(bus,
343: epr);
344: TestClientTransport ct = binding.getClientTransport();
345: InputStream is = getClass().getResourceAsStream(
346: "resources/spec/SequenceInfoResponse.xml");
347: TestInputStreamContext istreamCtx = new TestInputStreamContext();
348: istreamCtx.setInputStream(is);
349: ct.setInputStreamMessageContext(istreamCtx);
350:
351: IMocksControl control = EasyMock.createNiceControl();
352: RMHandler handler = control.createMock(RMHandler.class);
353: handler.getBinding();
354: EasyMock.expectLastCall().andReturn(binding).times(3);
355: //handler.getTransport();
356: //expectLastCall().andReturn(ct);
357: handler.getClientBinding();
358: EasyMock.expectLastCall().andReturn(binding).times(4);
359:
360: RMSource source = control.createMock(RMSource.class);
361: handler.getSource();
362: EasyMock.expectLastCall().andReturn(source);
363: source.removeSequence(EasyMock.isA(SourceSequence.class));
364: EasyMock.expectLastCall();
365:
366: control.replay();
367:
368: RMProxy service = new RMProxy(handler);
369:
370: Identifier sid = RMUtils.getWSRMFactory().createIdentifier();
371: sid.setValue("TerminatedSequence");
372: SourceSequence seq = new SourceSequence(sid, null, null);
373:
374: service.terminateSequence(seq);
375:
376: control.verify();
377: assertTrue("expected send", binding.isSent());
378: }
379:
380: private EndpointReferenceType getTo() {
381: return VersionTransformer.convert(RMUtils
382: .createReference(RMUtils.getAddressingConstants()
383: .getAnonymousURI()));
384: }
385: }
|