org.springframework.social.test.client
Class MockRestServiceServer

java.lang.Object
  extended by org.springframework.social.test.client.MockRestServiceServer

public class MockRestServiceServer
extends java.lang.Object

Main entry point for client-side REST testing. Typically used to test a RestTemplate, set up expectations on request messages, and create response messages.

The typical usage of this class is:

  1. Create a MockRestServiceServer instance by calling createServer(RestTemplate).
  2. Set up request expectations by calling 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.
  3. Create an appropriate response message by calling andRespond(ResponseCreator), possibly by using the default ResponseCreator implementations provided in ResponseCreators (which can be statically imported).
  4. Use the RestTemplate as normal, either directly of through client code.
  5. Call verify().
Note that because of the 'fluent' API offered by this class (and related classes), you can typically use the Code Completion features (i.e. ctrl-space) in your IDE to set up the mocks.


Method Summary
static MockRestServiceServer createServer(RestGatewaySupport gatewaySupport)
          Creates a MockRestServiceServer instance based on the given RestGatewaySupport.
static MockRestServiceServer createServer(RestTemplate restTemplate)
          Creates a MockRestServiceServer instance based on the given RestTemplate.
 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

createServer

public static MockRestServiceServer createServer(RestTemplate restTemplate)
Creates a MockRestServiceServer instance based on the given RestTemplate.

Parameters:
restTemplate - the RestTemplate
Returns:
the created server

createServer

public static MockRestServiceServer createServer(RestGatewaySupport gatewaySupport)
Creates a MockRestServiceServer instance based on the given RestGatewaySupport.

Parameters:
gatewaySupport - the client class
Returns:
the created server

expect

public ResponseActions expect(RequestMatcher requestMatcher)
Records an expectation specified by the given RequestMatcher. Returns a ResponseActions object that allows for creating the response, or to set up more expectations.

Parameters:
requestMatcher - the request matcher expected
Returns:
the response actions

verify

public void verify()
Verifies that all expectations were met.

Throws:
java.lang.AssertionError - in case of unmet expectations