title: How to test multiple RouteBuilders in Apache Camel
body: <p>I want to test multiple camel RouteBuilder in a single unit test
  what I have:</p>
  
  <p>Custom camel processor that changes state</p>
  
  <pre><code>public class MyProcessor implements Processor {
     MyState state;
     public MyProcessor(MyState state) {this.state = state;}
  
     @Override
     public void process(Exchange exchange) throws Exception {
     state.setState(state.getState() + 5);
     }}
  </code></pre>
  
  <p>Two simple RouteBuilders: first routes messages from "direct:start" to "direct:endroute1" second pick up messages from "direct:endroute1" and routes somewhere "mock:endroute2"</p>
  
  <pre><code>public class MyRouteBuilder1 extends RouteBuilder {
      MyState state;
      public MyRouteBuilder1(MyState state) {this.state = state;}
  
      @Override
      public void configure() throws Exception {
          from("direct:start").process(new MyProcessor(state)).to("direct:endroute1");
      }}
  
  public class MyRouteBuilder2 extends RouteBuilder {
      MyState state;
      public MyRouteBuilder2(MyState state) {this.state = state;}
  
      @Override
      public void configure() throws Exception {
          from("direct:endroute1").process(new MyProcessor(state)).to("mock:endroute2");
      }}
  </code></pre>
  
  <p>Writing unit test for a single route builder is straightforward:</p>
  
  <pre><code>public class MyTest extends CamelTestSupport {
      MyState state = new MyStateImpl();
  
      @EndpointInject(uri = "mock:result")
      protected MockEndpoint resultEndpoint;
  
      @Test
      public void testSingleRoute() throws Exception {
          resultEndpoint.expectedMessageCount(1);
          template.sendBody("direct:start", new Object());
          assertTrue(state.getState() == 5);
          resultEndpoint.assertIsSatisfied();
      }
  
      @Override
      protected RouteBuilder createRouteBuilder() {
       return new MyRouteBuilder1(state) {
              public void configure() throws Exception{
                 super.configure();
                 from("direct:endroute1").to("mock:result");
             }
       };
   }
  }
  </code></pre>
  
  <p>What I really want to do is somehow to override <code>CamelTestSupport.createRouteBuilder</code> that will test whole chain of message processing from <code>direct:start</code> to <code>mock:endroute2</code>. As a result <code>state.getState()</code> should be 10</p>