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

public final class Cookies extends Object
Static cookie utilities.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Cookie
    cookie(String name, String value)
    Create cookie with a name and a value, all other parameters will use the default values: The webapp path is initialized with "src/main/webapp" The path is initialized with "/" The port is initialized with zero. The cookie is not secured. The cookie is not http-only. The cookie max-age is null. .
    static Cookie
    cookie(String name, String value, String domain, String path, Long expires, Long maxAge, boolean secure, boolean httpOnly)
    Create cookie.
    static Cookie
    read(String rawValue)
    Create a cookie from header value.
    static Cookie
    secureCookie(String name, String value, String domain, String path, Long expires, Long maxAge)
    Create a secured cookie, it means that cookie will have secure flag and http only flag set to true.
    static String
    Serialize cookies as a string that is ready to be sent to a server over an HTTP request (a.k.a value of Cookie header).
    static Cookie
    sessionCookie(String name, String value, String domain, String path)
    Create a session cookie, it means that cookie will have secure flag and http only flag set to true and expires / max age values are set to zero.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • cookie

      public static Cookie cookie(String name, String value)
      Create cookie with a name and a value, all other parameters will use the default values:
      • The webapp path is initialized with "src/main/webapp"
      • The path is initialized with "/"
      • The port is initialized with zero.
      • The cookie is not secured.
      • The cookie is not http-only.
      • The cookie max-age is null.
      .
      Parameters:
      name - Cookie name.
      value - Cookie value.
      Returns:
      Cookie.
      Throws:
      NullPointerException - if name or value is null.
      IllegalArgumentException - if name is empty or blank.
    • cookie

      public static Cookie cookie(String name, String value, String domain, String path, Long expires, Long maxAge, boolean secure, boolean httpOnly)
      Create cookie.
      Parameters:
      name - Cookie name.
      value - Cookie value.
      domain - Cookie domain.
      path - Cookie path.
      expires - Cookie expires value.
      maxAge - Cookie max age value.
      secure - Secure flag.
      httpOnly - Http flag.
      Returns:
      Cookie.
      Throws:
      NullPointerException - if name or value is null.
      IllegalArgumentException - if name is empty or blank.
    • secureCookie

      public static Cookie secureCookie(String name, String value, String domain, String path, Long expires, Long maxAge)
      Create a secured cookie, it means that cookie will have secure flag and http only flag set to true.
      Parameters:
      name - Cookie name.
      value - Cookie value.
      domain - Cookie domain.
      path - Cookie path.
      expires - Cookie expires value.
      maxAge - Cookie max age.
      Returns:
      Cookie.
      Throws:
      NullPointerException - if name or value is null.
      IllegalArgumentException - if name is empty or blank.
    • sessionCookie

      public static Cookie sessionCookie(String name, String value, String domain, String path)
      Create a session cookie, it means that cookie will have secure flag and http only flag set to true and expires / max age values are set to zero.
      Parameters:
      name - Cookie name.
      value - Cookie value.
      domain - Cookie domain.
      path - Cookie path.
      Returns:
      Cookie.
      Throws:
      NullPointerException - if name or value is null.
      IllegalArgumentException - if name is empty or blank.
    • read

      public static Cookie read(String rawValue)
      Create a cookie from header value.
      Parameters:
      rawValue - Header value.
      Returns:
      Cookie.
    • serialize

      public static String serialize(Iterable<Cookie> cookies)
      Serialize cookies as a string that is ready to be sent to a server over an HTTP request (a.k.a value of Cookie header).
      Parameters:
      cookies - Cookies to serialize.
      Returns:
      The final value.