Yeah you need to mock and skip and then you need to find the mock endpoint
and attach it using the weaving code. So something like this:
in your advice:
mockEndpointsAndSkip("bean:*");
Then in your test:
final String beanURI = "mock:bean:myBean";
assertNotNull(beanURI); // << DONT FORGET THIS or you will chase ghosts a
lot
MockEndpoint mep = getMockEndpoint(beanURI);
mep.whenAnyExchangeReceived(new Processor() {
@Override
process(final Exchange exchange) {
throw RuntimeException("hi");
}
}
Then send the message to the route.
[1]
http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#whenAnyExchangeReceived(org.apache.camel.Processor)
*Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
*Author of: Hardcore Java (2003) and Maintainable Java (2012)*
*LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39*
On Mon, Oct 7, 2013 at 12:17 PM, berhack <[email protected]> wrote:
> I have context level defined error handling (retry interval and retry
> attempts defined) that I am trying to test out. Yet it will never be
> invoked no matter how I simulate the error with mock end points. Does
> anyone how this can work?
>
> Given my route I'm testing just looks like:
>
> from(myQueue).to("bean:myBean?method=processOrder")
>
> Here's what I've tried:
>
> Insert advice to skip send to bean endpoint, and send to mock:myBean
> instead. Have mock:myBean throw an exception. Error handler is NOT
> invoked
> (I can see no retry attempt at all in the logs).
>
> Override (via Spring injection) the bean endpoint with mock:myBean. Have
> mock:myBean throw an exception. Error handler is NOT invoked.
>
> In either above attempts, also tried setting the exception off the Exchange
> object (i.e. exchange.setException), instead of throwing an exception
> explicitly (what's the difference anyway?), again no luck, error handler
> not
> invoked.
>
> Here's what WORKS:
>
> When NO mock end point is involved, i.e. my original bean endpoint throws a
> null pointer exception, I can see error handler working.
>
>
> Any ideas?
>
> Thanks!
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Problem-with-mock-end-points-and-testing-error-handling-tp5741050.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>