You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Chris Melikian <ch...@melikian.net> on 2015/02/16 13:03:16 UTC
isMockEndpointsAndSkip documentation unclear
In http://camel.apache.org/mock.html, under the heading "Mocking endpoints
and skip sending to original endpoint", there are two examples, one using
adviceWith() and the other using isMockEndpointsAndSkip() for mocking
existing endpoints. The adviceWith() example mocks two endpoints whereas the
isMockEndPointsAndSkip() example only mocks one so is not equivalent.
The "Mocking existing endpoints using the camel-test component" section
shows an example for isMockEndpoints() where a wildcard is used but there is
nothing to say that isMockEndpointsAndSkip doesn't allow wildcards. This is
in line with my experience where I can return "direct:success" from
isMockEndpointsAndSkip() and my expectation passes but when I use "*" or
"direct:*" or "direct:.*" my expectation fails.
It would be good to clarify whether the isMockEndpointsAndSkip() method can
support multiple endpoints or single and include an example of multiple
endpoints if this is indeed possible. I'm using Camel 2.14.1.
Best regards, Chris.
--
View this message in context: http://camel.465427.n5.nabble.com/isMockEndpointsAndSkip-documentation-unclear-tp5762798.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: isMockEndpointsAndSkip documentation unclear
Posted by Chris Melikian <ch...@melikian.net>.
Argh. Should be "mock and skip original endpoints for all direct endpoints
whose id does NOT start with closeOpenOrders".
--
View this message in context: http://camel.465427.n5.nabble.com/isMockEndpointsAndSkip-documentation-unclear-tp5762798p5762841.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: isMockEndpointsAndSkip documentation unclear
Posted by Minh Tran <da...@gmail.com>.
lol Your welcome!
Personally I find that with mock and skip, you want to do this sparingly instead of skipping everything except the first endpoint as you’ve described. Instead I prefer to target certain endpoints so my regex looks something like
(direct:abc.*|direct:def.*|jms:blah.*|http4:foo.*)
So this only skips those 4 endpoints and I can use the normal mock end point for everything else.
On 17 Feb 2015, at 9:18 pm, Chris Melikian <ch...@melikian.net> wrote:
> Cám ơn Anh Minh!
>
> That was exactly my problem. Here's the solution that worked for me (after
> lots of trying!):-
>
> @Override
> public String isMockEndpointsAndSkip() {
> return "direct://(?!closeOpenOrders).*";
> }
>
> which translates to "mock and skip original endpoints for all direct
> endpoints whose id starts with closeOpenOrders".
>
> Maybe worth adding an example like this in the Camel docs for others who
> face the same issue? It would show what's possible?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/isMockEndpointsAndSkip-documentation-unclear-tp5762798p5762832.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
Re: isMockEndpointsAndSkip documentation unclear
Posted by Chris Melikian <ch...@melikian.net>.
Cám ơn Anh Minh!
That was exactly my problem. Here's the solution that worked for me (after
lots of trying!):-
@Override
public String isMockEndpointsAndSkip() {
return "direct://(?!closeOpenOrders).*";
}
which translates to "mock and skip original endpoints for all direct
endpoints whose id starts with closeOpenOrders".
Maybe worth adding an example like this in the Camel docs for others who
face the same issue? It would show what's possible?
--
View this message in context: http://camel.465427.n5.nabble.com/isMockEndpointsAndSkip-documentation-unclear-tp5762798p5762832.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: isMockEndpointsAndSkip documentation unclear
Posted by Minh Tran <da...@gmail.com>.
I encountered this problem as well when I first used this.
Because you used the star, it mocked and skipped every endpoint, including the start of your route. Just ensure the regex you provide doesn't match the start of your route. If you enable camel logging at info level, you'll see something like this that will tell you what has been mocked.
org.apache.camel.impl.InterceptSendToMockEndpointStrategy - Adviced endpoint [myuri] with mock endpoint [mock:myuri]
On 17/02/2015, at 1:23 AM, Chris Melikian <ch...@melikian.net> wrote:
> Thanks Claus, so how come:-
>
> @Override
> public String isMockEndpointsAndSkip() {
> return "*";
> }
>
> gives me a failure but
>
> @Override
> public String isMockEndpointsAndSkip() {
> return "direct:success";
> }
>
> works in my test?
>
> I'm testing that the endpoint receives an expected message count. I can't
> see where the bug in my code is otherwise.
>
>
>
> public class CloseOpenOrdersRouteTest extends CamelTestSupport {
>
> private CloseOpenOrdersRoute route = new CloseOpenOrdersRoute();
>
> @Override
> public String isMockEndpointsAndSkip() {
> return "direct:.*";
> }
>
> @Test
> public void closeOrderSuccessfully() throws Exception {
> MockEndpoint to = getMockEndpoint("mock:" + SuccessRoute.FROM_URI);
>
> template().sendBody(CloseOpenOrdersRoute.FROM_URI, "doesn't matter for
> this test");
> to.expectedMessageCount(1);
> }
>
> @After
> public void after() throws InterruptedException {
> assertMockEndpointsSatisfied();
> }
>
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception {
> return route;
> }
>
> }
>
> The class under test is:-
>
> public class CloseOpenOrdersRoute extends RouteBuilder {
>
> public static final String CLOSE_OPEN_ORDERS_ROUTE_ID =
> "closeOpenOrdersRouteId";
> public static final String FROM_URI = "direct:closeOpenOrders";
>
> @Override
> public void configure() throws Exception {
> from(FROM_URI).id(CLOSE_OPEN_ORDERS_ROUTE_ID)
> .log("request to close open orders received")
> .to(SuccessRoute.FROM_URI);
> }
>
> }
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/isMockEndpointsAndSkip-documentation-unclear-tp5762798p5762813.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
Re: isMockEndpointsAndSkip documentation unclear
Posted by Chris Melikian <ch...@melikian.net>.
Thanks Claus, so how come:-
@Override
public String isMockEndpointsAndSkip() {
return "*";
}
gives me a failure but
@Override
public String isMockEndpointsAndSkip() {
return "direct:success";
}
works in my test?
I'm testing that the endpoint receives an expected message count. I can't
see where the bug in my code is otherwise.
public class CloseOpenOrdersRouteTest extends CamelTestSupport {
private CloseOpenOrdersRoute route = new CloseOpenOrdersRoute();
@Override
public String isMockEndpointsAndSkip() {
return "direct:.*";
}
@Test
public void closeOrderSuccessfully() throws Exception {
MockEndpoint to = getMockEndpoint("mock:" + SuccessRoute.FROM_URI);
template().sendBody(CloseOpenOrdersRoute.FROM_URI, "doesn't matter for
this test");
to.expectedMessageCount(1);
}
@After
public void after() throws InterruptedException {
assertMockEndpointsSatisfied();
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return route;
}
}
The class under test is:-
public class CloseOpenOrdersRoute extends RouteBuilder {
public static final String CLOSE_OPEN_ORDERS_ROUTE_ID =
"closeOpenOrdersRouteId";
public static final String FROM_URI = "direct:closeOpenOrders";
@Override
public void configure() throws Exception {
from(FROM_URI).id(CLOSE_OPEN_ORDERS_ROUTE_ID)
.log("request to close open orders received")
.to(SuccessRoute.FROM_URI);
}
}
--
View this message in context: http://camel.465427.n5.nabble.com/isMockEndpointsAndSkip-documentation-unclear-tp5762798p5762813.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: isMockEndpointsAndSkip documentation unclear
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Yeah it uses the same endpoint pattern matching as the interceptor
does, so you can use jms* (using wildcard) for all jms endpoints eg.
Or use a regular expression for more advanced.
http://camel.apache.org/intercept
On Mon, Feb 16, 2015 at 1:03 PM, Chris Melikian <ch...@melikian.net> wrote:
> In http://camel.apache.org/mock.html, under the heading "Mocking endpoints
> and skip sending to original endpoint", there are two examples, one using
> adviceWith() and the other using isMockEndpointsAndSkip() for mocking
> existing endpoints. The adviceWith() example mocks two endpoints whereas the
> isMockEndPointsAndSkip() example only mocks one so is not equivalent.
>
> The "Mocking existing endpoints using the camel-test component" section
> shows an example for isMockEndpoints() where a wildcard is used but there is
> nothing to say that isMockEndpointsAndSkip doesn't allow wildcards. This is
> in line with my experience where I can return "direct:success" from
> isMockEndpointsAndSkip() and my expectation passes but when I use "*" or
> "direct:*" or "direct:.*" my expectation fails.
>
> It would be good to clarify whether the isMockEndpointsAndSkip() method can
> support multiple endpoints or single and include an example of multiple
> endpoints if this is indeed possible. I'm using Camel 2.14.1.
>
> Best regards, Chris.
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/isMockEndpointsAndSkip-documentation-unclear-tp5762798.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
hawtio: http://hawt.io/
fabric8: http://fabric8.io/