我正在测试我的应用程序,它将文件从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]
答案 0 :(得分:1)
如果启动上下文,则由ftp组件添加{i} CamelFileName
标头。
但是,由于您在测试中使用direct直接注入消息,因此可能并非如此。
尝试通过.setHeader("CamelFileName", constant("msg01.txt"))
手动添加标题来调整您的测试。