Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Wiki Markup
h2. Test Component

...



{include

...

:Testing Summary

...

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 will then set 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 will need to add the following dependency to their pom.xml for this component when using Camel 2.8 or older:

Code Block
xmlxml
 Include}

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 will then set 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 will need to add the following dependency to their {{pom.xml}} for this component when using *Camel 2.8* or older:
{code:xml}
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring</artifactId>
    <version>x.x.x</version>
    <!-- use the same version as your Camel core version -->
</dependency>
{code}
From Camel 2.9 onwards the [Test] component is provided directly in the camel-core.


h3.

...

 URI format

...



{code
}
test:expectedMessagesEndpointUri
{code}

Where *expectedMessagesEndpointUri* refers to some other [Component] URI that the expected message bodies are pulled from before starting the test

...

Example

For example, you could write a test case as follows:

Code Block
. 

h3. URI Options

{div:class=confluenceTableSmall}
|| Name || Default Value || Description ||
| {{timeout}} | {{2000}} | *Camel 2.12:* The timeout to use when polling for message bodies from the URI. |
{div}


h3. Example

For example, you could write a test case as follows:

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

If your test then invokes the [MockEndpoint.assertIsSatisfied(camelContext) method|http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/component/mock/MockEndpoint.html#assertIsSatisfied(org.apache.camel.CamelContext)], your test case will perform the necessary assertions.

...




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

...



{include

...

:Endpoint See

...

 Also}
* [Spring Testing]