jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jalka...@apache.org
Subject svn commit: r696486 - in /incubator/jspwiki/trunk: ./ src/com/ecyrd/jspwiki/ src/com/ecyrd/jspwiki/content/ tests/com/ecyrd/jspwiki/ tests/com/ecyrd/jspwiki/content/
Date Wed, 17 Sep 2008 22:01:35 GMT
Author: jalkanen
Date: Wed Sep 17 15:01:34 2008
New Revision: 696486

URL: http://svn.apache.org/viewvc?rev=696486&view=rev
Log:
Fixed the failing unit tests for PageRenamer.  The problem was caused by the wrong order in
the renaming; the attachments were asked for *after* the page had been moved, so the references
were never ok.

Also, self-references were not counted by ReferenceManager.  This was probably some old leftover
code; so added a new test and modified some old ones to make sure everything is accounted
for.

Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/ReleaseNotes
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ReferenceManager.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/PageRenamer.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ReferenceManagerTest.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestEngine.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/PageRenamerTest.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=696486&r1=696485&r2=696486&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Wed Sep 17 15:01:34 2008
@@ -1,3 +1,9 @@
+2008-09-18  Janne Jalkanen <jalkanen@apache.org>
+
+        * 2.8.0-beta-2
+        
+        * Fixed the failing unit tests for PageRenamer.
+        
 2008-09-05  Janne Jalkanen <jalkanen@apache.org>
 
         * 2.8.0-beta-1

Modified: incubator/jspwiki/trunk/ReleaseNotes
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ReleaseNotes?rev=696486&r1=696485&r2=696486&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ReleaseNotes (original)
+++ incubator/jspwiki/trunk/ReleaseNotes Wed Sep 17 15:01:34 2008
@@ -19,7 +19,8 @@
 * Simplified Chinese, Dutch and Italian localizations added!
 
 * There is no more need for JAAS files!  Hooray!  This has
-  been replaced with custom jspwiki properties.
+  been replaced with custom jspwiki properties.  Please see
+  the UPGRADING document.
 
 * Massive improvements to the default template, like
   section editing.
@@ -31,6 +32,12 @@
 
 * German language corepages
 
+* Support for the UniversalEditButton (http://universaleditbutton.org/).
+
+* Password hashes are now salted.  This means you can't share the passwords
+  if you have JSPWiki 2.6 instances, as the passwords are upgraded
+  transparently.
+
 The full log of any issues fixed can be found at:
 
 https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=12310732&styleName=Html&version=12312864
@@ -61,15 +68,14 @@
   authentication/permissions scheme.  Therefore, if you have very
   sensitive data in your wiki, you might not want to enable it.
 
-* Not all old plugins work.  Specifically, plugins from 2.2, which
-  1) use com.ecyrd.jspwiki package, will fail because they are not
-     signed with the same key as jspwiki.jar, and
-  2) any plugin, which constructs new WikiPages will fail because
-     of the constructor has been changed.
+* Not all old plugins work.  Specifically any plugins, which construct 
+  new WikiPages will fail because of the constructor has been changed.
+
+* The PageFilter API was changed in 2.6
 
 * Our documentation simply sucks at this point.  Please forgive us,
   and point where those fixes are needed.  We will improve upon
-  this during our progress towards a stable.
+  based your input.
 
 * The ShortURLConstructor does not work reliably.  Please use
   ShortViewURLConstructor, or Apache mod_rewrite.

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ReferenceManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ReferenceManager.java?rev=696486&r1=696485&r2=696486&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ReferenceManager.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ReferenceManager.java Wed Sep 17 15:01:34
2008
@@ -843,11 +843,12 @@
     private void updateReferredBy( String page, String referrer )
     {
         // We're not really interested in first level self-references.
+        /*
         if( page.equals( referrer ) )
         {
             return;
         }
-
+        */
         // Neither are we interested if plural forms refer to each other.
         if( m_matchEnglishPlurals )
         {

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java?rev=696486&r1=696485&r2=696486&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Wed Sep 17 15:01:34 2008
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "1";
+    public static final String     BUILD         = "2";
     
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/PageRenamer.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/PageRenamer.java?rev=696486&r1=696485&r2=696486&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/PageRenamer.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/PageRenamer.java Wed Sep 17 15:01:34
2008
@@ -112,7 +112,9 @@
         m_camelCase = TextUtil.getBooleanProperty( engine.getWikiProperties(), 
                                                    JSPWikiMarkupParser.PROP_CAMELCASELINKS,

                                                    m_camelCase );
-        
+
+        Set<String> referrers = getReferencesToChange( fromPage, engine );
+
         //
         //  Do the actual rename by changing from the frompage to the topage, including
         //  all of the attachments
@@ -138,7 +140,7 @@
         toPage.setAuthor( context.getCurrentUser().getName() );
         
         engine.getPageManager().putPageText( toPage, engine.getPureText( toPage ) );
-        
+
         //
         //  Update the references
         //
@@ -147,11 +149,11 @@
         engine.updateReferences( toPage );
 
         //
-        //  Update referrers first
+        //  Update referrers
         //
         if( changeReferrers )
         {
-            updateReferrers( context, fromPage, toPage );
+            updateReferrers( context, fromPage, toPage, referrers );
         }
 
 
@@ -170,36 +172,21 @@
      *  @param toPage The new page
      */
     @SuppressWarnings("unchecked")
-    private void updateReferrers( WikiContext context, WikiPage fromPage, WikiPage toPage
)
+    private void updateReferrers( WikiContext context, WikiPage fromPage, WikiPage toPage,
Set<String>referrers )
     {
         WikiEngine engine = context.getEngine();
-        Set<String> referrers = new TreeSet<String>();
-        
-        Collection<String> r = engine.getReferenceManager().findReferrers( fromPage.getName()
);
-        if( r != null ) referrers.addAll( r );
-        
-        try
-        {
-            Collection<Attachment> attachments = engine.getAttachmentManager().listAttachments(
fromPage );
-
-            for( Attachment att : attachments  )
-            {
-                Collection<String> c = engine.getReferenceManager().findReferrers(att.getName());
-
-                if( c != null ) referrers.addAll(c);
-            }
-        }
-        catch( ProviderException e )
-        {
-            // We will continue despite this error
-            log.error( "Provider error while fetching attachments for rename", e );
-        }
-
         
         if( referrers.isEmpty() ) return; // No referrers
         
         for( String pageName : referrers )
         {
+            //  In case the page was just changed from under us, let's do this
+            //  small kludge.
+            if( pageName.equals( fromPage.getName() ) )
+            {
+                pageName = toPage.getName();
+            }
+            
             WikiPage p = engine.getPage( pageName );
             
             String sourceText = engine.getPureText( p );
@@ -231,6 +218,32 @@
         }
     }
 
+    private Set<String> getReferencesToChange( WikiPage fromPage, WikiEngine engine
)
+    {
+        Set<String> referrers = new TreeSet<String>();
+        
+        Collection<String> r = engine.getReferenceManager().findReferrers( fromPage.getName()
);
+        if( r != null ) referrers.addAll( r );
+        
+        try
+        {
+            Collection<Attachment> attachments = engine.getAttachmentManager().listAttachments(
fromPage );
+
+            for( Attachment att : attachments  )
+            {
+                Collection<String> c = engine.getReferenceManager().findReferrers(att.getName());
+
+                if( c != null ) referrers.addAll(c);
+            }
+        }
+        catch( ProviderException e )
+        {
+            // We will continue despite this error
+            log.error( "Provider error while fetching attachments for rename", e );
+        }
+        return referrers;
+    }
+
     /**
      *  Replaces camelcase links.
      */
@@ -274,14 +287,19 @@
     {
         StringBuilder sb = new StringBuilder( sourceText.length()+32 );
         
+        //
+        //  This monstrosity just looks for a JSPWiki link pattern.  But it is pretty
+        //  cool for a regexp, isn't it?  If you can understand this in a single reading,
+        //  you have way too much time in your hands.
+        //
         Pattern linkPattern = Pattern.compile( "([\\[\\~]?)\\[([^\\|\\]]*)(\\|)?([^\\|\\]]*)(\\|)?([^\\|\\]]*)\\]"
);
         
         Matcher matcher = linkPattern.matcher( sourceText );
         
         int start = 0;
         
-        //System.out.println("====");
-        //System.out.println("SRC="+sourceText.trim());
+        // System.out.println("====");
+        // System.out.println("SRC="+sourceText.trim());
         while( matcher.find(start) )
         {
             char charBefore = (char)-1;
@@ -308,7 +326,7 @@
             System.out.println("   text="+text);
             System.out.println("   link="+link);
             System.out.println("   attr="+attr);
-             */
+            */
             if( link.length() == 0 )
             {
                 text = replaceSingleLink( context, text, from, to );

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ReferenceManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ReferenceManagerTest.java?rev=696486&r1=696485&r2=696486&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ReferenceManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/ReferenceManagerTest.java Wed Sep 17 15:01:34
2008
@@ -148,14 +148,14 @@
         assertNull( "TestPage referrers", c );
 
         c = mgr.findReferrers( "Foobar" );
-        assertTrue( "Foobar referrers", c.size()==1 && ((String) c.iterator().next()).equals("TestPage")
);
+        assertTrue( "Foobar referrers", c.size()==2  );
 
         c = mgr.findReferrers( "Foobar2" );
         assertTrue( "Foobar2 referrers", c.size()==1 && ((String) c.iterator().next()).equals("Foobar")
);
 
         c = mgr.findReferrers( "Foobars" );
-        assertEquals( "Foobars referrers", 1, c.size() );
-        assertEquals( "Foobars referrer 'TestPage'", "TestPage", (String) c.iterator().next()
);
+        assertEquals( "Foobars referrers", 2, c.size() );
+        //assertEquals( "Foobars referrer 'TestPage'", "TestPage", (String) c.iterator().next()
);
     }
 
     public void testRefersTo()
@@ -202,8 +202,7 @@
         Iterator it = c.iterator();
         String s1 = (String)it.next();
         assertTrue( "Foobar referrers", 
-                    c.size()==1 && 
-                    s1.equals("TestPage") );
+                    c.size()==2 );
     }
 
 
@@ -227,8 +226,8 @@
     {
         engine.saveText( "Foobars", "qwertz" );
         Collection c = mgr.findReferrers( "Foobars" );
-        assertEquals( "Foobars referrers", 1, c.size() );
-        assertEquals( "Foobars referrer is not TestPage", "TestPage", ((String) c.iterator().next())
);
+        assertEquals( "Foobars referrers", 2, c.size() );
+        assertTrue( "Foobars referrer is not TestPage", c.contains( "TestPage" ) &&
c.contains("Foobar"));
     }
 
     public void testUpdateBothExist2()
@@ -238,13 +237,13 @@
         engine.saveText( "TestPage", "Reference to [Foobar], [Foobars]." );
         
         Collection c = mgr.findReferrers( "Foobars" );
-        assertEquals( "Foobars referrers count", 1, c.size() );
+        assertEquals( "Foobars referrers count", 2, c.size() );
 
         Iterator i = c.iterator();
         String first = (String) i.next();
 
         assertTrue( "Foobars referrers", 
-                    first.equals("TestPage") );
+                    c.contains("TestPage") && c.contains("Foobar"));
     }
 
     public void testCircularRefs()
@@ -334,6 +333,14 @@
 
     }
 
+    public void testSelf() throws WikiException
+    {
+        engine.saveText( "BugOne", "BugOne" );
+        Collection ref = mgr.findReferrers( "BugOne" );
+        assertEquals("wrong size",1,ref.size());
+        assertEquals("ref", "BugOne", ref.iterator().next());
+    }
+    
     public static Test suite()
     {
         return new TestSuite( ReferenceManagerTest.class );

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestEngine.java?rev=696486&r1=696485&r2=696486&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestEngine.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/TestEngine.java Wed Sep 17 15:01:34 2008
@@ -221,6 +221,8 @@
 
             if( f.exists() )
                 f.delete();
+            
+            deleteAttachments( name );
         }
         catch( Exception e )
         {
@@ -231,11 +233,14 @@
     /**
      *  Deletes all attachments related to the given page.
      */
-    public void deleteAttachments( String page )
+    public static void deleteAttachments( String page )
     {
+        Properties properties = new Properties();
+
         try
         {
-            String files = getWikiProperties().getProperty( BasicAttachmentProvider.PROP_STORAGEDIR
);
+            properties.load( findTestProperties() );
+            String files = properties.getProperty( BasicAttachmentProvider.PROP_STORAGEDIR
);
 
             File f = new File( files, TextUtil.urlEncodeUTF8( page ) + BasicAttachmentProvider.DIR_EXTENSION
);
 

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/PageRenamerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/PageRenamerTest.java?rev=696486&r1=696485&r2=696486&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/PageRenamerTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/PageRenamerTest.java Wed Sep 17
15:01:34 2008
@@ -40,6 +40,10 @@
         TestEngine.deleteTestPage("Cdauth");
         TestEngine.deleteTestPage("TestPageReferring");
         TestEngine.deleteTestPage("TestPageReferredNew");
+        TestEngine.deleteTestPage("Main");
+        TestEngine.deleteTestPage("Main8887");
+        TestEngine.deleteTestPage("TestPage1234");
+        TestEngine.deleteTestPage("TestPageReferred");
 
         TestEngine.emptyWorkDir();
     }



Mime
View raw message