我有两条非常简单的路线(下面的代码不是原始类,我已经简化了它,比如删除设置器、日志等)
第一条路线:
public static final String MESSAGE_CONSUMER = "vm:myMessage";
public String myXmlProducer; //and getter method then
myXmlProducer = "file:myFileLocation?autoCreate=true&fileName="+ myFileName;
from(MESSAGE_CONSUMER)
//some process here
.to(myXmlProducer);
第二个:
public String fileConsumer = "file:myFileLocation";
public String ftpProducer = "ftp://ftpIp?username=username&password=password&maximumReconnectAttempts=0";
from(fileConsumer)
.to(ftpProducer );
我正在尝试为这两条路线编写一些测试,这是我的测试课程的一部分,
类中的配置部分:
public static final String MOCK_OUT = "mock:out";
public static final String DIRECT_IN = "direct:in";
public static final String MOCK_XML_URI = "mock:xmlFile";
...
@EndpointInject(uri = MOCK_OUT)
MockEndpoint mockOut;
@EndpointInject(uri = MOCK_XML_URI)
MockEndpoint mockXmlUri;
...
@Override
public RouteBuilder[] createRouteBuilders() {
final MyRoute route = new MyRoute();
route.setFtpProducer (MOCK_OUT);
RouteBuilder testHarness = new RouteBuilder() {
@Override
public void configure() throws Exception {
from(DIRECT_IN).routeId("testHarness.in")
.to(MyRoute.MESSAGE_CONSUMER)
from(route.getMyXmlProducer())
.convertBodyTo(Byte.class)
.to(mockXmlUri)
}
};
return new RouteBuilder[] {route, testHarness};
}
@Before
public void getTestData() throws IOException {
testInputData = IOUtils.toString(this.getClass().getResourceAsStream("/myTarget/inputData.txt"));
}
这个测试方法是绿色的:
@Test
public void testRoutingOk() throws InterruptedException {
mockOut.setExpectedMessageCount(1);
mockOut.message(0).body().isEqualTo(testInputData);
template.sendBody("file:myTestFileLocation", testInputData);
assertMockEndpointsSatisfied();
}
问题是以下测试,我对骆驼很陌生,并且已经用谷歌搜索找到原因,但我自己无法弄清楚:
@Test
public void testRoutingOk() throws InterruptedException {
mockXmlUri.setExpectedMessageCount(1);
mockXmlUri.message(0).body().isEqualTo(testInputData);
template.sendBody(DIRECT_IN, testInputData);
assertMockEndpointsSatisfied();
}
我收到资产错误,根本没有消息:
java.lang.AssertionError: mock://xmlFile Received message count. Expected: <1> but was: <0>
有没有人可以帮助我,拜托。