test.util
Class MakumbaJspTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.cactus.internal.AbstractCactusTestCase
              extended by org.apache.cactus.ServletTestCase
                  extended by org.apache.cactus.JspTestCase
                      extended by test.util.MakumbaJspTestCase
All Implemented Interfaces:
junit.framework.Test, org.apache.cactus.internal.CactusTestCase
Direct Known Subclasses:
ExceptionTest, FormsHQLTest, FormsOQLTest, ListHQLTest, ListOQLTest, MakumbaCommonTagsTest, MakumbaJspTestCase.MakumbaJspTestCaseDecorator

public abstract class MakumbaJspTestCase
extends org.apache.cactus.JspTestCase

Utility class which enables it to quickly write tests based on the execution of a JSP. Since we know the expected result, we can fetch this result and store it into a file, and then compare the next executions of the test against this file.

Version:
$Id: MakumbaJSPTest.java,v 1.1 25.09.2007 16:08:26 Manuel Exp $
Author:
Manuel Gay

Nested Class Summary
static class MakumbaJspTestCase.JspTest
           
static class MakumbaJspTestCase.MakumbaJspTestCaseDecorator
           
static class MakumbaJspTestCase.Suite
           
 
Field Summary
protected  Map<String,String> differentNameJspsMap
          for dynamically built suites, the tests whose included jsp has a different name
protected  Map<String,String> differentNameJspsReverseMap
           
(package private)  Set<String> disabledTests
           
protected  String jspDir
          JSP dir of the suite
protected  boolean recording
          recording mode
protected  com.meterware.httpunit.WebResponse submissionResponse
          some tests will compare content against the response of a form submission
protected  String[] tests
          for dynamically built suites, the names and order of tests
 
Fields inherited from class org.apache.cactus.JspTestCase
out, pageContext
 
Fields inherited from class org.apache.cactus.ServletTestCase
config, request, response, session
 
Constructor Summary
MakumbaJspTestCase()
           
 
Method Summary
protected  boolean compareTest(String result, String testName)
          Compares a test output to its stored (expected) result.
protected  void compareToFile(com.meterware.httpunit.WebResponse response, String testName)
           
protected  void compareToFileWithTestName(com.meterware.httpunit.WebResponse response)
          Compare the given WebResponse to the file that has the name of the current test
protected  void differentNameJsps(String name, String jsp)
           
protected  void disableTest(String test)
           
protected  void fetchValidTestResult(String output, String testName, boolean record)
          Method that helps to fetch the result of a test, on the first run.
protected  com.meterware.httpunit.WebForm getFormInJsp(String page)
          Retrieve the indicated page, compare the content to the comparison file with the test name, and return the first form in the page.
protected  com.meterware.httpunit.WebForm getFormInJsp(String page, boolean check)
          Retrieve the indicated page, optionally compare the content to the comparison file with the test name, and return the first form in the page.
protected  com.meterware.httpunit.WebForm getFormInJspWithTestName()
          Retrieve the page with the test name from the suite JSP dir, compare the content to the comparison file with the test name, and return the first form in the page.
protected  com.meterware.httpunit.WebForm getFormInJspWithTestName(boolean check)
          Retrieve the page with the test name from the suite JSP dir, optionally compare the content to the comparison file with the test name, and return the first form in the page.
 String getJspDir()
          The JSP dir of this suite
protected  com.meterware.httpunit.WebResponse getJspResponse(String page, boolean check)
          Retrieve the indicated page, optionally compare the content to the comparison file with the test name.
 boolean getRecordingMode()
          Recording mode of the suite, for generating comparison files.
protected  void includeJspWithTestName()
          Include the JSP from the JSP dir of this suite that has the name of the currently running test
static junit.framework.Test makeJspDirSuite(MakumbaJspTestCase prototype, String queryLang)
          Make a dynamic test suite, from a prototype object by looking into its JSP folder.
static junit.framework.Test makeJspSuite(MakumbaJspTestCase prototype, String queryLang)
          Make a dynamic test suite, from a prototype object.
static junit.framework.Test makeSuite(Class<?> claz, String queryLang)
          Make a test suite using the standard, reflection-based mechanism
 
Methods inherited from class org.apache.cactus.JspTestCase
createProtocolHandler
 
Methods inherited from class org.apache.cactus.internal.AbstractCactusTestCase
runBare, runBareServer
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, 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
 
Methods inherited from interface org.apache.cactus.internal.CactusTestCase
runBareServer
 

Field Detail

recording

protected boolean recording
recording mode


jspDir

protected String jspDir
JSP dir of the suite


tests

protected String[] tests
for dynamically built suites, the names and order of tests


differentNameJspsMap

protected Map<String,String> differentNameJspsMap
for dynamically built suites, the tests whose included jsp has a different name


differentNameJspsReverseMap

protected Map<String,String> differentNameJspsReverseMap

submissionResponse

protected com.meterware.httpunit.WebResponse submissionResponse
some tests will compare content against the response of a form submission


disabledTests

Set<String> disabledTests
Constructor Detail

MakumbaJspTestCase

public MakumbaJspTestCase()
Method Detail

compareTest

protected boolean compareTest(String result,
                              String testName)
                       throws Exception
Compares a test output to its stored (expected) result. The method detects automatically the name of the test based on the invoking method, so all there's to do is to pass it the new result.
TODO this should be much more verbose

Parameters:
result - the new result, from the currently running test
Returns:
true if this worked out, false otherwise.
Throws:
FileNotFoundException - in case the comparison basis file is not found, this indicates it
Exception

fetchValidTestResult

protected void fetchValidTestResult(String output,
                                    String testName,
                                    boolean record)
Method that helps to fetch the result of a test, on the first run. Just pass it the expected result, it will store it automatically. Don't forget to remove it after the first time!

Parameters:
output - the result (HTML code) of the page that was ran correctly.
testName -
record - TODO

compareToFileWithTestName

protected void compareToFileWithTestName(com.meterware.httpunit.WebResponse response)
                                  throws Exception
Compare the given WebResponse to the file that has the name of the current test

Parameters:
response - the WebResponse to compare
Throws:
Exception

compareToFile

protected void compareToFile(com.meterware.httpunit.WebResponse response,
                             String testName)
                      throws Exception
Throws:
Exception

includeJspWithTestName

protected void includeJspWithTestName()
                               throws ServletException,
                                      IOException
Include the JSP from the JSP dir of this suite that has the name of the currently running test

Throws:
ServletException
IOException

getFormInJspWithTestName

protected com.meterware.httpunit.WebForm getFormInJspWithTestName()
                                                           throws MalformedURLException,
                                                                  IOException,
                                                                  SAXException,
                                                                  Exception
Retrieve the page with the test name from the suite JSP dir, compare the content to the comparison file with the test name, and return the first form in the page.

Returns:
the first WebForm in the response page
Throws:
MalformedURLException
IOException
SAXException
Exception

getFormInJspWithTestName

protected com.meterware.httpunit.WebForm getFormInJspWithTestName(boolean check)
                                                           throws MalformedURLException,
                                                                  IOException,
                                                                  SAXException,
                                                                  Exception
Retrieve the page with the test name from the suite JSP dir, optionally compare the content to the comparison file with the test name, and return the first form in the page.

Parameters:
check - whether to compare the content with the comparison file with test name
Returns:
the first WebForm in the response page
Throws:
MalformedURLException
IOException
SAXException
Exception

getFormInJsp

protected com.meterware.httpunit.WebForm getFormInJsp(String page)
                                               throws MalformedURLException,
                                                      IOException,
                                                      SAXException,
                                                      Exception
Retrieve the indicated page, compare the content to the comparison file with the test name, and return the first form in the page.

Parameters:
page - the page to retrieve
Returns:
the first WebForm in the response page
Throws:
MalformedURLException
IOException
SAXException
Exception

getFormInJsp

protected com.meterware.httpunit.WebForm getFormInJsp(String page,
                                                      boolean check)
                                               throws MalformedURLException,
                                                      IOException,
                                                      SAXException,
                                                      Exception
Retrieve the indicated page, optionally compare the content to the comparison file with the test name, and return the first form in the page.

Parameters:
page - the page to retrieve
check - whether to compare the content with the comparison file with test name
Returns:
the first WebForm in the response page
Throws:
MalformedURLException
IOException
SAXException
Exception

getJspResponse

protected com.meterware.httpunit.WebResponse getJspResponse(String page,
                                                            boolean check)
                                                     throws MalformedURLException,
                                                            IOException,
                                                            SAXException,
                                                            Exception
Retrieve the indicated page, optionally compare the content to the comparison file with the test name.

Parameters:
page - the page to retrieve
check - whether to compare the content with the comparison file with test name
Returns:
the WebResponse from the page access
Throws:
MalformedURLException
IOException
SAXException
Exception

getJspDir

public String getJspDir()
The JSP dir of this suite

Returns:
a dir name relative to the root

getRecordingMode

public boolean getRecordingMode()
Recording mode of the suite, for generating comparison files.

Returns:
true if the suite should record its responses, false otherwise.

differentNameJsps

protected void differentNameJsps(String name,
                                 String jsp)

disableTest

protected void disableTest(String test)

makeJspSuite

public static junit.framework.Test makeJspSuite(MakumbaJspTestCase prototype,
                                                String queryLang)
Make a dynamic test suite, from a prototype object. This allows testTestName and endTestName to be missing. The test names are found in the tests[] array. Each test includes a JSP with (in principle) the same name, and compares to a comparison file. If a beginTestName method exists, it will be executed. If testTestName tests are present in the prototype class, they are honored _before_ all other tests.

Parameters:
prototype - the object whose tests[] array will be used to make the suite
queryLang - query language used in the test
Returns:
the test suite

makeSuite

public static junit.framework.Test makeSuite(Class<?> claz,
                                             String queryLang)
Make a test suite using the standard, reflection-based mechanism

Parameters:
claz - the class where the tests are extracted from
queryLang - the query language used in the test
Returns:
the test suite

makeJspDirSuite

public static junit.framework.Test makeJspDirSuite(MakumbaJspTestCase prototype,
                                                   String queryLang)
Make a dynamic test suite, from a prototype object by looking into its JSP folder. This allows testTestName and endTestName to be missing. The test names are found from the test*.jsp files in the JSP folder of the prototype. Each test includes a JSP with (in principle) the same name, and compares to a comparison file. If a beginTestName method exists, it will be executed.

Parameters:
prototype - the object whose tests[] array will be used to make the suite
queryLang - query language used in the test
Returns:
the test suite