You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sebh <se...@gmail.com> on 2013/12/20 12:31:40 UTC
@MockEndpointsAndSkip appears to not mock all endpoints when
testing with Spring
Hi,
I am using Camel 2.12.2 and Spring 3.2.4. I have the following route
definition:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="route1">
<from uri="direct:route1" />
<to uri="direct:route2"/>
</route>
</camelContext>
My expectation would be that the following test succeeds:
@RunWith(CamelSpringJUnit4ClassRunner.class)
@ContextConfiguration
@MockEndpointsAndSkip
public class RouteTest {
@Produce(uri="direct:route1") private ProducerTemplate producer;
@EndpointInject(uri="mock:direct:route2") private MockEndpoint endpoint;
@Test public void test_fails() throws Exception {
final Object body = new Integer(42);
endpoint.expectedBodiesReceived(body);
producer.sendBody(body);
endpoint.assertIsSatisfied(); // fails, 0 messages received
}
}
The test succeeds when I use @MockEndpointsAndSkip("direct:route2") instead.
Manipulating the route definition with the AdviceWithRouteBuilder works as
well:
context.getRouteDefinition("route1").adviceWith(context, new
AdviceWithRouteBuilder() {
@Override public void configure() throws Exception {
mockEndpointsAndSkip("*");
}
});
Is that intended?
--
View this message in context: http://camel.465427.n5.nabble.com/MockEndpointsAndSkip-appears-to-not-mock-all-endpoints-when-testing-with-Spring-tp5745105.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: @MockEndpointsAndSkip appears to not mock all endpoints when
testing with Spring
Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jan 1, 2014 at 3:11 PM, sebh <se...@gmail.com> wrote:
> Turns out that indeed all endpoints were mocked and skipped including the one
> that is used as a producer, resulting in no message being sent around.
>
> When using @MockEndpointsAndSkip(pattern) the producer should not be
> included by the pattern.
>
No it works as designed. You need to specify a pattern to mock only
the endpoints you actually need, or do a pattern that exclude the
endpoints you use to send messages from the unit test etc.
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/MockEndpointsAndSkip-appears-to-not-mock-all-endpoints-when-testing-with-Spring-tp5745105p5745395.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Make your Camel applications look hawt, try: http://hawt.io
Re: @MockEndpointsAndSkip appears to not mock all endpoints when
testing with Spring
Posted by sebh <se...@gmail.com>.
Turns out that indeed all endpoints were mocked and skipped including the one
that is used as a producer, resulting in no message being sent around.
When using @MockEndpointsAndSkip(pattern) the producer should not be
included by the pattern.
--
View this message in context: http://camel.465427.n5.nabble.com/MockEndpointsAndSkip-appears-to-not-mock-all-endpoints-when-testing-with-Spring-tp5745105p5745395.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: @MockEndpointsAndSkip appears to not mock all endpoints when
testing with Spring
Posted by Claus Ibsen <cl...@gmail.com>.
Check the unit tests to see what they do.
On Fri, Dec 20, 2013 at 1:57 PM, sebh <se...@gmail.com> wrote:
> I tried that, doesn't work either.
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/MockEndpointsAndSkip-appears-to-not-mock-all-endpoints-when-testing-with-Spring-tp5745105p5745116.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Make your Camel applications look hawt, try: http://hawt.io
Re: @MockEndpointsAndSkip appears to not mock all endpoints when
testing with Spring
Posted by sebh <se...@gmail.com>.
I tried that, doesn't work either.
--
View this message in context: http://camel.465427.n5.nabble.com/MockEndpointsAndSkip-appears-to-not-mock-all-endpoints-when-testing-with-Spring-tp5745105p5745116.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: @MockEndpointsAndSkip appears to not mock all endpoints when
testing with Spring
Posted by Claus Ibsen <cl...@gmail.com>.
Maybe try with
@MockEndpointsAndSkip("*")
On Fri, Dec 20, 2013 at 12:31 PM, sebh <se...@gmail.com> wrote:
> Hi,
>
> I am using Camel 2.12.2 and Spring 3.2.4. I have the following route
> definition:
>
> <camelContext xmlns="http://camel.apache.org/schema/spring">
> <route id="route1">
> <from uri="direct:route1" />
> <to uri="direct:route2"/>
> </route>
> </camelContext>
>
> My expectation would be that the following test succeeds:
>
> @RunWith(CamelSpringJUnit4ClassRunner.class)
> @ContextConfiguration
> @MockEndpointsAndSkip
> public class RouteTest {
> @Produce(uri="direct:route1") private ProducerTemplate producer;
> @EndpointInject(uri="mock:direct:route2") private MockEndpoint endpoint;
>
> @Test public void test_fails() throws Exception {
> final Object body = new Integer(42);
> endpoint.expectedBodiesReceived(body);
> producer.sendBody(body);
> endpoint.assertIsSatisfied(); // fails, 0 messages received
> }
> }
>
> The test succeeds when I use @MockEndpointsAndSkip("direct:route2") instead.
>
> Manipulating the route definition with the AdviceWithRouteBuilder works as
> well:
>
> context.getRouteDefinition("route1").adviceWith(context, new
> AdviceWithRouteBuilder() {
> @Override public void configure() throws Exception {
> mockEndpointsAndSkip("*");
> }
> });
>
> Is that intended?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/MockEndpointsAndSkip-appears-to-not-mock-all-endpoints-when-testing-with-Spring-tp5745105.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Make your Camel applications look hawt, try: http://hawt.io