title: Apache Camel Testing
body: <p>We're using Spring for DI and Camel for routing/messaging. I've been asked to set up some (JUnit) unit tests for our various components (which all route messages to one another in a pipeline fashion).</p>
  
  <p>After taking a gander at the general <a href="http://camel.apache.org/testing.html" rel="nofollow">Camel testing</a> doc and <a href="http://camel.apache.org/spring-testing.html" rel="nofollow">Camel-Spring testing</a> doc, it seems like the preferred method of unit testing camel endpoints is through the <em>Spring Test Context Framework</em> using subclasses of objects like <code>AbstractJUnit38SpringContextTests</code> and the sorts.</p>
  
  <p>I have absolutely zero experience with any of these APIs. So, although they make for interesting reading, it's tough for me to put them into context (no pun intended).</p>
  
  <p>As such there are a few initial concepts I am struggling with:</p>
  
  <p><strong>For one, when is it appropriate to use a <code>MockEndpoint</code>, vs <code>DataSet</code>, vs <code>Test</code>?</strong></p>
  
  <p>Also, the Camel-Spring doc (link is above) provides the following example:</p>
  
  <pre><code>@ContextConfiguration
  public class MyCamelTest extends AbstractJUnit38SpringContextTests {
  
      @Autowired
      protected CamelContext camelContext;
  
      @EndpointInject(uri = "mock:foo")
      protected MockEndpoint foo;
  
      public void testMocksAreValid() throws Exception {
  
          // lets add more expectations...
          MockEndpoint.assertIsSatisfied(camelContext);
  
          // now lets do some further assertions
          List&lt;Exchange&gt; list = foo.getReceivedExchanges();
  
          for (Exchange exchange : list) {
              Message in = exchange.getIn();
              ...
          }       
      }
  }
  </code></pre>
  
  <p>If I'm even <em>beginning</em> to understand this API, then it seems like the code above it reading all the messages from a <code>MockEndpoint</code> named <code>mock:foo</code>...but I don't see where those messages are coming from (how they get to the endpoint in the first place)!</p>
  
  <p><strong>So my second question is</strong>: what are the standard practices for determining which endpoints to "stub" (mock)? For instance what if the same JMS message queue is utilized by two endpoints living inside two different JARs/WARs: one a producer and the other, a consumer?  In this case, <code>ProducerComponent</code> (living inside <code>producer.war</code>) is a Camel endpoint that pushes messages to <code>someQueue</code>. And <code>ConsumerComponent</code> (living inside of <code>consumer.war</code>) is another Camel endpoint consuming messages off of <code>someQueue</code>.</p>
  
  <p><strong>How would SO organize the unit tests for both components?</strong></p>
  
  <p>Thanks in advance for any nudges in the right direction!</p>