|
Spring Web Services Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.ws.test.server.MockWebServiceClient
public class MockWebServiceClient
Main entry point for server-side Web service testing. Typically used to test a MessageDispatcher
(including its endpoints, mappings, etc) by
creating request messages, and setting up expectations about response messages.
MockWebServiceClient
instance by using createClient(ApplicationContext)
or
createClient(WebServiceMessageReceiver, WebServiceMessageFactory)
sendRequest(RequestCreator)
, possibly by using the default
RequestCreator
implementations provided in RequestCreators
(which can be statically imported).andExpect(ResponseMatcher)
,
possibly by using the default ResponseMatcher
implementations provided in ResponseMatchers
(which can be statically imported). Multiple expectations can be set up by chaining andExpect()
calls.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.sendMessage(withPayload(requestPayload)).andExpect(payload(expectedResponsePayload)); } }
Method Summary | |
---|---|
static MockWebServiceClient |
createClient(ApplicationContext applicationContext)
Creates a MockWebServiceClient instance based on the given ApplicationContext . |
static MockWebServiceClient |
createClient(WebServiceMessageReceiver messageReceiver,
WebServiceMessageFactory messageFactory)
Creates a MockWebServiceClient instance based on the given WebServiceMessageReceiver and WebServiceMessageFactory . |
ResponseActions |
sendRequest(RequestCreator requestCreator)
Sends a request message by using the given RequestCreator . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static MockWebServiceClient createClient(WebServiceMessageReceiver messageReceiver, WebServiceMessageFactory messageFactory)
MockWebServiceClient
instance based on the given WebServiceMessageReceiver
and WebServiceMessageFactory
.
messageReceiver
- the message receiver, typically a SoapMessageDispatcher
messageFactory
- the message factory
public static MockWebServiceClient createClient(ApplicationContext applicationContext)
MockWebServiceClient
instance based on the given ApplicationContext
.
This factory method works in a similar fashion as the standard
MessageDispatcherServlet
. That is:
WebServiceMessageReceiver
is configured in the given application context, it will use that.
If no message receiver is configured, it will create a default SoapMessageDispatcher
.WebServiceMessageFactory
is configured in the given application context, it will use that.
If no message factory is configured, it will create a default SaajSoapMessageFactory
.
applicationContext
- the application context to base the client on
public ResponseActions sendRequest(RequestCreator requestCreator)
RequestCreator
. Typically called by using the default request
creators provided by RequestCreators
.
requestCreator
- the request creator
RequestCreators
|
Spring Web Services Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |