velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henn...@apache.org
Subject svn commit: r595104 - in /velocity/texen/trunk/src/test/org/apache/texen: ExtendedTexenTestCase.java TexenClasspathTestCase.java TexenTestCase.java
Date Wed, 14 Nov 2007 22:43:16 GMT
Author: henning
Date: Wed Nov 14 14:43:15 2007
New Revision: 595104

URL: http://svn.apache.org/viewvc?rev=595104&view=rev
Log:
Update the test cases to run right from the junit testsuite.

Added:
    velocity/texen/trunk/src/test/org/apache/texen/ExtendedTexenTestCase.java   (with props)
Removed:
    velocity/texen/trunk/src/test/org/apache/texen/TexenClasspathTestCase.java
Modified:
    velocity/texen/trunk/src/test/org/apache/texen/TexenTestCase.java

Added: velocity/texen/trunk/src/test/org/apache/texen/ExtendedTexenTestCase.java
URL: http://svn.apache.org/viewvc/velocity/texen/trunk/src/test/org/apache/texen/ExtendedTexenTestCase.java?rev=595104&view=auto
==============================================================================
--- velocity/texen/trunk/src/test/org/apache/texen/ExtendedTexenTestCase.java (added)
+++ velocity/texen/trunk/src/test/org/apache/texen/ExtendedTexenTestCase.java Wed Nov 14 14:43:15
2007
@@ -0,0 +1,167 @@
+package org.apache.texen;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import java.io.File;
+import java.util.Collections;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.collections.ExtendedProperties;
+import org.apache.texen.test.ExtendedPropertiesContributor;
+import org.apache.texen.test.Log;
+import org.apache.texen.test.TestUtil;
+
+/**
+ * This is a test case for Texen. Simply executes a simple
+ * generative task and compares the output.
+ *
+ * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
+ * @version $Id$
+ */
+public class ExtendedTexenTestCase extends TestCase
+{
+    public static final String TEST_DIR_KEY = "test.compare.dir";
+    public static final String RESULTS_DIR_KEY = "test.results.dir";
+
+    private File testDir;
+
+    /**
+     * Creates a new instance.
+     *
+     */
+    public ExtendedTexenTestCase(final String name)
+    {
+        super(name);
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite(ExtendedTexenTestCase.class);
+    }
+
+    /**
+     * Find the directories.
+     */
+    public void setUp()
+    {
+        testDir = new File(System.getProperty(TEST_DIR_KEY, "test"));
+    }
+
+    /**
+     * Runs the test.
+     */
+    protected boolean compareTexenResults(final File compareDir, final File resultsDir)
+            throws Exception
+    {
+        return TestUtil.compareFiles(
+                new File(compareDir, "TurbineWeather.java").toString(),
+                new File(resultsDir, "TurbineWeather.java").toString()) &&
+                TestUtil.compareFiles(
+                        new File(compareDir, "TurbineWeatherService.java").toString(),
+                        new File(resultsDir, "TurbineWeatherService.java").toString()) &&
+                TestUtil.compareFiles(
+                        new File(compareDir, "WeatherService.java").toString(),
+                        new File(resultsDir, "WeatherService.java").toString()) &&
+                TestUtil.compareFiles(
+                        new File(compareDir, "book.txt").toString(),
+                        new File(resultsDir, "book.txt").toString()) &&
+                TestUtil.compareFiles(
+                        new File(compareDir, "Text.txt").toString(),
+                        new File(resultsDir, "Text.txt").toString());
+    }
+
+    public void testExtendedTexen() throws Exception
+    {
+        File compareDir = new File (testDir, "texen/compare");
+        File resultsDir = new File(System.getProperty(RESULTS_DIR_KEY, "bin/test"), "texen-generator");
+
+        TestUtil.assureResultsDirectoryExists(resultsDir);
+
+        Texen texen = new Texen();
+
+        ExtendedProperties properties = new ExtendedProperties();
+
+        TestUtil.loadProperties(new File(testDir, "texen/service.props"), properties);
+        TestUtil.loadProperties(new File(testDir, "texen/additional.props"), properties);
+
+        texen.setControlTemplate("Control.vm");
+        texen.setOutputDirectory(resultsDir);
+        texen.setTemplatePath(new File(testDir, "texen/templates").getCanonicalPath());
+        texen.setOutputFileName("report");
+        texen.setOutputEncoding("ISO-8859-1");
+        texen.setInputEncoding("ISO-8859-1");
+        texen.setUseClasspath(false);
+
+        texen.addContributors(Collections.singleton(new ExtendedPropertiesContributor(properties,
new TexenFileResolver() {
+            public File resolveFile(final String fileName) {
+                return new File(fileName);
+            }
+        })));
+
+        texen.setUseResourceLoaderCache(false);
+        texen.setLog(new Log());
+        texen.execute();
+
+        if (!compareTexenResults(compareDir, resultsDir))
+        {
+            fail("Texen results are incorrect.");
+        }
+    }
+
+    public void testExtendedTexenClasspath() throws Exception
+    {
+        File compareDir = new File (testDir, "texen/compare");
+        File resultsDir = new File(System.getProperty(RESULTS_DIR_KEY, "bin/test"), "texen-generator-classpath");
+
+        TestUtil.assureResultsDirectoryExists(resultsDir);
+
+        Texen texen = new Texen();
+
+        ExtendedProperties properties = new ExtendedProperties();
+
+        TestUtil.loadProperties("service.props", properties);
+        TestUtil.loadProperties("additional.props", properties);
+
+        texen.setControlTemplate("Control.vm");
+        texen.setOutputDirectory(resultsDir);
+        texen.setOutputFileName("report");
+        texen.setOutputEncoding("ISO-8859-1");
+        texen.setInputEncoding("ISO-8859-1");
+        texen.setUseResourceLoaderCache(false);
+
+        texen.addContributors(Collections.singleton(new ExtendedPropertiesContributor(properties,
new TexenFileResolver() {
+            public File resolveFile(final String fileName) {
+                return new File(fileName);
+            }
+        })));
+
+        texen.setUseClasspath(true);
+        texen.setLog(new Log());
+        texen.execute();
+
+        if (!compareTexenResults(compareDir, resultsDir))
+        {
+            fail("Texen classpath results are incorrect.");
+        }
+    }
+}

Propchange: velocity/texen/trunk/src/test/org/apache/texen/ExtendedTexenTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: velocity/texen/trunk/src/test/org/apache/texen/ExtendedTexenTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date Revision

Modified: velocity/texen/trunk/src/test/org/apache/texen/TexenTestCase.java
URL: http://svn.apache.org/viewvc/velocity/texen/trunk/src/test/org/apache/texen/TexenTestCase.java?rev=595104&r1=595103&r2=595104&view=diff
==============================================================================
--- velocity/texen/trunk/src/test/org/apache/texen/TexenTestCase.java (original)
+++ velocity/texen/trunk/src/test/org/apache/texen/TexenTestCase.java Wed Nov 14 14:43:15
2007
@@ -16,18 +16,20 @@
  * "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.    
+ * under the License.
  */
 
 import java.io.File;
+import java.util.Collections;
 
-import org.apache.texen.test.Log;
-import org.apache.texen.test.TestUtil;
-
+import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
-
+import org.apache.commons.collections.ExtendedProperties;
+import org.apache.texen.test.ExtendedPropertiesContributor;
+import org.apache.texen.test.Log;
+import org.apache.texen.test.TestUtil;
 
 /**
  * This is a test case for Texen. Simply executes a simple
@@ -40,20 +42,19 @@
 {
     public static final String TEST_DIR_KEY = "test.compare.dir";
     public static final String RESULTS_DIR_KEY = "test.results.dir";
-    
-    private String resultsDir;
-    private String compareDir;
+
+    private File testDir;
 
     /**
      * Creates a new instance.
      *
      */
-    public TexenTestCase(String name)
+    public TexenTestCase(final String name)
     {
         super(name);
     }
 
-    public static junit.framework.Test suite()
+    public static Test suite()
     {
         return new TestSuite(TexenTestCase.class);
     }
@@ -63,40 +64,104 @@
      */
     public void setUp()
     {
-        resultsDir = System.getProperty(RESULTS_DIR_KEY, "bin/test") + "/texen";
-        compareDir = System.getProperty(TEST_DIR_KEY, "test") + "/texen/compare";
+        testDir = new File(System.getProperty(TEST_DIR_KEY, "test"));
     }
 
     /**
      * Runs the test.
      */
-    public void testTexenResults ()
+    protected boolean compareTexenResults(final File compareDir, final File resultsDir)
             throws Exception
     {
+        return TestUtil.compareFiles(
+                new File(compareDir, "TurbineWeather.java").toString(),
+                new File(resultsDir, "TurbineWeather.java").toString()) &&
+                TestUtil.compareFiles(
+                        new File(compareDir, "TurbineWeatherService.java").toString(),
+                        new File(resultsDir, "TurbineWeatherService.java").toString()) &&
+                TestUtil.compareFiles(
+                        new File(compareDir, "WeatherService.java").toString(),
+                        new File(resultsDir, "WeatherService.java").toString()) &&
+                TestUtil.compareFiles(
+                        new File(compareDir, "book.txt").toString(),
+                        new File(resultsDir, "book.txt").toString()) &&
+                TestUtil.compareFiles(
+                        new File(compareDir, "Text.txt").toString(),
+                        new File(resultsDir, "Text.txt").toString());
+    }
+
+    public void testTexen() throws Exception
+    {
+        File compareDir = new File (testDir, "texen/compare");
+        File resultsDir = new File(System.getProperty(RESULTS_DIR_KEY, "bin/test"), "texen");
+
         TestUtil.assureResultsDirectoryExists(resultsDir);
 
-        // compare with custom context
-        if (!TestUtil.compareFiles(
-                new File(compareDir, "TurbineWeather.java").toString(),
-                new File(resultsDir, "TurbineWeather.java").toString()) ||
-            !TestUtil.compareFiles(
-                    new File(compareDir, "TurbineWeatherService.java").toString(),
-                    new File(resultsDir, "TurbineWeatherService.java").toString()) ||
-            !TestUtil.compareFiles(
-                    new File(compareDir, "WeatherService.java").toString(),
-                    new File(resultsDir, "WeatherService.java").toString()) ||
-            !TestUtil.compareFiles(
-                    new File(compareDir, "book.txt").toString(),
-                    new File(resultsDir, "book.txt").toString()) ||
-            !TestUtil.compareFiles(
-                    new File(compareDir, "Text.txt").toString(),
-                    new File(resultsDir, "Text.txt").toString()) )
+        Texen texen = new Texen();
+
+        ExtendedProperties properties = new ExtendedProperties();
+
+        TestUtil.loadProperties(new File(testDir, "texen/service.props"), properties);
+        TestUtil.loadProperties(new File(testDir, "texen/additional.props"), properties);
+
+        texen.setControlTemplate("Control.vm");
+        texen.setOutputDirectory(resultsDir);
+        texen.setTemplatePath(new File(testDir, "texen/templates").getCanonicalPath());
+        texen.setOutputFileName("report");
+        texen.setOutputEncoding("ISO-8859-1");
+        texen.setInputEncoding("ISO-8859-1");
+        texen.setUseClasspath(false);
+
+        texen.addContributors(Collections.singleton(new ExtendedPropertiesContributor(properties,
new TexenFileResolver() {
+            public File resolveFile(final String fileName) {
+                return new File(fileName);
+            }
+        })));
+
+        texen.setUseResourceLoaderCache(false);
+        texen.setLog(new Log());
+        texen.execute();
+
+        if (!compareTexenResults(compareDir, resultsDir))
         {
             fail("Texen results are incorrect.");
         }
-        else
+    }
+
+    public void testTexenClasspath() throws Exception
+    {
+        File compareDir = new File (testDir, "texen/compare");
+        File resultsDir = new File(System.getProperty(RESULTS_DIR_KEY, "bin/test"), "texen-classpath");
+
+        TestUtil.assureResultsDirectoryExists(resultsDir);
+
+        Texen texen = new Texen();
+
+        ExtendedProperties properties = new ExtendedProperties();
+
+        TestUtil.loadProperties("service.props", properties);
+        TestUtil.loadProperties("additional.props", properties);
+
+        texen.setControlTemplate("Control.vm");
+        texen.setOutputDirectory(resultsDir);
+        texen.setOutputFileName("report");
+        texen.setOutputEncoding("ISO-8859-1");
+        texen.setInputEncoding("ISO-8859-1");
+        texen.setUseResourceLoaderCache(false);
+
+        texen.addContributors(Collections.singleton(new ExtendedPropertiesContributor(properties,
new TexenFileResolver() {
+            public File resolveFile(final String fileName) {
+                return new File(fileName);
+            }
+        })));
+
+        texen.setUseClasspath(true);
+        texen.setLog(new Log());
+        texen.execute();
+
+        if (!compareTexenResults(compareDir, resultsDir))
         {
-            Log.log ("Passed!");
+            fail("Texen classpath results are incorrect.");
         }
     }
 }



Mime
View raw message