Class TestResponse

java.lang.Object
io.mangoo.test.http.TestResponse
Direct Known Subclasses:
TestBrowser

public class TestResponse extends Object
Author:
svenkubiak
  • Constructor Details

    • TestResponse

      public TestResponse()
    • TestResponse

      public TestResponse(String uri, String method)
  • Method Details

    • withHeader

      public TestResponse withHeader(String name, String value)
      Adds an additional header to the request
      Parameters:
      name - The name of the header
      value - The value of the header
      Returns:
      TestResponse instance
    • withHTTPMethod

      public TestResponse withHTTPMethod(String method)
      Sets the HTTP method to execute the request with
      Parameters:
      method - The HTTP Method
      Returns:
      TestResponse instance
    • withTimeout

      public TestResponse withTimeout(long amount, TemporalUnit unit)
      Sets the timeout of the HTTP request Default is 2 seconds
      Parameters:
      amount - The amount of time
      unit - The unit of time
      Returns:
      TestResponse instance
    • withBasicAuthentication

      public TestResponse withBasicAuthentication(String username, String password)
      Sets Basic HTTP Authentication the request
      Parameters:
      username - The username
      password - The password
      Returns:
      TestResponse instance
    • to

      public TestResponse to(String uri)
      Sets the URI to be executed by the request
      Parameters:
      uri - The URI to call
      Returns:
      TestResponse instance
    • withCookie

      public TestResponse withCookie(HttpCookie cookie)
      Adds an additional cookie to the request
      Parameters:
      cookie - The cookie to add
      Returns:
      TestResponse instance
    • withStringBody

      public TestResponse withStringBody(String body)
      Sets a String body to the request
      Parameters:
      body - The request body to use
      Returns:
      TestResponse instance
    • withContentType

      public TestResponse withContentType(String contentType)
      Sets the ContentType of the request
      Parameters:
      contentType - The content type to use
      Returns:
      TestResponse instance
    • withDisabledRedirects

      public TestResponse withDisabledRedirects()
      Disables redirects when the request is executed by setting followReditects to HttpClient.Redirect.NEVER Default is HttpClient.Redirect.ALWAYS
      Returns:
      TestResponse instance
    • withForm

      public TestResponse withForm(com.google.common.collect.Multimap<String,String> parameters)
      Simulates a FORM post by setting: Content-Type to application/x-www-form-urlencoded HTTP method to POST URLEncoding of the given parameters
      Parameters:
      parameters - The parameters to use
      Returns:
      TestResponse instance
    • execute

      public TestResponse execute()
      Executes the HTTP request
      Returns:
      TestResponse instance with response parameters
    • getContent

      public String getContent()
      Returns:
      The response content
    • getHttpResponse

      public HttpResponse<String> getHttpResponse()
      Returns:
      The HTTP response object
    • getStatusCode

      public int getStatusCode()
      Returns:
      The status code of the response
    • getContentType

      public String getContentType()
      Returns:
      The content type of the response
    • getResponseUrl

      public String getResponseUrl()
      Returns:
      The URL of the response
    • getCookies

      public List<HttpCookie> getCookies()
      Returns:
      The response cookie or an empty list
    • getCookie

      public HttpCookie getCookie(String name)
      Retrieves a cookie from the cookie store with a given name
      Parameters:
      name - The name of the cookie
      Returns:
      A Cookie or null if non found by name
    • getHeader

      public String getHeader(String name)
      Retrieves a specific header with the given name
      Parameters:
      name - The name of the header
      Returns:
      The value of the header or an empty string if not found