jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jalka...@apache.org
Subject svn commit: r885221 - /incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java
Date Sun, 29 Nov 2009 12:32:22 GMT
Author: jalkanen
Date: Sun Nov 29 12:32:21 2009
New Revision: 885221

URL: http://svn.apache.org/viewvc?rev=885221&view=rev
Log:
Adding a bunch of unit tests to improve coverage around versioning.

Modified:
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java?rev=885221&r1=885220&r2=885221&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java Sun
Nov 29 12:32:21 2009
@@ -22,6 +22,7 @@
 package org.apache.wiki.content;
 
 import java.util.Collection;
+import java.util.List;
 import java.util.Properties;
 
 import junit.framework.Test;
@@ -34,6 +35,8 @@
 import org.apache.wiki.api.WikiPage;
 import org.apache.wiki.providers.ProviderException;
 
+import stress.Benchmark;
+
 
 public class ContentManagerTest extends TestCase
 {
@@ -224,8 +227,15 @@
     {
         WikiPage p = m_mgr.addPage( WikiPath.valueOf( "TestPage" ), ContentManager.JSPWIKI_CONTENT_TYPE
);
         
+        Benchmark b = new Benchmark();
+        b.start();
+        
         storeVersions( p, 100 );
         
+        b.stop();
+        
+        System.out.println( "100 versions stored in "+b+", "+b.toString( 100 ) + " stores/second");
+        
         p = m_engine.getPage( "TestPage", 100 );
         assertEquals( "content 100","Test 100", p.getContentAsString() );
         assertEquals( "version 100", 100, p.getVersion() );
@@ -239,6 +249,94 @@
         assertEquals( "version 51", 51, p.getVersion() );
     }
     
+    public void testDeleteLastVersion() throws Exception
+    {
+        WikiPage p = m_engine.createPage("TestPage");
+        
+        storeVersions( p, 3 );
+        
+        WikiPage current = m_engine.getPage( "TestPage" );
+        
+        assertEquals( current.getVersion(), 3 );
+        
+        m_engine.deleteVersion( current );
+        
+        assertFalse( m_engine.pageExists( "TestPage", 3 ));
+        
+        current = m_engine.getPage("TestPage");
+        
+        assertEquals( current.getVersion(), 2 );
+        
+        try
+        {
+            m_engine.getPage("TestPage",3);
+            fail("Got v3");
+        }
+        catch(PageNotFoundException e) {}
+    }
+    
+    public void testDeleteInTheMiddle() throws Exception
+    {
+        WikiPage p = m_engine.createPage("TestPage");
+        
+        storeVersions( p, 3 );
+        
+        WikiPage current = m_engine.getPage( "TestPage", 2 );
+        
+        assertEquals( current.getVersion(), 2 );
+        
+        m_engine.deleteVersion( current );
+        
+        assertFalse( m_engine.pageExists( "TestPage", 2 ));
+        
+        current = m_engine.getPage("TestPage");
+        
+        assertEquals( current.getVersion(), 3 );
+        
+        try
+        {
+            m_engine.getPage("TestPage",2);
+            fail("Got v2");
+        }
+        catch(PageNotFoundException e) {}
+        
+        List<WikiPage> vh = m_engine.getVersionHistory( "TestPage" );
+        assertEquals( 2, vh.size() );
+        assertEquals( 1, vh.get(0).getVersion() );
+        assertEquals( 3, vh.get(1).getVersion() );
+    }
+
+    public void testDeleteFirst() throws Exception
+    {
+        WikiPage p = m_engine.createPage("TestPage");
+        
+        storeVersions( p, 3 );
+        
+        WikiPage current = m_engine.getPage( "TestPage", 1 );
+        
+        assertEquals( current.getVersion(), 1 );
+        
+        m_engine.deleteVersion( current );
+        
+        assertFalse( m_engine.pageExists( "TestPage", 1 ));
+        
+        current = m_engine.getPage("TestPage");
+        
+        assertEquals( current.getVersion(), 3 );
+        
+        try
+        {
+            m_engine.getPage("TestPage",1);
+            fail("Got v1");
+        }
+        catch(PageNotFoundException e) {}
+        
+        List<WikiPage> vh = m_engine.getVersionHistory( "TestPage" );
+        assertEquals( 2, vh.size() );
+        assertEquals( 2, vh.get(0).getVersion() );
+        assertEquals( 3, vh.get(1).getVersion() );
+    }
+    
     public void testDeleteAllVersions() throws Exception
     {
         WikiPage p = m_engine.createPage( "TestPage" );
@@ -250,14 +348,24 @@
             p = m_engine.getPage( "TestPage", i );
             
             m_engine.deleteVersion( p );
+            
+            assertFalse( "exists "+i, m_engine.pageExists( "TestPage", i ) );
+
+            try
+            {
+                p = m_engine.getPage( "TestPage", i );
+                fail("Didn't get exception for "+i);
+            }
+            catch( PageNotFoundException e ) {} // Expected
+
         }
     
         assertFalse( m_engine.pageExists( "TestPage" ) );
         
         try
         {
-            m_engine.getPage( "TestPage" );
-            fail("Didn't get exception!");
+            p = m_engine.getPage( "TestPage" );
+            fail("Didn't get exception for the whole page");
         }
         catch( PageNotFoundException e ) {} // Expected
     }



Mime
View raw message