mercredi 29 juillet 2015

Adding interceptors on endpoints in a live camelContext without any CamelTestSupport

I am trying to add camel testcases for an application that will be deployed on fuse esb. I presently have testcases based on CamelBlueprintTestSupport. I add Interceptors on the routes and endpoints and do my assertions.

I am now exploring the possibility of doing similar testcases using pax-exam so that the testcase can run directly on the fuse environment. I have setup my configuration for pax exam so that it loads all my bundles and config files and the camel routes are up and running.

But since I have to use the camelContext provided by my bundle, I can no longer use CamelBlueprintTestSupport or CamelTestSupport for that matter as both of these will create their own contexts rather than use the one provided by my OSGI bundle.

@RunWith(PaxExam.class)
@ExamReactorStrategy(ActiveMQPerClass.class)
public class XyzIT extends PaxEndToEndTestSupport{  

@Inject
protected BundleContext bundleContext;

protected MockEndpoint some_endpoint;

@Inject
@Filter("(camel.context.name=myCamelContext)")
protected CamelContext camelContext;

@Before
public void configureCamelContext(){        
    try{                    

        this.camelContext.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {                  
                interceptSendToEndpoint("direct:utilities:sm_route").id("sm_mock_intercept").to("mock:sm_mock");
                from("myQ:queue:{{jms.queue.error.uri}}").to("mock:error_uri");
            }
        });
    }
    catch(Exception ex){
        ex.printStackTrace();
    }       

}

@Test
public void xyzTest() throws Exception {

    //Some Test
}

}

THIS WILL NOT WORK

In such a scenario, How do I modify the camelContext provided by my bundle and add interceptors to it. I cannot set the isUseAdviceWith flag and so no advices will work. May be I am not supposed to use PAX-Exam in this way but is there any way to coax CamelContext to add intercepts or modify it in anyway without CamelTestSupport.

Aucun commentaire:

Enregistrer un commentaire