freemarker.testcase
Class AbstractTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by freemarker.testcase.AbstractTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
DummyTestCase, TestAssign, TestBoolean, TestBreak, TestComment, TestCompress, TestException, TestException2, TestException3, TestExecModel, TestExtendedHash, TestExtendedList, TestFormat, TestFreeMarkerTransform, TestFunction, TestHashLiteral, TestIdentifier, TestInclude, TestInclude2, TestIterator, TestJavaLoggingExceptionHandler, TestJavaTransform, TestLastCharacter, TestListIterators, TestListLiteral, TestLocalization, TestLog4jExceptionHandler, TestMultiModels, TestNewlines1, TestNewlines2, TestNewlines3, TestNoParse, TestNumberLiteral, TestNumerics, TestObjectModel, TestPerl5Methods, TestPerl5Substitute, TestPipeline, TestPrecedence, TestSerialization, TestStringNumber, TestSwitchCase, TestTransform, TestTypes, TestVariables

public abstract class AbstractTestCase
extends junit.framework.TestCase

Abstract class used to implement test cases for FreeMarker. This class is an abstract subclass of the TestCase class provided by JUnit. All FM-Classic testcases are subclassed off this class.

This class offers functionality to its subclasses to ease testing where a template is read in, and then written out with a specific data model. Passing the test means that the resulting page matches a given reference text. This class also supports the creation of those reference texts.

To write a new test by subclassing this class, you'll want to do the following:

Version:
$Id: AbstractTestCase.java 1012 2004-10-18 05:47:34Z run2000 $

Field Summary
protected  java.lang.String m_aFilename
          The filename of the reference text if the text doesn't match.
protected  java.lang.String m_aReferenceText
          The reference text against which the test case output is compared.
protected  java.lang.String m_aTemplateText
          The raw, unparsed text of the template.
 
Constructor Summary
AbstractTestCase(java.lang.String aTestName)
          Creates new AbstractTestCase, with a filename from which to populate reference text and template text.
 
Method Summary
protected  java.lang.String getReferenceText(java.lang.String aFilename)
          Gets the reference text for the implementing test class.
protected  java.lang.String getTemplateText(java.lang.String aFilename)
          Gets the template text for the implementing test class.
protected  java.lang.String getTestcasePath()
          Retrieve the root path of the FM-Classic distribution from a properties file.
protected  java.lang.String getTextFromFile(java.lang.String aFilename)
          Reads text from a file.
protected  void isTextIdentical(java.lang.String aReference, java.lang.String aOutput)
          Performs the test on the output text to indicate whether the text is identical to the reference text.
protected  void setUpFiles(java.lang.String aFilename)
          Sets up the reference and template files to be used for the test.
protected  void showTestResults(java.lang.String aReference, java.lang.String aOutput)
          Verify that the output of a test is identical to the reference text.
protected  void writeText(java.lang.String aFilename, java.lang.String aText)
          Writes text to a given filename.
 
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

m_aReferenceText

protected java.lang.String m_aReferenceText
The reference text against which the test case output is compared.


m_aTemplateText

protected java.lang.String m_aTemplateText
The raw, unparsed text of the template. Templates are compiled from this text.


m_aFilename

protected java.lang.String m_aFilename
The filename of the reference text if the text doesn't match.

Constructor Detail

AbstractTestCase

public AbstractTestCase(java.lang.String aTestName)
Creates new AbstractTestCase, with a filename from which to populate reference text and template text.

Method Detail

setUpFiles

protected void setUpFiles(java.lang.String aFilename)
Sets up the reference and template files to be used for the test. This would normally be called from the setUp() method in the JUnit framework.

Parameters:
aFilename - the filename to be used for retrieving the reference text and the template

getTextFromFile

protected java.lang.String getTextFromFile(java.lang.String aFilename)
                                    throws java.io.IOException
Reads text from a file. The file is obtained relative to the implementing class.

Parameters:
aFilename - the filename to read from
Returns:
the text of the specified file
Throws:
java.io.IOException

getReferenceText

protected java.lang.String getReferenceText(java.lang.String aFilename)
                                     throws java.io.IOException
Gets the reference text for the implementing test class.

Parameters:
aFilename - the filename of the text to be retrieved, relative to the reference directory
Returns:
the text of the specified file
Throws:
java.io.IOException

getTemplateText

protected java.lang.String getTemplateText(java.lang.String aFilename)
                                    throws java.io.IOException
Gets the template text for the implementing test class.

Parameters:
aFilename - the filename of the text to be retrieved, relative to the template directory
Returns:
the text of the specified file
Throws:
java.io.IOException

isTextIdentical

protected void isTextIdentical(java.lang.String aReference,
                               java.lang.String aOutput)
                        throws TestCaseException
Performs the test on the output text to indicate whether the text is identical to the reference text.

Parameters:
aReference - the reference text to be compared
aOutput - the text that was generated by the test case
Throws:
TestCaseException - the text is in some way different

showTestResults

protected void showTestResults(java.lang.String aReference,
                               java.lang.String aOutput)
Verify that the output of a test is identical to the reference text. If they are identical, say nothing (in the JUnit tradition). If they differ, output the first line number and character where they differ.

Parameters:
aReference - the reference text
aOutput - the output from the test

writeText

protected void writeText(java.lang.String aFilename,
                         java.lang.String aText)
                  throws java.io.IOException
Writes text to a given filename. Useful when we want to set up the reference file for future tests to compare against.

Parameters:
aFilename - the name of the file to be written
aText - the text to be written to the file
Throws:
java.io.IOException - the file could not be written

getTestcasePath

protected java.lang.String getTestcasePath()
                                    throws java.io.IOException
Retrieve the root path of the FM-Classic distribution from a properties file. This is used to set the root of the FM-Classic cache, which in turn is used to find the example source code.

Returns:
the path to the root of the FM-Classic distribution
Throws:
java.io.IOException - the testcase.properties file could not be read