I have a Camel Unit Test and I want to get access to the header values that are set on the Exchange on the first point in the route.
Route example :
<route id="VCM001_incoming">
<from uri="file:{{InLocation}}"/>
<convertBodyTo type="java.lang.String"/>
<setHeader headerName="FileNameWithoutExtension">
<simple>${file:onlyname.noext}</simple>
</setHeader>
<to uri="direct:splitFile"/>
</route>
Java code where it's used :
public List<String> createList(Exchange exchange) {
String fileName = (String) exchange.getIn().getHeader("FileNameWithoutExtension");
So all good to this point.
Now in my test I want to find out what header value is "FileNameWithoutExtension".
@Produce(uri = "file:{{InLocation}}")
private ProducerTemplate inputEndpoint;
@EndpointInject(uri = "mock:output1")
private MockEndpoint outputEndpointRPR;
@Test
public void testCamelRoute() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file:{{OutLocation}}").to(outputEndpoint);
}
inputEndpoint.sendBody("test-message");
Object[] expectedBodies = new Object[]{"Success: filename=xxx"};
// At this point I need the header 'FileNameWithoutExtension' to setup the correct 'expectedBodies'
outputEndpoint.expectedBodiesReceivedInAnyOrder(expectedBodies);
assertMockEndpointsSatisfied();
}
}
Know this is very late, for camel 2.15.2 you can use the following
outputEndpoint.expectedHeaderReceived("header", "value");
You could get it quite easily using:
outputEndpoint.getExchanges().get(0).getIn().getHeader("FileNameWithoutExtension");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With