dlr 00/10/22 17:16:42
Modified: src/java/org/apache/velocity/test TemplateTestCase.java
Log:
Easily allow the addition of template tests to the automated testing
framework. VelocityTest needs to be modified in light of the changes
to this class.
Revision Changes Path
1.3 +71 -6
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TemplateTestCase.java 2000/10/22 22:10:51 1.2
+++ TemplateTestCase.java 2000/10/23 00:16:42 1.3
@@ -62,25 +62,58 @@
import org.apache.velocity.io.FastWriter;
/**
- * Base functionality to be extended by all Apache Velocity test cases which
- * evaluate templates as part of their testing.
+ * Easily add test cases which evaluate templates and check their output.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
- * @version $Id: TemplateTestCase.java,v 1.2 2000/10/22 22:10:51 dlr Exp $
+ * @version $Id: TemplateTestCase.java,v 1.3 2000/10/23 00:16:42 dlr Exp $
*/
-public abstract class TemplateTestCase extends BaseTestCase
+public class TemplateTestCase extends BaseTestCase
{
/**
+ * VTL file extension.
+ */
+ private static final String TMPL_FILE_EXT = "vm";
+
+ /**
+ * Comparison file extension.
+ */
+ private static final String CMP_FILE_EXT = "cmp";
+
+ /**
+ * The base file name of the template and comparison file (i.e. array for
+ * array.vm and array.cmp).
+ */
+ protected String baseFileName;
+
+ /**
* The writer used to output evaluated templates.
*/
private FastWriter writer;
/**
* Creates a new instance.
+ *
+ * @param baseFileName The base name of the template and comparison file to
+ * use (i.e. array for array.vm and array.cmp).
+ */
+ public TemplateTestCase (String baseFileName)
+ {
+ super(getTestCaseName(baseFileName));
+ this.baseFileName = baseFileName;
+ }
+
+ /**
+ * Turns a base file name into a test case name.
+ *
+ * @param s The base file name.
+ * @return The test case name.
*/
- public TemplateTestCase (String name)
+ private static final String getTestCaseName (String s)
{
- super(name);
+ StringBuffer name = new StringBuffer();
+ name.append(Character.toTitleCase(s.charAt(0)));
+ name.append(s.substring(1, s.length()).toLowerCase());
+ return name.toString();
}
/**
@@ -91,6 +124,38 @@
public static junit.framework.Test suite ()
{
return BaseTestCase.suite();
+ }
+
+ /**
+ * 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
+ {
+ // TODO: Implement matching.
+ return true;
+ }
+
+ /**
+ * Runs the test.
+ */
+ public void runTest ()
+ {
+ try
+ {
+ if (!isMatch())
+ {
+ fail("Processed template did not match expected output");
+ }
+ }
+ catch (Exception e)
+ {
+ fail(e.getMessage());
+ }
}
/**