You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by twelve17 <sp...@twelve17.com> on 2012/06/14 02:54:14 UTC

testing: intercept route and process() *after* its completion?

Hello,

I've been diving into Camel testing lately, which, I'm not gonna lie, has
been quite fun.  Thanks to the Camel book for assistance. :)

I did run into one hangup in which I am not sure what the best
pattern/practice is.  

For my integration testing, I am using adviceWith() to "inject" processing
into an existing route.  The routebuilder class looks something like:

 @Override
 public void configure() throws Exception {
     interceptSendToEndpoint("bean:someEndpointToBeTested").process(new
DoSomeAssertionProcessor());
}

The code above runs the processor before the intercepted endpoint.   What I
would like to do is call a processor *after* the intercepted bean is
completed, so I can verify that the data it produced matches some expected
data set.  For the moment, I am using the above pattern to intercept the
endpoint that follows the actual one I want to test, which seems a little
fragile to me. 

I tried using "interceptFrom", but it does not get triggered, which makes me
believe it is only triggered if you are intercepting an input route, versus
matching an output route as if it were "from", from the perspective of when
the pipeline moves to the following route.

Am I making any sense here? :)

Any help would be appreciated.

Thanks,

Alex 


--
View this message in context: http://camel.465427.n5.nabble.com/testing-intercept-route-and-process-after-its-completion-tp5714460.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: testing: intercept route and process() *after* its completion?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

I have logged a ticket to not forget about this. We should take the
opportunity in Camel 3.0 to make the DSL better and support these
use-cases.
https://issues.apache.org/jira/browse/CAMEL-6901



On Thu, Jun 14, 2012 at 2:54 AM, twelve17 <sp...@twelve17.com> wrote:
> Hello,
>
> I've been diving into Camel testing lately, which, I'm not gonna lie, has
> been quite fun.  Thanks to the Camel book for assistance. :)
>
> I did run into one hangup in which I am not sure what the best
> pattern/practice is.
>
> For my integration testing, I am using adviceWith() to "inject" processing
> into an existing route.  The routebuilder class looks something like:
>
>  @Override
>  public void configure() throws Exception {
>      interceptSendToEndpoint("bean:someEndpointToBeTested").process(new
> DoSomeAssertionProcessor());
> }
>
> The code above runs the processor before the intercepted endpoint.   What I
> would like to do is call a processor *after* the intercepted bean is
> completed, so I can verify that the data it produced matches some expected
> data set.  For the moment, I am using the above pattern to intercept the
> endpoint that follows the actual one I want to test, which seems a little
> fragile to me.
>
> I tried using "interceptFrom", but it does not get triggered, which makes me
> believe it is only triggered if you are intercepting an input route, versus
> matching an output route as if it were "from", from the perspective of when
> the pipeline moves to the following route.
>
> Am I making any sense here? :)
>
> Any help would be appreciated.
>
> Thanks,
>
> Alex
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/testing-intercept-route-and-process-after-its-completion-tp5714460.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



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

Re: testing: intercept route and process() *after* its completion?

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jun 27, 2012 at 11:05 PM, twelve17 <sp...@twelve17.com> wrote:
>
> Claus Ibsen-2 wrote
>>
>> I read this as you want to do some kind of AOP around the sending a
>> message
>> to a given endpoint?
>> We could possible make that a bit easier from testing point of view.
>>
>> What you can do with the advice with, and code you posted above is to
>> - enable the skip sending to endpoint option
>> - do assertion before
>> - send manually to the endpoint
>> - do assertion afterwards
>>
>
> Hi Claus,
>
> Apologies for the delay in replying.  I am trying to perform precisely the
> steps you have outlined, perhaps a little less AOP-like than the example
> above, at least for the moment.  :)
>
> I have not been able to figure out which API to use to send manually to the
> endpoint within the processor before hand.  In other words, if my
> RouteBuilder looks like this:
>
> @Override
>  public void configure() throws Exception {
>
> interceptSendToEndpoint("bean:someEndpointToBeTested").skipSendToOriginalEndpoint().process(new
> DoSomeAssertionProcessor());
> }
>
> And my processor looks like this:
>
> public class DoSomeAssertionProcessor implements Processor {
>
>    @Override
>    public void process(Exchange exchange) throws Exception {
>                // 1. do pre endpoint assertion
>                // 2. send to original endpoint here, perhaps using
> NotifyBuilder to wait for it to finish?
>                // 3. do post endpoint assertion
>    }
> }
>
> How do I accomplish #2?  Should I just use a standard producer template?
>

Yeah a producer template would be fine. Then you can just send the
exchange to the endpoint.


> Regards,
>
> Alex
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/testing-intercept-route-and-process-after-its-completion-tp5714460p5715186.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: testing: intercept route and process() *after* its completion?

Posted by twelve17 <sp...@twelve17.com>.
Claus Ibsen-2 wrote
> 
> I read this as you want to do some kind of AOP around the sending a
> message
> to a given endpoint?
> We could possible make that a bit easier from testing point of view.
> 
> What you can do with the advice with, and code you posted above is to
> - enable the skip sending to endpoint option
> - do assertion before
> - send manually to the endpoint
> - do assertion afterwards
> 

Hi Claus,

Apologies for the delay in replying.  I am trying to perform precisely the
steps you have outlined, perhaps a little less AOP-like than the example
above, at least for the moment.  :)

I have not been able to figure out which API to use to send manually to the
endpoint within the processor before hand.  In other words, if my
RouteBuilder looks like this:

@Override 
 public void configure() throws Exception { 
    
interceptSendToEndpoint("bean:someEndpointToBeTested").skipSendToOriginalEndpoint().process(new
DoSomeAssertionProcessor()); 
} 

And my processor looks like this:

public class DoSomeAssertionProcessor implements Processor {

    @Override
    public void process(Exchange exchange) throws Exception {
                // 1. do pre endpoint assertion
                // 2. send to original endpoint here, perhaps using
NotifyBuilder to wait for it to finish?
                // 3. do post endpoint assertion
    }
}

How do I accomplish #2?  Should I just use a standard producer template?

Regards,

Alex

--
View this message in context: http://camel.465427.n5.nabble.com/testing-intercept-route-and-process-after-its-completion-tp5714460p5715186.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: testing: intercept route and process() *after* its completion?

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Jun 14, 2012 at 2:54 AM, twelve17 <sp...@twelve17.com> wrote:

> Hello,
>
> I've been diving into Camel testing lately, which, I'm not gonna lie, has
> been quite fun.  Thanks to the Camel book for assistance. :)
>
> I did run into one hangup in which I am not sure what the best
> pattern/practice is.
>
> For my integration testing, I am using adviceWith() to "inject" processing
> into an existing route.  The routebuilder class looks something like:
>
>  @Override
>  public void configure() throws Exception {
>     interceptSendToEndpoint("bean:someEndpointToBeTested").process(new
> DoSomeAssertionProcessor());
> }
>
> The code above runs the processor before the intercepted endpoint.   What I
> would like to do is call a processor *after* the intercepted bean is
> completed, so I can verify that the data it produced matches some expected
> data set.  For the moment, I am using the above pattern to intercept the
> endpoint that follows the actual one I want to test, which seems a little
> fragile to me.
>
> I tried using "interceptFrom", but it does not get triggered, which makes
> me
> believe it is only triggered if you are intercepting an input route, versus
> matching an output route as if it were "from", from the perspective of when
> the pipeline moves to the following route.
>
> Am I making any sense here? :)
>
> Any help would be appreciated.
>
>
I read this as you want to do some kind of AOP around the sending a message
to a given endpoint?
We could possible make that a bit easier from testing point of view.

What you can do with the advice with, and code you posted above is to
- enable the skip sending to endpoint option
- do assertion before
- send manually to the endpoint
- do assertion afterwards





> Thanks,
>
> Alex
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/testing-intercept-route-and-process-after-its-completion-tp5714460.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen