Interface ResponseStubbing

  • All Known Implementing Classes:
    Stubbing

    public interface ResponseStubbing
    This interface defines methods for the http stubbing THEN part. These methods provide a way to define one or more http responses for this stubbing.

    Multiple responses can be defined for one stubbing. These responses are returned in the same order as were defined. Once there is no next response left, the last one is used for all following requests (if you define only one response, which is a common scenario, this response will be used for every request that meets the WHEN part).

    • Method Detail

      • withContentType

        ResponseStubbing withContentType​(String contentType)
        Sets the content type of the http stub response. Calling this method overrides any previous calls. The content type information is communicated via the http Content-Type response header.

        This method either adds this header or overwrites any existing Content-Type header ensuring at most one such header will be present in the stub response.

        Parameters:
        contentType - response content type
        Returns:
        this ongoing stubbing
      • withHeader

        ResponseStubbing withHeader​(String name,
                                    String value)
        Adds a stub http response header. This method can be called multiple times for the same header name. The response will contain a header with all (multiple) values.
        Parameters:
        name - header name
        value - header value
        Returns:
        this ongoing stubbing
      • withBody

        ResponseStubbing withBody​(String responseBody)
        Sets the stub http response body as a string. This string will be encoded using an encoding set by withEncoding(java.nio.charset.Charset) Calling this method overrides any previous calls of this or any other withBody method.
        Parameters:
        responseBody - response body
        Returns:
        this ongoing stubbing
      • withBody

        ResponseStubbing withBody​(Reader reader)
        Sets the stub http response body as the content of the given reader. The string retrieved from the given reader will be encoded using an encoding set by withEncoding(java.nio.charset.Charset) Calling this method overrides any previous calls of this or any other withBody method.
        Parameters:
        reader - response body source
        Returns:
        this ongoing stubbing
      • withBody

        ResponseStubbing withBody​(InputStream is)
        Sets the stub http response body as the content of the given input stream. The source input stream is copied to the stub response body as-is, it is not affected by the encoding set by withEncoding(java.nio.charset.Charset) in any way. Calling this method overrides any previous calls of this or any other withBody method.
        Parameters:
        is - response body source
        Returns:
        this ongoing stubbing
      • withBody

        ResponseStubbing withBody​(byte[] responseBody)
        Sets the stub http response body as an array of bytes. The given array of bytes is used as the stub response body as-is, it is not affected by the encoding set by withEncoding(java.nio.charset.Charset) in any way. Calling this method overrides any previous calls of this or any other withBody method.
        Parameters:
        responseBody - response body
        Returns:
        this ongoing stubbing
      • withDelay

        ResponseStubbing withDelay​(long delayValue,
                                   TimeUnit delayUnit)
        Sets the response delay. The stub http response is returned after the specified amount of time. Calling this method overrides any previous calls of this method.
        Parameters:
        delayValue - a delay (in units defined by the delayUnit parameter) this stub response will be returned after
        delayUnit - unit of the delay parameter
        Returns:
        this ongoing stubbing
      • thenRespond

        ResponseStubbing thenRespond()
        Starts a definition of a subsequent stub response.
        Returns:
        this ongoing stubbing