Este contenido no está disponible en el idioma seleccionado.

Chapter 175. Test


Test Component

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:
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring</artifactId>
    <version>2.17.0.redhat-630xxx</version>
    <!-- use the same version as your Camel core version -->
</dependency>
Copy to Clipboard Toggle word wrap
From Camel 2.9 onwards the Test component is provided directly in the camel-core.

URI format

test:expectedMessagesEndpointUri
Copy to Clipboard Toggle word wrap
Where expectedMessagesEndpointUri refers to some other Component URI that the expected message bodies are pulled from before starting the test.

URI Options

Expand
Name Default Value Description
timeout 2000 Camel 2.12: The timeout to use when polling for message bodies from the URI.
anyOrder false Camel 2.17: Whether the expected messages should arrive in the same order or can be in any order.
split false Camel 2.17: If enabled, the messages loaded from the test endpoint will be split using \n, \r delimiters (new lines) so each line is an expected message. For example, to use a file endpoint to load a file where each line is an expected message.
delimiter \n|\r Camel 2.17: The split delimiter to use when split is enabled. By default the delimiter is new line based. The delimiter can be a regular expression.

Example

For example, you could write a test case as follows:
from("seda:someEndpoint").
  to("test:file://data/expectedOutput?noop=true");
Copy to Clipboard Toggle word wrap
If your test then invokes the MockEndpoint.assertIsSatisfied(camelContext) method, your test case will perform the necessary assertions.
To see how you can set other expectations on the test endpoint, see the Mock component.
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat