-
1. Re: testing routes when endpoints need to return a value
davsclaus Feb 24, 2010 12:37 AM (in response to lyfe)You can use mock and in your unit test set expectations on the mocks and have it verified after the test has run.
Otherwise you can look into the interceptSendToEndpoint which is part of Camel 2.x.
-
2. Re: testing routes when endpoints need to return a value
lyfe Feb 24, 2010 10:36 AM (in response to davsclaus)MOCK RESPONSE:
From what I've read about Mock, it will only verify what comes in. I'm looking for a way to also send a response back in order for the route to continue.
Using the below example with line numbers (I've fixed my typos):
(1) from("direct:content-based-routing")
(2) .to("jbi:endpoint:http://my.exit/PositiveService/Pos1?mep=in-out")
(3) .process(new Process())
(4) .to("jbi:endpoint:http://my.exit/PositiveService/Pos2?mep=in-out");
If I set up a mock endpoint for line 2, I can test what comes in. But it's not clear how I would have the mock endpoint for line 2 return a value so the mock endpoint at line 4 can be tested.
I'm I mistaken what the mock endpoint is capable of?
INTERCEPT RESPONSE:
I took a look at interceptSendToEndpoint. This looks very promising. Do you have an example of how I could apply this technique to the above example? I'm really trying to figure out a way to represent an endpoint that receives input and returns output.
-
3. Re: testing routes when endpoints need to return a value
davsclaus Feb 24, 2010 11:09 AM (in response to lyfe)You can use the whenAnyMessageReceived on the mock endpoint to provide a processor where you can manipulate the Exchange and set a response as you like.
For example doing that at step 2
-
4. Re: testing routes when endpoints need to return a value
davsclaus Feb 24, 2010 11:13 AM (in response to lyfe)The Camel in Action book contains an entire section in the test chapter #5, about using interceptSendToEndpoint in testing.
As always a good place to look for examples is also the camel source code in the src/test/java folder.
Just grep for interceptSendToEndpoint.
-
5. Re: testing routes when endpoints need to return a value
lyfe Feb 24, 2010 12:47 PM (in response to davsclaus)thanks. however, it should be whenAnyExchangeReceived. whenAnyMessageReceived is not a method defined on the MockEndpoint.
Edited by: lyfe on Feb 24, 2010 5:46 PM