001: package org.objectweb.celtix.bus.ws.rm;
002:
003: import java.util.ArrayList;
004:
005: import javax.xml.datatype.DatatypeConfigurationException;
006: import javax.xml.datatype.DatatypeFactory;
007: import javax.xml.datatype.Duration;
008: import javax.xml.ws.handler.Handler;
009:
010: import junit.framework.TestCase;
011:
012: import org.easymock.IMocksControl;
013: import org.easymock.classextension.EasyMock;
014: import org.objectweb.celtix.bindings.AbstractBindingBase;
015: import org.objectweb.celtix.bus.configuration.wsrm.SourcePolicyType;
016: import org.objectweb.celtix.bus.handlers.HandlerChainInvoker;
017: import org.objectweb.celtix.bus.ws.addressing.ContextUtils;
018: import org.objectweb.celtix.bus.ws.addressing.VersionTransformer;
019: import org.objectweb.celtix.context.ObjectMessageContext;
020: import org.objectweb.celtix.context.ObjectMessageContextImpl;
021: import org.objectweb.celtix.transports.Transport;
022: import org.objectweb.celtix.ws.rm.CreateSequenceType;
023: import org.objectweb.celtix.ws.rm.Identifier;
024: import org.objectweb.celtix.ws.rm.OfferType;
025: import org.objectweb.celtix.wsdl.EndpointReferenceUtils;
026:
027: public class CreateSequenceRequestTest extends TestCase {
028:
029: private static final String NON_ANONYMOUS_ACKSTO_ADDRESS = "http://localhost:9999/decoupled";
030: private static final Duration ONE_DAY;
031: private ObjectMessageContext objectCtx;
032: private RMSource source;
033: private AbstractBindingBase binding;
034: private Transport transport;
035: private HandlerChainInvoker hci;
036: private SourcePolicyType sp;
037: private IMocksControl control;
038:
039: static {
040: Duration d = null;
041: try {
042: DatatypeFactory df = DatatypeFactory.newInstance();
043: d = df.newDuration("PT24H");
044: } catch (DatatypeConfigurationException ex) {
045: ex.printStackTrace();
046: }
047: ONE_DAY = d;
048: }
049:
050: public void setUp() {
051: objectCtx = new ObjectMessageContextImpl();
052: control = EasyMock.createNiceControl();
053: source = control.createMock(RMSource.class);
054: binding = control.createMock(AbstractBindingBase.class);
055: transport = control.createMock(Transport.class);
056: hci = new HandlerChainInvoker(new ArrayList<Handler>());
057: sp = RMUtils.getWSRMConfFactory().createSourcePolicyType();
058:
059: binding.createObjectContext();
060: EasyMock.expectLastCall().andReturn(objectCtx);
061: binding.createHandlerInvoker();
062: EasyMock.expectLastCall().andReturn(hci);
063: source.getSourcePolicies();
064: EasyMock.expectLastCall().andReturn(sp);
065:
066: }
067:
068: public void testDefaultConstruction() {
069:
070: Identifier offeredSid = RMUtils.getWSRMFactory()
071: .createIdentifier();
072: source.generateSequenceIdentifier();
073: EasyMock.expectLastCall().andReturn(offeredSid);
074:
075: control.replay();
076:
077: CreateSequenceRequest req = new CreateSequenceRequest(binding,
078: transport, source, getEPR("to"), VersionTransformer
079: .convert(getEPR("acksTo")),
080: ContextUtils.WSA_OBJECT_FACTORY.createRelatesToType());
081: assertNotNull(req);
082:
083: assertNotNull(CreateSequenceRequest.createDataBindingCallback());
084:
085: Object[] params = req.getObjectMessageContext()
086: .getMessageObjects();
087: assertEquals(1, params.length);
088: CreateSequenceType cs = (CreateSequenceType) params[0];
089:
090: assertEquals(VersionTransformer.convert(getEPR("acksTo"))
091: .getAddress().getValue(), cs.getAcksTo().getAddress()
092: .getValue());
093: assertNull(cs.getExpires());
094:
095: // default is to include offers
096:
097: OfferType offer = cs.getOffer();
098: assertNotNull(offer);
099: assertNull(offer.getExpires());
100: assertNotNull(offer.getIdentifier());
101:
102: control.verify();
103: }
104:
105: public void testNonDefaultConstruction() {
106:
107: control.replay();
108:
109: sp.setAcksTo(NON_ANONYMOUS_ACKSTO_ADDRESS);
110: sp.setSequenceExpiration(ONE_DAY);
111: sp.setIncludeOffer(false);
112:
113: CreateSequenceRequest req = new CreateSequenceRequest(binding,
114: transport, source, getEPR("to"), VersionTransformer
115: .convert(getEPR("acksTo")),
116: ContextUtils.WSA_OBJECT_FACTORY.createRelatesToType());
117: assertNotNull(req);
118:
119: Object[] params = req.getObjectMessageContext()
120: .getMessageObjects();
121: assertEquals(1, params.length);
122: CreateSequenceType cs = (CreateSequenceType) params[0];
123:
124: assertEquals(NON_ANONYMOUS_ACKSTO_ADDRESS, cs.getAcksTo()
125: .getAddress().getValue());
126: assertEquals(ONE_DAY, cs.getExpires().getValue());
127: assertNull(cs.getOffer());
128:
129: control.verify();
130: }
131:
132: private org.objectweb.celtix.ws.addressing.EndpointReferenceType getEPR(
133: String s) {
134: return EndpointReferenceUtils
135: .getEndpointReference("http://nada.nothing.nowhere.null/"
136: + s);
137: }
138: }
|