You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by lleclerc <ll...@aim-rg.com> on 2012/11/26 20:34:53 UTC

Intercepting message for testing not working

Hi,

I am trying to do testing on a route, but I can't see what I am doing wrong.

I have this method from MyClass :

public RouteBuilder createRoute(...) {
...
from(timer).setHeader(Exchange.HTTP_QUERY, ...)
.to(http4)
.to(seda);
from(seda).unmarshal(..).process();
...
}

Now I want to test the route.

MyTestClass extends CamelTestSupport

@Override createRouteBuilder() and return my createRoute() in it.

Here is my testMethod() {

       context.getRouteDefinitions().get(0).adviceWith(context, new
AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {

                replaceFromWith("direct:test");

                interceptSendToEndpoint(http4)
                        .skipSendToOriginalEndpoint()
                        .process(new Processor() {
                            @Override
                            public void process(Exchange exchange) throws
Exception {
                                System.out.println("THIS MESSAGE IS NEVER
PRINTED");
                            }
                        });

                mockEndpoints();
            }
        });

        context.getRouteDefinitions().get(1).adviceWith(context, new
AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                weaveAddLast().to("mock:output");
            }
        });

        getMockEndpoint("mock:" +
fastMarkets.getSedaEndPointURI()).expectedMessageCount(1);
        getMockEndpoint("mock:output").expectedMessageCount(1);

        template.sendBody("direct:test", "THISTEST");

        assertMockEndpointsSatisfied();

        assertNotNull(context.hasEndpoint("direct:test"));
        assertNotNull(context.hasEndpoint(http4));

        assertNotNull(context.hasEndpoint("mock:" + http4));
        assertNotNull(context.hasEndpoint("mock:output"));
}

This test is SUCCESS, but it access the internet and the intercept is not
printing the message.

My http4 endpoint is on the internet and I don't want my test to need
internet. I am trying to intercept the message before it get there and just
process it and allow it to continue on the other routes.

I will be doing more tests to simulate http error or no response. Is it
possible to intercept a message before it is going out to the website ?

Advices affects the routes, are they reset for each @Test method or I should
use a new class for every test ?


Thanks !



--
View this message in context: http://camel.465427.n5.nabble.com/Intercepting-message-for-testing-not-working-tp5723257.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Intercepting message for testing not working

Posted by lleclerc <ll...@aim-rg.com>.
Using 2.10.2



--
View this message in context: http://camel.465427.n5.nabble.com/Intercepting-message-for-testing-not-working-tp5723257p5723400.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Intercepting message for testing not working

Posted by lleclerc <ll...@aim-rg.com>.
Here is the code
http://pastebin.com/kkVVb22x

Here is the logs
http://pastebin.com/CYPzBB8Q


I see the EndPoint is null, but it is on the camel side. Seems that setting
isUseAdviceWith to return true, prevent the creation of the endPoint, and
then I can't use advice on them, even though the route exist..

I still don't understand that part.

Do I need to create my EndPoints somewhere? 

Adding context.start(); at the top of my test allow the advice code to go
through but it is not triggering.




--
View this message in context: http://camel.465427.n5.nabble.com/Intercepting-message-for-testing-not-working-tp5723257p5723348.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Intercepting message for testing not working

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Nov 28, 2012 at 2:29 AM, lleclerc <ll...@aim-rg.com> wrote:
> Any idea ?
>

As said I suspect a NPE is thrown somewhere. Don't you see more in the logs?
What version of Camel do you use?


>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Intercepting-message-for-testing-not-working-tp5723257p5723325.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
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

Re: Intercepting message for testing not working

Posted by lleclerc <ll...@aim-rg.com>.
Any idea ?



--
View this message in context: http://camel.465427.n5.nabble.com/Intercepting-message-for-testing-not-working-tp5723257p5723325.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Intercepting message for testing not working

Posted by lleclerc <ll...@aim-rg.com>.
I do have it.

Removing http4 from classhpath give me this error instead :

org.apache.camel.FailedToCreateRouteException: Failed to create route route1
at: >>> To[http4:google.com] <<< in route: Route[[From[direct:test]] ->
[SetHeader[CamelHttpQuery, {usr... because of Failed to resolve endpoint:
http4://google.com due to: No component found with scheme: http4





--
View this message in context: http://camel.465427.n5.nabble.com/Intercepting-message-for-testing-not-working-tp5723257p5723307.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Intercepting message for testing not working

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Nov 27, 2012 at 3:44 PM, lleclerc <ll...@aim-rg.com> wrote:
> Thanks for the answer ! I missed that box !
> I got a second problem now..
>
> My application fail in the testMethod() onthis line :
> context.getRouteDefinitions().get(0).adviceWith(context, new
> AdviceWithRouteBuilder() {
>
> I get this error :
> org.apache.camel.FailedToCreateRouteException: Failed to create route route1
> at: >>> To[http4:google.com] <<< in route:
> Route[[From[timer:myTimer?delay=1000&period=500]] -> [SetHea... because of
> Failed to resolve endpoint: http4://google.com due to: null
>
> Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to
> resolve endpoint: http4://google.com due to: null
>
> Debugging context, I can see that my context does have the routes
>
> Route[[From[timer:myTimer?delay=1000&period=500]] ->
> [SetHeader[CamelHttpQuery, {...}], To[http4:google.com], To[seda:myQueue]]]
>
> context.getEndpoints() is empty.
>
> Am I still missing something ?
>

It smells like there is a NPE exception buried somewhere.
Do you got camel-http4 on the classpath ?

> Thank you!
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Intercepting-message-for-testing-not-working-tp5723257p5723305.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
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

Re: Intercepting message for testing not working

Posted by lleclerc <ll...@aim-rg.com>.
Thanks for the answer ! I missed that box !
I got a second problem now..

My application fail in the testMethod() onthis line :
context.getRouteDefinitions().get(0).adviceWith(context, new
AdviceWithRouteBuilder() {

I get this error :
org.apache.camel.FailedToCreateRouteException: Failed to create route route1
at: >>> To[http4:google.com] <<< in route:
Route[[From[timer:myTimer?delay=1000&period=500]] -> [SetHea... because of
Failed to resolve endpoint: http4://google.com due to: null

Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to
resolve endpoint: http4://google.com due to: null

Debugging context, I can see that my context does have the routes

Route[[From[timer:myTimer?delay=1000&period=500]] ->
[SetHeader[CamelHttpQuery, {...}], To[http4:google.com], To[seda:myQueue]]]

context.getEndpoints() is empty.

Am I still missing something ?

Thank you!





--
View this message in context: http://camel.465427.n5.nabble.com/Intercepting-message-for-testing-not-working-tp5723257p5723305.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Intercepting message for testing not working

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

See the green box on this page
http://camel.apache.org/advicewith.html


On Mon, Nov 26, 2012 at 8:34 PM, lleclerc <ll...@aim-rg.com> wrote:
> Hi,
>
> I am trying to do testing on a route, but I can't see what I am doing wrong.
>
> I have this method from MyClass :
>
> public RouteBuilder createRoute(...) {
> ...
> from(timer).setHeader(Exchange.HTTP_QUERY, ...)
> .to(http4)
> .to(seda);
> from(seda).unmarshal(..).process();
> ...
> }
>
> Now I want to test the route.
>
> MyTestClass extends CamelTestSupport
>
> @Override createRouteBuilder() and return my createRoute() in it.
>
> Here is my testMethod() {
>
>        context.getRouteDefinitions().get(0).adviceWith(context, new
> AdviceWithRouteBuilder() {
>             @Override
>             public void configure() throws Exception {
>
>                 replaceFromWith("direct:test");
>
>                 interceptSendToEndpoint(http4)
>                         .skipSendToOriginalEndpoint()
>                         .process(new Processor() {
>                             @Override
>                             public void process(Exchange exchange) throws
> Exception {
>                                 System.out.println("THIS MESSAGE IS NEVER
> PRINTED");
>                             }
>                         });
>
>                 mockEndpoints();
>             }
>         });
>
>         context.getRouteDefinitions().get(1).adviceWith(context, new
> AdviceWithRouteBuilder() {
>             @Override
>             public void configure() throws Exception {
>                 weaveAddLast().to("mock:output");
>             }
>         });
>
>         getMockEndpoint("mock:" +
> fastMarkets.getSedaEndPointURI()).expectedMessageCount(1);
>         getMockEndpoint("mock:output").expectedMessageCount(1);
>
>         template.sendBody("direct:test", "THISTEST");
>
>         assertMockEndpointsSatisfied();
>
>         assertNotNull(context.hasEndpoint("direct:test"));
>         assertNotNull(context.hasEndpoint(http4));
>
>         assertNotNull(context.hasEndpoint("mock:" + http4));
>         assertNotNull(context.hasEndpoint("mock:output"));
> }
>
> This test is SUCCESS, but it access the internet and the intercept is not
> printing the message.
>
> My http4 endpoint is on the internet and I don't want my test to need
> internet. I am trying to intercept the message before it get there and just
> process it and allow it to continue on the other routes.
>
> I will be doing more tests to simulate http error or no response. Is it
> possible to intercept a message before it is going out to the website ?
>
> Advices affects the routes, are they reset for each @Test method or I should
> use a new class for every test ?
>
>
> Thanks !
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Intercepting-message-for-testing-not-working-tp5723257.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
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