And the configure()-methode in the test class just returns a RouteBuilder.
It doesn't have to return a new created one ...

public class MyTest extends CamelTestSupport {
   @Override
   protected RouteBuilder createRouteBuilder() {
      RouteBuilder rb = new MyRouteBuilder();
      // adviceWith ...
      // "inject" new endpoint uris
      rb.setFromUri("direct:in");
      rb.setToDatabase("mock:db");
      return rb;
   }
}


Jan

> -----Ursprüngliche Nachricht-----
> Von: Christian Posta [mailto:christian.po...@gmail.com]
> Gesendet: Dienstag, 30. Juli 2013 05:10
> An: users@camel.apache.org
> Betreff: Re: Camel testing
> 
> So keep in mind that the "endpoints" to a route are just
> java.lang.String... So you can do:
> 
> String startRoute = "jms:incoming";
> String endRoute = "jms:outgoing";
> 
> from(startRoute)......to(endRoute)
> 
> And then have that string injectable, so you can do
> setEndRoute("mock:endpointName")...
> 
> But even if you don't want to do that, you can check out "adviceWith"
> which wraps the existing endpoint with interesting behavior, including
> mocking it out, and/or adding interceptors.
> 
> You should check out the doco at http://camel.apache.org/mock.html You
> can also check out this refcard that covers essential camel components,
> including the Mock component:
> http://refcardz.dzone.com/refcardz/essential-camel-components
> And lastly, but certainly not least.. the camel source code is packed
> with unit tests. There are no better examples than the unit tests from
> the camel code base:
> http://camel.apache.org/how-can-i-get-the-source-code.html
> 
> Cheers,
> Christian
> 
> 
> On Mon, Jul 29, 2013 at 9:15 AM, Costash <costache_v_v...@yahoo.com>
> wrote:
> 
> > Hi,
> >
> > I've just started to use camel, and I'm trying to understand and
> > create some unit tests, but i don t understand how Mok is working or
> > how unit tests should look like (i've read the tutorials and
> > documentation about camel test).
> > What do i mean by not understanging is:
> >
> > i have a defined route:
> > =========================
> > public class MyRouteBuilder extends RouteBuilder{ .....
> > @Override
> >         public void configure() throws Exception {
> > from("jms:queue:inputQueueName").process(new Processor()
> > {.........}).to("jms:queue:outputputQueueName");
> > ======================
> >
> > in all the examples found , a new Class extends CamelTestSupport {
> >
> > and also creating the rounting inside, so it can be moked:
> > ===============
> >    @Override
> >     protected RouteBuilder createRouteBuilder() {
> >         return new RouteBuilder() {
> >             public void configure() {
> >
> >
> >
> from("direct:start").filter(header("foo").isEqualTo("bar")).to("mock:re
> sult");
> >             }
> >         };
> >     }
> > ================
> > so the route is defined exactly here, so it can be moked and get the
> > endpoints.
> >
> > BUT, what about to test an allready created route?
> > I can't say .to("mock:result");
> >
> > i suposed it should be:
> >
> > =========
> >  @Override
> >     protected RouteBuilder createRouteBuilder() { return new
> > MyRouteBuilder(); } ==========
> >
> >
> > So my questions are:
> > 1. how can i test a route? (i can't define the rules of routing
> inside
> > the test class by overwriting the createRouteBuilder() , because i
> > already have the route implementation => duplicate code) 2. Should my
> > MyRouteBuilder have specific methods implemented so i can mok it
> after
> > in the test class?
> > 3. is it there another way to test the output messages of a router
> > besides Mok?
> >       - I did it in one way, but i think is not the "correct" one:
> >                - In a Test Class, I've created a Connection factory
> to
> > a jms queue and creating a context
> >                - I've added the desired route to be tested into the
> > context (  context.addRoute(new MyRoutebuilder()))
> >                - Started the context (so my router is running in
> > "backgroud" let s say)
> >                - i've put a message into the input queue of the
> router
> > with another test Router (from file to queue)
> >                - i've taken the message from output queue of the
> > router with a test router (From message to file)
> >                - compare the file with an expected one.
> >
> > But this is bad as concept for unit tests (let s say Junits), i
> think.
> >
> > 4. Do you a link, or something to a generic test example of a camel
> route?
> >
> > PS: Sorry if the are stupid questions
> >
> > Thanks,
> > Vlad
> >
> >
> >
> > --
> > View this message in context:
> > http://camel.465427.n5.nabble.com/Camel-testing-tp5736444.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
> 
> 
> 
> --
> *Christian Posta*
> http://www.christianposta.com/blog
> twitter: @christianposta

Reply via email to