Copied: incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/impl/DestinationSequenceImplTest.java (from r462829, incubator/cxf/tags/celtix/pre_apache/rt/ws/rm/src/test/java/org/objectweb/celtix/ws/rm/DestinationSequenceTest.java) URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/impl/DestinationSequenceImplTest.java?view=diff&rev=463282&p1=incubator/cxf/tags/celtix/pre_apache/rt/ws/rm/src/test/java/org/objectweb/celtix/ws/rm/DestinationSequenceTest.java&r1=462829&p2=incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/impl/DestinationSequenceImplTest.java&r2=463282 ============================================================================== --- incubator/cxf/tags/celtix/pre_apache/rt/ws/rm/src/test/java/org/objectweb/celtix/ws/rm/DestinationSequenceTest.java (original) +++ incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/impl/DestinationSequenceImplTest.java Thu Oct 12 08:34:05 2006 @@ -1,4 +1,22 @@ -package org.objectweb.celtix.ws.rm; +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.ws.rm.impl; import java.io.IOException; import java.math.BigInteger; @@ -6,95 +24,92 @@ import java.util.List; import java.util.Timer; -import javax.xml.datatype.DatatypeConfigurationException; import junit.framework.TestCase; +import org.apache.cxf.ws.addressing.v200408.EndpointReferenceType; +import org.apache.cxf.ws.rm.Identifier; +import org.apache.cxf.ws.rm.ObjectFactory; +import org.apache.cxf.ws.rm.SequenceAcknowledgement; +import org.apache.cxf.ws.rm.SequenceAcknowledgement.AcknowledgementRange; +import org.apache.cxf.ws.rm.SequenceFault; +import org.apache.cxf.ws.rm.interceptor.AcksPolicyType; +import org.apache.cxf.ws.rm.interceptor.DeliveryAssuranceType; +import org.apache.cxf.ws.rm.interceptor.DestinationPolicyType; +import org.apache.cxf.ws.rm.policy.RMAssertion; +import org.apache.cxf.ws.rm.policy.RMAssertion.AcknowledgementInterval; +import org.apache.cxf.ws.rm.policy.RMAssertion.BaseRetransmissionInterval; import org.easymock.classextension.IMocksControl; -import org.objectweb.celtix.bus.configuration.wsrm.AcksPolicyType; -import org.objectweb.celtix.bus.configuration.wsrm.DeliveryAssuranceType; -import org.objectweb.celtix.ws.addressing.v200408.EndpointReferenceType; -import org.objectweb.celtix.ws.rm.SequenceAcknowledgement.AcknowledgementRange; -import org.objectweb.celtix.ws.rm.policy.RMAssertionType; -import org.objectweb.celtix.ws.rm.policy.RMAssertionType.AcknowledgementInterval; -import org.objectweb.celtix.ws.rm.policy.RMAssertionType.BaseRetransmissionInterval; -import org.objectweb.celtix.ws.rm.policy.RMAssertionType.ExponentialBackoff; -import org.objectweb.celtix.ws.rm.wsdl.SequenceFault; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expectLastCall; import static org.easymock.classextension.EasyMock.createNiceControl; -public class DestinationSequenceTest extends TestCase { +public class DestinationSequenceImplTest extends TestCase { - IMocksControl control; - ObjectFactory factory = new ObjectFactory(); - Identifier id; - Expires expires; - EndpointReferenceType ref; - RMSource source; - RMDestination destination; - RMHandler handler; - ConfigurationHelper configurationHelper; - RMAssertionType rma; - AcksPolicyType ap; + private IMocksControl control; + private ObjectFactory factory; + private Identifier id; + private EndpointReferenceType ref; + private Destination destination; + private RMInterceptor interceptor; + private RMAssertion rma; + private AcksPolicyType ap; + private DestinationPolicyType dp; public void setUp() { control = createNiceControl(); - ref = control.createMock(EndpointReferenceType.class); - source = control.createMock(RMSource.class); - destination = control.createMock(RMDestination.class); - handler = control.createMock(RMHandler.class); - configurationHelper = control.createMock(ConfigurationHelper.class); - - expires = factory.createExpires(); + factory = new ObjectFactory(); + + ref = control.createMock(EndpointReferenceType.class); id = factory.createIdentifier(); id.setValue("seq"); - - ap = RMUtils.getWSRMConfFactory().createAcksPolicyType(); - rma = RMUtils.getWSRMPolicyFactory().createRMAssertionType(); - BaseRetransmissionInterval bri = - RMUtils.getWSRMPolicyFactory().createRMAssertionTypeBaseRetransmissionInterval(); - bri.setMilliseconds(new BigInteger("3000")); - rma.setBaseRetransmissionInterval(bri); - ExponentialBackoff eb = - RMUtils.getWSRMPolicyFactory().createRMAssertionTypeExponentialBackoff(); - eb.getOtherAttributes().put(ConfigurationHelper.EXPONENTIAL_BACKOFF_BASE_ATTR, - RetransmissionQueue.DEFAULT_EXPONENTIAL_BACKOFF); + + } + + public void tearDown() { + ref = null; + destination = null; + interceptor = null; + rma = null; + dp = null; + ap = null; } - public void testConstructors() throws DatatypeConfigurationException { - + public void testConstructors() { + Identifier otherId = factory.createIdentifier(); otherId.setValue("otherSeq"); - DestinationSequence seq = new DestinationSequence(id, ref, destination); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); assertEquals(id, seq.getIdentifier()); - assertNull(seq.getLastMessageNr()); + assertNull(seq.getLastMessageNumber()); assertSame(ref, seq.getAcksTo()); assertNotNull(seq.getAcknowledgment()); assertNotNull(seq.getMonitor()); SequenceAcknowledgement ack = RMUtils.getWSRMFactory().createSequenceAcknowledgement(); - seq = new DestinationSequence(id, ref, BigInteger.TEN, ack); + seq = new DestinationSequenceImpl(id, ref, BigInteger.TEN, ack); assertEquals(id, seq.getIdentifier()); - assertEquals(BigInteger.TEN, seq.getLastMessageNr()); + assertEquals(BigInteger.TEN, seq.getLastMessageNumber()); assertSame(ref, seq.getAcksTo()); assertSame(ack, seq.getAcknowledgment()); - assertNotNull(seq.getMonitor()); + assertNotNull(seq.getMonitor()); + } - public void testEqualsAndHashCode() { - DestinationSequence seq = new DestinationSequence(id, ref, destination); - DestinationSequence otherSeq = null; + public void testEqualsAndHashCode() { + + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); + DestinationSequenceImpl otherSeq = null; assertTrue(!seq.equals(otherSeq)); - otherSeq = new DestinationSequence(id, ref, destination); + otherSeq = new DestinationSequenceImpl(id, ref, destination); assertEquals(seq, otherSeq); assertEquals(seq.hashCode(), otherSeq.hashCode()); Identifier otherId = factory.createIdentifier(); otherId.setValue("otherSeq"); - otherSeq = new DestinationSequence(otherId, ref, destination); + otherSeq = new DestinationSequenceImpl(otherId, ref, destination); assertTrue(!seq.equals(otherSeq)); assertTrue(seq.hashCode() != otherSeq.hashCode()); assertTrue(!seq.equals(this)); @@ -102,12 +117,13 @@ public void testGetSetDestination() { control.replay(); - DestinationSequence seq = new DestinationSequence(id, ref, destination); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); seq.setDestination(destination); assertSame(destination, seq.getDestination()); } public void testGetEndpointIdentifier() { + /* destination.getHandler(); expectLastCall().andReturn(handler); handler.getConfigurationHelper(); @@ -116,14 +132,16 @@ expectLastCall().andReturn("abc.xyz"); control.replay(); - DestinationSequence seq = new DestinationSequence(id, ref, destination); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); seq.setDestination(destination); assertEquals("abc.xyz", seq.getEndpointIdentifier()); control.verify(); + */ } public void testGetAcknowledgementAsStream() throws SequenceFault { + /* destination.getHandler(); expectLastCall().andReturn(handler).times(3); handler.getStore(); @@ -144,22 +162,14 @@ assertNotNull(seq.getAcknowledgmentAsStream()); control.verify(); + */ } public void testAcknowledgeBasic() throws SequenceFault { - destination.getHandler(); - expectLastCall().andReturn(handler).times(6); - handler.getStore(); - expectLastCall().andReturn(null).times(2); - handler.getConfigurationHelper(); - expectLastCall().andReturn(configurationHelper).times(4); - configurationHelper.getRMAssertion(); - expectLastCall().andReturn(rma).times(2); - configurationHelper.getAcksPolicy(); - expectLastCall().andReturn(ap).times(2); + setUpDestination(); control.replay(); - DestinationSequence seq = new DestinationSequence(id, ref, destination); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); List<AcknowledgementRange> ranges = seq.getAcknowledgment().getAcknowledgementRange(); assertEquals(0, ranges.size()); @@ -179,19 +189,11 @@ } public void testAcknowledgeLastMessageNumberExceeded() throws SequenceFault { - - DestinationSequence seq = new DestinationSequence(id, ref, destination); - - RMAssertionType ra = control.createMock(RMAssertionType.class); - - expect(destination.getHandler()).andReturn(handler).times(3); - expect(handler.getStore()).andReturn(null); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper).times(2); - expect(configurationHelper.getRMAssertion()).andReturn(ra); - expect(ra.getAcknowledgementInterval()).andReturn(null); - expect(configurationHelper.getAcksPolicy()).andReturn(null); + setUpDestination(); control.replay(); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); + seq.acknowledge(BigInteger.ONE); seq.setLastMessageNumber(BigInteger.ONE); try { @@ -205,15 +207,10 @@ } public void testAcknowledgeAppendRange() throws SequenceFault { - - expect(destination.getHandler()).andReturn(handler).times(15); - expect(handler.getStore()).andReturn(null).times(5); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper).times(10); - expect(configurationHelper.getRMAssertion()).andReturn(rma).times(5); - expect(configurationHelper.getAcksPolicy()).andReturn(ap).times(5); + setUpDestination(); control.replay(); - DestinationSequence seq = new DestinationSequence(id, ref, destination); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); List<AcknowledgementRange> ranges = seq.getAcknowledgment().getAcknowledgementRange(); seq.acknowledge(new BigInteger("1")); seq.acknowledge(new BigInteger("2")); @@ -232,14 +229,10 @@ } public void testAcknowledgeInsertRange() throws SequenceFault { - expect(destination.getHandler()).andReturn(handler).times(21); - expect(handler.getStore()).andReturn(null).times(7); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper).times(14); - expect(configurationHelper.getRMAssertion()).andReturn(rma).times(7); - expect(configurationHelper.getAcksPolicy()).andReturn(ap).times(7); + setUpDestination(); control.replay(); - DestinationSequence seq = new DestinationSequence(id, ref, destination); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); List<AcknowledgementRange> ranges = seq.getAcknowledgment().getAcknowledgementRange(); seq.acknowledge(new BigInteger("1")); seq.acknowledge(new BigInteger("2")); @@ -264,14 +257,10 @@ } public void testAcknowledgePrependRange() throws SequenceFault { - expect(destination.getHandler()).andReturn(handler).times(18); - expect(handler.getStore()).andReturn(null).times(6); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper).times(12); - expect(configurationHelper.getRMAssertion()).andReturn(rma).times(6); - expect(configurationHelper.getAcksPolicy()).andReturn(ap).times(6); + setUpDestination(); control.replay(); - DestinationSequence seq = new DestinationSequence(id, ref, destination); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); List<AcknowledgementRange> ranges = seq.getAcknowledgment().getAcknowledgementRange(); seq.acknowledge(new BigInteger("4")); seq.acknowledge(new BigInteger("5")); @@ -291,14 +280,10 @@ } public void testMonitor() throws SequenceFault { - expect(destination.getHandler()).andReturn(handler).times(45); - expect(handler.getStore()).andReturn(null).times(15); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper).times(30); - expect(configurationHelper.getRMAssertion()).andReturn(rma).times(15); - expect(configurationHelper.getAcksPolicy()).andReturn(ap).times(15); + setUpDestination(); control.replay(); - DestinationSequence seq = new DestinationSequence(id, ref, destination); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); SequenceMonitor monitor = seq.getMonitor(); assertNotNull(monitor); monitor.setMonitorInterval(500); @@ -336,14 +321,10 @@ } public void testAcknowledgeImmediate() throws SequenceFault { - expect(destination.getHandler()).andReturn(handler).times(3); - expect(handler.getStore()).andReturn(null); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper).times(2); - expect(configurationHelper.getRMAssertion()).andReturn(rma).times(1); - expect(configurationHelper.getAcksPolicy()).andReturn(ap).times(1); + setUpDestination(); control.replay(); - DestinationSequence seq = new DestinationSequence(id, ref, destination); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); assertTrue(!seq.sendAcknowledgement()); seq.acknowledge(new BigInteger("1")); @@ -356,30 +337,25 @@ } public void testAcknowledgeDeferred() throws SequenceFault, IOException { - ap.setIntraMessageThreshold(0); - AcknowledgementInterval ai = - RMUtils.getWSRMPolicyFactory().createRMAssertionTypeAcknowledgementInterval(); - ai.setMilliseconds(new BigInteger("200")); - rma.setAcknowledgementInterval(ai); - - Timer timer = new Timer(); - expect(destination.getHandler()).andReturn(handler).times(11); - expect(handler.getStore()).andReturn(null).times(3); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper).times(6); - expect(handler.getTimer()).andReturn(timer).times(1); - expect(configurationHelper.getRMAssertion()).andReturn(rma).times(3); - expect(configurationHelper.getAcksPolicy()).andReturn(ap).times(3); + setUpDestination(true); - DestinationSequence seq = new DestinationSequence(id, ref, destination); - assertTrue(!seq.sendAcknowledgement()); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); - RMProxy proxy = control.createMock(RMProxy.class); - handler.getProxy(); + Proxy proxy = control.createMock(Proxy.class); + interceptor.getProxy(); expectLastCall().andReturn(proxy); proxy.acknowledge(seq); expectLastCall(); - control.replay(); + control.replay(); + + ap.setIntraMessageThreshold(0); + AcknowledgementInterval ai = new org.apache.cxf.ws.rm.policy.ObjectFactory() + .createRMAssertionAcknowledgementInterval(); + ai.setMilliseconds(new BigInteger("200")); + rma.setAcknowledgementInterval(ai); + + assertTrue(!seq.sendAcknowledgement()); seq.acknowledge(new BigInteger("1")); seq.acknowledge(new BigInteger("2")); @@ -400,7 +376,8 @@ } public void testCorrelationID() { - DestinationSequence seq = new DestinationSequence(id, ref, destination); + setUpDestination(); + DestinationSequenceImpl seq = new DestinationSequenceImpl(id, ref, destination); String correlationID = "abdc1234"; assertNull("unexpected correlation ID", seq.getCorrelationID()); seq.setCorrelationID(correlationID); @@ -410,28 +387,27 @@ } public void testApplyDeliveryAssuranceAtMostOnce() { - BigInteger mn = BigInteger.TEN; - DeliveryAssuranceType da = control.createMock(DeliveryAssuranceType.class); + setUpDestination(); + + BigInteger mn = BigInteger.TEN; SequenceAcknowledgement ack = control.createMock(SequenceAcknowledgement.class); List<AcknowledgementRange> ranges = new ArrayList<AcknowledgementRange>(); AcknowledgementRange r = control.createMock(AcknowledgementRange.class); - expect(destination.getHandler()).andReturn(handler); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper); - expect(configurationHelper.getDeliveryAssurance()).andReturn(da); - expect(da.isSetAtMostOnce()).andReturn(true); expect(ack.getAcknowledgementRange()).andReturn(ranges); + DeliveryAssuranceType da = control.createMock(DeliveryAssuranceType.class); + expect(interceptor.getDeliveryAssurance()).andReturn(da); + expect(da.isSetAtMostOnce()).andReturn(true); control.replay(); - DestinationSequence ds = new DestinationSequence(id, ref, null, ack); + DestinationSequenceImpl ds = new DestinationSequenceImpl(id, ref, null, ack); ds.setDestination(destination); assertTrue("message had already been delivered", ds.applyDeliveryAssurance(mn)); control.verify(); control.reset(); ranges.add(r); - expect(destination.getHandler()).andReturn(handler); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper); - expect(configurationHelper.getDeliveryAssurance()).andReturn(da); + expect(destination.getInterceptor()).andReturn(interceptor); + expect(interceptor.getDeliveryAssurance()).andReturn(da); expect(da.isSetAtMostOnce()).andReturn(true); expect(ack.getAcknowledgementRange()).andReturn(ranges); expect(r.getLower()).andReturn(new BigInteger("5")); @@ -439,46 +415,55 @@ control.replay(); assertTrue("message has not yet been delivered", !ds.applyDeliveryAssurance(mn)); control.verify(); + } public void testInOrderNoWait() { + setUpDestination(); + BigInteger mn = BigInteger.TEN; + DeliveryAssuranceType da = control.createMock(DeliveryAssuranceType.class); + expect(interceptor.getDeliveryAssurance()).andReturn(da).anyTimes(); + expect(da.isSetAtMostOnce()).andReturn(false); + expect(da.isSetAtLeastOnce()).andReturn(true); + expect(da.isSetInOrder()).andReturn(true); + SequenceAcknowledgement ack = control.createMock(SequenceAcknowledgement.class); List<AcknowledgementRange> ranges = new ArrayList<AcknowledgementRange>(); AcknowledgementRange r = control.createMock(AcknowledgementRange.class); ranges.add(r); - expect(destination.getHandler()).andReturn(handler); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper); - expect(configurationHelper.getDeliveryAssurance()).andReturn(da); - expect(da.isSetAtMostOnce()).andReturn(false); - expect(da.isSetAtLeastOnce()).andReturn(true); - expect(da.isSetInOrder()).andReturn(true); expect(ack.getAcknowledgementRange()).andReturn(ranges).times(3); expect(r.getLower()).andReturn(BigInteger.ONE); expect(r.getUpper()).andReturn(new BigInteger("15")); + control.replay(); - DestinationSequence ds = new DestinationSequence(id, ref, null, ack); + + DestinationSequenceImpl ds = new DestinationSequenceImpl(id, ref, null, ack); ds.setDestination(destination); assertTrue(ds.applyDeliveryAssurance(mn)); control.verify(); } public void testInOrderWait() { + setUpDestination(); + DeliveryAssuranceType da = control.createMock(DeliveryAssuranceType.class); - rma = control.createMock(RMAssertionType.class); - SequenceAcknowledgement ack = RMUtils.getWSRMFactory().createSequenceAcknowledgement(); + expect(interceptor.getDeliveryAssurance()).andReturn(da).anyTimes(); + expect(da.isSetAtMostOnce()).andReturn(false).anyTimes(); + expect(da.isSetAtLeastOnce()).andReturn(true).anyTimes(); + expect(da.isSetInOrder()).andReturn(true).anyTimes(); + + SequenceAcknowledgement ack = factory.createSequenceAcknowledgement(); List<AcknowledgementRange> ranges = new ArrayList<AcknowledgementRange>(); final int n = 5; final AcknowledgementRange r = - RMUtils.getWSRMFactory().createSequenceAcknowledgementAcknowledgementRange(); + factory.createSequenceAcknowledgementAcknowledgementRange(); r.setUpper(new BigInteger(Integer.toString(n))); ranges.add(r); - final DestinationSequence ds = new DestinationSequence(id, ref, null, ack); + final DestinationSequenceImpl ds = new DestinationSequenceImpl(id, ref, null, ack); ds.setDestination(destination); - - - + class Acknowledger extends Thread { BigInteger mn; @@ -495,19 +480,6 @@ } } } - - - - expect(destination.getHandler()).andReturn(handler).times(n * 4); - expect(handler.getStore()).andReturn(null).times(n); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper).times(n * 3); - expect(configurationHelper.getDeliveryAssurance()).andReturn(da).times(n); - expect(da.isSetAtMostOnce()).andReturn(false).times(n); - expect(da.isSetAtLeastOnce()).andReturn(true).times(n); - expect(da.isSetInOrder()).andReturn(true).times(n); - expect(configurationHelper.getRMAssertion()).andReturn(rma).times(n); - expect(rma.getAcknowledgementInterval()).andReturn(null).times(n); - expect(configurationHelper.getAcksPolicy()).andReturn(null).times(n); control.replay(); @@ -536,12 +508,13 @@ } public void testAllPredecessorsAcknowledged() { + SequenceAcknowledgement ack = control.createMock(SequenceAcknowledgement.class); List<AcknowledgementRange> ranges = new ArrayList<AcknowledgementRange>(); AcknowledgementRange r = control.createMock(AcknowledgementRange.class); expect(ack.getAcknowledgementRange()).andReturn(ranges); control.replay(); - DestinationSequence ds = new DestinationSequence(id, ref, null, ack); + DestinationSequenceImpl ds = new DestinationSequenceImpl(id, ref, null, ack); ds.setDestination(destination); assertTrue("all predecessors acknowledged", !ds.allPredecessorsAcknowledged(BigInteger.TEN)); control.verify(); @@ -577,5 +550,48 @@ assertTrue("all predecessors acknowledged", !ds.allPredecessorsAcknowledged(BigInteger.TEN)); control.verify(); } + + private void setUpDestination() { + setUpDestination(false); + } + + private void setUpDestination(boolean withTimer) { + + interceptor = control.createMock(RMInterceptor.class); + + org.apache.cxf.ws.rm.interceptor.ObjectFactory cfgFactory = + new org.apache.cxf.ws.rm.interceptor.ObjectFactory(); + dp = cfgFactory.createDestinationPolicyType(); + ap = cfgFactory.createAcksPolicyType(); + dp.setAcksPolicy(ap); + + org.apache.cxf.ws.rm.policy.ObjectFactory policyFactory = + new org.apache.cxf.ws.rm.policy.ObjectFactory(); + rma = policyFactory.createRMAssertion(); + BaseRetransmissionInterval bri = + policyFactory.createRMAssertionBaseRetransmissionInterval(); + bri.setMilliseconds(new BigInteger("3000")); + rma.setBaseRetransmissionInterval(bri); + + interceptor.getRMAssertion(); + expectLastCall().andReturn(rma).anyTimes(); + interceptor.getDestinationPolicy(); + expectLastCall().andReturn(dp).anyTimes(); + + interceptor.getStore(); + expectLastCall().andReturn(null).anyTimes(); + + destination = control.createMock(Destination.class); + destination.getInterceptor(); + expectLastCall().andReturn(interceptor).anyTimes(); + + if (withTimer) { + Timer timer = new Timer(); + interceptor.getTimer(); + expectLastCall().andReturn(timer).anyTimes(); + } + + } + }
Copied: incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/impl/SourceSequenceImplTest.java (from r462829, incubator/cxf/tags/celtix/pre_apache/rt/ws/rm/src/test/java/org/objectweb/celtix/ws/rm/SourceSequenceTest.java) URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/impl/SourceSequenceImplTest.java?view=diff&rev=463282&p1=incubator/cxf/tags/celtix/pre_apache/rt/ws/rm/src/test/java/org/objectweb/celtix/ws/rm/SourceSequenceTest.java&r1=462829&p2=incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/impl/SourceSequenceImplTest.java&r2=463282 ============================================================================== --- incubator/cxf/tags/celtix/pre_apache/rt/ws/rm/src/test/java/org/objectweb/celtix/ws/rm/SourceSequenceTest.java (original) +++ incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/impl/SourceSequenceImplTest.java Thu Oct 12 08:34:05 2006 @@ -1,43 +1,64 @@ -package org.objectweb.celtix.ws.rm; +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.ws.rm.impl; import java.math.BigInteger; import java.util.Date; -import javax.xml.datatype.DatatypeConfigurationException; -import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.Duration; import junit.framework.TestCase; +import org.apache.cxf.jaxb.DatatypeFactory; +import org.apache.cxf.ws.rm.Expires; +import org.apache.cxf.ws.rm.Identifier; +import org.apache.cxf.ws.rm.ObjectFactory; +import org.apache.cxf.ws.rm.SequenceAcknowledgement; +import org.apache.cxf.ws.rm.SequenceFault; +import org.apache.cxf.ws.rm.interceptor.SequenceTerminationPolicyType; +import org.apache.cxf.ws.rm.interceptor.SourcePolicyType; + import org.easymock.classextension.EasyMock; import org.easymock.classextension.IMocksControl; -import org.objectweb.celtix.bus.configuration.wsrm.AcksPolicyType; -import org.objectweb.celtix.bus.configuration.wsrm.SequenceTerminationPolicyType; -import org.objectweb.celtix.ws.rm.SequenceAcknowledgement.AcknowledgementRange; -import org.objectweb.celtix.ws.rm.policy.RMAssertionType; -import org.objectweb.celtix.ws.rm.policy.RMAssertionType.BaseRetransmissionInterval; -import org.objectweb.celtix.ws.rm.policy.RMAssertionType.ExponentialBackoff; -import org.objectweb.celtix.ws.rm.wsdl.SequenceFault; - -import static org.easymock.EasyMock.expect; - -public class SourceSequenceTest extends TestCase { - - IMocksControl control; - ObjectFactory factory = new ObjectFactory(); - Identifier id; - RMSource source; - RMDestination destination; - RMHandler handler; - ConfigurationHelper configurationHelper; - RMAssertionType rma; - AcksPolicyType ap; + +public class SourceSequenceImplTest extends TestCase { + + private IMocksControl control; + private ObjectFactory factory; + private Identifier id; + + private Source source; + // Destination destination; + private RMInterceptor interceptor; + private SourcePolicyType sp; + private SequenceTerminationPolicyType stp; + - public void setUp() { - + public void setUp() { + factory = new ObjectFactory(); id = factory.createIdentifier(); id.setValue("seq"); + control = EasyMock.createNiceControl(); + + /* ap = RMUtils.getWSRMConfFactory().createAcksPolicyType(); rma = RMUtils.getWSRMPolicyFactory().createRMAssertionType(); BaseRetransmissionInterval bri = @@ -48,17 +69,42 @@ RMUtils.getWSRMPolicyFactory().createRMAssertionTypeExponentialBackoff(); eb.getOtherAttributes().put(ConfigurationHelper.EXPONENTIAL_BACKOFF_BASE_ATTR, RetransmissionQueue.DEFAULT_EXPONENTIAL_BACKOFF); + */ } + + public void tearDown() { + source = null; + interceptor = null; + sp = null; + stp = null; + } + + void setUpSource() { + source = control.createMock(Source.class); + interceptor = control.createMock(RMInterceptor.class); + EasyMock.expect(source.getInterceptor()).andReturn(interceptor).anyTimes(); + + // default termination policy + + org.apache.cxf.ws.rm.interceptor.ObjectFactory cfgFactory = + new org.apache.cxf.ws.rm.interceptor.ObjectFactory(); + sp = cfgFactory.createSourcePolicyType(); + stp = cfgFactory + .createSequenceTerminationPolicyType(); + sp.setSequenceTerminationPolicy(stp); + EasyMock.expect(interceptor.getSourcePolicy()).andReturn(sp).anyTimes(); + } + public void testConstructors() { Identifier otherId = factory.createIdentifier(); otherId.setValue("otherSeq"); - SourceSequence seq = null; + SourceSequenceImpl seq = null; - seq = new SourceSequence(id); + seq = new SourceSequenceImpl(id); assertEquals(id, seq.getIdentifier()); assertTrue(!seq.isLastMessage()); assertTrue(!seq.isExpired()); @@ -70,7 +116,7 @@ Date expiry = new Date(System.currentTimeMillis() + 3600 * 1000); - seq = new SourceSequence(id, expiry, null); + seq = new SourceSequenceImpl(id, expiry, null); assertEquals(id, seq.getIdentifier()); assertTrue(!seq.isLastMessage()); assertTrue(!seq.isExpired()); @@ -80,66 +126,69 @@ assertTrue(!seq.allAcknowledged()); assertFalse(seq.offeredBy(otherId)); - seq = new SourceSequence(id, expiry, otherId); + seq = new SourceSequenceImpl(id, expiry, otherId); assertTrue(seq.offeredBy(otherId)); assertFalse(seq.offeredBy(id)); } - public void testSetExpires() throws DatatypeConfigurationException { - SourceSequence seq = new SourceSequence(id); + public void testSetExpires() { + SourceSequenceImpl seq = new SourceSequenceImpl(id); Expires expires = factory.createExpires(); - - DatatypeFactory dbf = DatatypeFactory.newInstance(); - Duration d = dbf.newDuration(0); - expires.setValue(d); seq.setExpires(expires); + assertTrue(!seq.isExpired()); - d = dbf.newDuration("PT0S"); - expires.setValue(d); + Duration d = DatatypeFactory.PT0S; + expires.setValue(d); seq.setExpires(expires); - assertTrue(!seq.isExpired()); + try { + Thread.sleep(1000); + } catch (InterruptedException ex) { + assertTrue(!seq.isExpired()); + } - d = dbf.newDuration(1000); + d = DatatypeFactory.createDuration("PT1S"); expires.setValue(d); seq.setExpires(expires); assertTrue(!seq.isExpired()); - d = dbf.newDuration("-PT1S"); + d = DatatypeFactory.createDuration("-PT1S"); expires.setValue(d); seq.setExpires(expires); assertTrue(seq.isExpired()); } - + public void testEqualsAndHashCode() { - SourceSequence seq = new SourceSequence(id); - SourceSequence otherSeq = null; + SourceSequenceImpl seq = new SourceSequenceImpl(id); + SourceSequenceImpl otherSeq = null; assertTrue(!seq.equals(otherSeq)); - otherSeq = new SourceSequence(id); + otherSeq = new SourceSequenceImpl(id); assertEquals(seq, otherSeq); assertEquals(seq.hashCode(), otherSeq.hashCode()); Identifier otherId = factory.createIdentifier(); otherId.setValue("otherSeq"); - otherSeq = new SourceSequence(otherId); + otherSeq = new SourceSequenceImpl(otherId); assertTrue(!seq.equals(otherSeq)); assertTrue(seq.hashCode() != otherSeq.hashCode()); assertTrue(!seq.equals(this)); } + public void testSetAcknowledged() { - SourceSequence seq = new SourceSequence(id); + SourceSequenceImpl seq = new SourceSequenceImpl(id); SequenceAcknowledgement ack = seq.getAcknowledgement(); - ack = RMUtils.getWSRMFactory().createSequenceAcknowledgement(); - AcknowledgementRange r = RMUtils.getWSRMFactory().createSequenceAcknowledgementAcknowledgementRange(); + ack = factory.createSequenceAcknowledgement(); + SequenceAcknowledgement.AcknowledgementRange r = + factory.createSequenceAcknowledgementAcknowledgementRange(); r.setLower(new BigInteger("1")); r.setUpper(new BigInteger("2")); ack.getAcknowledgementRange().add(r); - r = RMUtils.getWSRMFactory().createSequenceAcknowledgementAcknowledgementRange(); + r = factory.createSequenceAcknowledgementAcknowledgementRange(); r.setLower(new BigInteger("4")); r.setUpper(new BigInteger("6")); ack.getAcknowledgementRange().add(r); - r = RMUtils.getWSRMFactory().createSequenceAcknowledgementAcknowledgementRange(); + r = factory.createSequenceAcknowledgementAcknowledgementRange(); r.setLower(new BigInteger("8")); r.setUpper(new BigInteger("10")); ack.getAcknowledgementRange().add(r); @@ -149,16 +198,17 @@ assertTrue(!seq.isAcknowledged(new BigInteger("3"))); assertTrue(seq.isAcknowledged(new BigInteger("5"))); } - + public void testAllAcknowledged() throws SequenceFault { - SourceSequence seq = new SourceSequence(id, null, null, new BigInteger("4"), false); + SourceSequenceImpl seq = new SourceSequenceImpl(id, null, null, new BigInteger("4"), false); assertTrue(!seq.allAcknowledged()); seq.setLastMessage(true); assertTrue(!seq.allAcknowledged()); - SequenceAcknowledgement ack = RMUtils.getWSRMFactory().createSequenceAcknowledgement(); - AcknowledgementRange r = RMUtils.getWSRMFactory().createSequenceAcknowledgementAcknowledgementRange(); + SequenceAcknowledgement ack = factory.createSequenceAcknowledgement(); + SequenceAcknowledgement.AcknowledgementRange r = + factory.createSequenceAcknowledgementAcknowledgementRange(); r.setLower(BigInteger.ONE); r.setUpper(new BigInteger("2")); ack.getAcknowledgementRange().add(r); @@ -169,58 +219,58 @@ } public void testNextMessageNumber() { - SourceSequence seq = null; - control = EasyMock.createNiceControl(); - source = control.createMock(RMSource.class); - destination = control.createMock(RMDestination.class); - handler = control.createMock(RMHandler.class); - configurationHelper = control.createMock(ConfigurationHelper.class); + SourceSequenceImpl seq = null; + setUpSource(); + control.replay(); // default termination policy - - SequenceTerminationPolicyType stp = - RMUtils.getWSRMConfFactory().createSequenceTerminationPolicyType(); - - seq = new SourceSequence(id); + + seq = new SourceSequenceImpl(id); seq.setSource(source); - assertTrue(!nextMessages(seq, stp, 10)); + assertTrue(!nextMessages(seq, 10)); + control.verify(); // termination policy max length = 1 - seq = new SourceSequence(id); + seq = new SourceSequenceImpl(id); seq.setSource(source); stp.setMaxLength(BigInteger.ONE); - assertTrue(nextMessages(seq, stp, 10)); + assertTrue(nextMessages(seq, 10)); assertEquals(BigInteger.ONE, seq.getCurrentMessageNr()); + control.verify(); // termination policy max length = 5 - seq = new SourceSequence(id); + seq = new SourceSequenceImpl(id); seq.setSource(source); stp.setMaxLength(new BigInteger("5")); - assertTrue(!nextMessages(seq, stp, 2)); + assertTrue(!nextMessages(seq, 2)); + control.verify(); // termination policy max range exceeded - seq = new SourceSequence(id); + seq = new SourceSequenceImpl(id); seq.setSource(source); stp.setMaxLength(null); stp.setMaxRanges(new Integer(3)); acknowledge(seq, 1, 2, 4, 5, 6, 8, 9, 10); - assertTrue(nextMessages(seq, stp, 10)); + assertTrue(nextMessages(seq, 10)); assertEquals(BigInteger.ONE, seq.getCurrentMessageNr()); + control.verify(); // termination policy max range not exceeded - seq = new SourceSequence(id); + seq = new SourceSequenceImpl(id); seq.setSource(source); stp.setMaxLength(null); stp.setMaxRanges(new Integer(4)); acknowledge(seq, 1, 2, 4, 5, 6, 8, 9, 10); - assertTrue(!nextMessages(seq, stp, 10)); + assertTrue(!nextMessages(seq, 10)); + control.verify(); // termination policy max unacknowledged } + /* public void testGetEndpointIdentfier() { SourceSequence seq = null; control = EasyMock.createNiceControl(); @@ -239,29 +289,24 @@ assertEquals("abc.xyz", seq.getEndpointIdentifier()); control.verify(); } + */ public void testCheckOfferingSequenceClosed() { - SourceSequence seq = null; + SourceSequenceImpl seq = null; - control = EasyMock.createNiceControl(); - source = control.createMock(RMSource.class); - destination = control.createMock(RMDestination.class); - handler = control.createMock(RMHandler.class); - configurationHelper = control.createMock(ConfigurationHelper.class); - - DestinationSequence dseq = control.createMock(DestinationSequence.class); + setUpSource(); + + Destination destination = control.createMock(Destination.class); + EasyMock.expect(interceptor.getDestination(source)).andReturn(destination).anyTimes(); + DestinationSequenceImpl dseq = control.createMock(DestinationSequenceImpl.class); Identifier did = control.createMock(Identifier.class); - - - expect(source.getHandler()).andReturn(handler); - expect(handler.getDestination()).andReturn(destination); - expect(destination.getSequence(did)).andReturn(dseq); - expect(dseq.getLastMessageNr()).andReturn(BigInteger.ONE); - expect(did.getValue()).andReturn("dseq").times(2); + EasyMock.expect(destination.getSequenceImpl(did)).andReturn(dseq).anyTimes(); + EasyMock.expect(dseq.getLastMessageNumber()).andReturn(BigInteger.ONE).anyTimes(); + EasyMock.expect(did.getValue()).andReturn("dseq").anyTimes(); control.replay(); - seq = new SourceSequence(id, null, did); + seq = new SourceSequenceImpl(id, null, did); seq.setSource(source); seq.nextMessageNumber(did, BigInteger.ONE); assertTrue(seq.isLastMessage()); @@ -269,6 +314,7 @@ control.verify(); } + /* public void testIdentifierEquals() { control = EasyMock.createNiceControl(); Identifier id1 = null; @@ -286,38 +332,25 @@ id2.setValue("seq1"); assertTrue(AbstractSequenceImpl.identifierEquals(id1, id2)); } - - private boolean nextMessages(SourceSequence seq, SequenceTerminationPolicyType stp, int n) { - - control.reset(); - expect(source.getHandler()).andReturn(handler); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper); - expect(configurationHelper.getSequenceTerminationPolicy()) - .andReturn(stp); - control.replay(); - + */ + + + private boolean nextMessages(SourceSequenceImpl seq, + int n) { int i = 0; while ((i < n) && !seq.isLastMessage()) { assertNotNull(seq.nextMessageNumber()); - control.verify(); - control.reset(); - expect(source.getHandler()).andReturn(handler); - expect(handler.getConfigurationHelper()).andReturn(configurationHelper); - expect(configurationHelper.getSequenceTerminationPolicy()) - .andReturn(stp); - control.replay(); i++; } return seq.isLastMessage(); } - // this method cannot be private because of a bug in PMD which otherwise - // would report it as an 'unused private method' - protected void acknowledge(SourceSequence seq, int... messageNumbers) { + protected void acknowledge(SourceSequenceImpl seq, int... messageNumbers) { SequenceAcknowledgement ack = factory.createSequenceAcknowledgement(); int i = 0; while (i < messageNumbers.length) { - AcknowledgementRange r = factory.createSequenceAcknowledgementAcknowledgementRange(); + SequenceAcknowledgement.AcknowledgementRange r = + factory.createSequenceAcknowledgementAcknowledgementRange(); Integer li = new Integer(messageNumbers[i]); BigInteger l = new BigInteger(li.toString()); r.setLower(l); @@ -333,5 +366,4 @@ } seq.setAcknowledged(ack); } - }
