Class Stubbing

    • Method Detail

      • respond

        public ResponseStubbing respond()
        Finishes the WHEN part of this stubbing and starts the THEN part.
        Specified by:
        respond in interface RequestStubbing
        Returns:
        response stubbing instance to continue this stubbing
      • respondUsing

        public void respondUsing​(Responder responder)
        Finishes the WHEN part of this stubbing and allows to define the THEN part in a dynamic way.
        Specified by:
        respondUsing in interface RequestStubbing
        Parameters:
        responder - Responder instance (usually in a form of an anonymous inner class) which dynamically creates an http response to be returned when an incoming http request matches the WHEN part.
      • withContentType

        public 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.

        Specified by:
        withContentType in interface ResponseStubbing
        Parameters:
        contentType - response content type
        Returns:
        this ongoing stubbing
      • withBody

        public 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 ResponseStubbing.withEncoding(java.nio.charset.Charset) in any way. Calling this method overrides any previous calls of this or any other withBody method.
        Specified by:
        withBody in interface ResponseStubbing
        Parameters:
        responseBody - response body
        Returns:
        this ongoing stubbing
      • withHeader

        public 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.
        Specified by:
        withHeader in interface ResponseStubbing
        Parameters:
        name - header name
        value - header value
        Returns:
        this ongoing stubbing
      • withDelay

        public 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.
        Specified by:
        withDelay in interface ResponseStubbing
        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
      • createRule

        public HttpStub createRule()
        Creates a HttpStub instance from this Stubbing instance. Must be called once this stubbing has been finished.
        Returns:
        HttpStub instance configured using values from this stubbing