velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nbu...@apache.org
Subject svn commit: r752570 - in /velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test: BaseTestCase.java MacroForwardDefineTestCase.java VMContextLocalscopeTestCase.java misc/TestLogChute.java
Date Wed, 11 Mar 2009 18:54:29 GMT
Author: nbubna
Date: Wed Mar 11 18:54:28 2009
New Revision: 752570

URL: http://svn.apache.org/viewvc?rev=752570&view=rev
Log:
merge test improvements from trunk

Modified:
    velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/BaseTestCase.java
    velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/MacroForwardDefineTestCase.java
    velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/VMContextLocalscopeTestCase.java
    velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/misc/TestLogChute.java

Modified: velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/BaseTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/BaseTestCase.java?rev=752570&r1=752569&r2=752570&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/BaseTestCase.java (original)
+++ velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/BaseTestCase.java Wed
Mar 11 18:54:28 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
@@ -87,6 +89,31 @@
         // 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)
+    {
+        info("Template '"+name+"':  "+template);
+        getStringRepository().putStringResource(name, template);
+    }
+
+    protected void removeTemplate(String name)
+    {
+        info("Removed: '"+name+"'");
+        getStringRepository().removeStringResource(name);
+    }
+
     public void tearDown()
     {
         engine = null;
@@ -137,7 +164,7 @@
      */
     protected void assertTmplEquals(String expected, String template)
     {        
-        info("Expected:  '" + expected + "'");
+        info("Expected:  " + expected + " from '" + template + "'");
 
         StringWriter writer = new StringWriter();
         try
@@ -155,7 +182,7 @@
             throw new RuntimeException(e);
         }        
 
-        info("Result:  '" + writer.toString() + "'");
+        info("Result:  " + writer.toString());
         assertEquals(expected, writer.toString());  
     }
     

Modified: velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/MacroForwardDefineTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/MacroForwardDefineTestCase.java?rev=752570&r1=752569&r2=752570&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/MacroForwardDefineTestCase.java
(original)
+++ velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/MacroForwardDefineTestCase.java
Wed Mar 11 18:54:28 2009
@@ -81,12 +81,10 @@
         Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_REFERENCE_LOG_INVALID,"true");
 
         // actual instance of logger
-        logger = new TestLogChute();
-        logger.off();
+        logger = new TestLogChute(true, false);
         Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM,logger);
         Velocity.setProperty(TestLogChute.TEST_LOGGER_LEVEL, "debug");
         Velocity.init();
-        // DEBUG = true;
     }
 
     public static Test suite()
@@ -101,9 +99,9 @@
         Template template = Velocity.getTemplate("macros.vm");
 
         // try to get only messages during merge
-        logger.on();
+        logger.startCapture();
         template.merge(context, new StringWriter());
-        logger.off();
+        logger.stopCapture();
 
         String resultLog = logger.getLog();
         if ( !isMatch(resultLog, COMPARE_DIR, "velocity.log", "cmp"))

Modified: velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/VMContextLocalscopeTestCase.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/VMContextLocalscopeTestCase.java?rev=752570&r1=752569&r2=752570&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/VMContextLocalscopeTestCase.java
(original)
+++ velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/VMContextLocalscopeTestCase.java
Wed Mar 11 18:54:28 2009
@@ -19,7 +19,6 @@
  * under the License.    
  */
 
-import junit.framework.TestCase;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.context.InternalContextAdapterImpl;
 import org.apache.velocity.context.ProxyVMContext;
@@ -32,24 +31,32 @@
  * @author <a href="mailto:stephenh@chase3000.com">Stephen Habermann</a>
  * @version $Id$
  */
-public class VMContextLocalscopeTestCase extends TestCase {
+public class VMContextLocalscopeTestCase extends BaseTestCase {
 
-    private RuntimeInstance instance;
+    public VMContextLocalscopeTestCase(String name)
+    {
+        super(name);
+    }
 
-    public void setUp() throws Exception 
+    public void testViaEval()
     {
-        this.instance = new RuntimeInstance();
-        this.instance.setProperty(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, Boolean.TRUE);
-        this.instance.init();
+        engine.setProperty(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, Boolean.TRUE);
+        assertEvalEquals("$a", "#macro(a)#set($a = 'b')#end#a$a");
+        context.put("b", "b");
+        assertEvalEquals("b", "#macro(b)$b#set($b = 'c')#end#b");
+        assertContextValue("b", "b");
     }
 
     public void testLocalscopePutDoesntLeakButGetDoes() 
     {
+        RuntimeInstance instance = new RuntimeInstance();
+        instance.setProperty(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, Boolean.TRUE);
+        instance.init();
+
         VelocityContext base = new VelocityContext();
         base.put("outsideVar", "value1");
 
         ProxyVMContext vm = new ProxyVMContext(new InternalContextAdapterImpl(base), true);
-        vm.put("newLocalVar", "value2");
 
         // New variable put doesn't leak
         assertNull(base.get("newLocalVar"));

Modified: velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/misc/TestLogChute.java
URL: http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/misc/TestLogChute.java?rev=752570&r1=752569&r2=752570&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/misc/TestLogChute.java
(original)
+++ velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/misc/TestLogChute.java
Wed Mar 11 18:54:28 2009
@@ -90,7 +90,7 @@
 
     public boolean isLevelEnabled(int level)
     {
-        return !suppress && super.isLevelEnabled(level);
+        return (!suppress || capture) && super.isLevelEnabled(level);
     }
             
 



Mime
View raw message