クラス MockWebServiceClient
java.lang.ObjectSE
org.springframework.ws.test.server.MockWebServiceClient
サーバー側の Web サービステストのメインエントリポイント。通常、リクエストメッセージを作成し、レスポンスメッセージに関する期待値を設定することにより、
MessageDispatcher(エンドポイント、マッピングなどを含む)をテストするために使用されます。このクラスの一般的な使用箇所は次のとおりです。
createClient(ApplicationContext)またはcreateClient(WebServiceMessageReceiver, WebServiceMessageFactory)を使用してMockWebServiceClientインスタンスを作成しますsendRequest(RequestCreator)を呼び出して、おそらくRequestCreatorsで提供されているデフォルトのRequestCreator実装(静的にインポート可能)を使用して、リクエストメッセージを送信します。andExpect(ResponseMatcher)を呼び出して、おそらくResponseMatchersで提供されているデフォルトのResponseMatcher実装(静的にインポート可能)を使用して、レスポンスの期待値を設定します。andExpect()呼び出しを連鎖させることにより、複数の期待値を設定できます。
例:
import org.junit.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.xml.transform.StringSource;
import org.springframework.ws.test.server.MockWebServiceClient;
import static org.springframework.ws.test.server.RequestCreators.*;
import static org.springframework.ws.test.server.ResponseMatchers.*;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("applicationContext.xml")
public class MyWebServiceIntegrationTest {
// a standard MessageDispatcherServlet application context, containing endpoints, mappings, etc.
@Autowired
private ApplicationContext applicationContext;
private MockWebServiceClient mockClient;
@Before
public void createClient() throws Exception {
mockClient = MockWebServiceClient.createClient(applicationContext);
}
// test the CustomerCountEndpoint, which is wired up in the application context above
// and handles <customerCount/> messages
@Test
public void customerCountEndpoint() throws Exception {
Source requestPayload = new StringSource(
"<customerCountRequest xmlns='http://springframework.org/spring-ws'>" +
"<customerName>John Doe</customerName>" +
"</customerCountRequest>");
Source expectedResponsePayload = new StringSource(
"<customerCountResponse xmlns='http://springframework.org/spring-ws'>" +
"<customerCount>42</customerCount>" +
"</customerCountResponse>");
mockClient.sendRequest(withPayload(requestPayload)).andExpect(payload(expectedResponsePayload));
}
}
- 導入:
- 2.0
- 作成者:
- Arjen Poutsma, Lukas Krecan
メソッドのサマリー
修飾子と型メソッド説明static MockWebServiceClientcreateClient(org.springframework.context.ApplicationContext applicationContext) 指定されたApplicationContextに基づいてMockWebServiceClientインスタンスを作成します。static MockWebServiceClientcreateClient(WebServiceMessageReceiver messageReceiver, WebServiceMessageFactory messageFactory) 指定されたWebServiceMessageReceiverおよびWebServiceMessageFactoryに基づいてMockWebServiceClientインスタンスを作成します。sendRequest(RequestCreator requestCreator) 指定されたRequestCreatorを使用してリクエストメッセージを送信します。
メソッドの詳細
createClient
public static MockWebServiceClient createClient(WebServiceMessageReceiver messageReceiver, WebServiceMessageFactory messageFactory) 指定されたWebServiceMessageReceiverおよびWebServiceMessageFactoryに基づいてMockWebServiceClientインスタンスを作成します。- パラメーター:
messageReceiver- メッセージ受信者、通常はSoapMessageDispatchermessageFactory- メッセージファクトリ- 戻り値:
- 作成されたクライアント
createClient
public static MockWebServiceClient createClient(org.springframework.context.ApplicationContext applicationContext) 指定されたApplicationContextに基づいてMockWebServiceClientインスタンスを作成します。このファクトリメソッドは、標準のMessageDispatcherServletと同じように機能します。あれは:WebServiceMessageReceiverが特定のアプリケーションコンテキストで構成されている場合、それを使用します。メッセージレシーバーが構成されていない場合は、デフォルトのSoapMessageDispatcherが作成されます。WebServiceMessageFactoryが特定のアプリケーションコンテキストで構成されている場合、それを使用します。メッセージファクトリが設定されていない場合は、デフォルトのSaajSoapMessageFactoryが作成されます。
- パラメーター:
applicationContext- クライアントのベースとなるアプリケーションコンテキスト- 戻り値:
- 作成されたクライアント
sendRequest
指定されたRequestCreatorを使用してリクエストメッセージを送信します。通常、RequestCreatorsによって提供されるデフォルトのリクエストクリエーターを使用して呼び出されます。- パラメーター:
requestCreator- リクエスト作成者- 戻り値:
- レスポンスアクション
- 関連事項: