You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "sharad.goklani@in.airtel.com" <sh...@in.airtel.com> on 2013/05/23 10:25:52 UTC

Mock Endpoint behavior on sleep

Hi,

I am slightly tweaking the code example of chapter 6 of "camel in action"
(code enclosed below). On adding Thread.sleep(), the subsequent assertion is
failing:
     java.lang.AssertionError: mock://quote Body of message: 0. Expected:
<Camel rocks> but was: <null>

Any clue on why this is happening? And what can be done so that the
assertion succeeds?

Thanks,
Sharad Goklani

-- begin --
package xxx;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class FirstMockTest extends CamelTestSupport {
	@Override
	protected RouteBuilder createRouteBuilder() throws Exception {
		return new RouteBuilder() {
			@Override
			public void configure() throws Exception {
				from("jms:topic:quote").to("mock:quote");
			}
		};
	}
	
	@Override
	protected CamelContext createCamelContext() throws Exception {
		CamelContext context = super.createCamelContext();
		context.addComponent("jms", context.getComponent("seda"));
		return context;
	}
	
	@Test
	public void testQuote() throws Exception {
		MockEndpoint quote = getMockEndpoint("mock:quote");
		
		template.sendBody("jms:topic:quote", "Camel rocks");

		//If i sleep, assertion fails!
		Thread.sleep(1000);
		quote.expectedBodiesReceived("Camel rocks");
		quote.assertIsSatisfied();
		quote.expectedMessageCount(1);
		quote.assertIsSatisfied();
	}
}
-- end --



--
View this message in context: http://camel.465427.n5.nabble.com/Mock-Endpoint-behavior-on-sleep-tp5733002.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Mock Endpoint behavior on sleep

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You should set your expectations *first* on the mock endpoint,
*before* you send messages into Camel.

See figure 6.3 in the book.

On Thu, May 23, 2013 at 10:25 AM, sharad.goklani@in.airtel.com
<sh...@in.airtel.com> wrote:
> Hi,
>
> I am slightly tweaking the code example of chapter 6 of "camel in action"
> (code enclosed below). On adding Thread.sleep(), the subsequent assertion is
> failing:
>      java.lang.AssertionError: mock://quote Body of message: 0. Expected:
> <Camel rocks> but was: <null>
>
> Any clue on why this is happening? And what can be done so that the
> assertion succeeds?
>
> Thanks,
> Sharad Goklani
>
> -- begin --
> package xxx;
>
> import org.apache.camel.CamelContext;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.junit.Test;
>
> public class FirstMockTest extends CamelTestSupport {
>         @Override
>         protected RouteBuilder createRouteBuilder() throws Exception {
>                 return new RouteBuilder() {
>                         @Override
>                         public void configure() throws Exception {
>                                 from("jms:topic:quote").to("mock:quote");
>                         }
>                 };
>         }
>
>         @Override
>         protected CamelContext createCamelContext() throws Exception {
>                 CamelContext context = super.createCamelContext();
>                 context.addComponent("jms", context.getComponent("seda"));
>                 return context;
>         }
>
>         @Test
>         public void testQuote() throws Exception {
>                 MockEndpoint quote = getMockEndpoint("mock:quote");
>
>                 template.sendBody("jms:topic:quote", "Camel rocks");
>
>                 //If i sleep, assertion fails!
>                 Thread.sleep(1000);
>                 quote.expectedBodiesReceived("Camel rocks");
>                 quote.assertIsSatisfied();
>                 quote.expectedMessageCount(1);
>                 quote.assertIsSatisfied();
>         }
> }
> -- end --
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Mock-Endpoint-behavior-on-sleep-tp5733002.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

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