I had this same issue too when I started looking into unit testing in camel. 
The mocks in camel aren’t really like mocks that comes with libraries such as 
Mockito. Those mocks actually replace the interface in which it mocks. Whereas 
the mocks in camel act more like proxies to the endpoints. Since they are 
proxies, they can optionally choose to skip the endpoint for which it is 

So in order to do what you want in your criteria. 
1. Load up your camel routes you wish to test.
2. Tell camel which endpoint you want to mock, this varies depending on which 
test method you want to use. CamelSpringTestSupport uses inheritance whereas 
the Camel enhanced sprint test uses annotations. Both has some way of accepting 
a uri pattern to tell it which endpoints you want to mock.
3. At the same time you do step 2, you normally specify whether to optionally 
skip the endpoint it is mocking. In your case, you want it to skip.
4. Inject the MockEndpoint into your unit test, I think there are various ways 
I used @EndpointInject and then set expectations on them. Since you’re skipping 
the endpoints, you should mock the output as well especially if your original 
endpoint actually had output. Now execute your route using a ProducerTemplate 
and then finally verify that your MockEndpoints received what you expected.

You can find a lot more info in that link you got below 

> On 10/12/2016 05:54 AM, catequil wrote:
>> Background
>> I'm a newbie to Apache Camel. (3 months)
>> I have read the testing section to Camel in Action MEAP version.
>> I have read http://camel.apache.org/testing.html and
>> http://camel.apache.org/spring-testing.html
>> I have searched this forum, google and stackoverflow for answers.
>> I've tried using the adviceWith, but that is confusing too.
>> Current versions are Camel 2.16.2 and Spring 4.0.6 and Junit 4.12
>> Dependencies loaded: {camel-core, camel-spring, camel-cxf, camel-jackson,
>> camel-test, camel-test-spring40, camel-kafka, spring-test}
>> Criteria
>> DRY (No identical code in testing)
>> Cannot modify production code.
>> Must use Mocks as integration tests would take too long to run.
>> Must use CamelSpringTestSupport (The only configuration I can get to work in
>> my environment that supports spring and camel)
>> Question
>> The part I am struggling with the most, for a week now, is the Mocks.  They
>> do not make sense to me on how they work in relation to the production
>> version of the route.
>> Can some one please help me to create a unit test that works having all this
>> criteria and help me understand the Mocking for Endpoints?
>> --
>> View this message in context: 
>> http://camel.465427.n5.nabble.com/Camel-Spring-Unit-Testing-with-Mocks-tp5788635.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to