You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (JIRA)" <ji...@apache.org> on 2019/05/19 08:42:01 UTC

[jira] [Resolved] (CAMEL-13544) adviceWith in test should be fired before routes are started

     [ https://issues.apache.org/jira/browse/CAMEL-13544?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen resolved CAMEL-13544.
---------------------------------
    Resolution: Not A Problem
      Assignee: Claus Ibsen

Yeah you need to turn on isUseAdvice and start camel manually.

> 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
>            Assignee: Claus Ibsen
>            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)