geirm       01/03/19 07:37:58

  Modified:    src/java/org/apache/velocity/test ClasspathResourceTest.java
                        MultipleFileResourcePathTest.java
  Log:
  Added check/create for results directory (stolen from TemplateTestCase)
  so the directory is automatically created if not there...
  
  Revision  Changes    Path
  1.4       +30 -1     
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ClasspathResourceTest.java        2001/03/19 06:36:31     1.3
  +++ ClasspathResourceTest.java        2001/03/19 15:37:57     1.4
  @@ -58,6 +58,7 @@
   import java.io.FileOutputStream;
   import java.io.OutputStreamWriter;
   import java.io.Writer;
  +import java.io.File;
   
   import java.util.Properties;
   
  @@ -76,7 +77,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Dave Bryson</a>
  - * @version $Id: ClasspathResourceTest.java,v 1.3 2001/03/19 06:36:31 jvanzyl Exp $
  + * @version $Id: ClasspathResourceTest.java,v 1.4 2001/03/19 15:37:57 geirm Exp $
    */
   public class ClasspathResourceTest extends TestCase
   {
  @@ -154,6 +155,11 @@
       {
           try
           {
  +            /*
  +             *  lets ensure the results directory exists
  +             */
  +            assureResultsDirectoryExists();
  +
               Template template1 = Runtime.getTemplate(
                   getFileName(null, "template/test1", TMPL_FILE_EXT));
               
  @@ -193,6 +199,29 @@
           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);
  +            }
           }
       }
   
  
  
  
  1.4       +26 -1     
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MultipleFileResourcePathTest.java 2001/03/14 22:05:20     1.3
  +++ MultipleFileResourcePathTest.java 2001/03/19 15:37:57     1.4
  @@ -58,6 +58,7 @@
   import java.io.FileOutputStream;
   import java.io.OutputStreamWriter;
   import java.io.Writer;
  +import java.io.File;
   
   import java.util.Properties;
   
  @@ -76,7 +77,7 @@
    * Multiple paths in the file resource loader.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: MultipleFileResourcePathTest.java,v 1.3 2001/03/14 22:05:20 
jvanzyl Exp $
  + * @version $Id: MultipleFileResourcePathTest.java,v 1.4 2001/03/19 15:37:57 geirm 
Exp $
    */
   public class MultipleFileResourcePathTest extends TestCase
   {
  @@ -126,6 +127,8 @@
   
           try
           {
  +            assureResultsDirectoryExists();
  +
               Velocity.setProperty(
                   Velocity.FILE_RESOURCE_LOADER_PATH, FILE_RESOURCE_LOADER_PATH1);
   
  @@ -196,6 +199,28 @@
           }
       }
   
  +    /**
  +     * 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.
        *
  
  
  

Reply via email to