Class HttpRequestBodies

java.lang.Object
com.github.mjeanroy.junit.servers.client.HttpRequestBodies

public final class HttpRequestBodies extends Object
Request Body Factories.
  • Method Details

    • requestBody

      public static HttpRequestBody requestBody(String body)
      Create request body from given raw string.
      Parameters:
      body - The body string.
      Returns:
      The request body.
      Throws:
      NullPointerException - If body is null
    • jsonBody

      public static HttpRequestBody jsonBody(String body)
      Create request body from given raw string and "application/json" content type.
      Parameters:
      body - The JSON body string.
      Returns:
      The request body.
      Throws:
      NullPointerException - If body is null
    • xmlBody

      public static HttpRequestBody xmlBody(String body)
      Create request body from given raw string and "application/xml" content type.
      Parameters:
      body - The XML body string.
      Returns:
      The request body.
      Throws:
      NullPointerException - If body is null
    • textBody

      public static HttpRequestBody textBody(String body)
      Create request body from given raw string and "text/plain" content type.
      Parameters:
      body - The body string.
      Returns:
      The request body.
      Throws:
      NullPointerException - If body is null
    • fileBody

      public static HttpRequestBody fileBody(File file)
      Create request body from given file.
      Parameters:
      file - The body file.
      Returns:
      The request body.
      Throws:
      NullPointerException - If file is null
    • jpeg

      public static HttpRequestBody jpeg(File file)
      Create request body from given file, defined with "image/jpeg" content type.
      Parameters:
      file - The body file.
      Returns:
      The request body.
      Throws:
      NullPointerException - If file is null
    • jpeg

      public static HttpRequestBody jpeg(Path path)
      Create request body from given path, defined with "image/jpeg" content type.
      Parameters:
      path - The body path.
      Returns:
      The request body.
      Throws:
      NullPointerException - If file is null
    • png

      public static HttpRequestBody png(File file)
      Create request body from given file, defined with "image/png" content type.
      Parameters:
      file - The body file.
      Returns:
      The request body.
      Throws:
      NullPointerException - If file is null
    • png

      public static HttpRequestBody png(Path path)
      Create request body from given path, defined with "image/png" content type.
      Parameters:
      path - The body file.
      Returns:
      The request body.
      Throws:
      NullPointerException - If file is null
    • pdf

      public static HttpRequestBody pdf(File file)
      Create request body from given file, defined with "application/pdf" content type.
      Parameters:
      file - The body file.
      Returns:
      The request body.
      Throws:
      NullPointerException - If file is null
    • pdf

      public static HttpRequestBody pdf(Path path)
      Create request body from given path, defined with "application/pdf" content type.
      Parameters:
      path - The body file.
      Returns:
      The request body.
      Throws:
      NullPointerException - If file is null
    • fileBody

      public static HttpRequestBody fileBody(File file, String contentType)
      Create request body from given file.
      Parameters:
      file - The body file.
      contentType - The content type.
      Returns:
      The request body.
      Throws:
      NullPointerException - If file or contentType are null
      IllegalArgumentException - If contentType is empty or blank.
    • fileBody

      public static HttpRequestBody fileBody(Path path)
      Create request body from given file.
      Parameters:
      path - The body file.
      Returns:
      The request body.
      Throws:
      NullPointerException - If path is null
    • fileBody

      public static HttpRequestBody fileBody(Path path, String contentType)
      Create request body from given file.
      Parameters:
      path - The body file.
      contentType - The content type.
      Returns:
      The request body.
      Throws:
      NullPointerException - If path or contentType are null
      IllegalArgumentException - If contentType is empty or blank.
    • formUrlEncodedBody

      public static HttpRequestBody formUrlEncodedBody(Map<String,String> parameters)
      Create form urlencoded body from given parameters.
      Parameters:
      parameters - Body parameters.
      Returns:
      The request body.
    • formUrlEncodedBody

      public static HttpRequestBody formUrlEncodedBody(Collection<HttpParameter> parameters)
      Create form urlencoded body from given parameters.
      Parameters:
      parameters - Body parameters.
      Returns:
      The request body.
    • formUrlEncodedBody

      public static HttpRequestBody formUrlEncodedBody(HttpParameter parameter, HttpParameter... others)
      Create form urlencoded body from given parameters.
      Parameters:
      parameter - First parameter.
      others - Other parameters.
      Returns:
      The request body.
    • formBuilder

      public static HttpRequestBodyFormBuilder formBuilder()
      Create builder that can be used to create form urlencoded request body.
      Returns:
      The builder.
    • multipartBuilder

      public static HttpRequestBodyMultipartBuilder multipartBuilder()
      Create builder that can be used to create multipart request body.
      Returns:
      The builder.