001: package org.objectweb.celtix.bus.ws.rm;
002:
003: import javax.xml.datatype.DatatypeConfigurationException;
004: import javax.xml.datatype.DatatypeFactory;
005: import javax.xml.datatype.Duration;
006:
007: import junit.framework.TestCase;
008:
009: import org.easymock.classextension.IMocksControl;
010: import org.objectweb.celtix.bus.configuration.wsrm.DestinationPolicyType;
011: import org.objectweb.celtix.ws.addressing.AddressingProperties;
012: import org.objectweb.celtix.ws.addressing.AttributedURIType;
013: import org.objectweb.celtix.ws.addressing.v200408.AttributedURI;
014: import org.objectweb.celtix.ws.addressing.v200408.EndpointReferenceType;
015: import org.objectweb.celtix.ws.rm.CreateSequenceResponseType;
016: import org.objectweb.celtix.ws.rm.CreateSequenceType;
017: import org.objectweb.celtix.ws.rm.Expires;
018: import org.objectweb.celtix.ws.rm.Identifier;
019: import org.objectweb.celtix.ws.rm.OfferType;
020: import org.objectweb.celtix.ws.rm.wsdl.SequenceFault;
021:
022: import static org.easymock.classextension.EasyMock.*;
023:
024: public class RMServantTest extends TestCase {
025:
026: private IMocksControl control = createNiceControl();
027: private RMDestination dest;
028: private CreateSequenceType cs;
029: private AttributedURIType to;
030: private DestinationPolicyType dp;
031: private Identifier sid;
032: private AddressingProperties maps;
033:
034: public void testCreateSequenceDefault()
035: throws DatatypeConfigurationException, SequenceFault {
036:
037: setupCreateSequence(null, null, true, true);
038:
039: control.replay();
040:
041: CreateSequenceResponseType csr = (new RMServant())
042: .createSequence(dest, cs, maps);
043:
044: control.verify();
045:
046: assertSame(sid, csr.getIdentifier());
047: assertNotNull(csr.getAccept());
048: assertTrue(!Names.WSA_NONE_ADDRESS.equals(csr.getAccept()
049: .getAcksTo().getAddress().getValue()));
050: }
051:
052: public void testCreateSequenceRejectOffer()
053: throws DatatypeConfigurationException, SequenceFault {
054:
055: setupCreateSequence(null, null, true, false);
056:
057: control.replay();
058:
059: CreateSequenceResponseType csr = (new RMServant())
060: .createSequence(dest, cs, maps);
061:
062: control.verify();
063:
064: assertSame(sid, csr.getIdentifier());
065: assertNotNull(csr.getAccept());
066: assertEquals(Names.WSA_NONE_ADDRESS, csr.getAccept()
067: .getAcksTo().getAddress().getValue());
068: }
069:
070: public void testCreateSequenceNoOfferIncluded()
071: throws DatatypeConfigurationException, SequenceFault {
072:
073: setupCreateSequence(null, null, false, false);
074:
075: control.replay();
076:
077: CreateSequenceResponseType csr = (new RMServant())
078: .createSequence(dest, cs, maps);
079:
080: control.verify();
081:
082: assertSame(sid, csr.getIdentifier());
083: assertNull(csr.getAccept());
084: }
085:
086: public void testCreateSequenceRequestedDurationNotSupported()
087: throws DatatypeConfigurationException, SequenceFault {
088:
089: setupCreateSequence("PT24H", "PT48H", false, false);
090:
091: control.replay();
092:
093: CreateSequenceResponseType csr = (new RMServant())
094: .createSequence(dest, cs, maps);
095:
096: control.verify();
097:
098: assertSame(sid, csr.getIdentifier());
099: assertNull(csr.getAccept());
100: assertEquals("PT24H", csr.getExpires().getValue().toString());
101: }
102:
103: public void testTerminateSequence() throws SequenceFault {
104: dest = control.createMock(RMDestination.class);
105: sid = control.createMock(Identifier.class);
106:
107: (new RMServant()).terminateSequence(dest, sid);
108:
109: }
110:
111: // expires = "PT24H";
112:
113: private void setupCreateSequence(String supportedDuration,
114: String requestedDuration, boolean includeOffer,
115: boolean acceptOffer) throws DatatypeConfigurationException {
116:
117: dest = control.createMock(RMDestination.class);
118: to = control.createMock(AttributedURIType.class);
119: dp = control.createMock(DestinationPolicyType.class);
120: sid = control.createMock(Identifier.class);
121: cs = control.createMock(CreateSequenceType.class);
122: AttributedURIType messageID = control
123: .createMock(AttributedURIType.class);
124: maps = control.createMock(AddressingProperties.class);
125: maps.getMessageID();
126: expectLastCall().andReturn(messageID);
127:
128: dest.generateSequenceIdentifier();
129: expectLastCall().andReturn(sid);
130:
131: dest.getDestinationPolicies();
132: expectLastCall().andReturn(dp);
133:
134: Duration d = null;
135: if (null != supportedDuration) {
136: d = DatatypeFactory.newInstance().newDuration(
137: supportedDuration);
138: }
139: dp.getSequenceExpiration();
140: expectLastCall().andReturn(d);
141:
142: Expires ex = null;
143: if (null != requestedDuration) {
144: Duration rd = DatatypeFactory.newInstance().newDuration(
145: requestedDuration);
146: ex = RMUtils.getWSRMFactory().createExpires();
147: ex.setValue(rd);
148: }
149: cs.getExpires();
150: expectLastCall().andReturn(ex);
151:
152: setupOffer(includeOffer, acceptOffer);
153: }
154:
155: private void setupOffer(boolean includeOffer, boolean acceptOffer)
156: throws DatatypeConfigurationException {
157:
158: OfferType o = null;
159: if (includeOffer) {
160: o = control.createMock(OfferType.class);
161: }
162: cs.getOffer();
163: expectLastCall().andReturn(o);
164:
165: if (includeOffer) {
166: dp.isAcceptOffers();
167: expectLastCall().andReturn(acceptOffer);
168: }
169:
170: EndpointReferenceType acksTo = control
171: .createMock(EndpointReferenceType.class);
172: if (includeOffer && acceptOffer) {
173: maps.getTo();
174: expectLastCall().andReturn(to);
175: RMHandler handler = control.createMock(RMHandler.class);
176: dest.getHandler();
177: expectLastCall().andReturn(handler);
178: RMSource source = control.createMock(RMSource.class);
179: handler.getSource();
180: expectLastCall().andReturn(source);
181: o.getIdentifier();
182: expectLastCall().andReturn(
183: control.createMock(Identifier.class));
184: o.getExpires();
185: expectLastCall().andReturn(null);
186: cs.getAcksTo();
187: expectLastCall().andReturn(acksTo);
188: AttributedURI address = control
189: .createMock(AttributedURI.class);
190: acksTo.getAddress();
191: expectLastCall().andReturn(address);
192: source.addSequence(isA(SourceSequence.class));
193: expectLastCall();
194: source.setCurrent(isA(Identifier.class),
195: isA(SourceSequence.class));
196: expectLastCall();
197: }
198:
199: cs.getAcksTo();
200: expectLastCall().andReturn(acksTo);
201: }
202: }
|