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, ArrayMethodsTestCase, BaseSQLTest, BlockMacroTestCase, BreakDirectiveTestCase, BuiltInEventHandlerTestCase, ChainedUberspectorsTestCase, ClassMapTestCase, ClasspathResourceTestCase, CommentsTestCase, CommonsExtPropTestCase, ContextSafetyTestCase, DefineTestCase, EncodingTestCase, EvaluateTestCase, ExceptionTestCase, FilteredEventHandlingTestCase, ForeachTestCase, IfNullTestCase, IncludeErrorTestCase, IncludeEventHandlingTestCase, IndexTestCase, InfoTestCase, InlineScopeVMTestCase, Introspector2TestCase, Introspector3TestCase, IntrospectorTestCase, MacroForwardDefineTestCase, MethodOverloadingTestCase, MiscTestCase, MultiLoaderTestCase, MultipleFileResourcePathTestCase, ParseExceptionTestCase, ParseWithMacroLibsTestCase, PropertyMethodPrecedenceTestCase, ResourceCachingTestCase, ResourceExistsTestCase, ResourceLoaderInstanceTestCase, ScopeTestCase, SecureIntrospectionTestCase, SetTestCase, StaticUtilityMethodsTestCase, StopDirectiveTestCase, StrictCompareTestCase, StrictEscapeTestCase, StrictForeachTestCase, StrictMathTestCase, StrictReferenceTestCase, StringConcatenationTestCase, StringResourceLoaderTestCase, TemplateTestCase, TestBaseTestCase, TexenClasspathTestCase, TexenTestCase, TextblockTestCase, UberspectorTestCase, UnicodeEscapeTestCase, URLResourceLoaderTimeoutTestCase, VarargMethodsTestCase, Velocity355And552TestCase, Velocity532TestCase, Velocity537TestCase, Velocity544TestCase, Velocity579TestCase, Velocity580TestCase, Velocity587TestCase, Velocity589TestCase, Velocity614TestCase, Velocity615TestCase, Velocity616TestCase, Velocity625TestCase, Velocity627TestCase, Velocity629TestCase, Velocity62TestCase, Velocity630TestCase, Velocity631TestCase, Velocity644TestCase, Velocity667TestCase, Velocity682TestCase, Velocity689TestCase, Velocity701TestCase, Velocity702TestCase, Velocity709TestCase, Velocity727TestCase, Velocity728TestCase, Velocity729TestCase, Velocity730TestCase, Velocity742TestCase, Velocity753TestCase, Velocity755TestCase, Velocity758TestCase, Velocity762TestCase, Velocity785TestCase, VelocityAppTestCase, VelTools66TestCase, VMContextLocalscopeTestCase, VMLibraryTestCase, WrappedExceptionTestCase

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

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

Version:
$Id: BaseTestCase.java 898032 2010-01-11 19:51:03Z nbubna $
Author:
Daniel Rall, Nathan Bubna

Field Summary
protected  org.apache.velocity.VelocityContext context
           
protected  boolean DEBUG
           
protected  org.apache.velocity.app.VelocityEngine engine
           
protected  TestLogChute log
           
protected  String stringRepoName
           
 
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)
           
 
Method Summary
protected  void addTemplate(String name, String template)
           
protected  void assertContextValue(String key, Object expected)
          Ensure that a context value is as expected.
protected  void assertEvalEquals(String expected, String template)
          Ensure that a template renders as expected.
protected  Exception assertEvalException(String evil)
          Ensure that an exception occurs when the string is evaluated.
protected  Exception assertEvalException(String evil, Class exceptionType)
          Ensure that a specified type of exception occurs when evaluating the string.
protected  Exception assertEvalExceptionAt(String evil, int line, int col)
          Only ensure that the error message of the expected exception has the proper line and column info.
protected  Exception assertEvalExceptionAt(String evil, String template, int line, int col)
          Ensure that the error message of the expected exception has the proper location info.
protected  void assertSchmoo(String templateIsExpected)
          Ensure that the given string renders as itself when evaluated.
protected  void assertTmplEquals(String expected, String template)
          Compare an expected string with the given loaded template
protected  void assureResultsDirectoryExists(String resultsDirectory)
          Assures that the results directory exists.
protected  String evaluate(String template)
          Evaluate the specified String as a template and return the result as a String.
protected  String getFileContents(String dir, String baseFileName, String ext)
           
protected  String getFileName(String dir, String base, String ext)
          Concatenates the file name parts together appropriately.
protected  String getFileName(String dir, String base, String ext, boolean mustExist)
           
protected  org.apache.velocity.runtime.resource.util.StringResourceRepository getStringRepository()
           
protected static String getTestCaseName(String s)
          Turns a base file name into a test case name.
protected  void info(String msg)
           
protected  void info(String msg, Throwable t)
           
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.
protected  void removeTemplate(String name)
           
protected  void setUp()
           
protected  void setUpContext(org.apache.velocity.VelocityContext context)
           
protected  void setUpEngine(org.apache.velocity.app.VelocityEngine engine)
           
 void tearDown()
           
 void testBase()
           
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, 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

engine

protected org.apache.velocity.app.VelocityEngine engine

context

protected org.apache.velocity.VelocityContext context

DEBUG

protected boolean DEBUG

log

protected TestLogChute log

stringRepoName

protected String stringRepoName
Constructor Detail

BaseTestCase

public BaseTestCase(String name)
Method Detail

setUp

protected void setUp()
              throws Exception
Overrides:
setUp in class junit.framework.TestCase
Throws:
Exception

setUpEngine

protected void setUpEngine(org.apache.velocity.app.VelocityEngine engine)

setUpContext

protected void setUpContext(org.apache.velocity.VelocityContext context)

getStringRepository

protected org.apache.velocity.runtime.resource.util.StringResourceRepository getStringRepository()

addTemplate

protected void addTemplate(String name,
                           String template)

removeTemplate

protected void removeTemplate(String name)

tearDown

public void tearDown()
Overrides:
tearDown in class junit.framework.TestCase

info

protected void info(String msg)

info

protected void info(String msg,
                    Throwable t)

testBase

public void testBase()

assertTmplEquals

protected void assertTmplEquals(String expected,
                                String template)
Compare an expected string with the given loaded template


assertContextValue

protected void assertContextValue(String key,
                                  Object expected)
Ensure that a context value is as expected.


assertEvalEquals

protected void assertEvalEquals(String expected,
                                String template)
Ensure that a template renders as expected.


assertSchmoo

protected void assertSchmoo(String templateIsExpected)
Ensure that the given string renders as itself when evaluated.


assertEvalException

protected Exception assertEvalException(String evil)
Ensure that an exception occurs when the string is evaluated.


assertEvalException

protected Exception assertEvalException(String evil,
                                        Class exceptionType)
Ensure that a specified type of exception occurs when evaluating the string.


assertEvalExceptionAt

protected Exception assertEvalExceptionAt(String evil,
                                          String template,
                                          int line,
                                          int col)
Ensure that the error message of the expected exception has the proper location info.


assertEvalExceptionAt

protected Exception assertEvalExceptionAt(String evil,
                                          int line,
                                          int col)
Only ensure that the error message of the expected exception has the proper line and column info.


evaluate

protected String evaluate(String template)
Evaluate the specified String as a template and return the result as a String.


getFileName

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

Returns:
The full path to the file.

getFileName

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

assureResultsDirectoryExists

protected 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-2010 The Apache Software Foundation. All Rights Reserved.