5

I wrote this camel route:

@Component
public class FirstRoute extends RouteBuilder {

    private static final String DIRECT_ENDPOINT = "direct:test_direct";
    private static final String HTTP_ENDPOINT = "http:test_http";

    @Autowired
    private URIProcessor uriProcessor;

    @Override
    public void configure() throws Exception {
        restConfiguration().component("servlet").bindingMode(RestBindingMode.json);

        rest("/doTest/").post("/{comp}").to(DIRECT_ENDPOINT);

        test();
    }

    public void test() {        
        from(DIRECT_ENDPOINT).routeId("route_rest")
        .marshal().json(JsonLibrary.Jackson)
        .process(uriProcessor)
        .to(HTTP_ENDPOINT).unmarshal().json(JsonLibrary.Jackson, TestDto.class);

    }


}

It works fine.

I want to write a test class for this route, so in test class i wrote:

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new FirstRoute();

But when I run the test occurs an error.

This is the log of error:

org.apache.camel.FailedToCreateRouteException: Failed to create route route_rest at: >>> process[Processor@0x0] <<< in route: Route(route_rest)[[From[direct:testEsenzioneReddito]] -> [Ma... because of ref must be specified on: process[Processor@0x0]
    ...
Caused by: java.lang.IllegalArgumentException: ref must be specified on: process[Processor@0x0]
... 42 more


I have no idea what it could be, someone have does anyone have any suggestions? Thank you

  • you are probably getting this because when you are trying to create new instance for FirstRoute via `new` keyword, autowired fields do not get populated. Thus, in your test method, process does not get any value. – Ankur Aug 07 '19 at 09:26
  • Ok, I understand. Thank you. Use `context.getRoute("route_rest")` could be a solution? – Vincenzo Scorsone Aug 07 '19 at 09:56
  • refer this link : https://dev.to/matthieusb/integration-testing-on-existing-routes-with-apache-camel-and-spring-and-dbunit. Might be useful for you. – Ankur Aug 07 '19 at 10:57
  • 1
    This is because your `uriProcessor` is null. You need to properly inject (or mock) the processor. – Bedla Aug 07 '19 at 11:16

0 Answers0