You should see an INFO logging with the endpoints being mocked during the advice process. Don't you see that?
On Fri, Apr 4, 2014 at 9:09 PM, Doug Turnbull <[email protected]> wrote: > 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> -- Claus Ibsen ----------------- Red Hat, Inc. Email: [email protected] Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen Make your Camel applications look hawt, try: http://hawt.io
