3

既存のルートをテストするための統合テストを書いています。応答を取得するための推奨される方法は次のようになります ( Camel In Actionセクション 6.4.1 経由):

public class TestGetClaim extends CamelTestSupport {

    @Produce(uri = "seda:getClaimListStart")
    protected ProducerTemplate producer;

    @Test
    public void testNormalClient() {
        NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

        producer.sendBody(new ClientRequestBean("TESTCLIENT", "Y", "A"));
        boolean matches = notify.matches(5, TimeUnit.SECONDS);
        assertTrue(matches);

        BrowsableEndpoint be = context.getEndpoint("seda:getClaimListResponse", BrowsableEndpoint.class);
        List<Exchange> list = be.getExchanges();
        assertEquals(1, list.size());
        System.out.println("***RESPONSE is type "+list.get(0).getIn().getBody().getClass().getName());
    }
}

テストは実行されますが、何も返されません。はassertTrue(matches)5 秒のタイムアウト後に失敗します。

テストを次のように書き直すと、応答が得られます。

@Test
public void testNormalClient() {
    producer.sendBody(new ClientRequestBean("TESTCLIENT", "Y", "A"));
    Object resp = context.createConsumerTemplate().receiveBody("seda:getClaimListResponse");
    System.out.println("***RESPONSE is type "+resp.getClass().getName());
}

ドキュメントはこれについて少し軽いので、最初のアプローチで何が間違っているのか誰か教えてもらえますか? 代わりに 2 番目のアプローチに従うことに問題はありますか?

ありがとう。

更新 これを分解しましたが、ルートでの受信者リストの使用と組み合わせて、開始エンドポイントとしてのセダの混合に問題があるようです。NotifyBuilder の構造も変更しました (間違ったエンドポイントを指定していました)。

  • 開始エンドポイントを sedaではなくdirectに変更すると、テストは機能します。また
  • recipientListをコメントアウトすると 、テストが機能します。

これは、この問題を再現するルートの簡易バージョンです。

public class TestRouteBuilder extends RouteBuilder {

    @Override
    public void configure() throws Exception {
//      from("direct:start")    //works
        from("seda:start")  //doesn't work
        .recipientList(simple("exec:GetClaimList.bat?useStderrOnEmptyStdout=true&args=${body.client}"))
        .to("seda:finish");
    }

}

NotifyTestのソース コードを「Camel In Action」ソースからこのようなルート ビルダーに変更すると、失敗することに注意してください。

4

2 に答える 2

2

getEndpoint で "seda:getClaimListResponse" を使用して、エンドポイント URI が 100% 正しいことを確認してください

于 2010-11-11T06:57:34.333 に答える
0

FWIW: セダ キューと組み合わせた notifyBuilder は、完全には機能していないようです: 説明するテスト クラス:

public class NotifyBuilderTest extends CamelTestSupport {

// Try these out!
// String inputURI = "seda:foo";   // Fails
// String inputURI = "direct:foo"; // Passes

@Test
public void testNotifyBuilder() {

    NotifyBuilder b = new NotifyBuilder(context).from(inputURI)
            .whenExactlyCompleted(1).create();

    assertFalse( b.matches() );
    template.sendBody(inputURI, "Test");
    assertTrue( b.matches() );

    b.reset();

    assertFalse( b.matches() );
    template.sendBody(inputURI, "Test2");
    assertTrue( b.matches() );
}

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from(inputURI).to("mock:foo");
        }
    };
}
}
于 2013-07-26T19:45:33.740 に答える