Hi, I'm running an integration test using the CamelSpringJUnit4ClassRunner to test a route JMS -> Processor -> SFTP endpoint. In my test, I use a ProducerTemplate to fire a message to the JMS endpoint and mock the SFTP endpoint where I assert sftpMockEndpoint.setExpectedMessageCount(1). This all works fine.
I've now written a test where I send an invalid message to the JMS queue. Normally this is caught by the processor which logs the message and stops any further processing. The SFTP endpoint should not receive a message in this case, so I've added: sftpMockEndpoint.setExpectedMessageCount(0) When I run this test and pass in a valid message (i.e. one that reaches the SFTP endpoint), I'm still getting a positive result - the SFTP endpoint receives a message AND the setExpectedMessageCount(0) assertion passes. I believe that because the JMS queue is asynchronous, the assertions are being fired before the message has passed along the route - is this correct? E.g.: 1. set mock expectation sftpMockEndpoint.expectedMessageCount(0); 2. fire message to JMS queue. Starts an async process and return control to test method 3. test method runs sftpMockEndpoint.assertIsSatisfied(); which asserts that the SFTP mock has received no messages. Assertion is correct. 4. JMS messages continues to be processed and eventually makes it's way to the SFTP mock, which results in 1 message being received after the test assertions have been processed. Please could you confirm if this is the case and if there is anything I can do to suspend processing of the assertions until the message has gone all the way through the route? I tried adding a sftpMockEndpoint.whenAnyExchangeReceived(new Processor() { // throw Exception }); to trigger a failure in the test whenever the SFTP mock received an Exchange but unfortunately the Exception gets swallowed up by the test framework. The only solution I have found is to add a Thread.sleep(100); before the test assertions (assertIsSatisfied) are processed, but this is ugly and I don't want arbitrary sleeps within my code. Any help would be greatly appreciated and apologies for the length of this post - I wanted to include as much information as possible but not post great swathes of unintelligible code. Thanks again, John -- View this message in context: http://camel.465427.n5.nabble.com/mock-expectedMessageCount-0-resulting-in-a-false-positive-tp5723952.html Sent from the Camel - Users mailing list archive at Nabble.com.