Sorry for the confusing, I made a quick conclusion without reading the mail twice.

On Tue Jul 24 17:22:40 2012, Babak Vahdat wrote:
Hi

The issue being reported here has nothing to do with CAMEL-5440 as this one
is about:

MockEndpoint.expectedBodiesReceivedInAnyOrder()

And not:

MockEndpoint.expectedHeaderReceived()

I opened a JIRA ticket to fix this:

https://issues.apache.org/jira/browse/CAMEL-5460

Babak


Willem.Jiang wrote

This issue[1] has been fixed few weeks ago.
[1]https://issues.apache.org/jira/browse/CAMEL-5440

On Tue, Jul 24, 2012 at 5:51 AM, Christian Müller <
christian.mueller@> wrote:

Thanks for reporting William!

Do you consider to raise an JIRA [1] and attach your patch?

[1] https://issues.apache.org/jira/browse/CAMEL

Best,
Christian

On Mon, Jul 23, 2012 at 10:24 PM, wjmcdonald <
william.mcdonald@> wrote:

When trying to test bodies received like:
     mock.expectedBodiesReceivedInAnyOrder("100000", "400000", "300000",
"200000", "400000");

The assertMockEndpointsSatisfied() fails because it does not allow
duplicate
items in the list (eg. two "400000").

There is nothing in the javadoc headers that describes the contract
these
methods have (ie. duplicates allowed or not).  However, I believe that
duplicate message bodies allowed is the correct way it should work.

Looking at the implementation, the family of
expectedBodiesReceivedxxx()
use
a Set which doesn't allow duplicate items.  The following change to a
Multiset fixes the problem.  I don't know if it is threadsafe.

(Also, in general, I don't like using 'remove' from collection classes
in
an
iteration as a way of counting things, etc.  I'd prefer an empty
container
that you add to, rather than one that you subtract from.  Perhaps
modern
Java doesn't have any problems with 'remove()' in a loop anymore, or in
this
situation since its not using an Iterator.)

import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;

   /**
      * Adds an expectation that the given body values are received by
this
      * endpoint in any order
      */
     public void expectedBodiesReceivedInAnyOrder(final List<?> bodies)
{
         expectedMessageCount(bodies.size());
         this.expectedBodyValues = bodies;
         this.actualBodyValues = new ArrayList();

         expects(new Runnable() {
             public void run() {
              /* These two lines changed */
                 Multiset actualBodyValuesSet = HashMultiset.create();
                 actualBodyValuesSet.addAll(actualBodyValues);
                 for (int i = 0; i < expectedBodyValues.size(); i++) {
                     Exchange exchange = getReceivedExchange(i);
                     assertTrue("No exchange received for counter: " +
i,
exchange != null);

                     Object expectedBody = expectedBodyValues.get(i);
                     assertTrue("Message with body " + expectedBody
                             + " was expected but not found in " +
actualBodyValuesSet,
                             actualBodyValuesSet.remove(expectedBody));
                 }
             }
         });
     }

Can you fix this family of methods to accept duplicates?




--
View this message in context:

http://camel.465427.n5.nabble.com/MockEndpoint-expectedBodiesReceived-should-handle-duplicates-tp5716363.html
Sent from the Camel - Users mailing list archive at Nabble.com.







--
View this message in context: 
http://camel.465427.n5.nabble.com/MockEndpoint-expectedBodiesReceived-should-handle-duplicates-tp5716363p5716385.html
Sent from the Camel - Users mailing list archive at Nabble.com.




--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
        http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Reply via email to