camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lukas Winkler <winklerlu...@gmail.com>
Subject Re: AdviceWith in test not followed
Date Wed, 02 Aug 2017 11:15:21 GMT
That brought me on the right track:

    @Before
    public void setupContext() throws Exception{
        // Disable timer route so it can not pop while running tests
        context().stopRoute("metar-provider-timer");

        context.getRouteDefinition("metar-provider-formatter").adviceWith(context,
new AdviceWithRouteBuilder() {

            @Override
            public void configure() throws Exception {
                mockEndpointsAndSkip("direct:METARvalidator");
            }
        });
    }

    @Test
    public void testValidMetar() throws Exception {
        context.start();
        Document doc = this.readXML("/metar_valid.xml");
        // Define some expectations

        // Ensure expectations make sense for the route(s) we're testing
        getMockEndpoint("mock:direct:METARvalidator").expectedMessageCount(1);
        getMockEndpoint("mock:direct:METARvalidator").expectedHeaderReceived("locationIndicatorICAO",
"LOWW");

        context.createProducerTemplate().sendBody("direct:METARformatter", doc);

        // Validate our expectations
        assertMockEndpointsSatisfied();

        context.stop();
    }

That seems to do what i expected it to do. While it somewhat makes
sense that the injections fail when using adviseWith I am kind of
stumped that my AdviseRoute itself also did not work. I.e.:
                 interceptSendToEndpoint("direct:METARvalildator")
                                    .skipSendToOriginalEndpoint()
                                     .to("mock:direct:METARvalidator");
fails (message does not get send to mocking endpoint and travels down
the whole context), but
                 mockEndpointsAndSkip("direct:METARvalidator");
does what I want.
If someone has some insight into why this is happening I would love to
hear the reason for it.

Thanks for your help Stephan and thanks for reading list,
Lukas

On 2 August 2017 at 12:43, Burkard Stephan <Stephan.Burkard@visana.ch> wrote:
> OK I simplified the test (removed xml read, set header with xpath etc) and got the test
pass.
>
> I used "mockEndpointsAndSkip" in the setup and "getMockEndpoint" instead of an instance
variable mock.
>
> Hope you can adapt it for your (complete) case.
> Stephan
>
>     @Produce(uri = "direct:METARformatter")
>     protected ProducerTemplate input;
>
>     @Before
>     public void setupContext() throws Exception{
>         context.getRouteDefinition("fromMETARformatter").adviceWith(context, new AdviceWithRouteBuilder()
{
>             @Override
>             public void configure() throws Exception {
>                 mockEndpointsAndSkip("direct:*");
>             }
>         });
>     }
>
>     @Test
>     public void testValidMetar() throws Exception {
>         context.start();
>         getMockEndpoint("mock:direct:METARvalidator").expectedMessageCount(1);
>         input.sendBody("MyMessageBody");
>         // Validate our expectations
>         assertMockEndpointsSatisfied();
>     }
>
> -----Urspr√ľngliche Nachricht-----
> Von: Lukas Winkler [mailto:winklerlukas@gmail.com]
> Gesendet: Mittwoch, 2. August 2017 11:24
> An: users@camel.apache.org
> Betreff: Re: AdviceWith in test not followed
>
> Hallo Stephan,
>
> yes I already tried and just had another run, does not change a thing (also tried with
completely different mock endpoint just to be sure).
>
> Let me also use this opportunity to attach a few lines from the unittest run:
> [                          main] BlueprintCamelContext          INFO
> Route: metar-provider-formatter is stopped, was consuming from:
> Endpoint[direct://METARformatter]
> [                          main] BlueprintCamelContext          INFO
> Route: metar-provider-formatter is shutdown and removed, was consuming
> from: Endpoint[direct://METARformatter]
> [                          main] RouteDefinition                INFO
> AdviceWith route after:
> Route(metar-provider-formatter)[[From[direct:METARformatter]] -> [InterceptSendToEndpoint[direct:METARvalildator
-> [To[mock:outputFromFormatter]]], SetHeader[locationIndicatorICAO,
> xpath{XPath: //aixm:locationIndicatorICAO[1]/text()}],
> To[direct:METARvalidator]]]
> [                          main] BlueprintCamelContext          INFO
> Route: metar-provider-formatter started and consuming from:
> Endpoint[direct://METARformatter]
> [                          main] BlueprintCamelContext          INFO
> Apache Camel 2.17.0.redhat-630187 (CamelContext:
> metar-provider-context) is starting
> [                          main] BlueprintCamelContext          INFO
> Total 6 routes, of which 5 are started.
> [                          main] BlueprintCamelContext          INFO
> Apache Camel 2.17.0.redhat-630187 (CamelContext:
> metar-provider-context) started in 0.000 seconds
>
> - Lukas
>
> On 2 August 2017 at 11:15, Burkard Stephan <Stephan.Burkard@visana.ch> wrote:
>> Just a quick guess to try: have you tried to replace the "to(output)" with "to("mock:outputFromFormatter")"?
>>
>> Cheers
>> Stephan
>>
>>
>> -----Urspr√ľngliche Nachricht-----
>> Von: Lukas Winkler [mailto:winklerlukas@gmail.com]
>> Gesendet: Mittwoch, 2. August 2017 11:10
>> An: users@camel.apache.org
>> Betreff: AdviceWith in test not followed
>>
>> Dear list,
>>
>> starting out with Camel and run into a problem when trying to test part of my camel
context.
>>
>> Please find the test code as well as a snipped of the 'to test' route in the following
gist:
>> https://gist.github.com/ingwinlu/bb047cc409fb295b8d74b617ae04008c
>>
>> From the logs that are running I can see that the message I send through the test
gets routed via the original path.
>>
>> Camel Version is Apache Camel 2.17.0.redhat-630187
>>
>> BR and thanks for any help,
>> Lukas

Mime
View raw message