camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Turnbull <dturnb...@opensourceconnections.com>
Subject Using AdviceWith not intercepting when I send real Files through
Date Fri, 04 Apr 2014 19:09:18 GMT
Hello,

I'm attempting to use AdviceWith for testing a route The route looks like:

    from("file:inbox?doneFile=done")
    .unmarshall(csv)
    .split(body())
         .to("direct:csvRecords")

I've written a test that attempts to confirm that files get unmarshalled to
csv correctly and are sent to my mocked direct:csvRecords endpoint. As
such, my test looks like what is recommended from the Camel mock page
https://camel.apache.org/mock.html. The main difference is I'm sending
through real files, but treating direct:csvRecords as a mock to confirm
correct behavior.

public void mockAllEndpoints() throws Exception {
AdviceWithRouteBuilder mockDirect = new AdviceWithRouteBuilder() {

@Override
public void configure() throws Exception {
// mock the for testing
mockEndpoints();
}
 };
context.getRouteDefinitions().get(0)
.adviceWith(context, mockDirect);
}

Then in my test I have:

@Test
public void testReadCsvFileWhenDoneFile() throws Exception {
mockAllEndpoints();
MockEndpoint mockDirectCsv = getMockEndpoint("mock:direct:csvRecords");
File testCsv = new File("test.csv");
assertTrue(testCsv.exists());
 mockDirectCsv.expectedMessageCount(3);
FileUtils.copyFile(testCsv, new File("inbox/test.csv"));
FileUtils.touch(new File("inbox/done"));
Thread.sleep(100);
// Confirm nothing's been processed
mockDirectCsv.assertIsSatisfied();
}


The "assertIsSatisfied" fails because the expectation isn't met. I can
confirm that CSV deserialization and processing is happening because if I
add a .process() and to a println, I see all three csv records in that file
come out fine. I'd just like to be able to build tests around expected
behavior for my routes.

As far as I can tell the mock endpoint isn't getting hit with messages. If
I put a breakpoint in the mock endpoint code where the message counter is
incremented, it is never hit. So the assertIsSatisfied fails due to not
enough messages being brought through.

(I'm running Camel 2.12.3 on Windows 7. Java 7)

Thanks

-- 
Doug Turnbull
Search & Big Data Architect
OpenSource Connections <http://o19s.com>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message