01: package org.objectweb.celtix.bus.ws.rm;
02:
03: import java.math.BigInteger;
04: import java.util.Collection;
05: import java.util.Iterator;
06:
07: import junit.framework.TestCase;
08:
09: import org.easymock.classextension.IMocksControl;
10: import org.objectweb.celtix.ws.rm.Identifier;
11: import org.objectweb.celtix.ws.rm.SequenceAcknowledgement;
12: import org.objectweb.celtix.ws.rm.SequenceType;
13:
14: import static org.easymock.classextension.EasyMock.*;
15:
16: public class RMPropertiesImplTest extends TestCase {
17:
18: public void testSetSequence() {
19: RMPropertiesImpl rmps = new RMPropertiesImpl();
20: IMocksControl control = createNiceControl();
21:
22: SourceSequence seq = control.createMock(SourceSequence.class);
23: Identifier sid = control.createMock(Identifier.class);
24: seq.getIdentifier();
25: expectLastCall().andReturn(sid);
26: seq.getCurrentMessageNr();
27: expectLastCall().andReturn(BigInteger.TEN);
28: seq.isLastMessage();
29: expectLastCall().andReturn(false);
30:
31: control.replay();
32: rmps.setSequence(seq);
33: control.verify();
34:
35: SequenceType s = rmps.getSequence();
36: assertNotNull(s);
37: assertSame(s.getIdentifier(), sid);
38: assertEquals(s.getMessageNumber(), BigInteger.TEN);
39: assertNull(s.getLastMessage());
40:
41: control.reset();
42:
43: seq.getIdentifier();
44: expectLastCall().andReturn(sid);
45: seq.getCurrentMessageNr();
46: expectLastCall().andReturn(BigInteger.TEN);
47: seq.isLastMessage();
48: expectLastCall().andReturn(true);
49:
50: control.replay();
51: rmps.setSequence(seq);
52: control.verify();
53:
54: s = rmps.getSequence();
55: assertNotNull(s);
56: assertSame(s.getIdentifier(), sid);
57: assertEquals(s.getMessageNumber(), BigInteger.TEN);
58: assertNotNull(s.getLastMessage());
59: }
60:
61: public void testAddAck() {
62: RMPropertiesImpl rmps = new RMPropertiesImpl();
63: IMocksControl control = createNiceControl();
64:
65: DestinationSequence seq = control
66: .createMock(DestinationSequence.class);
67: SequenceAcknowledgement ack = control
68: .createMock(SequenceAcknowledgement.class);
69: seq.getAcknowledgment();
70: expectLastCall().andReturn(ack);
71:
72: DestinationSequence otherSeq = control
73: .createMock(DestinationSequence.class);
74: SequenceAcknowledgement otherAck = control
75: .createMock(SequenceAcknowledgement.class);
76: otherSeq.getAcknowledgment();
77: expectLastCall().andReturn(otherAck);
78:
79: control.replay();
80:
81: rmps.addAck(seq);
82: rmps.addAck(otherSeq);
83:
84: control.verify();
85:
86: Collection<SequenceAcknowledgement> acks = rmps.getAcks();
87: assertEquals(2, acks.size());
88: Iterator<SequenceAcknowledgement> it = acks.iterator();
89: assertSame(ack, it.next());
90: assertSame(otherAck, it.next());
91: }
92: }
|