Hi See the green box on this page http://camel.apache.org/advicewith.html
On Mon, Nov 26, 2012 at 8:34 PM, lleclerc <llecl...@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: cib...@redhat.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen