I have a route that end on a jdbc endpoint:
from(CONNECTOR).routeId(ROUTE_ID).process(createSelectStatement).to(jdbc);
The jdbc Endpoint is created this way:
public static final String DB_NAME = "db";
private void setupJdbcEndpoint() {
JdbcEndpoint endpoint = getContext().getEndpoint("jdbc:" + DB_NAME, JdbcEndpoint.class);
endpoint.setOutputClass(OUTClass.class.getName());
endpoint.setOutputType(JdbcOutputType.SelectList);
jdbc = endpoint;
}
In my unit test i want "mock and skip" the database:
@Override
public String isMockEndpointsAndSkip() {
return "jdbc:*";
}
I also tried other patterns: "jdbc:db", "jdbc://db" (this string is shown in log and is the output of toString)
But no matter what pattern used the database is called. Log shows
org.apache.camel.component.jdbc.JdbcProducer: Executing JDBC Statement: SELECT..
And the correct (empty) result is sent to mock endpoint at the end. And the mocked endpint mock:jdbc:db
or mock:jdbc://db
() never receives anything.
So how to skip this jdbc endpoint?
And how to get a reference to mock endpoints that are created with wildcards like '*'?
EDIT
With this setup i also see in log:
InterceptSendToMockEndpointStrategy: Adviced endpoint [jdbc://db] with mock endpoint [mock:jdbc:db]
So isMockEndpointAndSkip
seems to work?! But in my case the jdbc endpoint is not skipped.
2nd edit - tried answer from Vimsha
Not using isMockEndpointAndSkip
but providing an AdviceWithRouteBuilder didn't help (i think camel implements isMockEndpointAndSkip
the same way). I see in log (using the builder Vimsha suggested):
InterceptSendToEndpoint[jdbc:* -> [To[mock://jdbc://db]]], process[Processor@0x6e9a5ed8], To[jdbc://db]]]
Besides that the database is still called the mock endpoint did not see any exchange.
here is the builder in detail:
new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith(in);
interceptSendToEndpoint("jdbc:*").skipSendToOriginalEndpoint().to(dbMock);
}
};
Vimsha guided into right direction but for some reason this isn't working interceptSendToEndpoint("jdbc:*").skipSendToOriginalEndpoint()..
But this works in my route i added an id to jdbc endpoint:
...to(jdbc).id("jdbc")
in test i added this AdviceWithRouteBuilder:
new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith(in);
// interceptSendToEndpoint("jdbc:*").skipSendToOriginalEndpoint().to(dbMock);
weaveById("jdbcOut").replace().to(dbMock);
}
};
So weaveById
and replace do the job.