我正在测试我的应用程序,它将文件从 ftp 发送到我的计算机,并且我正在检查不要将一个文件复制两次。为此,我使用IdempotentConsumer
.
我的问题是我无法运行测试,因为这IdempotentConsumer
总是给我错误。
如何解决这个问题?
班级
@Component
public class Converter extends SpringRouteBuilder {
@Override
public void configure() throws Exception {
final XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
xmlJsonFormat.setTypeHints(String.valueOf("YES"));
from("ftp://Mike@localhost?" +
"noop=true&binary=true&consumer.delay=5s&include=.*xml")
.idempotentConsumer(header("CamelFileName"), FileIdempotentRepository.fileIdempotentRepository(new File("data", "repo.dat")))
.marshal(xmlJsonFormat).to("file://data").process(
new Processor() {
//System.out.println();
}
});
}
}
测试班
public class ConverterTest extends CamelTestSupport {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new Converter();
}
@Test
public void testAdvisedMockEndpoints() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:inputXML");
interceptSendToEndpoint("file://data")
.skipSendToOriginalEndpoint()
.to("mock:outXML");
}
});
context.start();
getMockEndpoint("mock:outXML").expectedMessageCount(1);
template.sendBody("direct:inputXML", "Test data");
assertMockEndpointsSatisfied();
}
}
我收到以下错误:
org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: Test data]
Caused by: org.apache.camel.processor.idempotent.NoMessageIdException: No message ID could be found using expression: header(CamelFileName) on message exchange: Exchange[Message: Test data]