You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Test Component

Testing of distributed and asynchronous processing is notoriously difficult. The Test Component provides a great tool for creating good integration test cases based on the Enterprise Integration Patterns using the various Components in Camel.

The Test component extends the Mock component to support pulling messages from another endpoint on startup to set the expected message bodies on the underlying Mock endpoint.

i.e. you use the test endpoint in a route and messages arriving on it will be implicitly compared to some expected messages extracted from some other location.

So you can use for example an expected set of message bodies as files. This will then setup a properly configured Mock endpoint which is only valid if the received messages match the number of expected messages and their message payloads are equal.

URI format

test:expectedMessagesEndpointUri

Where expectedMessagesEndpointUri refers to some other Component URI where the expected message bodies are pulled from before starting the test.

Example

For example you could write a test case as follows

from("seda:someEndpoint").
  to("test:file://data/expectedOutput?noop=true");

If your test then invokes the MockEndpoint.assertIsSatisfied(camelContext) method then your test case will perform the necessary assertions.

To see how you can set other expectations on the test endpoint, see the Mock component.

  • No labels