0

I have created a camel-route with multiple anonymous innerclass for processors as below:

from("direct:testRoute")
            .process(new Processor() {
                public void process(Exchange exchange) {
                    exchange.setProperty("prop1","value1");
                }
            })
            .to("direct:testRoute2")
            .process(new Processor() {
                public void process(Exchange exchange){
                    exchange.setProperty("prop2","value2");
                }
            });

I have created junit for this as below:

public class OrderReportingServiceTest extends CamelTestSupport {
    @Test
    public void testRoute() {
        Exchange exchange = new DefaultExchange(context);
        template.send("direct:testRoute", exchange);
    }

The problem is when I check for the junit code coverage second processor in my direct:testRoute is not covered. It works fine for first processor though.

  • 1
    Maybe it fails before the last one, eg when sending to direct:testRoute2. Do you have a route to consume from this endpoint? Also you can use template.sendBody instead of creating your own Exchange object. As when you do like that you need to check yourself on the exchange if it failed, and if an exception was thrown, see the javadoc api of Exchange and ProducerTemplate for more details – Claus Ibsen Jan 16 '19 at 14:53
  • @ClausIbsen Thanks for replying.. It works fine and direct:testRoute2 is also present. issue appears only when trying to do a code coverage. I could use template.sendbody but the current implementation works fine for the first processor so it should not be a problem. – Rohit Raghuvanshi Jan 17 '19 at 13:52
  • Do you see that the prop2 property is set? You can try to add a system out println or debug the unit test to see if its called. And what tooling are you using for junit code coverage? Maybe its more of that tooling issue than Camel problem. And what version of Camel do you use? – Claus Ibsen Jan 17 '19 at 16:22
  • Prop2 is not getting set.. by tooling you mean framework I am using camel-test 2.1.8 and extending the same in my test class – Rohit Raghuvanshi Jan 18 '19 at 05:17

0 Answers0