Author: wglass
Date: Sun Jan 29 20:44:01 2006
New Revision: 373432

URL: http://svn.apache.org/viewcvs?rev=373432&view=rev
Log:
test case for VELOCITY-95, VELOCITY-96

Added:
    
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/IncludeErrorTestCase.java
   (with props)
    jakarta/velocity/engine/trunk/test/includeerror/
    jakarta/velocity/engine/trunk/test/includeerror/haserror.txt   (with props)
    jakarta/velocity/engine/trunk/test/includeerror/haserror2.txt   (with props)
    jakarta/velocity/engine/trunk/test/includeerror/missinginclude.vm   (with 
props)
    jakarta/velocity/engine/trunk/test/includeerror/missingparse.vm   (with 
props)
    jakarta/velocity/engine/trunk/test/includeerror/parsemain.vm   (with props)
    jakarta/velocity/engine/trunk/test/includeerror/parsemain2.vm   (with props)

Added: 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/IncludeErrorTestCase.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/IncludeErrorTestCase.java?rev=373432&view=auto
==============================================================================
--- 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/IncludeErrorTestCase.java
 (added)
+++ 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/IncludeErrorTestCase.java
 Sun Jan 29 20:44:01 2006
@@ -0,0 +1,120 @@
+package org.apache.velocity.test;
+
+import java.io.StringWriter;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.context.Context;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/**
+ * Test that #parse and #include pass errors to calling code.
+ * Specifically checking against VELOCITY-95 and VELOCITY-96.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Will Glass-Husain</a>
+ * @version $Id$
+ */
+public class IncludeErrorTestCase extends BaseTestCase implements 
TemplateTestBase
+{
+    VelocityEngine ve;
+    
+    /**
+     * Default constructor.
+     */
+    public IncludeErrorTestCase(String name)
+    {
+        super(name);
+    }
+    
+    public static Test suite ()
+    {
+        return new TestSuite(IncludeErrorTestCase.class);
+    }
+
+    public void setUp() throws Exception
+    {
+        ve = new VelocityEngine();
+        ve.setProperty(
+                Velocity.FILE_RESOURCE_LOADER_PATH, "test/includeerror");
+
+        ve.init();
+    }
+
+
+
+    public void testMissingParseError() throws Exception 
+    {
+        checkException("missingparse.vm",ResourceNotFoundException.class);
+    }
+
+    public void testMissingIncludeError() throws Exception 
+    {
+        checkException("missinginclude.vm",ResourceNotFoundException.class);
+    }
+
+    public void testParseError() throws Exception 
+    {
+        checkException("parsemain.vm",ParseErrorException.class);
+    }
+    
+    public void testParseError2() throws Exception 
+    {
+        checkException("parsemain2.vm",ParseErrorException.class);
+    }
+    
+    
+    /**
+     * Check that an exception is thrown for the given template
+     * @param templateName
+     * @param exceptionClass
+     * @throws Exception
+     */
+    private void checkException(String templateName,Class exceptionClass)
+    throws Exception
+    {
+        Context context = new VelocityContext();
+        StringWriter writer = new StringWriter();
+        Template template = ve.getTemplate(templateName, "UTF-8");
+
+        try 
+        {
+            template.merge(context, writer);
+            writer.flush();
+            fail("File should have thrown an exception");
+        } 
+        catch (Exception E) 
+        {
+            assertTrue(exceptionClass.isAssignableFrom(E.getClass()));
+        }
+        finally 
+        {
+            writer.close();
+        }
+        
+    }
+
+}

Propchange: 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/IncludeErrorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/IncludeErrorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: jakarta/velocity/engine/trunk/test/includeerror/haserror.txt
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/test/includeerror/haserror.txt?rev=373432&view=auto
==============================================================================
--- jakarta/velocity/engine/trunk/test/includeerror/haserror.txt (added)
+++ jakarta/velocity/engine/trunk/test/includeerror/haserror.txt Sun Jan 29 
20:44:01 2006
@@ -0,0 +1,7 @@
+## This file has a Velocity error.
+## It's intentionally not saved with a 'vm' suffix
+## to avoid errors in IDE
+
+#foreach($i in (1..10)
+
+$i
\ No newline at end of file

Propchange: jakarta/velocity/engine/trunk/test/includeerror/haserror.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/velocity/engine/trunk/test/includeerror/haserror.txt
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: jakarta/velocity/engine/trunk/test/includeerror/haserror2.txt
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/test/includeerror/haserror2.txt?rev=373432&view=auto
==============================================================================
--- jakarta/velocity/engine/trunk/test/includeerror/haserror2.txt (added)
+++ jakarta/velocity/engine/trunk/test/includeerror/haserror2.txt Sun Jan 29 
20:44:01 2006
@@ -0,0 +1,10 @@
+## This file has a Velocity error.
+## It's intentionally not saved with a 'vm' suffix
+## to avoid errors in IDE
+
+## Note: text directly from VELOCITY-96
+
+#macro (myMacro $arg1 $list)
+This is text from velPTest2.vm
+#myMacro('name', ['apples', 'oranges']
+More text

Propchange: jakarta/velocity/engine/trunk/test/includeerror/haserror2.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/velocity/engine/trunk/test/includeerror/haserror2.txt
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: jakarta/velocity/engine/trunk/test/includeerror/missinginclude.vm
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/test/includeerror/missinginclude.vm?rev=373432&view=auto
==============================================================================
--- jakarta/velocity/engine/trunk/test/includeerror/missinginclude.vm (added)
+++ jakarta/velocity/engine/trunk/test/includeerror/missinginclude.vm Sun Jan 
29 20:44:01 2006
@@ -0,0 +1,8 @@
+## tests to see if
+## missing include throws an error
+
+text
+
+#include("doesntexist.vm")
+
+text
\ No newline at end of file

Propchange: jakarta/velocity/engine/trunk/test/includeerror/missinginclude.vm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/velocity/engine/trunk/test/includeerror/missinginclude.vm
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: jakarta/velocity/engine/trunk/test/includeerror/missingparse.vm
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/test/includeerror/missingparse.vm?rev=373432&view=auto
==============================================================================
--- jakarta/velocity/engine/trunk/test/includeerror/missingparse.vm (added)
+++ jakarta/velocity/engine/trunk/test/includeerror/missingparse.vm Sun Jan 29 
20:44:01 2006
@@ -0,0 +1,8 @@
+## tests to see if
+## missing parse throws an error
+
+text
+
+#parse("doesntexist.vm")
+
+text
\ No newline at end of file

Propchange: jakarta/velocity/engine/trunk/test/includeerror/missingparse.vm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/velocity/engine/trunk/test/includeerror/missingparse.vm
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: jakarta/velocity/engine/trunk/test/includeerror/parsemain.vm
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/test/includeerror/parsemain.vm?rev=373432&view=auto
==============================================================================
--- jakarta/velocity/engine/trunk/test/includeerror/parsemain.vm (added)
+++ jakarta/velocity/engine/trunk/test/includeerror/parsemain.vm Sun Jan 29 
20:44:01 2006
@@ -0,0 +1,8 @@
+## tests to see if
+## ParseException in parsed file is caught
+
+text
+
+#parse("haserror.txt")
+
+text
\ No newline at end of file

Propchange: jakarta/velocity/engine/trunk/test/includeerror/parsemain.vm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/velocity/engine/trunk/test/includeerror/parsemain.vm
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Added: jakarta/velocity/engine/trunk/test/includeerror/parsemain2.vm
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/engine/trunk/test/includeerror/parsemain2.vm?rev=373432&view=auto
==============================================================================
--- jakarta/velocity/engine/trunk/test/includeerror/parsemain2.vm (added)
+++ jakarta/velocity/engine/trunk/test/includeerror/parsemain2.vm Sun Jan 29 
20:44:01 2006
@@ -0,0 +1,8 @@
+## tests to see if
+## ParseException in parsed file is caught
+
+text
+
+#parse("haserror2.txt")
+
+text
\ No newline at end of file

Propchange: jakarta/velocity/engine/trunk/test/includeerror/parsemain2.vm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/velocity/engine/trunk/test/includeerror/parsemain2.vm
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to