|
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.client.MockWebServiceServer
public class MockWebServiceServer
Main entry point for client-side Web service testing. Typically used to test a WebServiceTemplate
, set up expectations on request messages, and create response messages.
MockWebServiceServer
instance by calling createServer(WebServiceTemplate)
,
createServer(WebServiceGatewaySupport)
, or createServer(ApplicationContext)
.
expect(RequestMatcher)
, possibly by using the default
RequestMatcher
implementations provided in RequestMatchers
(which can be statically imported).
Multiple expectations can be set up by chaining ResponseActions.andExpect(RequestMatcher)
calls.andRespond(ResponseCreator)
, possibly by using the default
ResponseCreator
implementations provided in ResponseCreators
(which can be statically imported).WebServiceTemplate
as normal, either directly of through client code.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(); } }
Method Summary | |
---|---|
static MockWebServiceServer |
createServer(ApplicationContext applicationContext)
Creates a MockWebServiceServer instance based on the given ApplicationContext . |
static MockWebServiceServer |
createServer(WebServiceGatewaySupport gatewaySupport)
Creates a MockWebServiceServer instance based on the given WebServiceGatewaySupport . |
static MockWebServiceServer |
createServer(WebServiceTemplate webServiceTemplate)
Creates a MockWebServiceServer instance based on the given WebServiceTemplate . |
ResponseActions |
expect(RequestMatcher requestMatcher)
Records an expectation specified by the given RequestMatcher . |
void |
verify()
Verifies that all expectations were met. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static MockWebServiceServer createServer(WebServiceTemplate webServiceTemplate)
MockWebServiceServer
instance based on the given WebServiceTemplate
.
webServiceTemplate
- the web service template
public static MockWebServiceServer createServer(WebServiceGatewaySupport gatewaySupport)
MockWebServiceServer
instance based on the given WebServiceGatewaySupport
.
gatewaySupport
- the client class
public static MockWebServiceServer createServer(ApplicationContext applicationContext)
MockWebServiceServer
instance based on the given ApplicationContext
.
This factory method will try and find a configured WebServiceTemplate
in the given application context.
If no template can be found, it will try and find a WebServiceGatewaySupport
, and use its configured
template. If neither can be found, an exception is thrown.
applicationContext
- the application context to base the client on
IllegalArgumentException
- if the given application context contains neither a WebServiceTemplate
nor a WebServiceGatewaySupport
.public ResponseActions expect(RequestMatcher requestMatcher)
RequestMatcher
. Returns a ResponseActions
object
that allows for creating the response, or to set up more expectations.
requestMatcher
- the request matcher expected
public void verify()
AssertionError
- in case of unmet expectations
|
Spring Web Services Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |