com.uwyn.rife.test
Class MockConversation

java.lang.Object
  extended by com.uwyn.rife.test.MockConversation

public class MockConversation
extends Object

Simulates a conversation between a web browser and a servlet container.

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. Your tests can thus reference existing site XML declarations, combine different sites into one, build a new site-structure on-the-fly in Java, modify existing element declarations, override property injections, ...

Note that RIFE relies on EngineClassLoader to provide continuations functionalities to pure Java elements. If you want to test elements that use continuations, you have to make sure the first class in your test setup is loaded by EngineClassLoader. The easiest way to do so is to run your main class with RunWithEngineClassLoader.

Since:
1.1
Version:
$Revision: 3634 $
Author:
Geert Bevin (gbevin[remove] at uwyn dot com)

Constructor Summary
MockConversation(Site site)
          Creates a new MockConversation instance for a particular site.
 
Method Summary
 void addCookie(Cookie cookie)
          Add a cookie.
 void addCookie(String name, String value)
          Add a cookie with only a name and a value, the other fields will be empty.
 MockConversation contextPath(String contextPath)
          Sets the context path that will be used by this conversation.
 MockConversation cookie(Cookie cookie)
          Add a cookie.
 MockConversation cookie(String name, String value)
          Add a cookie with only a name and a value, the other fields will be empty.
 MockResponse doRequest(String url)
          Perform a request for a particular URL.
 MockResponse doRequest(String url, MockRequest request)
          Perform a request for a particular URL and request configuration.
 String getContextPath()
          Retrieves the context path that is used by this conversation.
 Cookie getCookie(String name)
          Retrieves a cookie.
 Cookie[] getCookies()
          Retrieves all cookies.
 String getCookieValue(String name)
          Retrieves the value of a cookie.
 String getScheme()
          Retrieves the scheme that is used by this conversation.
 String getServerName()
          Retrieves the server name that is used by this conversation.
 int getServerPort()
          Retrieves the server port that is used by this conversation.
 boolean hasCookie(String name)
          Checks whether a cookie is present.
 MockConversation scheme(String scheme)
          Sets the scheme that will be used by this conversation.
 MockConversation serverName(String serverName)
          Sets the server name that will be used by this conversation.
 MockConversation 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 setScheme(String scheme)
          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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MockConversation

public MockConversation(Site site)
                 throws EngineException
Creates a new MockConversation instance for a particular site.

Parameters:
site - the site structure that will be tested
Throws:
EngineException
Since:
1.1
Method Detail

doRequest

public MockResponse doRequest(String url)
                       throws EngineException
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; or

null if the scheme, hostname and port don't correspond to the conversation setup

Throws:
EngineException
Since:
1.1
See Also:
doRequest(String, MockRequest)

doRequest

public MockResponse doRequest(String url,
                              MockRequest request)
                       throws EngineException
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:

http://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 tested
request - the request that will be used
Returns:
the response of the request as a MockResponse instance; or

null if the scheme, hostname and port don't correspond to the conversation setup

Throws:
EngineException
Since:
1.1
See Also:
doRequest(String)

getScheme

public String getScheme()
Retrieves the scheme that is used by this conversation.

Returns:
the scheme of this conversation
Since:
1.1
See Also:
setScheme(java.lang.String), scheme(java.lang.String)

setScheme

public void setScheme(String scheme)
Sets the scheme that will be used by this conversation.

Parameters:
scheme - the scheme
Since:
1.1
See Also:
getScheme(), scheme(java.lang.String)

scheme

public MockConversation scheme(String scheme)
Sets the scheme that will be used by this conversation.

Parameters:
scheme - the scheme
Returns:
this MockConversation instance
Since:
1.1
See Also:
getScheme(), setScheme(java.lang.String)

getServerName

public String getServerName()
Retrieves the server name that is used by this conversation.

Returns:
the server name of this conversation
Since:
1.1
See Also:
setServerName(java.lang.String), serverName(java.lang.String)

setServerName

public void setServerName(String serverName)
Sets the server name that will be used by this conversation.

Parameters:
serverName - the server name
Since:
1.1
See Also:
getServerName(), serverName(java.lang.String)

serverName

public MockConversation serverName(String serverName)
Sets the server name that will be used by this conversation.

Parameters:
serverName - the server name
Returns:
this MockConversation instance
Since:
1.1
See Also:
getServerName(), setServerName(java.lang.String)

getServerPort

public int getServerPort()
Retrieves the server port that is used by this conversation.

Returns:
the server port of this conversation
Since:
1.1
See Also:
setServerPort(int), serverPort(int)

setServerPort

public void setServerPort(int serverPort)
Sets the server port that will be used by this conversation.

Parameters:
serverPort - the server port
Since:
1.1
See Also:
getServerPort(), serverPort(int)

serverPort

public MockConversation serverPort(int serverPort)
Sets the server port that will be used by this conversation.

Parameters:
serverPort - the server port
Returns:
this MockConversation instance
Since:
1.1
See Also:
getServerPort(), setServerPort(int)

getContextPath

public String getContextPath()
Retrieves the context path that is used by this conversation.

Returns:
the context path of this conversation
Since:
1.1
See Also:
setContextPath(java.lang.String), contextPath(java.lang.String)

setContextPath

public void setContextPath(String contextPath)
Sets the context path that will be used by this conversation.

Parameters:
contextPath - the context path
Since:
1.1
See Also:
getContextPath(), contextPath(java.lang.String)

contextPath

public MockConversation contextPath(String contextPath)
Sets the context path that will be used by this conversation.

Parameters:
contextPath - the context path
Returns:
this MockConversation instance
Since:
1.1
See Also:
getContextPath(), setContextPath(java.lang.String)

hasCookie

public boolean hasCookie(String name)
Checks whether a cookie is present.

Parameters:
name - the name of the cookie.
Returns:
true if the cookie was present; or

false otherwise

Since:
1.1
See Also:
getCookie(String), getCookieValue(String), getCookies(), addCookie(Cookie), addCookie(String, String)

getCookie

public Cookie getCookie(String name)
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.1
See Also:
hasCookie(String), getCookieValue(String), getCookies(), addCookie(Cookie), addCookie(String, String)

getCookieValue

public String getCookieValue(String name)
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.1
See Also:
hasCookie(String), getCookie(String), getCookies(), addCookie(Cookie), addCookie(String, String)

getCookies

public Cookie[] getCookies()
Retrieves all cookies.

Returns:
an array with all the cookies; or

null if no cookies are present

Since:
1.1
See Also:
hasCookie(String), getCookie(String), getCookieValue(String), addCookie(Cookie), addCookie(String, String)

addCookie

public void addCookie(Cookie cookie)
Add a cookie.

Parameters:
cookie - the cookie instance that will be added
Since:
1.1
See Also:
hasCookie(String), getCookie(String), getCookieValue(String), getCookies(), addCookie(String, String)

addCookie

public void addCookie(String name,
                      String value)
Add a cookie with only a name and a value, the other fields will be empty.

Parameters:
name - the name of the cookie
value - the value of the cookie
Since:
1.1
See Also:
hasCookie(String), getCookie(String), getCookieValue(String), getCookies(), addCookie(Cookie)

cookie

public MockConversation cookie(Cookie cookie)
Add a cookie.

Parameters:
cookie - the cookie instance that will be added
Returns:
this MockConversation instance
Since:
1.1
See Also:
hasCookie(String), getCookie(String), getCookieValue(String), getCookies(), addCookie(Cookie), addCookie(String, String)

cookie

public MockConversation cookie(String name,
                               String value)
Add a cookie with only a name and a value, the other fields will be empty.

Parameters:
name - the name of the cookie
value - the value of the cookie
Returns:
this MockConversation instance
Since:
1.1
See Also:
hasCookie(String), getCookie(String), getCookieValue(String), getCookies(), addCookie(Cookie), addCookie(String, String)


Copyright © 2001-2007 Uwyn sprl/bvba. All Rights Reserved.