Class MockConversation
Cookies will be remembered between requests and can be easily examined.
To check which new cookies have been set during a request, the MockResponse.getNewCookieNames()
method can be used.
An instance of this class is tied to a regular Site
structure
instance.
- Since:
- 1.0
-
Constructor Summary
ConstructorDescriptionMockConversation
(Site site) Creates a newMockConversation
instance for a particular site. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a cookie.void
Add a cookie with only a name and a value, the other fields will be empty.contextPath
(String contextPath) Sets the context path that will be used by this conversation.Add a cookie.Add a cookie with only a name and a value, the other fields will be empty.Perform a request for a particular URL.doRequest
(String url, MockRequest request) Perform a request for a particular URL and request configuration.Retrieves the context path that is used by this conversation.Retrieves a cookie.Cookie[]
Retrieves all cookies.getCookieValue
(String name) Retrieves the value of a cookie.Retrieves the scheme that is used by this conversation.Retrieves the server name that is used by this conversation.int
Retrieves the server port that is used by this conversation.getSite()
Retrieves this conversation'sSite
.boolean
Checks whether a cookie is present.Returns the properties uses by this conversation.Sets the scheme that will be used by this conversation.serverName
(String serverName) Sets the server name that will be used by this conversation.serverPort
(int serverPort) Sets the server port that will be used by this conversation.void
setContextPath
(String contextPath) Sets the context path that will be used by this conversation.void
Sets the scheme that will be used by this conversation.void
setServerName
(String serverName) Sets the server name that will be used by this conversation.void
setServerPort
(int serverPort) Sets the server port that will be used by this conversation.
-
Constructor Details
-
MockConversation
Creates a newMockConversation
instance for a particular site.- Parameters:
site
- the site structure that will be tested- Throws:
EngineException
- Since:
- 1.0
-
-
Method Details
-
getSite
Retrieves this conversation'sSite
.- Returns:
- this conversation's site
- Since:
- 1.6.1
-
doRequest
Perform a request for a particular URL.- Parameters:
url
- the url that should be tested- Returns:
- the response of the request as a
MockResponse
instance; ornull
if the scheme, hostname and port don't correspond to the conversation setup - Throws:
EngineException
- Since:
- 1.0
- See Also:
-
doRequest
Perform a request for a particular URL and request configuration.The request can either be complete with the scheme and hostname, or an absolute path. These two URLs are thus considered the same:
https://localhost/some/url?name1=value1&name2=value2
/some/url?name1=value1&name2=value2
Note that when the complete URL form is used, it should correspond to the scheme, hostname and port configuration of this conversation.
- Parameters:
url
- the url that should be testedrequest
- the request that will be used- Returns:
- the response of the request as a
MockResponse
instance; ornull
if the scheme, hostname and port don't correspond to the conversation setup - Throws:
EngineException
- Since:
- 1.0
- See Also:
-
getScheme
Retrieves the scheme that is used by this conversation.- Returns:
- the scheme of this conversation
- Since:
- 1.0
- See Also:
-
setScheme
Sets the scheme that will be used by this conversation.- Parameters:
scheme
- the scheme- Since:
- 1.0
- See Also:
-
scheme
Sets the scheme that will be used by this conversation.- Parameters:
scheme
- the scheme- Returns:
- this
MockConversation
instance - Since:
- 1.0
- See Also:
-
getServerName
Retrieves the server name that is used by this conversation.- Returns:
- the server name of this conversation
- Since:
- 1.0
- See Also:
-
setServerName
Sets the server name that will be used by this conversation.- Parameters:
serverName
- the server name- Since:
- 1.0
- See Also:
-
serverName
Sets the server name that will be used by this conversation.- Parameters:
serverName
- the server name- Returns:
- this
MockConversation
instance - Since:
- 1.0
- See Also:
-
getServerPort
public int getServerPort()Retrieves the server port that is used by this conversation.- Returns:
- the server port of this conversation
- Since:
- 1.0
- See Also:
-
setServerPort
public void setServerPort(int serverPort) Sets the server port that will be used by this conversation.- Parameters:
serverPort
- the server port- Since:
- 1.0
- See Also:
-
serverPort
Sets the server port that will be used by this conversation.- Parameters:
serverPort
- the server port- Returns:
- this
MockConversation
instance - Since:
- 1.0
- See Also:
-
getContextPath
Retrieves the context path that is used by this conversation.- Returns:
- the context path of this conversation
- Since:
- 1.0
- See Also:
-
setContextPath
Sets the context path that will be used by this conversation.- Parameters:
contextPath
- the context path- Since:
- 1.0
- See Also:
-
contextPath
Sets the context path that will be used by this conversation.- Parameters:
contextPath
- the context path- Returns:
- this
MockConversation
instance - Since:
- 1.0
- See Also:
-
properties
Returns the properties uses by this conversation.- Returns:
- the instance of
HierarchicalProperties
that is used by this conversation - Since:
- 1.0
-
hasCookie
Checks whether a cookie is present.- Parameters:
name
- the name of the cookie.- Returns:
true
if the cookie was present; orfalse
otherwise- Since:
- 1.0
- See Also:
-
getCookie
Retrieves a cookie.- Parameters:
name
- the name of the cookie.- Returns:
- the instance of the cookie; or
null
if no such cookie is present - Since:
- 1.0
- See Also:
-
getCookieValue
Retrieves the value of a cookie.- Parameters:
name
- the name of the cookie.- Returns:
- the value of the cookie; or
null
if no such cookie is present - Since:
- 1.0
- See Also:
-
getCookies
Retrieves all cookies.- Returns:
- an array with all the cookies; or
null
if no cookies are present - Since:
- 1.0
- See Also:
-
addCookie
Add a cookie.- Parameters:
cookie
- the cookie instance that will be added- Since:
- 1.0
- See Also:
-
addCookie
Add a cookie with only a name and a value, the other fields will be empty.- Parameters:
name
- the name of the cookievalue
- the value of the cookie- Since:
- 1.0
- See Also:
-
cookie
Add a cookie.- Parameters:
cookie
- the cookie instance that will be added- Returns:
- this
MockConversation
instance - Since:
- 1.0
- See Also:
-
cookie
Add a cookie with only a name and a value, the other fields will be empty.- Parameters:
name
- the name of the cookievalue
- the value of the cookie- Returns:
- this
MockConversation
instance - Since:
- 1.0
- See Also:
-