net.sourceforge.jwebunit
Class TestContext

java.lang.Object
  |
  +--net.sourceforge.jwebunit.TestContext

public class TestContext
extends java.lang.Object

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

Author:
Wilkes Joiner, Jim Weaver

Constructor Summary
TestContext()
          Construct a test client context.
 
Method Summary
 void addCookie(java.lang.String name, java.lang.String value)
          Add a cookie to the test context.
 java.lang.String getBaseUrl()
          Return the base URL for the test context.
 java.util.List getCookies()
          Return the cookies which have been added to the test context.
 java.lang.String getEncodingScheme()
          Return the encoding scheme for the test context.
 java.util.Locale getLocale()
          Return the locale established for the test context.
 java.lang.String getPassword()
          Return the user password.
 java.lang.String getResourceBundleName()
          Return the test context resource bundle for expected value lookups.
 java.lang.String getUser()
          Return the authorized user for the test context.
 boolean hasAuthorization()
          Return true if a user / password 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.
 void setAuthorization(java.lang.String user, java.lang.String passwd)
          Set authentication information for the test context.
 void setBaseUrl(java.lang.String url)
          Set the base url for the test context.
 void setEncodingScheme(java.lang.String encodingScheme)
          Set the encoding scheme for the test context which is applied to response text.
 void setLocale(java.util.Locale locale)
          Set the locale for the test context.
 void setResourceBundleName(java.lang.String name)
          Set a resource bundle to use for the test context (will be used to lookup expected values by key in WebTester).
 java.lang.String toEncodedString(java.lang.String text)
          Return the value of a String in the encoding specified by the test context.
 
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

setAuthorization

public void setAuthorization(java.lang.String user,
                             java.lang.String passwd)
Set authentication information for the test context. This information is used by HttpUnitDialog to set authorization on the WebConversation when the dialog is begun.
Parameters:
user - user name
passwd - password

addCookie

public void addCookie(java.lang.String name,
                      java.lang.String value)
Add a cookie to the test context. These cookies are set on the WebConversation when an HttpUnitDialog is begun.
Parameters:
name - cookie name.
value - cookie value.

hasAuthorization

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

hasCookies

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

getUser

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

getPassword

public java.lang.String getPassword()
Return the user password.

getCookies

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

getLocale

public java.util.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(java.util.Locale locale)
Set the locale for the test context.

getEncodingScheme

public java.lang.String getEncodingScheme()
Return the encoding scheme for the test context. The default encoding scheme is ISO-8859-1.

setEncodingScheme

public void setEncodingScheme(java.lang.String encodingScheme)
Set the encoding scheme for the test context which is applied to response text.

toEncodedString

public java.lang.String toEncodedString(java.lang.String text)
Return the value of a String in the encoding specified by the test context.
Parameters:
text - input text.
Returns:
String representing bytes of text converted by context's encoding scheme.

setResourceBundleName

public void setResourceBundleName(java.lang.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 java.lang.String getResourceBundleName()
Return the test context resource bundle for expected value lookups.

getBaseUrl

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

setBaseUrl

public void setBaseUrl(java.lang.String url)
Set the base url for the test context.
Parameters:
url - Base url value - A trailing "/" is appended if not provided.


Copyright © 2002 ThoughtWorks, Inc. All Rights Reserved.