Unable to create MockEndpoint for camel-timer

389 views Asked by At

I am using Camel Timer component to read blobs from Azure storage container. A route is created which will poll for blobs every 10secs and is processed by the CloudBlobProcessor.

from("timer://testRoute?fixedRate=true&period=10s")
    .to("azure-blob://storageAccountName/storageContainerName?credentials=#credentials")
    .to(CloudBlobProcessor)
    .to("mock:result");

I want to write a testcase by creating a mock endpoint something like this

MockEndpoint timerMockEndpoint = context.getEndpoint("timer://testRoute?fixedRate=true&period=10s", MockEndpoint.class);

But, I receive a below exception while creating the above mock endpoint.

java.lang.IllegalArgumentException: The endpoint is not of type: 
class org.apache.camel.component.mock.MockEndpoint but is: org.apache.camel.component.timer.TimerEndpoint

Below is the code where I am trying to skip sending to the original endpoint

@Override
protected RoutesBuilder createRouteBuilder() throws Exception {
return new AdviceWithRouteBuilder() {
  @Override
  public void configure() throws Exception {
    interceptSendToEndpoint("timer://testRoute?fixedRate=true&period=10s").skipSendToOriginalEndpoint()
        .log("Original Batch Endpoint skipped")
        .to("azure-blob://*")
        .to(CloudBlobProcessor).to("mock:result");
    from("timer://testRoute?fixedRate=true&period=10s").to("mock:result");
  }
};
}
1

There are 1 answers

1
joni On

What I understand, we're trying to solve two different problems here:

  1. MockEndpoint != TimerEndpoint
  2. Interceptions

Answer to the first one is simple: MockEndpoints follow syntax mock:name. TimerEndpoint is a different endpoint and a totally different object. I don't know what you're aiming to do with the MockEndpoint here, but we just can't technically have a TimerEndpoint object as a MockEndpoint object. Why? Because that's how object oriented programming and Java work.

Let's take a look on the second problem. I've less than a year experience with Camel and I've only used interception once last year, but I hope I can guide you to some helpful direction.

The point of interception is to say "don't do that, do this instead". In this use case, it seems that we're only trying to skip sending a request to azure-blob endpoint. I'd try intercepting azure-blob://storageAccountName/storageContainerName?credentials=#credentials.

So instead of your interception, I'd try writing an interception like this:

interceptSendToEndpoint("azure-blob://storageAccountName/storageContainerName?credentials=#credentials")
    .skipSendToOriginalEndpoint()
    .log("Intercepted!");

In this case, instead of sending the request to azure-blob we intercept that request. We're telling Camel to skip the send to original endpoint, which means nothing will be sent to azure-blob://storageAccountName/storageContainerName?credentials=#credentials. Instead, we'll log "Intercepted!".