Class Cookies
java.lang.Object
com.github.mjeanroy.junit.servers.client.Cookies
Static cookie utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Cookie
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 isnull
. .static Cookie
cookie
(String name, String value, String domain, String path, Long expires, Long maxAge, boolean secure, boolean httpOnly) Create cookie.static Cookie
Create a cookie from header value.static Cookie
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 ofCookie
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.
-
Method Details
-
cookie
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.
- The webapp path is initialized with
-
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
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
Create a cookie from header value.- Parameters:
rawValue
- Header value.- Returns:
- Cookie.
-
serialize
Serialize cookies as a string that is ready to be sent to a server over an HTTP request (a.k.a value ofCookie
header).- Parameters:
cookies
- Cookies to serialize.- Returns:
- The final value.
-