私はいくつかのクライアント側ロジックといくつかのサーバー側ロジックを使用するテストを書いています。クライアント側では、データを操作してJMSキューに格納するWebサービスにREST呼び出しを行います。後でJMSコールを作成してJMSトピックに書き込まれた内容を確認し、驚くべき結果を得ています。ここArquillainの複数のスレッド
は、この問題を定義するテストコードの興味深い部分である:
@Test
@OperateOnDeployment("my-deployable")
public void testMessageInTopic() throws Exception {
// make a rest call with the minimal request
makeRequest(getMyXmlAsString());
// compare the message with the one sent to the topic
connection = factory.createConnection();
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final MessageConsumer consumer = session.createConsumer(topic);
connection.start();
System.out.println("### listening for a response");
final TextMessage receivedMessage = (TextMessage) consumer.receive();
final String expectedString = "sampleFromTest"
final String receivedText = receivedMessage.getText();
System.out.println("### got this message " + receivedText);
assertEquals("the message in the received topic is the same", expectedString, receivedText);
System.out.println("#### the message was as expected");
}
makeRequest(最終文字列データ)メソッドは、以下のない:
public makeRequest(final String data) {
final String url = getAppEndpoint("http://localhost:8080/doit");
final ClientRequest req= new ClientRequest(url);
req.header(HttpHeaderNames.CONTENT_TYPE, MediaType.TEXT_PLAIN);
req.body(MediaType.TEXT_PLAIN, data);
response = req.post(MyResponse.class);
}
ログを観察すると、ここで
09:38:59,448 INFO [stdout] (pool-2-thread-1) ### got this message sampleFromTest
09:38:59,448 INFO [stdout] (pool-2-thread-1) #### the message was as expected
09:38:59,488 INFO [stdout] (pool-2-thread-2) ### listening for a response
埋め込みテストクライアント側のテストを組み合わせるとスレッドが問題になるので、うまくいきません。私は、@Beforeテストメソッドで残りの呼び出しを行うか、またはWebサービスを注入し、プログラムでそれをリクエストしてこの問題を回避することができます。しかし、完全な統合パスをテストすることに興味があるので、クライアントとサーバーの要求を混合することは良い考えのようです。私の質問は、クライアントサイドのリクエストを作成し、コンテナが受け取ったデータを解析するシナリオを実行できるかどうかです。