javaapache-cameljunit5

How can I enable `useAdviceWith` in a CamelTestSupport unit test?


We have a number of Camel route unit tests in JUnit 5 that extend CamelTestSupport. They currently override the isUseAdviceWith method to return true, so that the Camel context is not started automatically and using adviceWith in the tests does not trigger a restart of the context. So far, so good.

After upgrading to Camel 4.7.0, the isUseAdviceWith method is deprecated. This appears to be due to work on CAMEL-20785 and CAMEL-20843. These are good changes, FWIW :) From what I understand, the replacement for overriding isUseAdviceWith would be to configure

testConfigurationBuilder.withUseAdviceWith(true);

in the setupResources method or in a @BeforeEach method.

My questions are: (1) do I understand that correctly? And (2) if that is the path forward, is it a mistake that withUseAdviceWith is currently protected and can therefore not be called when setting up the unit test? If the above is not the way forward, I'd love to learn what is, because I have not been able to find it so far in the documentation.


Solution

  • I probably shouldn't have been that restrictive with the TestExecutionConfiguration class. Preventing enabling withAdviceWith is a mistake and I logged it as CAMEL-21078. It will be fixed for Camel 4.8.0.