I try to write an end to end test for my Apache Camel process that goes through a pipeline consisting of many routes. But I have got stuck on the very first one.
My route definition looks like following
@Override
public void config() {
rest("/admin/k2/employee")
.post()
.routeId(ROUTE_BUILDER_ID)
.to(SEDA + K2EmployeesRouteBuilder.ROUTE_BUILDER_ID);
}
In my unit test i mock everything ad to the testing in isolation.
Buit for my e2e test I want to perform a REAL http post call to the /admin/k2/employee endpoint.
The trouble is that my application contains 50+ RouteBuilders and hundreds of other Components not related with my route under test.
If I try to use
@CamelSpringBootTest
@SpringBootTest
the entire SpringBoot context is loaded with all those 50+ routes that need to be fully configured or mocked - otherwise the context fail to load and the test fails.
I can load only my RouteBuilder (+ eventualy related dependencies) using
@SpringBootTest( classes= { ... })
This works fine for my integration tests where i call direct endpoint to start the test.
But for my e2e test the problem is that the embeded Tomcat server does not start and I cannot do the real http request.
If I add Application.java to the classes then all the routes try to load into context again.
So the question is: Is it possible to run a route(s) with a rest producer together with embeded Tomcat server but in isolation without the rest of the application?
-
Are the routes in separate packages such that you can load only one (or small number of) packages, leaving out all except the one route you want to test?Steve Huston– Steve Huston2025年05月02日 00:38:34 +00:00Commented May 2, 2025 at 0:38
-
Yes, in general I keep one RouteBulider with related classes per packageJirMed– JirMed2025年05月02日 09:52:13 +00:00Commented May 2, 2025 at 9:52