Testing camel route via pax exam

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Testing camel route via pax exam

Marco Westermann
Hi,

  I try to test a camel route via pax exam. In general I followed the
tutorial by jb
(http://blog.nanthrax.net/2014/08/testing-utest-and-itest-apache-camel-blueprint-route/)

The route I'd like to test sends a message to an activemq queue.
Therefor I'd like to grab that message in my test and send it to the
mock:result endpoint. But now I have the problem that my test fails with
an error:

Failed to resolve endpoint: activemq://queue:qstep.order.sales due to:
No component found with scheme: activemq

I thought I have to add the component to the camel context.. therefor I
implemented the following method in the route builder:

@Override
publicModelCamelContextgetContext() {
     ModelCamelContext context =super.getContext();
     context.addComponent("activemq", newActiveMQComponent());
     returncontext;
}

But then I get the error: Cannot add component as its already previously
added: activemq

Here is my test environment:

servicemix 4.5.2 as testcontainer

test class: http://pastebin.com/4zqdNtZC

thank you for any hints you could give.

regards, Marco




Reply | Threaded
Open this post in threaded view
|

Re: Testing camel route via pax exam

Andrew Block
Marco,

Instead of overriding the getContext in the RouteBuilder, try overriding the createCamelContext method of the CamelTestSupport class with the following

@Override
        protected CamelContext createCamelContext() throws Exception {
                CamelContext context = super.createCamelContext();
                context.addComponent("activemq", new ActiveMQComponent());
                       
                return context;
        }

This should allow you to also remove attempting to add the component in your unit test method

- Andy

-- 
Andrew Block


On August 26, 2015 at 8:05:07 AM, Marco Westermann ([hidden email]) wrote:

Hi,  

I try to test a camel route via pax exam. In general I followed the  
tutorial by jb  
(http://blog.nanthrax.net/2014/08/testing-utest-and-itest-apache-camel-blueprint-route/)  

The route I'd like to test sends a message to an activemq queue.  
Therefor I'd like to grab that message in my test and send it to the  
mock:result endpoint. But now I have the problem that my test fails with  
an error:  

Failed to resolve endpoint: activemq://queue:qstep.order.sales due to:  
No component found with scheme: activemq  

I thought I have to add the component to the camel context.. therefor I  
implemented the following method in the route builder:  

@Override  
publicModelCamelContextgetContext() {  
ModelCamelContext context =super.getContext();  
context.addComponent("activemq", newActiveMQComponent());  
returncontext;  
}  

But then I get the error: Cannot add component as its already previously  
added: activemq  

Here is my test environment:  

servicemix 4.5.2 as testcontainer  

test class: http://pastebin.com/4zqdNtZC 

thank you for any hints you could give.  

regards, Marco