title: Testing Camel with MockEndpoints
body: <p>I've got a series of "pipelined" components that all communicate through ActiveMQ message queues. Each component uses Camel to treat each of these queues as an Endpoint. Each component uses the same basic pattern:</p>
  
  <p><img src="https://i.stack.imgur.com/zHi7h.jpg" alt="Basic component pattern"></p>
  
  <p>Where each component consumes messages off of an input queue, processes the message(s), and then places 1+ messages on an outbound/output queue. The "output" queue then becomes the "input" queue for the next component in the chain. Pretty basic.</p>
  
  <p>I am now trying to roll up my sleeves and provide unit testing for each component using the <code>MockEndpoints</code> provided by Camel's test API. I have been pouring over the javadocs and the few examples on Camel's website, but am having difficulty connecting all the dots.</p>
  
  <p>It seems to me that, for each component, a portion of my unit testing is going to want to accomplish the following three things:</p>
  
  <ul>
  <li>Test to see if there are messages waiting on a particular "input" queue</li>
  <li>Pull those messages down and process them</li>
  <li>Push new messages to an "output" queue and verify that they made it there</li>
  </ul>
  
  <p>I <em>believe</em> I need to create <code>MockEndpoints</code> for each queue like so:</p>
  
  <pre><code>@EndpointInject(uri = "mock:inputQueue")
  protected MockEndpoint intputQueue;
  
  @EndpointInject(uri = "mock:outputQueue")
  protected MockEndpoint outputQueue;
  </code></pre>
  
  <p>So now, in my JUnit test methods, I can set up expectations and interact with these endpoints:</p>
  
  <pre><code>@Test
  public final void processMethodShouldSendToOutputQueue()
  {
      Component comp = new Component();
      comp.process();
  
      outputQueue.assertIsSatisfied();
  }
  </code></pre>
  
  <p>I'm just not understanding how to wire everything up correctly:</p>
  
  <ul>
  <li>How do I connect <code>comp</code> to the <code>inputQueue</code> and <code>outputQueue</code> MockEndpoints?</li>
  <li>For each <code>MockEndpoint</code>, how do I set up expectations so that <code>assertIsSatisfied()</code> checks that a message is present inside a particular queue, or that a particular queue contains messages?</li>
  </ul>