concept test in category camel

appears as: test, tests, test, The test, tests, The test
Camel in Action

This is an excerpt from Manning's book Camel in Action.

Here, in a single Java statement, you define a route that consumes files from a file endpoint. Messages are then routed to the filter EIP, which will use an XPath predicate to test whether the message is not a test order. If a message passes the test, it’s forwarded to the JMS endpoint. Messages failing the filter test are dropped.

When you run this example, it should output the result of the test as shown here:

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

Figure 9.4 Three steps for testing: set expectations, run the test, and verify the result

c09_04.png

Before the test is started, you set the expectations of what should happen ❶. Then you run the test ❷. Finally, you verify the outcome of the test against the expectations ❸. The Camel mock component allows you to easily implement these steps when testing Camel applications. On the mock endpoints, you can set expectations that are used to verify the test results when the test completes.

To make testing easier, you use weaveAddLast ❷ to route to a mock endpoint at the end of the route. Remember to start Camel ❸ before you start sending messages into the route and assert that the test is correct ❹.