我是JUnit的新手。我正在尝试为骆驼路线和处理器编写测试用例。我不知道如何开始。这是我的路线
from("activemq:queue1").process("queueprocessor").toD("activemq:queue2").
我需要模拟终端和处理器的帮助。
答案 0 :(得分:0)
在此处使用“ isMockEndpoints”对所有端点进行了模拟,并向端点(activemq:queue2)添加了预期的正文内容,并向模拟端点(activemq:queue1)发送了与输入相同的内容,以验证断言是否满足。
public class MockEndpointsJUnit4Test extends CamelTestSupport {
@Override
public String isMockEndpoints() {
// override this method and return the pattern for which endpoints to mock.
// use * to indicate all
return "*";
}
@Test
public void testMockAllEndpoints() throws Exception {
// notice we have automatic mocked all endpoints and the name of the endpoints is "mock:uri"
getMockEndpoint("mock:activemq:queue2").expectedMessageCount(1);
getMockEndpoint("mock:activemq:queue2").expectedBodiesReceived("Hello World");
template.sendBody("mock:activemq:queue1", "Hello World");
getMockEndpoint("mock:activemq:queue2").assertIsSatisfied();
/* additional test to ensure correct endpoints in registry */
/* all the endpoints was mocked */
assertNotNull(context.hasEndpoint("mock:activemq:queue1"));
assertNotNull(context.hasEndpoint("mock:activemq:queue2"));
}
}