クラス MockWebServiceServer
java.lang.ObjectSE
org.springframework.ws.test.client.MockWebServiceServer
クライアント側の Web サービステストのメインエントリポイント。通常、
WebServiceTemplate
のテスト、リクエストメッセージに対する期待値の設定、レスポンスメッセージの作成に使用されます。このクラスの一般的な使用箇所は次のとおりです。
createServer(WebServiceTemplate)
、createServer(WebServiceGatewaySupport)
、createServer(ApplicationContext)
を呼び出して、MockWebServiceServer
インスタンスを作成します。expect(RequestMatcher)
を呼び出して、おそらくRequestMatchers
で提供されているデフォルトのRequestMatcher
実装(静的にインポート可能)を使用して、リクエストの期待値を設定します。ResponseActions.andExpect(RequestMatcher)
呼び出しを連鎖させることにより、複数の期待値を設定できます。andRespond(ResponseCreator)
を呼び出して、おそらくResponseCreators
で提供されているデフォルトのResponseCreator
実装(静的にインポート可能)を使用して、適切なレスポンスメッセージを作成します。WebServiceTemplate
は、クライアントコードを介して直接、または通常どおりに使用します。verify()
を呼び出します。
例:
import org.junit.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.xml.transform.StringSource; import org.springframework.ws.test.client.MockWebServiceServer; import static org.springframework.ws.test.client.RequestMatchers.*; import static org.springframework.ws.test.client.ResponseCreators.*; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("applicationContext.xml") public class MyWebServiceClientIntegrationTest { // MyWebServiceClient extends WebServiceGatewaySupport, and is configured in applicationContext.xml @Autowired private MyWebServiceClient client; private MockWebServiceServer mockServer; @Before public void createServer() throws Exception { mockServer = MockWebServiceServer.createServer(client); } @Test public void getCustomerCount() throws Exception { Source expectedRequestPayload = new StringSource("<customerCountRequest xmlns=\"http://springframework.org/spring-ws/test\" />"); Source responsePayload = new StringSource("<customerCountResponse xmlns='http://springframework.org/spring-ws/test'>" + "<customerCount>10</customerCount>" + "</customerCountResponse>"); mockServer.expect(payload(expectedRequestPayload)).andRespond(withPayload(responsePayload)); // client.getCustomerCount() uses the WebServiceTemplate int customerCount = client.getCustomerCount(); assertEquals(10, response.getCustomerCount()); mockServer.verify(); } }
- 導入:
- 2.0
- 作成者:
- Arjen Poutsma, Lukas Krecan, Greg Turnquist
コンストラクターの概要
コンストラクターメソッドのサマリー
修飾子と型メソッド説明static MockWebServiceServer
createServer
(org.springframework.context.ApplicationContext applicationContext) 指定されたApplicationContext
に基づいてMockWebServiceServer
インスタンスを作成します。static MockWebServiceServer
createServer
(WebServiceGatewaySupport gatewaySupport) 指定されたWebServiceGatewaySupport
に基づいてMockWebServiceServer
インスタンスを作成します。static MockWebServiceServer
createServer
(WebServiceTemplate webServiceTemplate) 指定されたWebServiceTemplate
に基づいてMockWebServiceServer
インスタンスを作成します。expect
(RequestMatcher requestMatcher) 指定されたRequestMatcher
によって指定された期待値を記録します。void
reset()
MockWebServiceMessageSender
の期待をリセットします。void
verify()
MockWebServiceMessageSender
のすべての期待が満たされていることを確認します。
コンストラクターの詳細
MockWebServiceServer
メソッドの詳細
createServer
指定されたWebServiceTemplate
に基づいてMockWebServiceServer
インスタンスを作成します。- パラメーター:
webServiceTemplate
- Web サービステンプレート- 戻り値:
- 作成されたサーバー
createServer
指定されたWebServiceGatewaySupport
に基づいてMockWebServiceServer
インスタンスを作成します。- パラメーター:
gatewaySupport
- クライアントクラス- 戻り値:
- 作成されたサーバー
createServer
public static MockWebServiceServer createServer(org.springframework.context.ApplicationContext applicationContext) 指定されたApplicationContext
に基づいてMockWebServiceServer
インスタンスを作成します。このファクトリメソッドは、指定されたアプリケーションコンテキストで構成済みの
WebServiceTemplate
を見つけようとします。テンプレートが見つからない場合は、WebServiceGatewaySupport
を見つけようとし、構成されたテンプレートを使用します。どちらも見つからない場合は、例外がスローされます。- パラメーター:
applicationContext
- クライアントのベースとなるアプリケーションコンテキスト- 戻り値:
- 作成されたサーバー
- 例外:
IllegalArgumentExceptionSE
- 指定されたアプリケーションコンテキストにWebServiceTemplate
もWebServiceGatewaySupport
も含まれていない場合。
expect
指定されたRequestMatcher
によって指定された期待値を記録します。レスポンスの作成、またはより多くの期待値の設定を可能にするResponseActions
オブジェクトを返します。- パラメーター:
requestMatcher
- リクエストマッチャーが期待されます- 戻り値:
- レスポンスアクション
verify
public void verify()MockWebServiceMessageSender
のすべての期待が満たされていることを確認します。- 例外:
AssertionErrorSE
- 期待が満たされない場合
reset
public void reset()MockWebServiceMessageSender
の期待をリセットします。