0
votes

Am new to Apache camel, working with it from last 2 weeks.

I have written a single route for FTP download and then unzipping the downloaded files from FTP and then parsing the csv files to a bean objects.

Now i have to write unit test cases for this route, so i divided them in parts like 1 for FT,1 for Unzipping and 1 for parsing to bean, am through with writing a FTP test successfully, but for the next two tasks am not clear on how to proceed for unzipping and parsing to bean unit test, can anyone please help me on this?

Thanks for the help

1
That's not a unit test; it's an integration test. You should test each piece individually and mock the rest.duffymo
Each piece individually! please can u give me some light on that sample code is from("{{ftp.server}}").to("file:tmp/inbound").log("Processsing ${file:name}") .setHeader("flightkey", simple("${file:onlyname.noext}")) .split(new ZipSplitter()).streaming() .convertBodyTo(String.class) .setHeader(Exchange.FILE_NAME, simple("${header.flightkey}/${file:name}")) .to("file:tmp/inbound").log("CamelFileName ${header.CamelFileName}")Jayyanthii Thakur
Test your bits. Check the Apache Camel unit tests. If they've tested their stuff, there's no need for you to check them. Maybe you need to think in terms of mocks here.duffymo

1 Answers

1
votes

take a look at Camel AdviceWith for testing the route flow using mock endpoints to assert its setup properly...

public void testAdvised() throws Exception {
    // advice the first route using the inlined route builder
    context.getRouteDefinitions().get(0).adviceWith(context, new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // intercept sending to mock:foo and do something else
            interceptSendToEndpoint("mock:foo")
                    .skipSendToOriginalEndpoint()
                    .to("log:foo")
                    .to("mock:advised");
        }
    });

    getMockEndpoint("mock:foo").expectedMessageCount(0);
    getMockEndpoint("mock:advised").expectedMessageCount(1);
    getMockEndpoint("mock:result").expectedMessageCount(1);

    template.sendBody("direct:start", "Hello World");

    assertMockEndpointsSatisfied();
}