velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r746433 - /velocity/engine/trunk/src/test/org/apache/velocity/test/BaseTestCase.java
Date Sat, 21 Feb 2009 03:52:12 GMT
Author: nbubna
Date: Sat Feb 21 03:52:11 2009
New Revision: 746433

URL: http://svn.apache.org/viewvc?rev=746433&view=rev
Log:
make it easier to run test through resource loaders by providing a string repo

Modified:
    velocity/engine/trunk/src/test/org/apache/velocity/test/BaseTestCase.java

Modified: velocity/engine/trunk/src/test/org/apache/velocity/test/BaseTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/test/org/apache/velocity/test/BaseTestCase.java?rev=746433&r1=746432&r2=746433&view=diff
==============================================================================
--- velocity/engine/trunk/src/test/org/apache/velocity/test/BaseTestCase.java (original)
+++ velocity/engine/trunk/src/test/org/apache/velocity/test/BaseTestCase.java Sat Feb 21 03:52:11
2009
@@ -33,6 +33,8 @@
 import org.apache.velocity.util.StringUtils;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.test.misc.TestLogChute;
+import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
+import org.apache.velocity.runtime.resource.util.StringResourceRepository;
 
 /**
  * Base test case that provides utility methods for
@@ -48,6 +50,7 @@
     protected VelocityContext context;
     protected boolean DEBUG = false;
     protected TestLogChute log;
+    protected String stringRepoName = "string.repo";
 
     public BaseTestCase(String name)
     {
@@ -71,6 +74,13 @@
         log.setEnabledLevel(TestLogChute.INFO_ID);
         log.setSystemErrLevel(TestLogChute.WARN_ID);
         engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, log);
+
+        // use string resource loader by default, instead of file
+        engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "file,string");
+        engine.addProperty("string.resource.loader.class", StringResourceLoader.class.getName());
+        engine.addProperty("string.resource.loader.repository.name", stringRepoName);
+        engine.addProperty("string.resource.loader.repository.static", "false");
+
         setUpEngine(engine);
 
         context = new VelocityContext();
@@ -87,6 +97,29 @@
         // extension hook
     }
 
+    protected StringResourceRepository getStringRepository()
+    {
+        StringResourceRepository repo =
+            (StringResourceRepository)engine.getApplicationAttribute(stringRepoName);
+        if (repo == null)
+        {
+            engine.init();
+            repo =
+                (StringResourceRepository)engine.getApplicationAttribute(stringRepoName);
+        }
+        return repo;
+    }
+
+    protected void addTemplate(String name, String template)
+    {
+        getStringRepository().putStringResource(name, template);
+    }
+
+    protected void removeTemplate(String name)
+    {
+        getStringRepository().removeStringResource(name);
+    }
+
     public void tearDown()
     {
         engine = null;
@@ -125,7 +158,7 @@
 
     public void testBase()
     {
-        if (DEBUG)
+        if (DEBUG && engine != null)
         {
             assertSchmoo("");
             assertSchmoo("abc\n123");



Mime
View raw message