OK, that is quite calming. I almost began to review the error handling of all 
Camel applications with subroutes. But the fact that it worked in the real 
runtime environment was an indicator that it is "just" a test setup problem.

Perhaps it is another problem of the Spring-Boot test initialization. Route 
testing with Spring-Boot seems to have some issues.

I had a problem some months ago with MockEndpoints and Spring-Boot route tests: 
http://camel.465427.n5.nabble.com/Deaf-MockEndpoints-when-using-Spring-DirtiesContext-td5802788.html#a5803232

Thanks a lot
Stephan


-----Ursprüngliche Nachricht-----
Von: Quinn Stevenson [mailto:qu...@pronoia-solutions.com] 
Gesendet: Mittwoch, 3. Januar 2018 16:35
An: users@camel.apache.org
Betreff: Re: MockEndpoint does not receive message if error occures in subroute

I looked at the test again, and I’m pretty sure the issue has something to do 
with the initialization logic.  I re-wrote the same tests using 
CamelTestSupport and they both pass (without the addition of the 
NoErrorHandlerBuilder).

public class CamelRouteTest extends CamelTestSupport {

  @EndpointInject(uri = "mock://seda:output")
  protected MockEndpoint outputMock;

  @EndpointInject(uri = "mock://seda:error")
  protected MockEndpoint errorMock;

  @Override
  public String isMockEndpoints() {
    return "*";
  }

  @Override
  protected RoutesBuilder createRouteBuilder() throws Exception {
    return new CamelRoute();
  }

  @Test
  public void testMessageOk() throws Exception {
    Map<String, Object> headers = new HashMap<>();

    headers.put(CamelRoute.HEADER_CONDITION_FULFILLED, Boolean.TRUE);

    errorMock.expectedMessageCount(0);
    errorMock.setAssertPeriod(1000);
    outputMock.expectedMessageCount(1);
    outputMock.expectedHeaderReceived(CamelRoute.HEADER_CONDITION_FULFILLED, 
Boolean.TRUE);

    template.sendBodyAndHeaders("direct:input", "This messages is OK", headers);

    assertMockEndpointsSatisfied();
  }

  @Test
  public void testErrorInChoiceWhen() throws Exception {
    Map<String, Object> headers = new HashMap<>();
    headers.put(CamelRoute.HEADER_CONDITION_FULFILLED, Boolean.FALSE);

    errorMock.expectedMessageCount(1);
    errorMock.expectedHeaderReceived(CamelRoute.HEADER_CONDITION_FULFILLED, 
Boolean.FALSE);
    outputMock.expectedMessageCount(0);
    outputMock.setAssertPeriod(1000);

    template.sendBodyAndHeaders("direct:input", "This messages produces an 
error in the choice/when block", headers);

    assertMockEndpointsSatisfied();
  }
}



> On Jan 3, 2018, at 6:44 AM, Burkard Stephan <stephan.burk...@visana.ch> wrote:
> 
> Thanks Quinn.
> 
> 
> 
> I knew that "global" onException clauses are only scoped to their 
> RouteBuilder.
> 
> 
> 
> Follow-up question: Why are they not working for a subroute inside the same 
> RouteBuilder?
> 
> 
> 
> Context for other readers: In the following example, the onException clause 
> works fine for the "direct:input" route, but not for the "direct:subroute" 
> route. For the latter, the default ErrorHandler is used.
> 
> 
> 
> public void configure() throws Exception {
> 
>            onException(Throwable.class)
> 
>                                   .handled(true)
> 
>                                   [do error handling]
> 
>                                   .to("seda:error");
> 
> 
> 
>            from("direct:input")
> 
>                                   [do whatever needed]
> 
>                                   .to("direct:subroute")
> 
>                                   [do whatever needed]
> 
>                                   .to("seda:output");
> 
> 
> 
>            from("direct:subroute")
> 
>                                   [do whatever needed]
> 
> }
> 
> 
> 
> Thanks
> 
> Stephan
> 
> 
> 
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: Quinn Stevenson [mailto:qu...@pronoia-solutions.com]
> Gesendet: Mittwoch, 20. Dezember 2017 20:41
> An: users@camel.apache.org
> Betreff: Re: MockEndpoint does not receive message if error occures in 
> subroute
> 
> 
> 
> I’m not sure why this is working in the real world, but the reason the test 
> is failing is the default error handler is picking up the exception from the 
> call to the direct://Validate <direct://Validate> route.  If you add 
> ".errorHandler(new NoErrorHandlerBuilder())” to the direct://Validate 
> <direct://Validate> route, your test will pass.
> 
> 
> 
> Quinn Stevenson
> 
> qu...@pronoia-solutions.com<mailto:qu...@pronoia-solutions.com>
> 
> (801) 244-7758
> 
> 
> 
> 
> 
> 
> 
>> On Dec 1, 2017, at 6:07 AM, Burkard Stephan 
>> <stephan.burk...@visana.ch<mailto:stephan.burk...@visana.ch>> wrote:
> 
>> 
> 
>> Hi Camel users
> 
>> 
> 
>> I have attached a simplified example project (Maven) to illustrate a strange 
>> problem I have in the tests of a current project.
> 
>> 
> 
>> *** Setup ***
> 
>> - There is a Camel route that receives messages
> 
>> - It sends them to a validation subroute
> 
>> - The validation subroute uses a choice/when block to check a header
> 
>> value
> 
>> 
> 
>> - If the header is ok, the message goes to the standard output
> 
>> endpoint
> 
>> - If the header is wrong, an exception is thrown and the error handler
> 
>> kicks in
> 
>> - The error handler sends the message to an alternative endpoint
> 
>> 
> 
>> *** Problem ***
> 
>> If you open the project and run the route tests, you will see that one test 
>> fails.
> 
>> - It sends a message with the wrong header, so an exception is thrown
> 
>> - In the console output you can see that the error route processes the
> 
>> message (as expected) ==> But the error endpoint mock does not receive
> 
>> the message (WHY? This is wrong!)
> 
>> 
> 
>> *** It works in real life ***
> 
>> - When I run the real project with the real endpoints, the error
> 
>> endpoint produces the messages
> 
>> - It is only in the test this does not work
> 
>> 
> 
>> *** Strange effect ***
> 
>> When I move the choice/when block from the subroute to the main route,
> 
>> the test is successful
> 
>> 
> 
>> Can anyone explain this? Is this a bug or am I doing/expecting something 
>> wrong?
> 
>> 
> 
>> Thanks
> 
>> Stephan
> 
>> 
> 
>> 
> 
>> <CamelRouteTestDemo.zip>
> 
> 

Reply via email to