net.sourceforge.jwebunit.util
Class TestContext

java.lang.Object
  extended by net.sourceforge.jwebunit.util.TestContext

public class TestContext
extends Object

Establish context for tests (things such as locale, base url for the application, cookies, authorization). The context can be accessed through the net.sourceforge.jwebunit.WebTestCaseor WebTester.

Author:
Wilkes Joiner, Jim Weaver, Julien Henry

Constructor Summary
TestContext()
          Construct a test client context.
 
Method Summary
 void addCookie(javax.servlet.http.Cookie cookie)
          Add a cookie to the test context.
 void addCookie(String name, String value, String domain)
          Add a cookie to the test context.
 void addRequestHeader(String name, String value)
          Add a custom request header.
 void clearAuthorizations()
          Clear all authorizations (basic, digest, ntlm, proxy).
 void clearRequestHeaders()
          Clear custom request headers.
 URL getBaseUrl()
          Return the base URL for the test context.
 List getCookies()
          Return the cookies which have been added to the test context.
 String getDomain()
          Return the user domain.
 Locale getLocale()
          Return the locale established for the test context.
 String getPassword()
          Return the user password.
 String getProxyHost()
          Return the proxy server name
 String getProxyPasswd()
          Return the proxy password
 int getProxyPort()
          Return the proxy server port
 String getProxyUser()
          Return the proxy user name
 Map getRequestHeaders()
          Get custom request headers.
 String getResourceBundleName()
          Return the test context resource bundle for expected value lookups.
 String getUser()
          Return the authorized user for the test context.
 String getUserAgent()
           
 boolean hasAuthorization()
          Return true if a basic authentication has been set on the context via setAuthorization(java.lang.String, java.lang.String).
 boolean hasCookies()
          Return true if one or more cookies have been added to the test context.
 boolean hasNTLMAuthorization()
          Return true if a NTLM authentication has been set on the context via setNTLMAuthorization(java.lang.String, java.lang.String, java.lang.String).
 boolean hasProxyAuthorization()
          Return true if a proxy authentication has been set on the context via setProxyAuthorization(java.lang.String, java.lang.String, java.lang.String, int).
 boolean hasUserAgent()
           
 void removeRequestHeader(String name)
          Remove a custom request header.
 void setAuthorization(String user, String passwd)
          Set basic authentication information for the test context.
 void setBaseUrl(String url)
          Set the base url for the test context.
 void setBaseUrl(URL url)
          Set the base url for the test context.
 void setLocale(Locale locale)
          Set the locale for the test context.
 void setNTLMAuthorization(String user, String passwd, String domain)
          Set NTLM authentication information for the test context.
 void setProxyAuthorization(String user, String passwd, String host, int port)
          Set proxy authentication information for the test context.
 void setResourceBundleName(String name)
          Set a resource bundle to use for the test context (will be used to lookup expected values by key in WebTester).
 void setUserAgent(String userAgent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestContext

public TestContext()
Construct a test client context.

Method Detail

clearAuthorizations

public void clearAuthorizations()
Clear all authorizations (basic, digest, ntlm, proxy).


setAuthorization

public void setAuthorization(String user,
                             String passwd)
Set basic authentication information for the test context.

Parameters:
user - user name
passwd - password

setNTLMAuthorization

public void setNTLMAuthorization(String user,
                                 String passwd,
                                 String domain)
Set NTLM authentication information for the test context.

Parameters:
user - user name
passwd - password

setProxyAuthorization

public void setProxyAuthorization(String user,
                                  String passwd,
                                  String host,
                                  int port)
Set proxy authentication information for the test context.

Parameters:
user - user name (null if none)
passwd - password (null if none)
host - proxy host name (null if applicable to any host).
port - proxy port (negative if applicable to any port).

addCookie

public void addCookie(String name,
                      String value,
                      String domain)
Add a cookie to the test context. These cookies are set on the conversation when you use a {WebTester#beginAt}.

Parameters:
name - cookie name.
value - cookie value.
domain - cookie domain (ie localhost or www.foo.bar).

addCookie

public void addCookie(javax.servlet.http.Cookie cookie)
Add a cookie to the test context. These cookies are set on the conversation when you use a {WebTester#beginAt}.

Parameters:
cookie - a cookie.

hasAuthorization

public boolean hasAuthorization()
Return true if a basic authentication has been set on the context via setAuthorization(java.lang.String, java.lang.String).


hasNTLMAuthorization

public boolean hasNTLMAuthorization()
Return true if a NTLM authentication has been set on the context via setNTLMAuthorization(java.lang.String, java.lang.String, java.lang.String).


hasProxyAuthorization

public boolean hasProxyAuthorization()
Return true if a proxy authentication has been set on the context via setProxyAuthorization(java.lang.String, java.lang.String, java.lang.String, int).


hasCookies

public boolean hasCookies()
Return true if one or more cookies have been added to the test context.


getUser

public String getUser()
Return the authorized user for the test context.


getPassword

public String getPassword()
Return the user password.


getDomain

public String getDomain()
Return the user domain.


getCookies

public List getCookies()
Return the cookies which have been added to the test context.


getUserAgent

public String getUserAgent()

setUserAgent

public void setUserAgent(String userAgent)

hasUserAgent

public boolean hasUserAgent()

getLocale

public Locale getLocale()
Return the locale established for the test context. If the locale has not been explicitly set, Locale.getDefault() will be returned.


setLocale

public void setLocale(Locale locale)
Set the locale for the test context.


setResourceBundleName

public void setResourceBundleName(String name)
Set a resource bundle to use for the test context (will be used to lookup expected values by key in WebTester).

Parameters:
name - path name of the resource bundle.

getResourceBundleName

public String getResourceBundleName()
Return the test context resource bundle for expected value lookups.


getProxyHost

public String getProxyHost()
Return the proxy server name


getProxyPort

public int getProxyPort()
Return the proxy server port


getProxyUser

public String getProxyUser()
Return the proxy user name


getProxyPasswd

public String getProxyPasswd()
Return the proxy password


getBaseUrl

public URL getBaseUrl()
Return the base URL for the test context. The default base URL is port 8080 on localhost.


setBaseUrl

public void setBaseUrl(String url)
Set the base url for the test context.

Parameters:
url - Base url value - A trailing "/" is appended if not provided.

setBaseUrl

public void setBaseUrl(URL url)
Set the base url for the test context.

Parameters:
url - Base url value. Anything after trailing "/" will be skipped.

addRequestHeader

public void addRequestHeader(String name,
                             String value)
Add a custom request header.

Parameters:
name - header name.
value - header value.

removeRequestHeader

public void removeRequestHeader(String name)
Remove a custom request header.

Parameters:
name - header name.

getRequestHeaders

public Map getRequestHeaders()
Get custom request headers.

Parameters:
name - header name.
value - header value.

clearRequestHeaders

public void clearRequestHeaders()
Clear custom request headers.



Copyright © 2002-2007 SourceForge. All Rights Reserved.