jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mets...@apache.org
Subject svn commit: r1566293 - in /jspwiki/trunk: ChangeLog jspwiki-war/src/main/java/org/apache/wiki/Release.java jspwiki-war/src/test/java/org/apache/wiki/ReferenceManagerTest.java jspwiki-war/src/test/java/org/apache/wiki/TestEngine.java
Date Sun, 09 Feb 2014 13:15:15 GMT
Author: metskem
Date: Sun Feb  9 13:15:15 2014
New Revision: 1566293

URL: http://svn.apache.org/r1566293
Log:
2014-02-09  Harry Metske (metskem@apache.org)
       * 2.10.0-svn-71

       * Fixed JSPWIKI-813 - ReferenceManagerTest - two cases fail, patch by Brian Burch

Modified:
    jspwiki/trunk/ChangeLog
    jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java
    jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/ReferenceManagerTest.java
    jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/TestEngine.java

Modified: jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/jspwiki/trunk/ChangeLog?rev=1566293&r1=1566292&r2=1566293&view=diff
==============================================================================
--- jspwiki/trunk/ChangeLog (original)
+++ jspwiki/trunk/ChangeLog Sun Feb  9 13:15:15 2014
@@ -1,3 +1,8 @@
+2014-02-09  Harry Metske (metskem@apache.org)
+       * 2.10.0-svn-71
+
+       * Fixed JSPWIKI-813 - ReferenceManagerTest - two cases fail, patch by Brian Burch
+
 2014-02-08  Harry Metske (metskem@apache.org)
        * 2.10.0-svn-70
 

Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java?rev=1566293&r1=1566292&r2=1566293&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java (original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/Release.java Sun Feb  9 13:15:15
2014
@@ -72,7 +72,7 @@ public final class Release {
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "70";
+    public static final String     BUILD         = "71";
     
     /**
      *  This is the generic version string you should use when printing out the version.
 It is of 

Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/ReferenceManagerTest.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/ReferenceManagerTest.java?rev=1566293&r1=1566292&r2=1566293&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/ReferenceManagerTest.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/ReferenceManagerTest.java Sun
Feb  9 13:15:15 2014
@@ -23,17 +23,19 @@ import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import net.sf.ehcache.CacheManager;
+
 import org.apache.wiki.api.exceptions.WikiException;
-import org.apache.wiki.providers.FileSystemProvider;
 
 /**
+ * The ReferenceManager maintains all hyperlinks between wiki pages.
  */
 public class ReferenceManagerTest extends TestCase
 {
     Properties props = TestEngine.getTestProperties();
     TestEngine engine;
     ReferenceManager mgr;
-    
+
     public ReferenceManagerTest( String s )
     {
         super( s );
@@ -44,26 +46,14 @@ public class ReferenceManagerTest extend
     {
         props.setProperty( "jspwiki.translatorReader.matchEnglishPlurals", "true");
 
-        //
-        //  We must make sure that the reference manager cache is cleaned first.
-        //
-        String workDir = props.getProperty( "jspwiki.workDir" );
-
-        if( workDir != null )
-        {
-            File refmgrfile = new File( workDir, "refmgr.ser" );
-            if( refmgrfile.exists() ) refmgrfile.delete();
-        }
+        // make sure that the reference manager cache is cleaned first
+        TestEngine.emptyWorkDir(null);
+        CacheManager.getInstance().removalAll();
 
-        String fileDir = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
-        
-        if( fileDir != null )
-        {
-            TestEngine.deleteAll( new File(fileDir) );
-        }
-        
         engine = new TestEngine(props);
 
+        // create two handy wiki pages used in most test cases
+        // Danger! all wiki page names must start with a capital letter!
         engine.saveText( "TestPage", "Reference to [Foobar]." );
         engine.saveText( "Foobar", "Reference to [Foobar2], [Foobars], [Foobar]" );
 
@@ -73,57 +63,48 @@ public class ReferenceManagerTest extend
     public void tearDown()
         throws Exception
     {
-        engine.deletePage( "TestPage" );
-        engine.deletePage( "Foobar" );
-        engine.deletePage( "Foobars" );
-        engine.deletePage( "Foobar2" );
-        engine.deletePage( "Foobar2s" );
-        engine.deletePage( "BugCommentPreviewDeletesAllComments" );
-        engine.deletePage( "FatalBugs" );
-        engine.deletePage( "RandomPage" );
-        engine.deletePage( "NewBugs" );
-        engine.deletePage( "OpenBug" );
-        engine.deletePage( "OpenBugs" );
-        engine.deletePage( "NewBug" );
-        engine.deletePage( "BugOne" );
-        engine.deletePage( "BugTwo" );
+        // any wiki page that was created must be deleted!
+        TestEngine.emptyWikiDir();
     }
 
     public void testNonExistant1()
         throws Exception
     {
         Collection c = mgr.findReferrers("Foobar2");
-        
+
+        assertNotNull( "referrers expected", c );
         assertTrue( c.size() == 1 && c.contains("Foobar") );
     }
-    
+
     public void testNonExistant2()
     {
         Collection c = mgr.findReferrers("TestBug");
-        
+
         assertNull( c );
     }
-    
+
     public void testRemove()
         throws Exception
     {
         Collection c = mgr.findReferrers("Foobar2");
-        
+
+        assertNotNull( "referrers expected", c );
         assertTrue( c.size() == 1 && c.contains("Foobar") );
 
         engine.deletePage( "Foobar" );
-        
+
         c = mgr.findReferrers("Foobar2");
-        
+
         assertNull( c );
-        
+
         engine.saveText( "Foobar", "[Foobar2]");
-        
+
         c = mgr.findReferrers("Foobar2");
-        
-        assertTrue( c.size() == 1 && c.contains("Foobar") );        
+
+        assertNotNull( "referrers expected", c );
+        assertTrue( c.size() == 1 && c.contains("Foobar") );
     }
-    
+
     public void testUnreferenced()
         throws Exception
     {
@@ -154,7 +135,7 @@ public class ReferenceManagerTest extend
         throws Exception
     {
         Collection c = mgr.findUncreated();
-        
+
         assertTrue( c.size()==1 && ((String) c.iterator().next()).equals("Foobar2")
);
     }
 
@@ -165,12 +146,15 @@ public class ReferenceManagerTest extend
         assertNull( "TestPage referrers", c );
 
         c = mgr.findReferrers( "Foobar" );
+        assertNotNull( "referrers expected", c );
         assertTrue( "Foobar referrers", c.size()==2  );
 
         c = mgr.findReferrers( "Foobar2" );
+        assertNotNull( "referrers expected", c );
         assertTrue( "Foobar2 referrers", c.size()==1 && ((String) c.iterator().next()).equals("Foobar")
);
 
         c = mgr.findReferrers( "Foobars" );
+        assertNotNull( "referrers expected", c );
         assertEquals( "Foobars referrers", 2, c.size() );
         //assertEquals( "Foobars referrer 'TestPage'", "TestPage", (String) c.iterator().next()
);
     }
@@ -179,12 +163,12 @@ public class ReferenceManagerTest extend
         throws Exception
     {
         Collection s = mgr.findRefersTo( "Foobar" );
-        
+
         assertTrue( "does not have Foobar", s.contains("Foobar") );
         // assertTrue( "does not have Foobars", s.contains("Foobars") );
         assertTrue( "does not have Foobar2", s.contains("Foobar2") );
     }
-    
+
     /**
      *  Should fail in 2.2.14-beta
      * @throws Exception
@@ -195,13 +179,14 @@ public class ReferenceManagerTest extend
         engine.saveText( "RandomPage", "FatalBugs" );
         engine.saveText( "FatalBugs", "<foo>" );
         engine.saveText( "BugCommentPreviewDeletesAllComments", "FatalBug" );
-        
+
         Collection c = mgr.findReferrers( "FatalBugs" );
-        
+
+        assertNotNull( "referrers expected", c );
         assertEquals( "FatalBugs referrers number", 2, c.size()  );
     }
 
-    /** 
+    /**
      *  Is a page recognized as referenced if only plural form links exist.
      */
 
@@ -216,14 +201,15 @@ public class ReferenceManagerTest extend
         assertTrue( "Foobar unreferenced", c.size()==1 && ((String) c.iterator().next()).equals("TestPage")
);
 
         c = mgr.findReferrers( "Foobar" );
+        assertNotNull( "referrers expected", c );
         Iterator it = c.iterator();
         String s1 = (String)it.next();
-        assertTrue( "Foobar referrers", 
+        assertTrue( "Foobar referrers",
                     c.size()==2 );
     }
 
 
-    /** 
+    /**
      *  Opposite to testUpdatePluralOnlyRef(). Is a page with plural form recognized as
      *  the page referenced by a singular link.
      */
@@ -235,6 +221,7 @@ public class ReferenceManagerTest extend
         assertTrue( "no uncreated", mgr.findUncreated().size()==0 );
 
         Collection c = mgr.findReferrers( "Foobar2s" );
+        assertNotNull( "referrers expected", c );
         assertTrue( "referrers", c!=null && c.size()==1 && ((String) c.iterator().next()).equals("Foobar")
);
     }
 
@@ -243,6 +230,7 @@ public class ReferenceManagerTest extend
     {
         engine.saveText( "Foobars", "qwertz" );
         Collection c = mgr.findReferrers( "Foobars" );
+        assertNotNull( "referrers expected", c );
         assertEquals( "Foobars referrers", 2, c.size() );
         assertTrue( "Foobars referrer is not TestPage", c.contains( "TestPage" ) &&
c.contains("Foobar"));
     }
@@ -252,14 +240,15 @@ public class ReferenceManagerTest extend
     {
         engine.saveText( "Foobars", "qwertz" );
         engine.saveText( "TestPage", "Reference to [Foobar], [Foobars]." );
-        
+
         Collection c = mgr.findReferrers( "Foobars" );
+        assertNotNull( "referrers expected", c );
         assertEquals( "Foobars referrers count", 2, c.size() );
 
         Iterator i = c.iterator();
         String first = (String) i.next();
 
-        assertTrue( "Foobars referrers", 
+        assertTrue( "Foobars referrers",
                     c.contains("TestPage") && c.contains("Foobar"));
     }
 
@@ -267,7 +256,7 @@ public class ReferenceManagerTest extend
         throws Exception
     {
         engine.saveText( "Foobar2", "ref to [TestPage]" );
-        
+
         assertTrue( "no uncreated", mgr.findUncreated().size()==0 );
         assertTrue( "no unreferenced", mgr.findUnreferenced().size()==0 );
     }
@@ -278,9 +267,9 @@ public class ReferenceManagerTest extend
         engine.saveText( "BugOne", "NewBug" );
         engine.saveText( "NewBugs", "foo" );
         engine.saveText( "OpenBugs", "bar" );
-        
+
         engine.saveText( "BugOne", "OpenBug" );
-        
+
         Collection ref = mgr.findReferrers( "NewBugs" );
         assertNull("newbugs",ref); // No referrers must be found
 
@@ -288,10 +277,12 @@ public class ReferenceManagerTest extend
         assertNull("newbug",ref); // No referrers must be found
 
         ref = mgr.findReferrers( "OpenBugs" );
+        assertNotNull("referrers expected", ref);
         assertEquals("openbugs",1,ref.size());
         assertEquals("openbugs2","BugOne",ref.iterator().next());
 
         ref = mgr.findReferrers( "OpenBug" );
+        assertNotNull("referrers expected", ref);
         assertEquals("openbug",1,ref.size());
         assertEquals("openbug2","BugOne",ref.iterator().next());
 
@@ -303,9 +294,9 @@ public class ReferenceManagerTest extend
         engine.saveText( "BugOne", "NewBug" );
         engine.saveText( "NewBug", "foo" );
         engine.saveText( "OpenBug", "bar" );
-    
+
         engine.saveText( "BugOne", "OpenBug" );
-    
+
         Collection ref = mgr.findReferrers( "NewBugs" );
         assertNull("newbugs",ref); // No referrers must be found
 
@@ -313,10 +304,12 @@ public class ReferenceManagerTest extend
         assertNull("newbug",ref); // No referrers must be found
 
         ref = mgr.findReferrers( "OpenBugs" );
+        assertNotNull("referrers expected", ref);
         assertEquals("openbugs",1,ref.size());
         assertEquals("openbugs2","BugOne",ref.iterator().next());
 
         ref = mgr.findReferrers( "OpenBug" );
+        assertNotNull("referrers expected", ref);
         assertEquals("openbug",1,ref.size());
         assertEquals("openbug2","BugOne",ref.iterator().next());
 
@@ -329,22 +322,26 @@ public class ReferenceManagerTest extend
         engine.saveText( "BugTwo", "NewBug" );
         engine.saveText( "NewBugs", "foo" );
         engine.saveText( "OpenBugs", "bar" );
-    
+
         engine.saveText( "BugOne", "OpenBug" );
-    
+
         Collection ref = mgr.findReferrers( "NewBugs" );
-        assertEquals("newbugs",1,ref.size()); 
-        assertEquals("newbugs2","BugTwo",ref.iterator().next()); 
+        assertNotNull("referrers expected", ref);
+        assertEquals("newbugs",1,ref.size());
+        assertEquals("newbugs2","BugTwo",ref.iterator().next());
 
         ref = mgr.findReferrers( "NewBug" );
-        assertEquals("newbugs",1,ref.size()); 
-        assertEquals("newbugs2","BugTwo",ref.iterator().next()); 
+        assertNotNull("referrers expected", ref);
+        assertEquals("newbugs",1,ref.size());
+        assertEquals("newbugs2","BugTwo",ref.iterator().next());
 
         ref = mgr.findReferrers( "OpenBugs" );
+        assertNotNull("referrers expected", ref);
         assertEquals("openbugs",1,ref.size());
         assertEquals("openbugs2","BugOne",ref.iterator().next());
 
         ref = mgr.findReferrers( "OpenBug" );
+        assertNotNull("referrers expected", ref);
         assertEquals("openbug",1,ref.size());
         assertEquals("openbug2","BugOne",ref.iterator().next());
 
@@ -354,21 +351,22 @@ public class ReferenceManagerTest extend
     {
         engine.saveText( "BugOne", "BugOne" );
         Collection ref = mgr.findReferrers( "BugOne" );
+        assertNotNull("referrers expected", ref);
         assertEquals("wrong size",1,ref.size());
         assertEquals("ref", "BugOne", ref.iterator().next());
     }
-    
+
     public static Test suite()
     {
         return new TestSuite( ReferenceManagerTest.class );
     }
-    
+
     public static void main(String[] args)
     {
         junit.textui.TestRunner.main( new String[] { ReferenceManagerTest.class.getName()
} );
     }
-    
-    
+
+
     /**
      * Test method: dumps the contents of  ReferenceManager link lists to stdout.
      * This method is NOT synchronized, and should be used in testing
@@ -396,8 +394,8 @@ public class ReferenceManagerTest extend
                 }
                 buf.append( "\n" );
             }
-            
-            
+
+
             buf.append( "----------------------------------------------------------------\n"
);
             buf.append( "Refers To list:\n" );
             keys = rm.getRefersTo().keySet();
@@ -426,7 +424,7 @@ public class ReferenceManagerTest extend
         {
             buf.append("Problem in dump(): " + e + "\n" );
         }
-        
+
         return( buf.toString() );
     }
 

Modified: jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/TestEngine.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/TestEngine.java?rev=1566293&r1=1566292&r2=1566293&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/TestEngine.java (original)
+++ jspwiki/trunk/jspwiki-war/src/test/java/org/apache/wiki/TestEngine.java Sun Feb  9 13:15:15
2014
@@ -1,4 +1,4 @@
-/* 
+/*
     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
@@ -14,7 +14,7 @@
     "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.
  */
 
 package org.apache.wiki;
@@ -69,7 +69,7 @@ public class TestEngine extends WikiEngi
      * Creates WikiSession with the privileges of the administrative user.
      * For testing purposes, obviously.
      * @return the wiki session
-     * @throws WikiSecurityException 
+     * @throws WikiSecurityException
      */
     public WikiSession adminSession() throws WikiSecurityException
     {
@@ -105,7 +105,7 @@ public class TestEngine extends WikiEngi
      * Creates WikiSession with the privileges of the Janne.
      * For testing purposes, obviously.
      * @return the wiki session
-     * @throws WikiSecurityException 
+     * @throws WikiSecurityException
      */
     public WikiSession janneSession() throws WikiSecurityException
     {
@@ -125,12 +125,12 @@ public class TestEngine extends WikiEngi
         throws WikiException
     {
         super( new MockServletContext( "test" ), "test", cleanTestProps( props ) );
-        
+
         // Stash the WikiEngine in the servlet context
         ServletContext servletContext = this.getServletContext();
         servletContext.setAttribute("org.apache.wiki.WikiEngine", this);
     }
-    
+
     /**
      * Creates a correctly-instantiated mock HttpServletRequest with an associated
      * HttpSession.
@@ -175,6 +175,25 @@ public class TestEngine extends WikiEngi
         }
     }
 
+    public static void emptyWikiDir() {
+        emptyWikiDir( null );
+    }
+
+    public static void emptyWikiDir(Properties properties) {
+        if (properties == null) {
+            properties = getTestProperties();
+        }
+
+        String wikidir = properties.getProperty( AbstractFileProvider.PROP_PAGEDIR );
+        if ( wikidir != null ) {
+            File f = new File( wikidir );
+
+            if (f.exists() && f.isDirectory()) {
+                deleteAll( f );
+            }
+        }
+    }
+
     public static final Properties getTestProperties() {
         if (combinedProperties == null) {
             combinedProperties = PropertyReader.getCombinedProperties(PropertyReader.CUSTOM_JSPWIKI_CONFIG);
@@ -269,7 +288,7 @@ public class TestEngine extends WikiEngi
 
             if( f.exists() )
                 f.delete();
-            
+
             deleteAttachments( name );
             firePageEvent( WikiPageEvent.PAGE_DELETED, name );
         }
@@ -383,7 +402,7 @@ public class TestEngine extends WikiEngi
             e.printStackTrace();
         }
     }
-    
+
     /**
      * Supplies a clean set of test properties for the TestEngine constructor.
      * @param props the properties supplied by callers



Mime
View raw message