camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Quinn Stevenson <qu...@pronoia-solutions.com>
Subject Re: Doing bean inject in camel test
Date Fri, 04 Mar 2016 15:19:00 GMT
It looks like you’re trying to inject a bean endpoint (from the URI) into a mock endpoint
- the types don’t line up.


> On Mar 3, 2016, at 10:50 AM, D <subharaj.manna@gmail.com> wrote:
> 
> I have a camel app which look something like below:-
> 
> public class OrderMainApp {
>    public static void main(String... args) throws Exception {
>    OrderMainApp orderMainApp = new OrderMainApp();
>    DefaultCamelContext camelContext = new DefaultCamelContext();
>    ProducerTemplate producer = camelContext.createProducerTemplate();
>    camelContext.setRegistry(orderMainApp.createRegistry(producer));
>    camelContext.addRoutes(new OrderRouteBuilder(producer));
>    camelContext.start();
>    }
> 
>    protected JndiRegistry createRegistry(ProducerTemplate producer) throws
> Exception {
>    JndiRegistry jndi = new JndiRegistry();
>    OrderHelper orderHelper = new OrderHelper();
>    orderHelper.setProducer(producer);
>    jndi.bind("orderHelper", orderHelper);
>    return jndi;
>    }
> }
> 
> In OrderRouteBuilder configure has routes like below:-
> 
> //processor is a custom JSONProcessor extending Processor
> from("jetty:http://localhost:8888/orchestratorservice").process(processor);
> from("direct:getMarketplaceOrders").to("bean:orderHelper?method=getMarketplaceOrders");
> 
> My test class look something like below:-
> 
> public class OrderMainAppTest extends CamelTestSupport {
> 
>    @Produce(uri = "direct:getMarketplaceOrders")
>    protected ProducerTemplate template;
> 
>    @EndpointInject(uri = "bean:orderHelper?method=getMarketplaceOrders")
>    protected MockEndpoint resultEndpoint;
> 
>    @Test
>    public void testSendMatchingMessage() throws Exception {
>    String expectedBody = "<matched/>";
> 
>    template.sendBody("{\"fromDateTime\": \"2016-01-11 10:12:13\"}");
> 
>    resultEndpoint.expectedBodiesReceived(expectedBody);
> 
>    resultEndpoint.assertIsSatisfied();
>    }
> 
>    @Override
>    protected RouteBuilder createRouteBuilder() {
>    return new RouteBuilder() {
>        @Override
>        public void configure() {
> 
> from("direct:getMarketplaceOrders").to("bean:orderHelper?method=getMarketplaceOrders");
>        }
>    };
>    }
> }
> 
> Whenever I am running the test I am getting the below exception:-
> 
> java.lang.IllegalArgumentException: Invalid type:
> org.apache.camel.component.mock.MockEndpoint which cannot be injected via
> @EndpointInject/@Produce for:
> Endpoint[bean://orderHelper?method=getMarketplaceOrders]
> 
> I am guessing this is because I am not able to pass on OrderHelper to the
> camel test context. Can some one let me know how can I inject the bean in
> the mock result end point?
> 
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Doing-bean-inject-in-camel-test-tp5778565.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message