I have a problem with adjusting the Camel route on the need of tests.
I have following route defined:
from(source)
.routeId(ROUTE_GENERAL_ID)
.wireTap(inputMetrics)
.to(mappingStep)
.process(enrichingWithInternalData)
.process(enrichingWithExternalData)
I want to test the route which ends with the wiretap. So there is no need to perform processing of the steps from the "main" route. These ones mentioned below:
.to(mappingStep)
.process(enrichingWithInternalData)
.process(enrichingWithExternalData)
If there is no need to run them, I want to remove them to not waste time on the executing them. I was able to remove them, but I could only accomplish it by removing them one by one using adviceWith.
adviceWith(context, ROUTE_GENERAL_ID, builder -> builder.weaveByToUri("mappingStep").remove())
adviceWith(context, ROUTE_GENERAL_ID, builder -> builder.weaveByToUri("enrichingWithInternalData").remove())
adviceWith(context, ROUTE_GENERAL_ID, builder -> builder.weaveByToUri("enrichingWithExternalData").remove())
But this solution requires to modify test, when any step will be added/removed to main path. Another idea is to manually iterate over the route. But I'm curious, if there is something already in camel, which I can use here. Or maybe you know more smooth solution for it.
You can divide your original route, for example like this:
from(source)
.routeId(ROUTE_GENERAL_ID)
.wireTap(inputMetrics)
.to("direct:mappingStep");
from("direct:mappinStep")
.routeId("mappingStep")
.process(enrichingWithInternalData)
.process(enrichingWithExternalData);
Now you can skip the routing to the direct:mappingStep
endpoint in your test like follows. Also don't forget to tell your test, you're using AdviceWith
:
...
@Override
public boolean isUseAdviceWith() {
return true;
}
@Test
public void testRoute() throws Exception {
adviceWith(context, ROUTE_GENERAL_ID, builder -> builder.weaveByToUri("mappingStep").remove())
...
}