001: package org.objectweb.celtix.bus.ws.rm;
002:
003: import java.math.BigInteger;
004: import java.util.ArrayList;
005: import java.util.Collection;
006:
007: import junit.framework.TestCase;
008:
009: import org.easymock.classextension.EasyMock;
010: import org.easymock.classextension.IMocksControl;
011: import org.objectweb.celtix.bus.configuration.wsrm.DestinationPolicyType;
012: import org.objectweb.celtix.configuration.Configuration;
013: import org.objectweb.celtix.ws.addressing.v200408.EndpointReferenceType;
014: import org.objectweb.celtix.ws.rm.Identifier;
015: import org.objectweb.celtix.ws.rm.SequenceType;
016: import org.objectweb.celtix.ws.rm.persistence.RMDestinationSequence;
017: import org.objectweb.celtix.ws.rm.persistence.RMStore;
018: import org.objectweb.celtix.ws.rm.policy.RMAssertionType;
019: import org.objectweb.celtix.ws.rm.wsdl.SequenceFault;
020:
021: public class RMDestinationTest extends TestCase {
022:
023: private IMocksControl control;
024: private RMHandler handler;
025: private EndpointReferenceType address;
026:
027: public void setUp() {
028: control = EasyMock.createNiceControl();
029: handler = control.createMock(RMHandler.class);
030: address = control.createMock(EndpointReferenceType.class);
031: }
032:
033: public void testSequenceAccess() {
034: RMStore store = control.createMock(RMStore.class);
035: EasyMock.expect(handler.getStore()).andReturn(store).times(2);
036: store.createDestinationSequence(EasyMock
037: .isA(RMDestinationSequence.class));
038: EasyMock.expectLastCall();
039: store.removeDestinationSequence(EasyMock.isA(Identifier.class));
040: EasyMock.expectLastCall();
041:
042: control.replay();
043: RMDestination d = new RMDestination(handler);
044: Identifier sid = d.generateSequenceIdentifier();
045: DestinationSequence seq = new DestinationSequence(sid, address,
046: d);
047: d.addSequence(seq);
048: assertSame(seq, d.getSequence(sid));
049: assertEquals(1, d.getAllSequences().size());
050: d.removeSequence(seq);
051: assertNull(d.getSequence(sid));
052: assertEquals(0, d.getAllSequences().size());
053: control.verify();
054: }
055:
056: public void testGetDestinationPolicies() {
057: Configuration c = control.createMock(Configuration.class);
058: DestinationPolicyType dp = null;
059: EasyMock.expect(handler.getConfiguration()).andReturn(c);
060: EasyMock.expect(
061: c.getObject(DestinationPolicyType.class,
062: "destinationPolicies")).andReturn(dp);
063: control.replay();
064: RMDestination d = new RMDestination(handler);
065: assertNotNull(d.getDestinationPolicies());
066: control.verify();
067:
068: control.reset();
069: dp = control.createMock(DestinationPolicyType.class);
070: EasyMock.expect(handler.getConfiguration()).andReturn(c);
071: EasyMock.expect(
072: c.getObject(DestinationPolicyType.class,
073: "destinationPolicies")).andReturn(dp);
074: control.replay();
075: assertNotNull(d.getDestinationPolicies());
076: control.verify();
077: }
078:
079: public void testAcknowledge() throws SequenceFault {
080: RMStore store = control.createMock(RMStore.class);
081: EasyMock.expect(handler.getStore()).andReturn(store);
082: store.createDestinationSequence(EasyMock
083: .isA(RMDestinationSequence.class));
084: EasyMock.expectLastCall();
085: Configuration c = control.createMock(Configuration.class);
086: EasyMock.expect(handler.getConfiguration()).andReturn(c);
087: EasyMock.expect(
088: c.getObject(RMAssertionType.class, "rmAssertion"))
089: .andReturn(null);
090: EasyMock.expect(handler.getConfiguration()).andReturn(c);
091: EasyMock.expect(
092: c.getObject(DestinationPolicyType.class,
093: "destinationPolicies")).andReturn(null);
094:
095: control.replay();
096: RMDestination d = new RMDestination(handler);
097: Identifier sid = d.generateSequenceIdentifier();
098: DestinationSequence seq = new DestinationSequence(sid, address,
099: d);
100: d.addSequence(seq);
101: SequenceType st = RMUtils.getWSRMFactory().createSequenceType();
102: st.setIdentifier(sid);
103: BigInteger m = new BigInteger("3");
104: st.setMessageNumber(m);
105: d
106: .acknowledge(st, RMUtils.getAddressingConstants()
107: .getNoneURI());
108:
109: Identifier unknown = d.generateSequenceIdentifier();
110: st.setIdentifier(unknown);
111: try {
112: d.acknowledge(st, RMUtils.getAddressingConstants()
113: .getNoneURI());
114: fail("Expected sequenceFault not thrown.");
115: } catch (SequenceFault sf) {
116: assertEquals("UnknownSequence", sf.getFaultInfo()
117: .getFaultCode().getLocalPart());
118: }
119: control.verify();
120: }
121:
122: public void testRestore() {
123: RMStore store = control.createMock(RMStore.class);
124: EasyMock.expect(handler.getStore()).andReturn(store);
125: Configuration c = control.createMock(Configuration.class);
126: EasyMock.expect(handler.getConfiguration()).andReturn(c);
127: Configuration pc = control.createMock(Configuration.class);
128: EasyMock.expect(c.getParent()).andReturn(pc);
129: EasyMock.expect(pc.getId()).andReturn("endpoint");
130: Collection<RMDestinationSequence> dss = new ArrayList<RMDestinationSequence>();
131: EasyMock.expect(store.getDestinationSequences("endpoint"))
132: .andReturn(dss);
133:
134: control.replay();
135: RMDestination d = new RMDestination(handler);
136: d.restore();
137: assertEquals(0, d.getAllSequences().size());
138: control.verify();
139: }
140:
141: }
|