Class StubResponse.Builder

    • Method Detail

      • status

        public StubResponse.Builder status​(int status)
        Sets the stub response http status. If not called, 200 will be used as a default.
        Parameters:
        status - stub response status (cannot be negative)
        Returns:
        this builder
      • body

        public StubResponse.Builder body​(byte[] body)
        Sets the response body as an array of bytes. Calling this method resets all data previously provided by body(String, Charset). If the response body is not set at all, an empty body is used.
        Parameters:
        body - stub response body as an array of bytes (cannot be null).
        Returns:
        this builder
      • body

        public StubResponse.Builder body​(String body,
                                         Charset encoding)
        Sets the response body as a string. Calling this method resets all data previously provided by body(byte[]). If the response body is not set at all, an empty body is used.
        Parameters:
        body - stub response body as a string (cannot be null)
        encoding - encoding of the body (cannot be null)
        Returns:
        this builder
      • headers

        public StubResponse.Builder headers​(KeyValues headers)
        Sets new stub response headers (all previously set headers are discarded).
        Parameters:
        headers - stub response headers (cannot be null)
        Returns:
        this builder
      • header

        public StubResponse.Builder header​(String name,
                                           String value)
        Adds a new stub response header. Supports multivalue headers (if a header with the same name has already been added before, adds another value to it)
        Parameters:
        name - header name (cannot be empty)
        value - header value (cannot be null, however can be empty for valueless headers)
        Returns:
        this headers
      • delay

        public StubResponse.Builder delay​(long delayValue,
                                          TimeUnit delayUnit)
        Sets the response delay. If not called 0 will be used as a default.
        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 builder