This section describe how to convert projects that create and manage a CamelContext directly (i.e.; not relying on CamelTestSupport).
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-test-infra-core</artifactId> <version>${project.version}</version> <type>test-jar</type> <scope>test</scope> </dependency>
@RegisterExtension private static CamelContextExtension camelContextExtension = new DefaultCamelContextExtension();
Tips: when running multiple tests in the same class, it may be necessary to completed trash the context instance. In this case, create an instance of TransientCamelContextExtension and JUnit will properly dispose the instance and create a new one.
private CamelContext context; @BeforeEach void setupTest() throws Exception { context = camelContextExtension.getContext(); }
@RouteFixture annotation:@RouteFixture public void setupRoute(CamelContext camelContext) throws Exception { camelContext.addRoutes(new RouteBuilder() { @Override public void configure() { restConfiguration() .host("localhost") .component("dummy-rest"); from("direct:foo") .routeId("foo") .to("mock:foo"); } }); }
public method annotated with the @ContextFixture annotation:@ContextFixture public void setupContext(CamelContext camelContext) throws Exception{ // configure the context }
CamelTestSupport<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-test-infra-core</artifactId> <version>${project.version}</version> <type>test-jar</type> <scope>test</scope> </dependency>
CamelTestSupport with the implementation of support interfaces from CamelTestSupportHelper, ConfigurableRoute and ConfigurableContext. These brings several helper methods from CamelTestSupport and simulate the legacy behavior.public class MyTest implements ConfigurableRoute, CamelTestSupportHelper { // ... }
@RegisterExtension public static CamelContextExtension camelContextExtension = new DefaultCamelContextExtension();
Tips: when running multiple tests in the same class, it may be necessary to completed trash the context instance. In this case, create an instance of TransientCamelContextExtension and JUnit will properly dispose the instance and create a new one.
@Order(1) @RegisterExtension public static MyLocalContainerService service = new MyLocalContainerService(); @Order(2) @RegisterExtension public static CamelContextExtension camelContextExtension = new DefaultCamelContextExtension();
createRouteBuilder, so just create a new method that calls that old method, but, make sure to annotated it with the @RouteFixture annotation:@Override @RouteFixture public void createRouteBuilder(CamelContext context) throws Exception { final RouteBuilder routeBuilder = createRouteBuilder(); if (routeBuilder != null) { context.addRoutes(routeBuilder); } }
public method annotated with the @ContextFixture annotation:@ContextFixture public void setupContext(CamelContext camelContext) throws Exception { // configure the context }