CamelSpringBootRunner and AdviceWith

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

CamelSpringBootRunner and AdviceWith

Boris Stanojević
When using CamelSpringBootRunner (camel 2.20) for my tests I'm not able to
"adviceWith" my Routes any more since CamelContext is already started by "
CamelSpringBootExecutionListener" and therefore adviceWith doesn't take
place.

Any suggestions?

Many thanks!!
Reply | Threaded
Open this post in threaded view
|

Re: CamelSpringBootRunner and AdviceWith

Claus Ibsen-2
Hi

Can you post sample code, and have you added the @UseAdviceWith annotation

On Tue, Oct 24, 2017 at 2:58 PM, Boris Stanojević
<[hidden email]> wrote:
> When using CamelSpringBootRunner (camel 2.20) for my tests I'm not able to
> "adviceWith" my Routes any more since CamelContext is already started by "
> CamelSpringBootExecutionListener" and therefore adviceWith doesn't take
> place.
>
> Any suggestions?
>
> Many thanks!!



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: CamelSpringBootRunner and AdviceWith

Boris Stanojević
Hi,
sure...

*@RunWith(CamelSpringBootRunner.class)*
*@UseAdviceWith*
@ActiveProfiles("test")
@DirtiesContext
public class MyRouteBuilderTest extends AbstractRouteBuilderTest {

    @Autowired
    private MyRouteBuilder routeBuilder;

    @Test
    public void testMyRoute() throws Exception {

        *////* *camelContext is here already started !!!!!! :( //////*
*        //// therefore the following customization does not take place ///*

camelContext.getRouteDefinition(routeBuilder.getMainRouteId()).adviceWith(camelContext,
new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                interceptSendToEndpoint("direct:my-direct-endpoint")
                        .skipSendToOriginalEndpoint()
                        .to("mock:advised");
            }
        });

        // Because of @UseAdviceWith, the context must be started manually
        camelContext.start();
        .............
        .............
    }
}

As mentioned before, the CamelSpringBootExecutionListener in 2.20.0 starts
already the camelContext which was earlier not the case:

public class CamelSpringBootExecutionListener extends
AbstractTestExecutionListener {

    @Override
    public void prepareTestInstance(TestContext testContext) throws Exception {

        .........

        SpringCamelContext.setNoStart(false);
        CamelContext camelContext = context.getBean(CamelContext.class);

        // after our customizations we should start the CamelContext
        camelContext.start();

    }

    ...........

}


2017-10-27 9:05 GMT+02:00 Claus Ibsen <[hidden email]>:

> Hi
>
> Can you post sample code, and have you added the @UseAdviceWith annotation
>
> On Tue, Oct 24, 2017 at 2:58 PM, Boris Stanojević
> <[hidden email]> wrote:
> > When using CamelSpringBootRunner (camel 2.20) for my tests I'm not able
> to
> > "adviceWith" my Routes any more since CamelContext is already started by
> "
> > CamelSpringBootExecutionListener" and therefore adviceWith doesn't take
> > place.
> >
> > Any suggestions?
> >
> > Many thanks!!
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>
Reply | Threaded
Open this post in threaded view
|

Re: CamelSpringBootRunner and AdviceWith

Claus Ibsen-2
Hi

Yes its a bug and I logged a ticket
https://issues.apache.org/jira/browse/CAMEL-11955

On Fri, Oct 27, 2017 at 9:53 AM, Boris Stanojević
<[hidden email]> wrote:

> Hi,
> sure...
>
> *@RunWith(CamelSpringBootRunner.class)*
> *@UseAdviceWith*
> @ActiveProfiles("test")
> @DirtiesContext
> public class MyRouteBuilderTest extends AbstractRouteBuilderTest {
>
>     @Autowired
>     private MyRouteBuilder routeBuilder;
>
>     @Test
>     public void testMyRoute() throws Exception {
>
>         *////* *camelContext is here already started !!!!!! :( //////*
> *        //// therefore the following customization does not take place ///*
>
> camelContext.getRouteDefinition(routeBuilder.getMainRouteId()).adviceWith(camelContext,
> new AdviceWithRouteBuilder() {
>             @Override
>             public void configure() throws Exception {
>                 interceptSendToEndpoint("direct:my-direct-endpoint")
>                         .skipSendToOriginalEndpoint()
>                         .to("mock:advised");
>             }
>         });
>
>         // Because of @UseAdviceWith, the context must be started manually
>         camelContext.start();
>         .............
>         .............
>     }
> }
>
> As mentioned before, the CamelSpringBootExecutionListener in 2.20.0 starts
> already the camelContext which was earlier not the case:
>
> public class CamelSpringBootExecutionListener extends
> AbstractTestExecutionListener {
>
>     @Override
>     public void prepareTestInstance(TestContext testContext) throws Exception {
>
>         .........
>
>         SpringCamelContext.setNoStart(false);
>         CamelContext camelContext = context.getBean(CamelContext.class);
>
>         // after our customizations we should start the CamelContext
>         camelContext.start();
>
>     }
>
>     ...........
>
> }
>
>
> 2017-10-27 9:05 GMT+02:00 Claus Ibsen <[hidden email]>:
>
>> Hi
>>
>> Can you post sample code, and have you added the @UseAdviceWith annotation
>>
>> On Tue, Oct 24, 2017 at 2:58 PM, Boris Stanojević
>> <[hidden email]> wrote:
>> > When using CamelSpringBootRunner (camel 2.20) for my tests I'm not able
>> to
>> > "adviceWith" my Routes any more since CamelContext is already started by
>> "
>> > CamelSpringBootExecutionListener" and therefore adviceWith doesn't take
>> > place.
>> >
>> > Any suggestions?
>> >
>> > Many thanks!!
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>>



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2