Kavin
Kavin

Reputation: 41

How to setHeader in Camel Test

I am working with the task in which, I have set header in one of the processor.

exchange.getIn().setHeader("ResourceSpec", equipmentSpec.getSpec());

While writing the test cases, it was expecting for value.because of that test cases getting failed.

Mock-RouteTest:

void advice(@Observes CamelContextStartingEvent event, CamelContext context) throws Exception {

    context.getRouteDefinition(test.update)
           .adviceWith(context, new AdviceWithRouteBuilder() {
               @Override
               public void configure() {           
                   weaveByToString(".*lineInquiryBy.*")
                       .replace()
                       .to("mock:lineInquiry");
               }
           });

Need help to set header in mock. So that while executing, processor can get the value.

Using camel-test and camel-test-cdi.

Thanks

Upvotes: 0

Views: 1695

Answers (1)

burki
burki

Reputation: 7005

Not sure if I understand your question. What I understood:

  1. You have a processor that sets the header ResourceSpec
  2. You have a test that removes that processor with adviceWith from the route
  3. Therefore a later route step fails because the header ResourceSpec is not set

If I understood your question correct, you can simply "insert" the setHeader where you remove the processor

weaveByToString(".*lineInquiryBy.*")
    .replace()
    .to("mock:lineInquiry")
    .setHeader("ResourceSpec", constant("static value"));

If you need a dynamic value (for example from a message header), you can use the Camel Simple expression language:

.setHeader("ResourceSpec", simple("${header.myHeader}"));

Upvotes: 0

Related Questions