226.3. 簡単な例

使用中の Mock エンドポイントの簡単な例を次に示します。まず、エンドポイントがコンテキストで解決されます。次に、期待値を設定し、テストが実行された後、期待値が満たされていることをアサートします。

MockEndpoint resultEndpoint = context.resolveEndpoint("mock:foo", MockEndpoint.class);

// set expectations
resultEndpoint.expectedMessageCount(2);

// send some messages

// now lets assert that the mock:foo endpoint received 2 messages
resultEndpoint.assertIsSatisfied();

通常、テストの実行後に期待が満たされていることをテストするには、常に assertIsSatisfied() メソッドを呼び出します。

assertIsSatisfied () が呼び出されると、Camel はデフォルトで 10 秒間待機します。これは setResultWaitTime (millis) メソッドを設定することで設定できます。