org.apache.velocity.test
Class BaseTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.velocity.test.BaseTestCase
All Implemented Interfaces:
junit.framework.Test, TemplateTestBase
Direct Known Subclasses:
AbsoluteFileResourceLoaderTestCase, AnakiaTestCase, BaseSQLTest, BuiltInEventHandlerTestCase, ChainedUberspectorsTestCase, ClassMapTestCase, ClasspathResourceTestCase, CommentsTestCase, CommonsExtPropTestCase, ContextSafetyTestCase, EncodingTestCase, EvaluateTestCase, ExceptionTestCase, FilteredEventHandlingTestCase, IncludeErrorTestCase, IncludeEventHandlingTestCase, InfoTestCase, InlineScopeVMTestCase, Introspector2TestCase, Introspector3TestCase, IntrospectorTestCase, MacroForwardDefineTestCase, MethodOverloadingTestCase, MiscTestCase, MultiLoaderTestCase, MultipleFileResourcePathTestCase, ParseExceptionTestCase, ParseWithMacroLibsTestCase, ResourceCachingTestCase, ResourceExistsTestCase, ResourceLoaderInstanceTestCase, SecureIntrospectionTestCase, SetTestCase, StringResourceLoaderTestCase, TemplateTestCase, TestBaseTestCase, TexenClasspathTestCase, TexenTestCase, UberspectorTestCase, UnicodeEscapeTestCase, Velocity537TestCase, Velocity580TestCase, VelocityAppTestCase, VelTools66TestCase, VMLibraryTestCase, WrappedExceptionTestCase

public abstract class BaseTestCase
extends junit.framework.TestCase
implements TemplateTestBase

Base test case that provides a few utility methods for the rest of the tests.

Version:
$Id: BaseTestCase.java 689111 2008-08-26 15:27:06Z nbubna $
Author:
Daniel Rall

Field Summary
 
Fields inherited from interface org.apache.velocity.test.TemplateTestBase
CMP_FILE_EXT, COMPARE_DIR, FILE_RESOURCE_LOADER_PATH, RESULT_DIR, RESULT_FILE_EXT, TEST_CASE_PROPERTIES, TEST_COMPARE_DIR, TEST_RESULT_DIR, TMPL_FILE_EXT
 
Constructor Summary
BaseTestCase(String name)
          Default constructor.
 
Method Summary
protected static void assureResultsDirectoryExists(String resultsDirectory)
          Assures that the results directory exists.
protected  String getFileContents(String dir, String baseFileName, String ext)
           
protected static String getFileName(String dir, String base, String ext)
          Concatenates the file name parts together appropriately.
protected static String getFileName(String dir, String base, String ext, boolean mustExist)
           
protected static String getTestCaseName(String s)
          Turns a base file name into a test case name.
protected  boolean isMatch(String result, String compareDir, String baseFileName, String compareExt)
          Returns whether the processed template matches the content of the provided comparison file.
protected  boolean isMatch(String resultsDir, String compareDir, String baseFileName, String resultExt, String compareExt)
          Returns whether the processed template matches the content of the provided comparison file.
protected  String normalizeNewlines(String source)
          Normalizes lines to account for platform differences.
 
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
 

Constructor Detail

BaseTestCase

public BaseTestCase(String name)
Default constructor.

Method Detail

getFileName

protected static String getFileName(String dir,
                                    String base,
                                    String ext)
Concatenates the file name parts together appropriately.

Returns:
The full path to the file.

getFileName

protected static String getFileName(String dir,
                                    String base,
                                    String ext,
                                    boolean mustExist)

assureResultsDirectoryExists

protected static void assureResultsDirectoryExists(String resultsDirectory)
Assures that the results directory exists. If the results directory cannot be created, fails the test.


normalizeNewlines

protected String normalizeNewlines(String source)
Normalizes lines to account for platform differences. Macs use a single \r, DOS derived operating systems use \r\n, and Unix uses \n. Replace each with a single \n.

Returns:
source with all line terminations changed to Unix style

isMatch

protected boolean isMatch(String resultsDir,
                          String compareDir,
                          String baseFileName,
                          String resultExt,
                          String compareExt)
                   throws Exception
Returns whether the processed template matches the content of the provided comparison file.

Returns:
Whether the output matches the contents of the comparison file.
Throws:
Exception - Test failure condition.

getFileContents

protected String getFileContents(String dir,
                                 String baseFileName,
                                 String ext)

isMatch

protected boolean isMatch(String result,
                          String compareDir,
                          String baseFileName,
                          String compareExt)
                   throws Exception
Returns whether the processed template matches the content of the provided comparison file.

Returns:
Whether the output matches the contents of the comparison file.
Throws:
Exception - Test failure condition.

getTestCaseName

protected static final String getTestCaseName(String s)
Turns a base file name into a test case name.

Parameters:
s - The base file name.
Returns:
The test case name.


Copyright © 2000-2008 The Apache Software Foundation. All Rights Reserved.