org.jboss.jsfunit.framework
Class WebClientSpec

java.lang.Object
  extended by org.jboss.jsfunit.framework.WebClientSpec
All Implemented Interfaces:
EventListener, javax.servlet.http.HttpSessionBindingListener

public class WebClientSpec
extends Object
implements javax.servlet.http.HttpSessionBindingListener

The WebClientSpec allows configuration of the HtmlUnit WebClient and its interaction with JSFUnit.

Since:
1.0
Author:
Stan Silvert

Field Summary
static String SESSION_KEY
           
 
Constructor Summary
WebClientSpec(String initialPage)
          Create a new WebClientSpec.
WebClientSpec(String initialPage, com.gargoylesoftware.htmlunit.BrowserVersion browserVersion)
          Create a new WebClientSpec.
WebClientSpec(String initialPage, com.gargoylesoftware.htmlunit.BrowserVersion browserVersion, String proxyHost, int proxyPort)
          Create a new WebClientSpec for use with a proxy server.
 
Method Summary
 void addCookie(String name, String value)
          Add a cookie that will be sent with every request.
protected  void addCookiesToHeader()
           
 com.gargoylesoftware.htmlunit.Page doInitialRequest()
          Perform the initial request to the server.
 com.gargoylesoftware.htmlunit.BrowserVersion getBrowserVersion()
          Get the BrowserVersion to be used by the WebClient.
 Map<String,String> getCookies()
          Get an unmodifiable Map of all the cookies to be sent with each request.
 String getInitialPage()
          Return the initialPage passed into the constructor.
 String getProxyHost()
          Get the Proxy Host used by the WebClient.
 int getProxyPort()
          Get the Proxy Port used by the WebClient.
static Map getRedirectorRequestParams()
          Get an immutable Map of all request params sent to the ServletRedirector or ServletTestRunner.
 com.gargoylesoftware.htmlunit.WebClient getWebClient()
          Get the WebClient instances used for the JSFSession.
 String removeCookie(String name)
          Remove a cookie sent with every request.
 void setInitialRequestStrategy(InitialRequestStrategy requestStrategy)
          Set the strategy to be used when making the initial request to the server.
 void valueBound(javax.servlet.http.HttpSessionBindingEvent httpSessionBindingEvent)
           
 void valueUnbound(javax.servlet.http.HttpSessionBindingEvent httpSessionBindingEvent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION_KEY

public static final String SESSION_KEY
Constructor Detail

WebClientSpec

public WebClientSpec(String initialPage)
Create a new WebClientSpec. Note that the initialPage param should be something that maps into the FacesServlet. In the case where the FacesServlet is extension mapped in web.xml, this param will be something like "/index.jsf" or "/index.faces". If the FacesServlet is path-mapped then the initialPage param will be something like "/faces/index.jsp".

Parameters:
initialPage - The page used to start a client session with JSF. Example: "/index.jsf"

WebClientSpec

public WebClientSpec(String initialPage,
                     com.gargoylesoftware.htmlunit.BrowserVersion browserVersion)
Create a new WebClientSpec. Note that the initialPage param should be something that maps into the FacesServlet. In the case where the FacesServlet is extension mapped in web.xml, this param will be something like "/index.jsf" or "/index.faces". If the FacesServlet is path-mapped then the initialPage param will be something like "/faces/index.jsp".

Parameters:
initialPage - The page used to start a client session with JSF. Example: "/index.jsf"
browserVersion - The browser version to simulate.

WebClientSpec

public WebClientSpec(String initialPage,
                     com.gargoylesoftware.htmlunit.BrowserVersion browserVersion,
                     String proxyHost,
                     int proxyPort)
Create a new WebClientSpec for use with a proxy server. Note that the initialPage param should be something that maps into the FacesServlet. In the case where the FacesServlet is extension mapped in web.xml, this param will be something like "/index.jsf" or "/index.faces". If the FacesServlet is path-mapped then the initialPage param will be something like "/faces/index.jsp".

Parameters:
initialPage - The page used to start a client session with JSF. Example: "/index.jsf"
browserVersion - The browser version to simulate.
proxyHost - The proxy server.
proxyPort - The proxy port.
Method Detail

getRedirectorRequestParams

public static Map getRedirectorRequestParams()
Get an immutable Map of all request params sent to the ServletRedirector or ServletTestRunner. Note that the Map returned is the same one returned from ServletRequest.getParameterMap(). This Map is defined with a key of type String and a value of type String array - not plain String.

Returns:
The Map of params.
Since:
1.1

getInitialPage

public String getInitialPage()
Return the initialPage passed into the constructor.

Returns:
The initialPage.

getWebClient

public com.gargoylesoftware.htmlunit.WebClient getWebClient()
Get the WebClient instances used for the JSFSession.

Returns:
The WebClient.

getBrowserVersion

public com.gargoylesoftware.htmlunit.BrowserVersion getBrowserVersion()
Get the BrowserVersion to be used by the WebClient.

Returns:
The BrowserVersion.

getProxyHost

public String getProxyHost()
Get the Proxy Host used by the WebClient.

Returns:
the Proxy Host

getProxyPort

public int getProxyPort()
Get the Proxy Port used by the WebClient.

Returns:
The Proxy Port

setInitialRequestStrategy

public void setInitialRequestStrategy(InitialRequestStrategy requestStrategy)
Set the strategy to be used when making the initial request to the server.

Parameters:
requestStrategy - The InitialRequestStrategy implementation.

addCookie

public void addCookie(String name,
                      String value)
Add a cookie that will be sent with every request.

Parameters:
name - The cookie name.
value - The cookie value.

removeCookie

public String removeCookie(String name)
Remove a cookie sent with every request.

Parameters:
name - The name of the cookie
Returns:
The value of the cookie removed.

getCookies

public Map<String,String> getCookies()
Get an unmodifiable Map of all the cookies to be sent with each request.

Returns:
The cookie Map.

doInitialRequest

public com.gargoylesoftware.htmlunit.Page doInitialRequest()
                                                    throws IOException
Perform the initial request to the server. This is typically only called by the JSFSession.

Returns:
The Page created when the initial request is done.
Throws:
IOException - if HtmlUnit encountered an error.

addCookiesToHeader

protected void addCookiesToHeader()

valueUnbound

public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent httpSessionBindingEvent)
Specified by:
valueUnbound in interface javax.servlet.http.HttpSessionBindingListener

valueBound

public void valueBound(javax.servlet.http.HttpSessionBindingEvent httpSessionBindingEvent)
Specified by:
valueBound in interface javax.servlet.http.HttpSessionBindingListener


Copyright © 2007-2010 JBoss, a division of Red Hat, Inc.. All Rights Reserved.