我有两个非常简单的路由(下面的代码不是原始类,我简化了它就像删除setter,日志等)
第一条路线:
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();
}
问题是接下来的测试,我在骆驼中很安静,并且用Google搜索找到原因,但是我自己无法弄明白:
@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>
请有人帮助我。
答案 0 :(得分:0)