com.bitmechanic.maxq
Class HttpTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by com.bitmechanic.maxq.HttpTestCase
All Implemented Interfaces:
junit.framework.Test

public class HttpTestCase
extends junit.framework.TestCase


Field Summary
protected  org.apache.commons.httpclient.HttpClient client
           
protected  java.lang.String data
           
protected  org.apache.commons.httpclient.HttpMethod method
           
 
Constructor Summary
HttpTestCase(java.lang.String name)
           
 
Method Summary
 void get(java.lang.String url)
           
 void get(java.lang.String url, java.lang.Object[] args)
           
 org.apache.commons.httpclient.HttpMethod getMethod()
           
 java.lang.String getResponse()
          Converts the byte[] method.response as a string, regarding to the encoding
 byte[] getResponseAsBytes()
          Just returns the response as an array of bytes
 int getResponseCode()
           
 org.python.core.PyDictionary getResponseHeader()
          Returns response headers as a Python dictionary.
 java.lang.String getScriptArg()
          Returns any argument for the script.
 java.lang.String getStrutsToken()
          This operation returns the value of the Struts TOKEN in the response
static java.lang.String getUrlReplace()
           
static java.lang.String getUrlSearch()
           
 org.apache.commons.httpclient.NameValuePair[] paramsToNV(java.lang.Object[] params)
          Converts parameters in naturally python representation (a list of tuples) to the form expected by HttpClient.
 void post(java.lang.String url)
           
 void post(java.lang.String url, java.lang.Object[] args)
           
 void postMultiPart(java.lang.String url, java.lang.String data, int contLen)
          Performs a POST in the form of multipart/form-data
 void postMultiPart(java.lang.String url, java.lang.String data, int contLen, java.lang.Object[] args)
          Performs a POST in the form of multipart/form-data
protected  void printResponse()
           
static java.lang.String replaceURL(java.lang.String url)
           
protected  boolean responseContains(java.lang.String text)
          Checks if the text is in the response data.
protected  boolean responseContainsURI(java.lang.String uri)
          Checks if the response contains the uri provided.
protected  void responseOK()
          Checks to see if the HTTP response is 200, 302, or 304.
 void Run()
          This is called when our test scripts are run standalone, not when we are running a JUnit test harness.
 void setCharset(java.lang.String cs)
           
 void setConnections(HttpTestCase test)
           
static void setURLReplace(java.lang.String search, java.lang.String replace)
           
static java.lang.String staticUrlDecode(java.lang.String s)
           
 java.lang.String urlDecode(java.lang.String s)
          URL Decodes the given string.
 boolean userConfirm(java.lang.String msg)
          Puts up an OK/Cancel message box and returns whether the user clicked OK.
 java.lang.String userInput(java.lang.String msg)
          Puts up a message box with a prompt and returns whatever the user enters.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

method

protected org.apache.commons.httpclient.HttpMethod method

client

protected org.apache.commons.httpclient.HttpClient client

data

protected java.lang.String data
Constructor Detail

HttpTestCase

public HttpTestCase(java.lang.String name)
Method Detail

setCharset

public void setCharset(java.lang.String cs)

getUrlReplace

public static java.lang.String getUrlReplace()

getUrlSearch

public static java.lang.String getUrlSearch()

setURLReplace

public static void setURLReplace(java.lang.String search,
                                 java.lang.String replace)

replaceURL

public static java.lang.String replaceURL(java.lang.String url)

Run

public void Run()
         throws java.lang.Throwable
This is called when our test scripts are run standalone, not when we are running a JUnit test harness. Therefore we need not involve JUnit as it just confuses the error output.

Throws:
java.lang.Throwable

getMethod

public org.apache.commons.httpclient.HttpMethod getMethod()

get

public void get(java.lang.String url)
         throws java.io.IOException
Throws:
java.io.IOException

get

public void get(java.lang.String url,
                java.lang.Object[] args)
         throws java.io.IOException
Throws:
java.io.IOException

post

public void post(java.lang.String url)
          throws java.io.IOException
Throws:
java.io.IOException

post

public void post(java.lang.String url,
                 java.lang.Object[] args)
          throws java.io.IOException
Throws:
java.io.IOException

postMultiPart

public void postMultiPart(java.lang.String url,
                          java.lang.String data,
                          int contLen)
                   throws java.io.IOException
Performs a POST in the form of multipart/form-data

Throws:
java.io.IOException

postMultiPart

public void postMultiPart(java.lang.String url,
                          java.lang.String data,
                          int contLen,
                          java.lang.Object[] args)
                   throws java.io.IOException
Performs a POST in the form of multipart/form-data

Throws:
java.io.IOException

setConnections

public void setConnections(HttpTestCase test)

paramsToNV

public org.apache.commons.httpclient.NameValuePair[] paramsToNV(java.lang.Object[] params)
Converts parameters in naturally python representation (a list of tuples) to the form expected by HttpClient.


urlDecode

public java.lang.String urlDecode(java.lang.String s)
URL Decodes the given string. GET/POST data recored by the recorder that have + or % in the value get passed through in the generated python code.

Code reproduced from a comp.lang.java.programmer USENET post.


staticUrlDecode

public static java.lang.String staticUrlDecode(java.lang.String s)

responseOK

protected void responseOK()
                   throws org.apache.commons.httpclient.URIException
Checks to see if the HTTP response is 200, 302, or 304. If not, the assertion fails.

Throws:
org.apache.commons.httpclient.URIException

responseContainsURI

protected boolean responseContainsURI(java.lang.String uri)
                               throws org.apache.commons.httpclient.URIException
Checks if the response contains the uri provided. This is useful to check if a page sent a redirect to the client. If it sent a redirect, will will point at the target path that the client was redirected to.

Parameters:
uri - URI to check the URI against
Returns:
true if uri is in the URI of the response
Throws:
org.apache.commons.httpclient.URIException

responseContains

protected boolean responseContains(java.lang.String text)
Checks if the text is in the response data. This is useful if you want to make surethat the server included a given String in the response.

Parameters:
text - String that the response should contain
Returns:
True if text is in the body of the HTTP response

printResponse

protected void printResponse()

getResponse

public java.lang.String getResponse()
Converts the byte[] method.response as a string, regarding to the encoding


getResponseAsBytes

public byte[] getResponseAsBytes()
Just returns the response as an array of bytes


getResponseCode

public int getResponseCode()

getResponseHeader

public org.python.core.PyDictionary getResponseHeader()
Returns response headers as a Python dictionary.


getScriptArg

public java.lang.String getScriptArg()
Returns any argument for the script. This argument is normally provided using the "--script-arg" command-line option.


userConfirm

public boolean userConfirm(java.lang.String msg)
Puts up an OK/Cancel message box and returns whether the user clicked OK.


userInput

public java.lang.String userInput(java.lang.String msg)
Puts up a message box with a prompt and returns whatever the user enters. If the user clicks Cancel then null is returned.


getStrutsToken

public java.lang.String getStrutsToken()
This operation returns the value of the Struts TOKEN in the response

Returns:
strutsToken A String with the value of the Struts TOKEN