2 Replies Latest reply on Feb 24, 2009 1:35 PM by milton

    How to load several routes in different classes in unit tests?

    milton

      Hi there,

       

      Is it possible to load several camel routes in unit tests?

       

      For example, I have the following route:

       

      public class CompleteRoute extends RouteBuilder {

            

          public static final String jettyURL = "http://127.0.0.1:89/sender";

       

          public void configure() throws Exception {

               from("jetty:" + jettyURL)

                    .convertBodyTo(String.class)

                    .to(TransformRoute.DIRECT_TRANSFORM);

          }

      }

       

      This route, as you can see, calls an endpoint of another route, the TransformRoute:

       

      public class TransformRoute extends RouteBuilder {

            

           public static final String DIRECT_TRANSFORM = "direct:transform";

       

           public void configure() throws Exception {

                from(DIRECT_TRANSFORM)

                     .to("xslt:transform.xsl");

           }

      }

       

      Then i did an unit test for CompleteRoute:

       

      public class CompleteRouteTest extends ContextTestSupport {

            

           private static final String MOCK_RESULT = "mock:result";

           MockEndpoint resultEndPoint;

            

           @Override

           protected void setUp() throws Exception {

                super.setUp();

                resultEndPoint = resolveMandatoryEndpoint(MOCK_RESULT, MockEndpoint.class);

           }

            

           @Override

           protected RouteBuilder createRouteBuilder() throws Exception {

                return new CompleteRoute() {

                     @Override

                     public void configure() throws Exception {

                          super.configure();                    

                     }

                };

           }

            

           public void testCompleteRouteOK() throws Exception {

                String expectedBody = ReadFile.getFileContents("src/main/resources/msg_ok.xml");

                String sentBody = ReadFile.getFileContents("src/test/resources/xml_test.xml");

                 

                resultEndPoint.expectedBodiesReceived(expectedBody);

                resultEndPoint.expectedMessageCount(1);

                 

                Object request = template.requestBody(CompleteRoute.jettyURL, sentBody);

                template.sendBody(MOCK_RESULT, request);

                 

                resultEndPoint.assertIsSatisfied();

           }

      }

       

      When I run it, it loads the Jetty component just fine, but it won't load the TranformRoute, so I get the following error:

       

      "DirectProducer WARN  No getConsumers() available on Producer[direct:transform] for Exchange[]"

       

      Any clues? Any help would be much appreciated

       

      PS: if I run it with mvn camel:run it works just fine

       

      Edited by: milton on Feb 24, 2009 3:03 PM