0

Maybe a rather uncommon issue, but I'd like to mock certain Camel routes, in the JUnit setup method

@BeforeEach
void setUp() {
}

before the

@Override
public void configure() throws Exception {

}

is executed, which seems to happen, as soon as the CamelContext is autowired

@Autowired
protected CamelContext camelContext;

What do I need to do, to prevent autostarting of the Camel Context, in order to be able to mock my routes in the setup method and start it manually?

2 Answers 2

0

You can enable advice with in the unit test - then you need to start Camel manually.

https://camel.apache.org/manual/advice-with.html#_enabling_advice_during_testing

Sign up to request clarification or add additional context in comments.

Comments

0

This post is old but I don't like unanswered questions. So declare a MockEnpoint like so:

@EndpointInject("mock:mockExampleQueue")
MockEndpoint mockExampleQueue;

and add it to the routes at initialisation:

@BeforeAll
void setUpClass() throws Exception { 
  camelContext.addRoutes(
    new RouteBuilder() {
      @Override
      public void configure() {
        from("jms:queue:" + EXAMPLE_QUEUE)
          .to(mockExampleQueue);
        }
      });
  ..
}

EXAMPLE_QUEUE ist the queue you want to observe and that you must have definded in your code. Than make expectations:

mockExampleQueue.setExpectedCount(2);
mockExampleQueue.setResultWaitTime(20000);

and send a message or do what ever to let the routes do their expected jobs. Finally check that your expectations are fulfilled:

mockExampleQueue.assertIsSatisfied(); 

In an optional step you may check further details:

List<Exchange> receivedExchanges = mockExampleQueue.getReceivedExchanges();
...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.