For Camel 3.16.0 we are removing the deprecated container-based test modules and replacing them with a new set of modules called Camel test-infra.
They continue to support container-based tests via TestContainers, however they abstract the underlying test infrastructure.
One of the great benefits for our project is that they allow us to more easily switch from container-based tests, to external instances. Previously, we would need to create a new test or implement a more complex design if we wanted to test both a container instance and an external service instance (i.e.: one for a JMS broker container and another test for a remote JMS instance, one for a LocalStack container and another for the Amazon Web Services, etc). This new design helps us to reduce the maintenance effort for Camel, while also extending our ability to test for edge scenarios.
To achieve this we removed the necessity of extending classes such as
CamelSpringTestSupport and other similar classes in order to implement a container-based test. Instead, the new component leverages JUnit 5 extension mechanism, such as by using the
@RegisterExtension annotation, to inject abstract services into a test.
For example, to inject an abstract Kafka service into a test class, this is all it takes with the Camel’s
@RegisterExtension public static KafkaService service = KafkaServiceFactory.createService();
Naturally, the service instance comes with the appropriate methods to resolve URLs, ports, authentication parameters and more that may be necessary to run the test.
test-infra is in fact, a collection of modules. They include support for a broad range of services that can support both Camel’s testing needs as well as Camel’s users. For the upcoming Camel 3.16.0 release, these are the 38 supported modules:
From the perspective of Camel users and the overall community, these modules also bring many benefits.
For developers writing integrations using Camel, they are now able to use the same test service abstraction as our tests. This can reduce code duplications for our end users and help them benefit from test infrastructure components that are battle tested in Camel itself. Additionally, these components can be more easily extended to cover other scenarios. For instance, they can be used to implement a custom service that runs and manages the test infrastructure in a Kubernetes cluster.
There is also benefits for vendors creating products based on Apache Camel. Now they have the ability to test for edge scenarios more easily. They can switch from testing locally to testing against remote services with a few command-line parameters applied to their build or test automation.