我正在尝试使用FunctionalTestComponent
来捕获Mule中的消息,这样我就可以在中间流中断言某些Header属性。但事件永远不会收到,我的测试总是在失败的地方通过。如何配置我的测试以捕获事件?这是我的测试方法:
@Test
public void testCallback() throws Exception {
FunctionalTestComponent ftc = getFunctionalTestComponent("test");
ftc.setEventCallback(new EventCallback()
{
public void eventReceived(MuleEventContext context, Object component)
throws Exception
{
assertTrue(false);
System.out.println("Thanks for calling me back");
}
});
MuleClient client = muleContext.getClient();
MuleMessage reply = client.send("vm://test", TEST_MESSAGE, null, 5000);
}
配置只有2个流,第二个流中有一个test:component,由vm:// test flow引用。
我能让它工作的唯一方法是使用一个锁存器和一个AtomicReference
来保存MuleMessage,这样我就可以在muleClient.send
之后运行断言。
FunctionalTestComponent ftc = getFunctionalTestComponent("test");
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<MuleMessage> message = new AtomicReference<MuleMessage>();
EventCallback callback = new EventCallback() {
public void eventReceived(MuleEventContext context, Object component)
throws Exception {
if (1 == latch.getCount()) {
message.set(context.getMessage());
System.out.println("1111");
latch.countDown();
}
}
};
ftc.setEventCallback(callback);
MuleClient client = muleContext.getClient();
client.send("vm://test", TEST_MESSAGE, null);
latch.await(10, TimeUnit.SECONDS);
MuleMessage msg = (MuleMessage) message.get();