Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

There are some examples of the Mock endpoint in use in the camel-core processor tests.

A Spring Example

First, here's the spring.xml file

Wiki Markup
{snippet:id=example|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/mock/spring.xml}

As you can see, it defines a simple routing rule which consumes messages from the local src/test/data directory. The noop flag just means not to delete or move the file after its been processed.

Also note we instantiate a bean called myBean, here is the source of the MyAssertions bean.

Wiki Markup
{snippet:id=example|lang=java|url=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/MyAssertions.java}

The bean is injected with a bunch of Mock endpoints using the @EndpointInject annotation, it then sets a bunch of expectations on startup (using Spring's InitializingBean interface and afterPropertiesSet() method) before the CamelContext starts up.

Then in our test case (which could be JUnit or TesNG) we lookup myBean in Spring (or have it injected into our test) and then invoke the assertEndpointsValid() method on it to verify that the mock endpoints have their assertions met. You could then inspect the message exchanges that were delivered to any of the endpoints using the getReceivedExchanges() method on the Mock endpoint and perform further assertions or debug logging.

Here is the actual JUnit test case we use.

Include Page
CAMEL:Endpoint See Also
CAMEL:Endpoint See Also