You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jv...@apache.org on 2001/03/19 23:39:00 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/test AnakiaTestCase.java ClasspathResourceTest.java ConfigurationTestCase.java ContextSafetyTestCase.java ExternalLoggerTest.java InlineScopeVMTestCase.java IntrospectorTestCase.java MethodInvocationExceptionTest.java MultipleFileResourcePathTest.java TemplateTestCase.java TexenTestCase.java VelocityAppTestCase.java
jvanzyl 01/03/19 14:39:00
Modified: src/java/org/apache/velocity/test AnakiaTestCase.java
ClasspathResourceTest.java
ConfigurationTestCase.java
ContextSafetyTestCase.java ExternalLoggerTest.java
InlineScopeVMTestCase.java
IntrospectorTestCase.java
MethodInvocationExceptionTest.java
MultipleFileResourcePathTest.java
TemplateTestCase.java TexenTestCase.java
VelocityAppTestCase.java
Log:
- making a base class test case to get rid of all the redundant
code
- made sure that the results directory exists for all tests that
produce output that needs to be verified.
Revision Changes Path
1.4 +5 -67 jakarta-velocity/src/java/org/apache/velocity/test/AnakiaTestCase.java
Index: AnakiaTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/AnakiaTestCase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AnakiaTestCase.java 2001/03/19 19:10:33 1.3
+++ AnakiaTestCase.java 2001/03/19 22:38:57 1.4
@@ -70,9 +70,9 @@
* first running Anakia and then running this test.
*
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
- * @version $Id: AnakiaTestCase.java,v 1.3 2001/03/19 19:10:33 jon Exp $
+ * @version $Id: AnakiaTestCase.java,v 1.4 2001/03/19 22:38:57 jvanzyl Exp $
*/
-public class AnakiaTestCase extends TestCase
+public class AnakiaTestCase extends BaseTestCase
{
private static final String COMPARE_DIR = "../test/anakia/compare";
private static final String RESULTS_DIR = "../test/anakia/results";
@@ -93,13 +93,6 @@
}
/**
- * Sets up the test.
- */
- protected void setUp ()
- {
- }
-
- /**
* Runs the test. This is empty on purpose because the
* code to do the Anakia output is in the .xml file that runs
* this test.
@@ -108,7 +101,9 @@
{
try
{
- if (!isMatch())
+ assureResultsDirectoryExists(RESULTS_DIR);
+
+ if (!isMatch(RESULTS_DIR,COMPARE_DIR,"index",FILE_EXT,FILE_EXT))
{
fail("Output is incorrect!");
}
@@ -123,62 +118,5 @@
* do nothing.
*/
}
- }
-
- /**
- * Concatenates the file name parts together appropriately.
- *
- * @return The full path to the file.
- */
- private static String getFileName (String dir, String base, String ext)
- {
- StringBuffer buf = new StringBuffer();
- if (dir != null)
- {
- buf.append(dir).append('/');
- }
- buf.append(base).append('.').append(ext);
- return buf.toString();
- }
-
- /**
- * Turns a base file name into a test case name.
- *
- * @param s The base file name.
- * @return The test case name.
- */
- private static final String getTestCaseName (String s)
- {
- StringBuffer name = new StringBuffer();
- name.append(Character.toTitleCase(s.charAt(0)));
- name.append(s.substring(1, s.length()).toLowerCase());
- return name.toString();
- }
-
- /**
- * Returns whether the processed template matches the content of the
- * provided comparison file.
- *
- * @return Whether the output matches the contents of the comparison file.
- *
- * @exception Exception Test failure condition.
- */
- protected boolean isMatch () throws Exception
- {
- String result = StringUtils.fileContentsToString
- (getFileName(RESULTS_DIR, "index", FILE_EXT));
-
- String compare = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, "index", FILE_EXT));
-
- return result.equals(compare);
- }
-
- /**
- * Performs cleanup activities for this test case.
- */
- protected void tearDown () throws Exception
- {
- /* No op. */
}
}
1.5 +11 -94 jakarta-velocity/src/java/org/apache/velocity/test/ClasspathResourceTest.java
Index: ClasspathResourceTest.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/ClasspathResourceTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ClasspathResourceTest.java 2001/03/19 15:37:57 1.4
+++ ClasspathResourceTest.java 2001/03/19 22:38:57 1.5
@@ -77,9 +77,9 @@
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
* @author <a href="mailto:daveb@miceda-data.com">Dave Bryson</a>
- * @version $Id: ClasspathResourceTest.java,v 1.4 2001/03/19 15:37:57 geirm Exp $
+ * @version $Id: ClasspathResourceTest.java,v 1.5 2001/03/19 22:38:57 jvanzyl Exp $
*/
-public class ClasspathResourceTest extends TestCase
+public class ClasspathResourceTest extends BaseTestCase
{
/**
* VTL file extension.
@@ -99,7 +99,7 @@
/**
* Results relative to the build directory.
*/
- private static final String RESULT_DIR = "../test/cpload/results";
+ private static final String RESULTS_DIR = "../test/cpload/results";
/**
* Results relative to the build directory.
@@ -115,6 +115,8 @@
try
{
+ assureResultsDirectoryExists(RESULTS_DIR);
+
Velocity.setProperty(Velocity.RESOURCE_LOADER, "classpath");
/*
@@ -158,7 +160,7 @@
/*
* lets ensure the results directory exists
*/
- assureResultsDirectoryExists();
+ assureResultsDirectoryExists(RESULTS_DIR);
Template template1 = Runtime.getTemplate(
getFileName(null, "template/test1", TMPL_FILE_EXT));
@@ -168,11 +170,11 @@
FileOutputStream fos1 =
new FileOutputStream (
- getFileName(RESULT_DIR, "test1", RESULT_FILE_EXT));
+ getFileName(RESULTS_DIR, "test1", RESULT_FILE_EXT));
FileOutputStream fos2 =
new FileOutputStream (
- getFileName(RESULT_DIR, "test2", RESULT_FILE_EXT));
+ getFileName(RESULTS_DIR, "test2", RESULT_FILE_EXT));
Writer writer1 = new BufferedWriter(new OutputStreamWriter(fos1));
Writer writer2 = new BufferedWriter(new OutputStreamWriter(fos2));
@@ -191,100 +193,15 @@
writer2.flush();
writer2.close();
- if (!isOutputCorrect())
+ if (!isMatch(RESULTS_DIR,COMPARE_DIR,"test1",RESULT_FILE_EXT,CMP_FILE_EXT) ||
+ !isMatch(RESULTS_DIR,COMPARE_DIR,"test2",RESULT_FILE_EXT,CMP_FILE_EXT))
{
- fail("Output incorrect.");
+ fail("Output is incorrect!");
}
}
catch (Exception e)
{
fail(e.getMessage());
}
- }
-
- /**
- * Assures that the results directory exists. If the results directory
- * cannot be created, fails the test.
- */
- private static void assureResultsDirectoryExists ()
- {
- File resultDir = new File(RESULT_DIR);
- if (!resultDir.exists())
- {
- Runtime.info("Results directory does not exist (" + RESULT_DIR + ")");
- if (resultDir.mkdirs())
- {
- Runtime.info("Created results directory" + RESULT_DIR);
- }
- else
- {
- String errMsg = "Unable to create results directory" + RESULT_DIR;
- Runtime.warn(errMsg);
- fail(errMsg);
- }
- }
- }
-
- /**
- * Concatenates the file name parts together appropriately.
- *
- * @return The full path to the file.
- */
- private static String getFileName (String dir, String base, String ext)
- {
- StringBuffer buf = new StringBuffer();
- if (dir != null)
- {
- buf.append(dir).append('/');
- }
- buf.append(base).append('.').append(ext);
- return buf.toString();
- }
-
- /**
- * Turns a base file name into a test case name.
- *
- * @param s The base file name.
- * @return The test case name.
- */
- private static final String getTestCaseName (String s)
- {
- StringBuffer name = new StringBuffer();
- name.append(Character.toTitleCase(s.charAt(0)));
- name.append(s.substring(1, s.length()).toLowerCase());
- return name.toString();
- }
-
- /**
- * Returns whether the processed template matches the content of the
- * provided comparison file.
- *
- * @return Whether the output matches the contents of the comparison file.
- *
- * @exception Exception Test failure condition.
- */
- protected boolean isOutputCorrect() throws Exception
- {
- String result1 = StringUtils.fileContentsToString
- (getFileName(RESULT_DIR, "test1", RESULT_FILE_EXT));
-
- String compare1 = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, "test1", CMP_FILE_EXT));
-
- String result2 = StringUtils.fileContentsToString
- (getFileName(RESULT_DIR, "test2", RESULT_FILE_EXT));
-
- String compare2 = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, "test2", CMP_FILE_EXT));
-
- return ( result1.equals(compare1) && result2.equals(compare2));
- }
-
- /**
- * Performs cleanup activities for this test case.
- */
- protected void tearDown () throws Exception
- {
- // No op.
}
}
1.2 +5 -47 jakarta-velocity/src/java/org/apache/velocity/test/ConfigurationTestCase.java
Index: ConfigurationTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/ConfigurationTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ConfigurationTestCase.java 2001/03/17 19:00:30 1.1
+++ ConfigurationTestCase.java 2001/03/19 22:38:57 1.2
@@ -70,9 +70,9 @@
* Tests for the Configuration class.
*
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: ConfigurationTestCase.java,v 1.1 2001/03/17 19:00:30 jvanzyl Exp $
+ * @version $Id: ConfigurationTestCase.java,v 1.2 2001/03/19 22:38:57 jvanzyl Exp $
*/
-public class ConfigurationTestCase extends TestCase
+public class ConfigurationTestCase extends BaseTestCase
{
/**
* Comparison directory.
@@ -113,6 +113,8 @@
{
try
{
+ assureResultsDirectoryExists(RESULTS_DIR);
+
Configuration c = new Configuration(TEST_CONFIG);
FileWriter result = new FileWriter(
@@ -166,7 +168,7 @@
result.flush();
result.close();
- if (!isMatch())
+ if (!isMatch(RESULTS_DIR, COMPARE_DIR, "output","res","cmp"))
{
fail("Output incorrect.");
}
@@ -208,49 +210,5 @@
result.write(message + "\n");
result.write("--------------------------------------------------\n");
result.write("\n");
- }
-
- /**
- * Concatenates the file name parts together appropriately.
- *
- * @return The full path to the file.
- */
- private static String getFileName (String dir, String base, String ext)
- {
- StringBuffer buf = new StringBuffer();
- if (dir != null)
- {
- buf.append(dir).append('/');
- }
- buf.append(base).append('.').append(ext);
-
- return buf.toString();
- }
-
- /**
- * Returns whether the processed template matches the content of the
- * provided comparison file.
- *
- * @return Whether the output matches the contents of the comparison file.
- *
- * @exception Exception Test failure condition.
- */
- protected boolean isMatch () throws Exception
- {
- String result = StringUtils.fileContentsToString
- (getFileName(RESULTS_DIR, "output", "res"));
-
- String compare = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, "output", "cmp"));
-
- return result.equals(compare);
- }
-
- /**
- * Performs cleanup activities for this test case.
- */
- protected void tearDown () throws Exception
- {
- /* No op. */
}
}
1.8 +8 -66 jakarta-velocity/src/java/org/apache/velocity/test/ContextSafetyTestCase.java
Index: ContextSafetyTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/ContextSafetyTestCase.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ContextSafetyTestCase.java 2001/03/14 22:05:18 1.7
+++ ContextSafetyTestCase.java 2001/03/19 22:38:57 1.8
@@ -82,9 +82,9 @@
* RuntimeTestCase causes the Runtime to be initialized twice.
*
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
- * @version $Id: ContextSafetyTestCase.java,v 1.7 2001/03/14 22:05:18 jvanzyl Exp $
+ * @version $Id: ContextSafetyTestCase.java,v 1.8 2001/03/19 22:38:57 jvanzyl Exp $
*/
-public class ContextSafetyTestCase extends TestCase implements TemplateTestBase
+public class ContextSafetyTestCase extends BaseTestCase implements TemplateTestBase
{
public ContextSafetyTestCase()
{
@@ -135,6 +135,8 @@
try
{
+ assureResultsDirectoryExists(RESULT_DIR);
+
/*
* get the template and the output
*/
@@ -171,7 +173,10 @@
writer2.flush();
writer2.close();
- if (!isOutputCorrect())
+ if (!isMatch(RESULT_DIR,COMPARE_DIR,"context_safety1",
+ RESULT_FILE_EXT,CMP_FILE_EXT) ||
+ !isMatch(RESULT_DIR,COMPARE_DIR,"context_safety2",
+ RESULT_FILE_EXT,CMP_FILE_EXT))
{
fail("Output incorrect.");
}
@@ -180,68 +185,5 @@
{
fail(e.getMessage());
}
- }
-
- /**
- * Concatenates the file name parts together appropriately.
- *
- * @return The full path to the file.
- */
- private static String getFileName (String dir, String base, String ext)
- {
- StringBuffer buf = new StringBuffer();
- if (dir != null)
- {
- buf.append(dir).append('/');
- }
- buf.append(base).append('.').append(ext);
- return buf.toString();
- }
-
- /**
- * Turns a base file name into a test case name.
- *
- * @param s The base file name.
- * @return The test case name.
- */
- private static final String getTestCaseName (String s)
- {
- StringBuffer name = new StringBuffer();
- name.append(Character.toTitleCase(s.charAt(0)));
- name.append(s.substring(1, s.length()).toLowerCase());
- return name.toString();
- }
-
- /**
- * Returns whether the processed template matches the content of the
- * provided comparison file.
- *
- * @return Whether the output matches the contents of the comparison file.
- *
- * @exception Exception Test failure condition.
- */
- protected boolean isOutputCorrect() throws Exception
- {
- String result1 = StringUtils.fileContentsToString
- (getFileName(RESULT_DIR, "context_safety1", RESULT_FILE_EXT));
-
- String compare1 = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, "context_safety1", CMP_FILE_EXT));
-
- String result2 = StringUtils.fileContentsToString
- (getFileName(RESULT_DIR, "context_safety2", RESULT_FILE_EXT));
-
- String compare2 = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, "context_safety2", CMP_FILE_EXT));
-
- return ( result1.equals(compare1) && result2.equals(compare2));
- }
-
- /**
- * Performs cleanup activities for this test case.
- */
- protected void tearDown () throws Exception
- {
- // No op.
}
}
1.2 +1 -9 jakarta-velocity/src/java/org/apache/velocity/test/ExternalLoggerTest.java
Index: ExternalLoggerTest.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/ExternalLoggerTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExternalLoggerTest.java 2001/03/19 05:08:16 1.1
+++ ExternalLoggerTest.java 2001/03/19 22:38:57 1.2
@@ -64,7 +64,7 @@
* Tests if we can hand Velocity an arbitrary class for logging.
*
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
- * @version $Id: ExternalLoggerTest.java,v 1.1 2001/03/19 05:08:16 geirm Exp $
+ * @version $Id: ExternalLoggerTest.java,v 1.2 2001/03/19 22:38:57 jvanzyl Exp $
*/
public class ExternalLoggerTest extends TestCase implements LogSystem
{
@@ -123,13 +123,5 @@
public void logVelocityMessage(int level, String message)
{
logString = message;
- }
-
- /**
- * Performs cleanup activities for this test case.
- */
- protected void tearDown () throws Exception
- {
- // No op.
}
}
1.10 +8 -66 jakarta-velocity/src/java/org/apache/velocity/test/InlineScopeVMTestCase.java
Index: InlineScopeVMTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/InlineScopeVMTestCase.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- InlineScopeVMTestCase.java 2001/03/14 22:05:19 1.9
+++ InlineScopeVMTestCase.java 2001/03/19 22:38:57 1.10
@@ -77,9 +77,9 @@
*
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
* @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
- * @version $Id: InlineScopeVMTestCase.java,v 1.9 2001/03/14 22:05:19 jvanzyl Exp $
+ * @version $Id: InlineScopeVMTestCase.java,v 1.10 2001/03/19 22:38:57 jvanzyl Exp $
*/
-public class InlineScopeVMTestCase extends TestCase implements TemplateTestBase
+public class InlineScopeVMTestCase extends BaseTestCase implements TemplateTestBase
{
/**
* The name of this test case.
@@ -127,6 +127,8 @@
{
try
{
+ assureResultsDirectoryExists(RESULT_DIR);
+
/*
* Get the template and the output. Do them backwards.
* vm_test2 uses a local VM and vm_test1 doesn't
@@ -163,7 +165,10 @@
writer2.flush();
writer2.close();
- if (!isOutputCorrect())
+ if (!isMatch(RESULT_DIR,COMPARE_DIR,"vm_test1",
+ RESULT_FILE_EXT,CMP_FILE_EXT) ||
+ !isMatch(RESULT_DIR,COMPARE_DIR,"vm_test2",
+ RESULT_FILE_EXT,CMP_FILE_EXT))
{
fail("Output incorrect.");
}
@@ -172,68 +177,5 @@
{
fail(e.getMessage());
}
- }
-
- /**
- * Concatenates the file name parts together appropriately.
- *
- * @return The full path to the file.
- */
- private static String getFileName (String dir, String base, String ext)
- {
- StringBuffer buf = new StringBuffer();
- if (dir != null)
- {
- buf.append(dir).append('/');
- }
- buf.append(base).append('.').append(ext);
- return buf.toString();
- }
-
- /**
- * Turns a base file name into a test case name.
- *
- * @param s The base file name.
- * @return The test case name.
- */
- private static final String getTestCaseName (String s)
- {
- StringBuffer name = new StringBuffer();
- name.append(Character.toTitleCase(s.charAt(0)));
- name.append(s.substring(1, s.length()).toLowerCase());
- return name.toString();
- }
-
- /**
- * Returns whether the processed template matches the content of the
- * provided comparison file.
- *
- * @return Whether the output matches the contents of the comparison file.
- *
- * @exception Exception Test failure condition.
- */
- protected boolean isOutputCorrect() throws Exception
- {
- String result1 = StringUtils.fileContentsToString
- (getFileName(RESULT_DIR, "vm_test1", RESULT_FILE_EXT));
-
- String compare1 = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, "vm_test1", CMP_FILE_EXT));
-
- String result2 = StringUtils.fileContentsToString
- (getFileName(RESULT_DIR, "vm_test2", RESULT_FILE_EXT));
-
- String compare2 = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, "vm_test2", CMP_FILE_EXT));
-
- return ( result1.equals(compare1) && result2.equals(compare2));
- }
-
- /**
- * Performs cleanup activities for this test case.
- */
- protected void tearDown () throws Exception
- {
- // No op.
}
}
1.7 +2 -2 jakarta-velocity/src/java/org/apache/velocity/test/IntrospectorTestCase.java
Index: IntrospectorTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/IntrospectorTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- IntrospectorTestCase.java 2001/03/12 00:31:14 1.6
+++ IntrospectorTestCase.java 2001/03/19 22:38:57 1.7
@@ -72,9 +72,9 @@
* for now.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: IntrospectorTestCase.java,v 1.6 2001/03/12 00:31:14 jon Exp $
+ * @version $Id: IntrospectorTestCase.java,v 1.7 2001/03/19 22:38:57 jvanzyl Exp $
*/
-public class IntrospectorTestCase extends TestCase
+public class IntrospectorTestCase extends BaseTestCase
{
private Method method;
private String result;
1.2 +1 -9 jakarta-velocity/src/java/org/apache/velocity/test/MethodInvocationExceptionTest.java
Index: MethodInvocationExceptionTest.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/MethodInvocationExceptionTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MethodInvocationExceptionTest.java 2001/03/19 17:10:01 1.1
+++ MethodInvocationExceptionTest.java 2001/03/19 22:38:58 1.2
@@ -69,7 +69,7 @@
* Tests if we can hand Velocity an arbitrary class for logging.
*
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
- * @version $Id: MethodInvocationExceptionTest.java,v 1.1 2001/03/19 17:10:01 geirm Exp $
+ * @version $Id: MethodInvocationExceptionTest.java,v 1.2 2001/03/19 22:38:58 jvanzyl Exp $
*/
public class MethodInvocationExceptionTest extends TestCase
{
@@ -148,13 +148,5 @@
{
System.out.println("DooException");
throw new NullPointerException();
- }
-
- /**
- * Performs cleanup activities for this test case.
- */
- protected void tearDown () throws Exception
- {
- // No op.
}
}
1.5 +10 -92 jakarta-velocity/src/java/org/apache/velocity/test/MultipleFileResourcePathTest.java
Index: MultipleFileResourcePathTest.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/MultipleFileResourcePathTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MultipleFileResourcePathTest.java 2001/03/19 15:37:57 1.4
+++ MultipleFileResourcePathTest.java 2001/03/19 22:38:58 1.5
@@ -77,9 +77,9 @@
* Multiple paths in the file resource loader.
*
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
- * @version $Id: MultipleFileResourcePathTest.java,v 1.4 2001/03/19 15:37:57 geirm Exp $
+ * @version $Id: MultipleFileResourcePathTest.java,v 1.5 2001/03/19 22:38:58 jvanzyl Exp $
*/
-public class MultipleFileResourcePathTest extends TestCase
+public class MultipleFileResourcePathTest extends BaseTestCase
{
/**
* VTL file extension.
@@ -111,7 +111,7 @@
/**
* Results relative to the build directory.
*/
- private static final String RESULT_DIR = "../test/multi/results";
+ private static final String RESULTS_DIR = "../test/multi/results";
/**
* Results relative to the build directory.
@@ -127,7 +127,7 @@
try
{
- assureResultsDirectoryExists();
+ assureResultsDirectoryExists(RESULTS_DIR);
Velocity.setProperty(
Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH1);
@@ -165,11 +165,11 @@
FileOutputStream fos1 =
new FileOutputStream (
- getFileName(RESULT_DIR, "path1", RESULT_FILE_EXT));
+ getFileName(RESULTS_DIR, "path1", RESULT_FILE_EXT));
FileOutputStream fos2 =
new FileOutputStream (
- getFileName(RESULT_DIR, "path2", RESULT_FILE_EXT));
+ getFileName(RESULTS_DIR, "path2", RESULT_FILE_EXT));
Writer writer1 = new BufferedWriter(new OutputStreamWriter(fos1));
Writer writer2 = new BufferedWriter(new OutputStreamWriter(fos2));
@@ -188,7 +188,10 @@
writer2.flush();
writer2.close();
- if (!isOutputCorrect())
+ if (!isMatch(RESULTS_DIR, COMPARE_DIR, "path1",
+ RESULT_FILE_EXT, CMP_FILE_EXT) ||
+ !isMatch(RESULTS_DIR, COMPARE_DIR, "path2",
+ RESULT_FILE_EXT, CMP_FILE_EXT))
{
fail("Output incorrect.");
}
@@ -197,90 +200,5 @@
{
fail(e.getMessage());
}
- }
-
- /**
- * Assures that the results directory exists. If the results directory
- * cannot be created, fails the test.
- */
- private static void assureResultsDirectoryExists()
- {
- File resultDir = new File(RESULT_DIR);
- if (!resultDir.exists())
- {
- Runtime.info("Results directory does not exist (" + RESULT_DIR + ")");
- if (resultDir.mkdirs())
- {
- Runtime.info("Created results directory" + RESULT_DIR);
- }
- else
- {
- String errMsg = "Unable to create results directory" + RESULT_DIR;
- Runtime.warn(errMsg);
- fail(errMsg);
- }
- }
- }
- /**
- * Concatenates the file name parts together appropriately.
- *
- * @return The full path to the file.
- */
- private static String getFileName (String dir, String base, String ext)
- {
- StringBuffer buf = new StringBuffer();
- if (dir != null)
- {
- buf.append(dir).append('/');
- }
- buf.append(base).append('.').append(ext);
- return buf.toString();
- }
-
- /**
- * Turns a base file name into a test case name.
- *
- * @param s The base file name.
- * @return The test case name.
- */
- private static final String getTestCaseName (String s)
- {
- StringBuffer name = new StringBuffer();
- name.append(Character.toTitleCase(s.charAt(0)));
- name.append(s.substring(1, s.length()).toLowerCase());
- return name.toString();
- }
-
- /**
- * Returns whether the processed template matches the content of the
- * provided comparison file.
- *
- * @return Whether the output matches the contents of the comparison file.
- *
- * @exception Exception Test failure condition.
- */
- protected boolean isOutputCorrect() throws Exception
- {
- String result1 = StringUtils.fileContentsToString
- (getFileName(RESULT_DIR, "path1", RESULT_FILE_EXT));
-
- String compare1 = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, "path1", CMP_FILE_EXT));
-
- String result2 = StringUtils.fileContentsToString
- (getFileName(RESULT_DIR, "path2", RESULT_FILE_EXT));
-
- String compare2 = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, "path2", CMP_FILE_EXT));
-
- return ( result1.equals(compare1) && result2.equals(compare2));
- }
-
- /**
- * Performs cleanup activities for this test case.
- */
- protected void tearDown () throws Exception
- {
- // No op.
}
}
1.29 +5 -84 jakarta-velocity/src/java/org/apache/velocity/test/TemplateTestCase.java
Index: TemplateTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/TemplateTestCase.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- TemplateTestCase.java 2001/03/13 02:23:09 1.28
+++ TemplateTestCase.java 2001/03/19 22:38:58 1.29
@@ -99,9 +99,9 @@
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
- * @version $Id: TemplateTestCase.java,v 1.28 2001/03/13 02:23:09 dlr Exp $
+ * @version $Id: TemplateTestCase.java,v 1.29 2001/03/19 22:38:58 jvanzyl Exp $
*/
-public class TemplateTestCase extends TestCase implements TemplateTestBase
+public class TemplateTestCase extends BaseTestCase implements TemplateTestBase
{
/**
* The base file name of the template and comparison file (i.e. array for
@@ -203,7 +203,7 @@
Template template = Runtime.getTemplate
(getFileName(null, baseFileName, TMPL_FILE_EXT));
- assureResultsDirectoryExists();
+ assureResultsDirectoryExists(RESULT_DIR);
/* get the file to write to */
FileOutputStream fos =
@@ -219,7 +219,8 @@
writer.flush();
writer.close();
- if (!isMatch())
+ if (!isMatch(RESULT_DIR,COMPARE_DIR,baseFileName,
+ RESULT_FILE_EXT,CMP_FILE_EXT))
{
fail("Processed template did not match expected output");
}
@@ -228,85 +229,5 @@
{
fail(e.getMessage());
}
- }
-
- /**
- * Concatenates the file name parts together appropriately.
- *
- * @return The full path to the file.
- */
- private static String getFileName (String dir, String base, String ext)
- {
- StringBuffer buf = new StringBuffer();
- if (dir != null)
- {
- buf.append(dir).append('/');
- }
- buf.append(base).append('.').append(ext);
- return buf.toString();
- }
-
- /**
- * Assures that the results directory exists. If the results directory
- * cannot be created, fails the test.
- */
- private static void assureResultsDirectoryExists ()
- {
- File resultDir = new File(RESULT_DIR);
- if (!resultDir.exists())
- {
- Runtime.info("Template results directory does not exist");
- if (resultDir.mkdirs())
- {
- Runtime.info("Created template results directory");
- }
- else
- {
- String errMsg = "Unable to create template results directory";
- Runtime.warn(errMsg);
- fail(errMsg);
- }
- }
- }
-
- /**
- * Turns a base file name into a test case name.
- *
- * @param s The base file name.
- * @return The test case name.
- */
- private static final String getTestCaseName (String s)
- {
- StringBuffer name = new StringBuffer();
- name.append(Character.toTitleCase(s.charAt(0)));
- name.append(s.substring(1, s.length()).toLowerCase());
- return name.toString();
- }
-
- /**
- * Returns whether the processed template matches the content of the
- * provided comparison file.
- *
- * @return Whether the output matches the contents of the comparison file.
- *
- * @exception Exception Test failure condition.
- */
- protected boolean isMatch () throws Exception
- {
- String result = StringUtils.fileContentsToString
- (getFileName(RESULT_DIR, baseFileName, RESULT_FILE_EXT));
-
- String compare = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, baseFileName, CMP_FILE_EXT));
-
- return result.equals(compare);
- }
-
- /**
- * Performs cleanup activities for this test case.
- */
- protected void tearDown () throws Exception
- {
- /* No op. */
}
}
1.2 +12 -67 jakarta-velocity/src/java/org/apache/velocity/test/TexenTestCase.java
Index: TexenTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/TexenTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TexenTestCase.java 2001/03/19 06:36:31 1.1
+++ TexenTestCase.java 2001/03/19 22:38:58 1.2
@@ -69,21 +69,21 @@
* generative task and compares the output.
*
* @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
- * @version $Id: TexenTestCase.java,v 1.1 2001/03/19 06:36:31 jvanzyl Exp $
+ * @version $Id: TexenTestCase.java,v 1.2 2001/03/19 22:38:58 jvanzyl Exp $
*/
-public class TexenTestCase extends TestCase
+public class TexenTestCase extends BaseTestCase
{
/**
- * Directory where comparison output is stored.
- */
- private static final String COMPARE_DIR = "../test/texen/compare";
-
- /**
* Directory where results are generated.
*/
private static final String RESULTS_DIR = "../test/texen/results";
/**
+ * Directory where comparison output is stored.
+ */
+ private static final String COMPARE_DIR = "../test/texen/compare";
+
+ /**
* Creates a new instance.
*
*/
@@ -111,9 +111,11 @@
{
try
{
- if (!isMatch("TurbineWeather") ||
- !isMatch("TurbineWeatherService") ||
- !isMatch("WeatherService"))
+ assureResultsDirectoryExists(RESULTS_DIR);
+
+ if (!isMatch(RESULTS_DIR,COMPARE_DIR,"TurbineWeather","java","java") ||
+ !isMatch(RESULTS_DIR,COMPARE_DIR,"TurbineWeatherService","java","java") ||
+ !isMatch(RESULTS_DIR,COMPARE_DIR,"WeatherService","java","java"))
{
fail("Output is incorrect!");
}
@@ -124,62 +126,5 @@
* do nothing.
*/
}
- }
-
- /**
- * Concatenates the file name parts together appropriately.
- *
- * @return The full path to the file.
- */
- private static String getFileName (String dir, String base, String ext)
- {
- StringBuffer buf = new StringBuffer();
- if (dir != null)
- {
- buf.append(dir).append('/');
- }
- buf.append(base).append('.').append(ext);
- return buf.toString();
- }
-
- /**
- * Turns a base file name into a test case name.
- *
- * @param s The base file name.
- * @return The test case name.
- */
- private static final String getTestCaseName (String s)
- {
- StringBuffer name = new StringBuffer();
- name.append(Character.toTitleCase(s.charAt(0)));
- name.append(s.substring(1, s.length()).toLowerCase());
- return name.toString();
- }
-
- /**
- * Returns whether the processed template matches the content of the
- * provided comparison file.
- *
- * @return Whether the output matches the contents of the comparison file.
- *
- * @exception Exception Test failure condition.
- */
- protected boolean isMatch (String file) throws Exception
- {
- String result = StringUtils.fileContentsToString
- (getFileName(RESULTS_DIR, file, "java"));
-
- String compare = StringUtils.fileContentsToString
- (getFileName(COMPARE_DIR, file, "java"));
-
- return result.equals(compare);
- }
-
- /**
- * Performs cleanup activities for this test case.
- */
- protected void tearDown () throws Exception
- {
- /* No op. */
}
}
1.3 +3 -54 jakarta-velocity/src/java/org/apache/velocity/test/VelocityAppTestCase.java
Index: VelocityAppTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/test/VelocityAppTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- VelocityAppTestCase.java 2001/03/14 22:05:23 1.2
+++ VelocityAppTestCase.java 2001/03/19 22:38:58 1.3
@@ -77,9 +77,9 @@
*
* @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
* @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
- * @version $Id: VelocityAppTestCase.java,v 1.2 2001/03/14 22:05:23 jvanzyl Exp $
+ * @version $Id: VelocityAppTestCase.java,v 1.3 2001/03/19 22:38:58 jvanzyl Exp $
*/
-public class VelocityAppTestCase extends TestCase implements TemplateTestBase
+public class VelocityAppTestCase extends BaseTestCase implements TemplateTestBase
{
private StringWriter compare1 = new StringWriter();
private String input1 = "My name is $name -> $Floog";
@@ -132,7 +132,7 @@
Velocity.invokeVelocimacro("floog", "test", new String[2],
context, result3);
*/
- if (!isOutputCorrect())
+ if (!result1.equals(compare1.toString()))
{
fail("Output incorrect.");
}
@@ -141,56 +141,5 @@
{
fail(e.getMessage());
}
- }
-
- /**
- * Returns whether the processed template matches the content of the
- * provided comparison file.
- *
- * @return Whether the output matches the contents of the comparison file.
- *
- * @exception Exception Test failure condition.
- */
- protected boolean isOutputCorrect() throws Exception
- {
- return ( result1.equals(compare1.toString()));
- }
-
- /**
- * Concatenates the file name parts together appropriately.
- *
- * @return The full path to the file.
- */
- private static String getFileName (String dir, String base, String ext)
- {
- StringBuffer buf = new StringBuffer();
- if (dir != null)
- {
- buf.append(dir).append('/');
- }
- buf.append(base).append('.').append(ext);
- return buf.toString();
- }
-
- /**
- * Turns a base file name into a test case name.
- *
- * @param s The base file name.
- * @return The test case name.
- */
- private static final String getTestCaseName (String s)
- {
- StringBuffer name = new StringBuffer();
- name.append(Character.toTitleCase(s.charAt(0)));
- name.append(s.substring(1, s.length()).toLowerCase());
- return name.toString();
- }
-
- /**
- * Performs cleanup activities for this test case.
- */
- protected void tearDown () throws Exception
- {
- // No op.
}
}