FunctionalTestComponent
フローの途中で特定のヘッダー プロパティに対してアサートできるように、Mule でメッセージをキャッチするためにを使用しようとしています。しかし、イベントは決して受信されず、私のテストは常に失敗するはずの場所で成功します。イベントをキャッチするようにテストを構成するにはどうすればよいですか? これが私のテスト方法です:
@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);
}
構成は、vm://test フローによって参照される 2 番目のフローに test:component がある 2 つのフローだけです。
それを機能させる唯一の方法は、ラッチと を使用し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();