camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Castyn <>
Subject Re: Unit Testing Question
Date Thu, 16 Jan 2014 17:08:52 GMT
I've been reading over all of the test documentation and Mock documentation. 
It seems that I should be able to just setup a mock endpoint for the URI of
the processor and use the producer template to send the information to the
endpoint and run the asserts on that endpoint.  Is that a proper usage?

I don't really understand yet how mock endpoints work, I am seeking a simple
example to help get me over this.

Let's say I have a processor testProc that just does something trivial such

public class testProc implements Processor {
	public void process(Exchange exchange) throws Exception {
		exchange.getIn().setHeader("myHeader", "Yay");

let's say this processor is defined as a bean:
<bean id="myProcessor" class="com.test.testProc"/>

How do you use the mock and producer template to test this within a test
class?  How do I wire the mock endpoint to the processor uri?  What do I
need to do to setup the mock endpoint for this

public class ProcessStatusManagerTest extends CamelTestSupport{

	@EndpointInject(uri = "mock:myProcessor")
	protected MockEndpoint resultEndpoint;  
	@Produce(uri = "direct:start")
	protected ProducerTemplate template;
	public void procTest() throws Exception {

So assuming this sort of general flow is correct, I suppose my main hurdle
of understanding is based on not knowing how a mock endpoint can get wired
to an existing uri endpoint in the context.  I saw some mention of
context.resolveEndpoint(), but in the version I am using (Camel 2.8) I
actually don't see a resolve endpoint on
org.apache.camel.test.CamelTestSupport.context.  So how do I modify this to
run for the proper processor uri?

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message