You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by David Karlsen <da...@gmail.com> on 2012/11/05 21:27:20 UTC
Strange MockEndpoint.expectedBodiesReceived behaviour
I'm confused about how expectedBodiesReceived behaves.
I have a route where I mock a jms endpoint (the endpoint is sent to in
an onException route as follows:
<camel:onException>
<camel:exception>java.lang.Exception</camel:exception>
<camel:handled>
<camel:constant>true</camel:constant>
</camel:handled>
<camel:to
id="inboundFromRtsErrorQueue"
uri="jms:queue:{{rts.online.mq.reservationsReceiveErrorQueue}}?connectionFactory=#rtsConnectionFactory&destinationResolver=#rtsDestinationResolver"
/>
I then override the sending to inboundFromRtsErrorQueue by id in the
setup of my testclass.
Everything works ok:
mockInboundFromRtsErrorQueue.setExpectedMessageCount( 1 );
Exchange failedExchange =
mockInboundFromRtsErrorQueue.getExchanges().get( 0 );
Assert.assertEquals( payload, failedExchange.getIn().getBody() );
//mockInboundFromRtsErrorQueue.expectedBodiesReceived( payload
); //strangely this does not pass - but the above does
mockInboundFromRtsErrorQueue.assertIsSatisfied();
but I'm surprised that if I comment in the second-last line it will
fail. Why? As line no 2&3 does exactly the same??
--
--
David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
Re: Strange MockEndpoint.expectedBodiesReceived behaviour
Posted by Claus Ibsen <cl...@gmail.com>.
Make sure you set you expectations on the mocks first in your unit
test. Before any messages gets routed etc.
On Mon, Nov 5, 2012 at 9:27 PM, David Karlsen <da...@gmail.com> wrote:
> I'm confused about how expectedBodiesReceived behaves.
>
> I have a route where I mock a jms endpoint (the endpoint is sent to in
> an onException route as follows:
>
> <camel:onException>
>
> <camel:exception>java.lang.Exception</camel:exception>
> <camel:handled>
> <camel:constant>true</camel:constant>
> </camel:handled>
> <camel:to
> id="inboundFromRtsErrorQueue"
> uri="jms:queue:{{rts.online.mq.reservationsReceiveErrorQueue}}?connectionFactory=#rtsConnectionFactory&destinationResolver=#rtsDestinationResolver"
> />
>
>
> I then override the sending to inboundFromRtsErrorQueue by id in the
> setup of my testclass.
>
> Everything works ok:
>
>
> mockInboundFromRtsErrorQueue.setExpectedMessageCount( 1 );
> Exchange failedExchange =
> mockInboundFromRtsErrorQueue.getExchanges().get( 0 );
> Assert.assertEquals( payload, failedExchange.getIn().getBody() );
> //mockInboundFromRtsErrorQueue.expectedBodiesReceived( payload
> ); //strangely this does not pass - but the above does
> mockInboundFromRtsErrorQueue.assertIsSatisfied();
>
>
> but I'm surprised that if I comment in the second-last line it will
> fail. Why? As line no 2&3 does exactly the same??
>
> --
> --
> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Re: Strange MockEndpoint.expectedBodiesReceived behaviour
Posted by David Karlsen <da...@gmail.com>.
Doesn't this code look suspicious (look at actual bodies):
public void expectedBodiesReceived(final List<?> bodies) {
expectedMessageCount(bodies.size());
this.expectedBodyValues = bodies;
this.actualBodyValues = new ArrayList<Object>();
expects(new Runnable() {
public void run() {
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);
Object actualBody = null;
if (i < actualBodyValues.size()) {
actualBody = actualBodyValues.get(i);
}
actualBody = extractActualValue(exchange,
actualBody, expectedBody);
assertEquals("Body of message: " + i,
expectedBody, actualBody);
}
}
});
}
2012/11/5 David Karlsen <da...@gmail.com>:
> Same:
>
> Body of message: 0. Expected: <<?xml version="1.0...
>
> If I had the order like before (defining the asserts after the test)
> it read body of message: null
>
> 2012/11/5 Raul Kripalani <ra...@evosent.com>:
>> Try setting the expectation before you actually hit the endpoint with any
>> messages. Hit the endpoint with your test logic. Then assert.
>>
>> Does it work then?
>>
>> Regards.
>>
>> Sent from a mobile device
>> On 5 Nov 2012 20:27, "David Karlsen" <da...@gmail.com> wrote:
>>
>>> I'm confused about how expectedBodiesReceived behaves.
>>>
>>> I have a route where I mock a jms endpoint (the endpoint is sent to in
>>> an onException route as follows:
>>>
>>> <camel:onException>
>>>
>>> <camel:exception>java.lang.Exception</camel:exception>
>>> <camel:handled>
>>>
>>> <camel:constant>true</camel:constant>
>>> </camel:handled>
>>> <camel:to
>>> id="inboundFromRtsErrorQueue"
>>>
>>> uri="jms:queue:{{rts.online.mq.reservationsReceiveErrorQueue}}?connectionFactory=#rtsConnectionFactory&destinationResolver=#rtsDestinationResolver"
>>> />
>>>
>>>
>>> I then override the sending to inboundFromRtsErrorQueue by id in the
>>> setup of my testclass.
>>>
>>> Everything works ok:
>>>
>>>
>>> mockInboundFromRtsErrorQueue.setExpectedMessageCount( 1 );
>>> Exchange failedExchange =
>>> mockInboundFromRtsErrorQueue.getExchanges().get( 0 );
>>> Assert.assertEquals( payload, failedExchange.getIn().getBody() );
>>> //mockInboundFromRtsErrorQueue.expectedBodiesReceived( payload
>>> ); //strangely this does not pass - but the above does
>>> mockInboundFromRtsErrorQueue.assertIsSatisfied();
>>>
>>>
>>> but I'm surprised that if I comment in the second-last line it will
>>> fail. Why? As line no 2&3 does exactly the same??
>>>
>>> --
>>> --
>>> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
>>>
>
>
>
> --
> --
> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
--
--
David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
Re: Strange MockEndpoint.expectedBodiesReceived behaviour
Posted by David Karlsen <da...@gmail.com>.
Same:
Body of message: 0. Expected: <<?xml version="1.0...
If I had the order like before (defining the asserts after the test)
it read body of message: null
2012/11/5 Raul Kripalani <ra...@evosent.com>:
> Try setting the expectation before you actually hit the endpoint with any
> messages. Hit the endpoint with your test logic. Then assert.
>
> Does it work then?
>
> Regards.
>
> Sent from a mobile device
> On 5 Nov 2012 20:27, "David Karlsen" <da...@gmail.com> wrote:
>
>> I'm confused about how expectedBodiesReceived behaves.
>>
>> I have a route where I mock a jms endpoint (the endpoint is sent to in
>> an onException route as follows:
>>
>> <camel:onException>
>>
>> <camel:exception>java.lang.Exception</camel:exception>
>> <camel:handled>
>>
>> <camel:constant>true</camel:constant>
>> </camel:handled>
>> <camel:to
>> id="inboundFromRtsErrorQueue"
>>
>> uri="jms:queue:{{rts.online.mq.reservationsReceiveErrorQueue}}?connectionFactory=#rtsConnectionFactory&destinationResolver=#rtsDestinationResolver"
>> />
>>
>>
>> I then override the sending to inboundFromRtsErrorQueue by id in the
>> setup of my testclass.
>>
>> Everything works ok:
>>
>>
>> mockInboundFromRtsErrorQueue.setExpectedMessageCount( 1 );
>> Exchange failedExchange =
>> mockInboundFromRtsErrorQueue.getExchanges().get( 0 );
>> Assert.assertEquals( payload, failedExchange.getIn().getBody() );
>> //mockInboundFromRtsErrorQueue.expectedBodiesReceived( payload
>> ); //strangely this does not pass - but the above does
>> mockInboundFromRtsErrorQueue.assertIsSatisfied();
>>
>>
>> but I'm surprised that if I comment in the second-last line it will
>> fail. Why? As line no 2&3 does exactly the same??
>>
>> --
>> --
>> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
>>
--
--
David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
Re: Strange MockEndpoint.expectedBodiesReceived behaviour
Posted by Raul Kripalani <ra...@evosent.com>.
Try setting the expectation before you actually hit the endpoint with any
messages. Hit the endpoint with your test logic. Then assert.
Does it work then?
Regards.
Sent from a mobile device
On 5 Nov 2012 20:27, "David Karlsen" <da...@gmail.com> wrote:
> I'm confused about how expectedBodiesReceived behaves.
>
> I have a route where I mock a jms endpoint (the endpoint is sent to in
> an onException route as follows:
>
> <camel:onException>
>
> <camel:exception>java.lang.Exception</camel:exception>
> <camel:handled>
>
> <camel:constant>true</camel:constant>
> </camel:handled>
> <camel:to
> id="inboundFromRtsErrorQueue"
>
> uri="jms:queue:{{rts.online.mq.reservationsReceiveErrorQueue}}?connectionFactory=#rtsConnectionFactory&destinationResolver=#rtsDestinationResolver"
> />
>
>
> I then override the sending to inboundFromRtsErrorQueue by id in the
> setup of my testclass.
>
> Everything works ok:
>
>
> mockInboundFromRtsErrorQueue.setExpectedMessageCount( 1 );
> Exchange failedExchange =
> mockInboundFromRtsErrorQueue.getExchanges().get( 0 );
> Assert.assertEquals( payload, failedExchange.getIn().getBody() );
> //mockInboundFromRtsErrorQueue.expectedBodiesReceived( payload
> ); //strangely this does not pass - but the above does
> mockInboundFromRtsErrorQueue.assertIsSatisfied();
>
>
> but I'm surprised that if I comment in the second-last line it will
> fail. Why? As line no 2&3 does exactly the same??
>
> --
> --
> David J. M. Karlsen - http://www.linkedin.com/in/davidkarlsen
>