You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by wjmcdonald <wi...@transcentra.com> on 2012/07/23 22:24:47 UTC

MockEndpoint expectedBodiesReceived should handle duplicates

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.

Re: MockEndpoint expectedBodiesReceived should handle duplicates

Posted by Willem Jiang <wi...@gmail.com>.
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


Re: MockEndpoint expectedBodiesReceived should handle duplicates

Posted by Babak Vahdat <ba...@swissonline.ch>.
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.

Re: MockEndpoint expectedBodiesReceived should handle duplicates

Posted by Willem Jiang <wi...@gmail.com>.
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@gmail.com> 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@transcentra.com> 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.
> >
>

Re: MockEndpoint expectedBodiesReceived should handle duplicates

Posted by Willem Jiang <wi...@gmail.com>.
You can log a JIRA even you are not a committer :)

On Wed Jul 25 00:23:25 2012, wjmcdonald wrote:
> Oh. Sorry - I presumed I had to be a committer to do that.  I'll consider
> it in the future however.
>
> TIA,
>          --Bill
> William McDonald
> Sr. Software Developer   |  TransCentra, Inc.
> Office: 1-602-635-5910  |   Mobile: 1-602-741-3664  |
> william.mcdonald@transcentra.com   |   www.TransCentra.com
> Regulus Group and J&B Software are now TransCentra
>
> This email message is intended for the named recipient only and may be
> privileged and/or confidential. If you are not the intended or named
> recipient or have received this email in error then you should not copy,
> forward or disclose it to any other person. The views and opinions
> expressed in this email are those of the sender and may not represent the
> views and opinions of TransCentra.
>
>
>
> From:   "Christian Mueller [via Camel]"
> <ml...@n5.nabble.com>
> To:     wjmcdonald <wi...@transcentra.com>
> Date:   07/23/2012 02:50 PM
> Subject:        Re: MockEndpoint expectedBodiesReceived should handle
> duplicates
>
>
>
> 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 <
> [hidden email]> 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.
>>
>
>
>
> If you reply to this email, your message will be added to the discussion
> below:
> http://camel.465427.n5.nabble.com/MockEndpoint-expectedBodiesReceived-should-handle-duplicates-tp5716363p5716367.html
>
> To unsubscribe from MockEndpoint expectedBodiesReceived should handle
> duplicates, click here.
> NAML
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/MockEndpoint-expectedBodiesReceived-should-handle-duplicates-tp5716363p5716417.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


Re: MockEndpoint expectedBodiesReceived should handle duplicates

Posted by Babak Vahdat <ba...@swissonline.ch>.
Yeah you can find the details here about how you could contribute: 

http://camel.apache.org/contributing.html

And the issue you have reported is already fixed which will be part of the
upcoming 2.11 / 2.10.1 / 2.9.3 releases.

Babak 



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

Re: MockEndpoint expectedBodiesReceived should handle duplicates

Posted by wjmcdonald <wi...@transcentra.com>.
Oh. Sorry - I presumed I had to be a committer to do that.  I'll consider 
it in the future however.

TIA,
        --Bill
William McDonald
Sr. Software Developer   |  TransCentra, Inc.
Office: 1-602-635-5910  |   Mobile: 1-602-741-3664  | 
william.mcdonald@transcentra.com   |   www.TransCentra.com
Regulus Group and J&B Software are now TransCentra

This email message is intended for the named recipient only and may be 
privileged and/or confidential. If you are not the intended or named 
recipient or have received this email in error then you should not copy, 
forward or disclose it to any other person. The views and opinions 
expressed in this email are those of the sender and may not represent the 
views and opinions of TransCentra.



From:   "Christian Mueller [via Camel]" 
<ml...@n5.nabble.com>
To:     wjmcdonald <wi...@transcentra.com>
Date:   07/23/2012 02:50 PM
Subject:        Re: MockEndpoint expectedBodiesReceived should handle 
duplicates



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 < 
[hidden email]> 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. 
> 



If you reply to this email, your message will be added to the discussion 
below:
http://camel.465427.n5.nabble.com/MockEndpoint-expectedBodiesReceived-should-handle-duplicates-tp5716363p5716367.html 

To unsubscribe from MockEndpoint expectedBodiesReceived should handle 
duplicates, click here.
NAML 




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

Re: MockEndpoint expectedBodiesReceived should handle duplicates

Posted by Christian Müller <ch...@gmail.com>.
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@transcentra.com> 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.
>