jon 01/03/11 16:31:18
Modified: src/java/org/apache/velocity/test ContextSafetyTestCase.java
IntrospectorTestCase.java TemplateTestCase.java
Added: src/java/org/apache/velocity/test TemplateTestBase.java
TemplateTestSuite.java
Removed: src/java/org/apache/velocity/test VelocityTestSuite.java
Log:
renamed VelocityTestSuite to TemplateTestSuite
removed BaseTestCase from most TestCases as it isn't needed
made ContextSafetyTestCase run on its own
created clean abstraction for the TemplateTestCase so that it is
known to run a single TTC...and TemplateTestSuite runs the whole
suite of tests
added a base interface class that is for holding static strings
Revision Changes Path
1.6 +22 -29
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ContextSafetyTestCase.java 2001/03/05 11:47:34 1.5
+++ ContextSafetyTestCase.java 2001/03/12 00:31:13 1.6
@@ -68,6 +68,7 @@
import org.apache.velocity.runtime.Runtime;
import org.apache.velocity.util.StringUtils;
+import junit.framework.TestCase;
/**
* Tests if we are context safe : can we switch objects in the context
@@ -80,46 +81,38 @@
* RuntimeTestCase causes the Runtime to be initialized twice.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: ContextSafetyTestCase.java,v 1.5 2001/03/05 11:47:34 jvanzyl Exp $
+ * @version $Id: ContextSafetyTestCase.java,v 1.6 2001/03/12 00:31:13 jon Exp $
*/
-public class ContextSafetyTestCase extends BaseTestCase
+public class ContextSafetyTestCase extends TestCase implements TemplateTestBase
{
- /**
- * VTL file extension.
- */
- private static final String TMPL_FILE_EXT = "vm";
-
- /**
- * Comparison file extension.
- */
- private static final String CMP_FILE_EXT = "cmp";
-
- /**
- * Comparison file extension.
- */
- private static final String RESULT_FILE_EXT = "res";
-
- /**
- * Results relative to the build directory.
- */
- private static final String RESULT_DIR = "../test/templates/results";
-
- /**
- * Results relative to the build directory.
- */
- private static final String COMPARE_DIR = "../test/templates/compare";
-
- ContextSafetyTestCase()
+ public ContextSafetyTestCase()
{
super("ContextSafetyTestCase");
+ try
+ {
+ Runtime.setDefaultProperties();
+ Runtime.setSourceProperty(
+ Runtime.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);
+ Runtime.init();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Cannot setup ContextSafetyTestCase!");
+ e.printStackTrace();
+ System.exit(1);
+ }
}
+ public static junit.framework.Test suite()
+ {
+ return new ContextSafetyTestCase();
+ }
+
/**
* Runs the test.
*/
public void runTest ()
{
-
/*
* make a Vector and String array because
* they are treated differently in Foreach()
1.6 +19 -16
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- IntrospectorTestCase.java 2001/03/05 11:47:37 1.5
+++ IntrospectorTestCase.java 2001/03/12 00:31:14 1.6
@@ -60,7 +60,7 @@
import org.apache.velocity.util.introspection.Introspector;
-import junit.framework.TestSuite;
+import junit.framework.TestCase;
/**
* Test case for the Velocity Introspector which uses
@@ -72,15 +72,20 @@
* for now.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
- * @version $Id: IntrospectorTestCase.java,v 1.5 2001/03/05 11:47:37 jvanzyl Exp $
+ * @version $Id: IntrospectorTestCase.java,v 1.6 2001/03/12 00:31:14 jon Exp $
*/
-public class IntrospectorTestCase extends BaseTestCase
+public class IntrospectorTestCase extends TestCase
{
private Method method;
private String result;
private String type;
private ArrayList failures = new ArrayList();
+ IntrospectorTestCase()
+ {
+ super("IntrospectorTestCase");
+ }
+
/**
* Creates a new instance.
*/
@@ -89,6 +94,17 @@
super(name);
}
+ /**
+ * Get the containing <code>TestSuite</code>. This is always
+ * <code>VelocityTestSuite</code>.
+ *
+ * @return The <code>TestSuite</code> to run.
+ */
+ public static junit.framework.Test suite ()
+ {
+ return new IntrospectorTestCase();
+ }
+
public void runTest()
{
MethodProvider mp = new MethodProvider();
@@ -192,19 +208,6 @@
{
e.printStackTrace();
}
- }
-
- /**
- * Get the containing <code>TestSuite</code>. This is always
- * <code>VelocityTestSuite</code>.
- *
- * @return The <code>TestSuite</code> to run.
- */
- public static junit.framework.Test suite ()
- {
- TestSuite suite = new TestSuite();
- suite.addTest(new IntrospectorTestCase("Introspector Tests"));
- return suite;
}
static class MethodProvider
1.24 +14 -28
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.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- TemplateTestCase.java 2001/03/05 11:47:41 1.23
+++ TemplateTestCase.java 2001/03/12 00:31:14 1.24
@@ -54,15 +54,19 @@
* <http://www.apache.org/>.
*/
+import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.HashMap;
+import java.util.Properties;
import java.util.Vector;
import org.apache.velocity.VelocityContext;
@@ -71,6 +75,8 @@
import org.apache.velocity.test.provider.TestProvider;
import org.apache.velocity.util.StringUtils;
+import junit.framework.TestCase;
+
/**
* Easily add test cases which evaluate templates and check their output.
*
@@ -94,36 +100,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
- * @version $Id: TemplateTestCase.java,v 1.23 2001/03/05 11:47:41 jvanzyl Exp $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
+ * @version $Id: TemplateTestCase.java,v 1.24 2001/03/12 00:31:14 jon Exp $
*/
-public class TemplateTestCase extends BaseTestCase
+public class TemplateTestCase extends TestCase implements TemplateTestBase
{
/**
- * VTL file extension.
- */
- private static final String TMPL_FILE_EXT = "vm";
-
- /**
- * Comparison file extension.
- */
- private static final String CMP_FILE_EXT = "cmp";
-
- /**
- * Comparison file extension.
- */
- private static final String RESULT_FILE_EXT = "res";
-
- /**
- * Results relative to the build directory.
- */
- private static final String RESULT_DIR = "../test/templates/results";
-
- /**
- * Results relative to the build directory.
- */
- private static final String COMPARE_DIR = "../test/templates/compare";
-
- /**
* The base file name of the template and comparison file (i.e. array for
* array.vm and array.cmp).
*/
@@ -149,6 +131,11 @@
this.baseFileName = baseFileName;
}
+ public static junit.framework.Test suite()
+ {
+ return new TemplateTestSuite();
+ }
+
/**
* Sets up the test.
*/
@@ -202,7 +189,6 @@
context2.put("iterator", vec.iterator());
context1.put("map", h );
context.put("obarr", oarr );
-
}
/**
1.1
jakarta-velocity/src/java/org/apache/velocity/test/TemplateTestBase.java
Index: TemplateTestBase.java
===================================================================
package org.apache.velocity.test;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
* @version $Id: TemplateTestBase.java,v 1.1 2001/03/12 00:31:14 jon Exp $
*/
public interface TemplateTestBase
{
/**
* VTL file extension.
*/
public final static String TMPL_FILE_EXT = "vm";
/**
* Comparison file extension.
*/
public final static String CMP_FILE_EXT = "cmp";
/**
* Comparison file extension.
*/
public final static String RESULT_FILE_EXT = "res";
/**
* Path for templates. This property will override the
* value in the default velocity properties file.
*/
public final static String FILE_RESOURCE_LOADER_PATH =
"../test/templates";
/**
* Properties file that lists which template tests to run.
*/
public final static String TEST_CASE_PROPERTIES =
FILE_RESOURCE_LOADER_PATH + "/templates.properties";
/**
* Results relative to the build directory.
*/
public final static String RESULT_DIR =
FILE_RESOURCE_LOADER_PATH + "/results";
/**
* Results relative to the build directory.
*/
public final static String COMPARE_DIR =
FILE_RESOURCE_LOADER_PATH + "/compare";
}
1.1
jakarta-velocity/src/java/org/apache/velocity/test/TemplateTestSuite.java
Index: TemplateTestSuite.java
===================================================================
package org.apache.velocity.test;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.IOException;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.util.Properties;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.velocity.runtime.Runtime;
import junit.framework.TestSuite;
/**
* Test suite for Templates.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Daniel Rall</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
* @version $Id: TemplateTestSuite.java,v 1.1 2001/03/12 00:31:15 jon Exp $
*/
public class TemplateTestSuite extends TestSuite implements TemplateTestBase
{
private Properties testProperties;
/**
* Creates an instace of the Apache Velocity test suite.
*/
public TemplateTestSuite()
{
try
{
Runtime.setDefaultProperties();
Runtime.setSourceProperty(
Runtime.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH);
Runtime.init();
testProperties = new Properties();
testProperties.load(new FileInputStream(TEST_CASE_PROPERTIES));
}
catch (Exception e)
{
System.err.println("Cannot setup VelocityTestSuite!");
e.printStackTrace();
System.exit(1);
}
addTemplateTestCases();
}
/**
* Adds the template test cases to run to this test suite. Template test
* cases are listed in the <code>TEST_CASE_PROPERTIES</code> file.
*/
private void addTemplateTestCases()
{
String template;
for (int i = 1 ;; i++)
{
template = testProperties.getProperty(getTemplateTestKey(i));
if (template != null)
{
System.out.println("Adding TemplateTestCase : " + template);
addTest(new TemplateTestCase(template));
}
else
{
// Assume we're done adding template test cases.
break;
}
}
}
/**
* Macro which returns the properties file key for the specified template
* test number.
*
* @param nbr The template test number to return a property key for.
* @return The property key.
*/
private static final String getTemplateTestKey(int nbr)
{
return ("test.template." + nbr);
}
}