camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: replace endpoint uri in error handler for testing purposes
Date Sat, 13 Apr 2013 08:11:22 GMT
Hi

You can have a getter/setter on the route builder class, and then just
use the setter when testing to change the uri.
And from the configure method you can use the getter to get the uri
when using it in the error handler.

On Fri, Apr 12, 2013 at 12:06 PM, Tomasz Pasierb <tompasik@poczta.fm> wrote:
> Hi,
>
> I'm trying to test a route that has a error handler installed and I cannot find a way
to replace an enpoint (in the error handler) for which I do not have a component in my unit
test.
>
> I chose a strategy to test an existing (final) route and modify it (using weaving) in
the unit test in a way that allows me to test a given feature/functionality.
>
>
> The contents of the route builder's configure method are like the following (that's of
course just a simplification of my code).
>
> public void configure() throws Exception {
>     errorHandler(deadLetterChannel("oaq:queue:ERROR"));
>
>     from("oaq:queue:{{inputQueue}}")
>         .to("xslt:someXslFile.xsl")
>         .to("oaq:queue:{{outputQueue}}").id("outputQueueId");
> }
>
> and my test is as follows:
>
> public void regularForeignTransferToBeWrittenToDB() throws Exception {
>     camelContext.getRouteDefinition("handleForeignTransfers")
>         .adviceWith(camelContext, new AdviceWithRouteBuilder() {
>
>               @Override
>               public void configure() throws Exception {
>                   replaceFromWith("direct:start");
>                   weaveById("outputQueueId").replace().to("mock:queue");
>               }
>               camelContext.start();
>
>               // producer.sendBodyAndHeaders(input, headers);   send some input
>
>               // make some assertions
> }
>
> It works fine if I comment out the invocation of "errorHandler" method.
>
> I'd rather not have the "oaq" component - I'd like to replace it on the fly in my test
method. If I have to I'll install a mock compenent for "oaq" namespace.
>
> Is there a way to "weave" changes into the error handler or a way of replacing the error
handler's enpoint uri before the route is actually created in such a scenario?
>
>
> Regards,
> Tom



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Mime
View raw message