...
You typically always call the assertIsSatisfied() method to test that the expectations were met after running a test.
...
You can see from the javadoc of MockEndpoint the various helper methods you can use to set expectations. The main methods available are as follows:
Method | Description |
---|---|
to define the expected message count on the endpoint | |
to define the minimum number of expected messages on the endpoint | |
to define the expected bodies that should be received (in order) | |
to define the expected header that should be received | |
to add an expectation that messages are received in order using the given Expression to compare messages | |
to add an expectation that messages are received in order using the given Expression to compare messages | |
to add an expectation that no duplicate messages are received; using an Expression to calculate a unique identifier for each message. This could be something like the JMSMessageID if using JMS, or some unique reference number within the message. |
...
In addition you can use the message(int messageIndex) method to add assertions about a specific message that is received.
...
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=activemq/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=activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/mock/MyAssertions.java} |
...
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 | ||||
---|---|---|---|---|
|
...