Test — a mock endpoint that tests messages based on a set of expected messages
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. That is, 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 then sets up 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.
Maven users need to add the following dependency to their pom.xml
to
use this component when using Apache Camel 2.8 and
later.
Example 16. Test dependency
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-test</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
![]() | Note |
---|---|
From Apache Camel 2.9 onwards, the Test component is provided
directly in |
Test endpoints use the following URI format:
test:expectedMessagesEndpointUri
Where expectedMessagesEndpointUri
refers to some other
Component endpoint URI
from which the expected message bodies are pulled.
Name | Default | Description |
---|---|---|
timeout
|
2000
|
Apache Camel 2.12: Specifies the timeout to use when polling for message bodies from the URI. |
For example, you could write a test case as follows:
from("seda:someEndpoint"). to("test:file://data/expectedOutput?noop=true");
If your test invokes the MockEndpoint.assertIsSatisfied(camelContext) method, your test case will perform the necessary assertions.
Here is a real example test case using Mock and Spring along with its Spring XML.
To see how you can set other expectations on the test endpoint, see the Mock component.