[ 
https://issues.apache.org/jira/browse/CAMEL-13544?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16843164#comment-16843164
 ] 

Jan Bednar commented on CAMEL-13544:
------------------------------------

This is not a bug IMHO. [https://camel.apache.org/advicewith.html]
{quote}It's recommended to only advice routes which are not started already. If 
you advice already started routes, then it may not work as expected.

It's recommended to override the *{{isUseAdviceWith()}}* method and return true 
to tell Camel you are using advice with in your unit tests. Then after you have 
done the *{{adviceWith()}}*, then you must start *{{CamelContext}}* manually.
{quote}

> adviceWith in test should be fired before routes are started
> ------------------------------------------------------------
>
>                 Key: CAMEL-13544
>                 URL: https://issues.apache.org/jira/browse/CAMEL-13544
>             Project: Camel
>          Issue Type: Bug
>            Reporter: Kamil
>            Priority: Major
>
> This test should pass:
> {code:java}
> import java.util.concurrent.atomic.AtomicInteger;
> import org.apache.camel.CamelContext;
> import org.apache.camel.RoutesBuilder;
> import org.apache.camel.builder.AdviceWithRouteBuilder;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.assertj.core.api.Assertions;
> import org.junit.Test;
> public class MyRouteTest extends CamelTestSupport {
>   private static final String ROUTE_ID = "mytest";
>   private final AtomicInteger counter = new AtomicInteger(0);
>   @Override
>   public RoutesBuilder createRouteBuilder() throws Exception {
>     return new RouteBuilder() {
>       @Override
>       public void configure() throws Exception {
>         from("quartz2://test?cron=0/1+*+*+*+*+?")
>           .id(ROUTE_ID)
>           .bean(counter, "incrementAndGet", false)
>           .to("stream:out");
>       }
>     };
>   }
>   @Override
>   public void setUp() throws Exception {
>       super.setUp();
>       final CamelContext camelContext = context();
>       camelContext.getRouteDefinition(ROUTE_ID)
>         .adviceWith(camelContext, new AdviceWithRouteBuilder() {
>           @Override
>           public void configure() throws Exception {
>             replaceFromWith("direct:quartz");
>             weaveAddLast().to("mock:extract");
>           }
>         });
>   }
>   @Test
>   public void shouldReceive2Messages() throws InterruptedException {
>     // given
>     final MockEndpoint quartzMock = getMockEndpoint("mock:extract");
>     // declare
>     quartzMock.expectedMessageCount(2);
>     // when
>     template.sendBody("direct:quartz", "tick");
>     template.sendBody("direct:quartz", "tick");
>     // then
>     quartzMock.assertIsSatisfied();
>     Assertions.assertThat(counter).hasValue(2);
>   }
> }
> {code}
> Unfortunatelly, before adviceWith is invoked, quartz sends already two 
> messages



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to