0

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

hk6279
  • 1,881
  • 2
  • 22
  • 32
Kavin
  • 43
  • 8

1 Answers1

0

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}"));
burki
  • 6,741
  • 1
  • 15
  • 31
  • i tried it in same way...but it was throwing error. – Kavin Jul 10 '20 at 12:16
  • 1) setHeader(String name), 2) setHeader(String name, Expression expression), 3) setHeader(String name, Supplier Supplier)...there are the options i can see it in suggestion. – Kavin Jul 10 '20 at 12:18
  • Sorry, my bad. I updated my answer with two examples for an expression. one with a static value, applied with `constant`. And one with a dynamic value taken from a message header, applied with `simple`. – burki Jul 10 '20 at 14:56
  • @burki..Thanks..i was getting exception on a line before getHeader() – Kavin Jul 10 '20 at 17:10