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
ConstructorsConstructorDescriptionMockConversation(Site site) Creates a newMockConversationinstance for a particular site. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a cookie.voidAdd 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.intRetrieves the server port that is used by this conversation.getSite()Retrieves this conversation'sSite.booleanChecks 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.voidsetContextPath(String contextPath) Sets the context path that will be used by this conversation.voidSets the scheme that will be used by this conversation.voidsetServerName(String serverName) Sets the server name that will be used by this conversation.voidsetServerPort(int serverPort) Sets the server port that will be used by this conversation.
-
Constructor Details
-
MockConversation
Creates a newMockConversationinstance 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
MockResponseinstance; ornullif 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
MockResponseinstance; ornullif 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
MockConversationinstance - 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
MockConversationinstance - 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
MockConversationinstance - 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
MockConversationinstance - Since:
- 1.0
- See Also:
-
properties
Returns the properties uses by this conversation.- Returns:
- the instance of
HierarchicalPropertiesthat is used by this conversation - Since:
- 1.0
-
hasCookie
Checks whether a cookie is present.- Parameters:
name- the name of the cookie.- Returns:
trueif the cookie was present; orfalseotherwise- Since:
- 1.0
- See Also:
-
getCookie
Retrieves a cookie.- Parameters:
name- the name of the cookie.- Returns:
- the instance of the cookie; or
nullif 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
nullif no such cookie is present - Since:
- 1.0
- See Also:
-
getCookies
Retrieves all cookies.- Returns:
- an array with all the cookies; or
nullif 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
MockConversationinstance - 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
MockConversationinstance - Since:
- 1.0
- See Also:
-