You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2009/03/18 05:44:01 UTC

svn commit: r755475 [1/2] - in /incubator/jspwiki/trunk: ./ src/java/org/apache/wiki/ src/java/org/apache/wiki/action/ src/java/org/apache/wiki/attachment/ src/java/org/apache/wiki/content/ src/java/org/apache/wiki/plugin/ src/java/org/apache/wiki/prov...

Author: ajaquith
Date: Wed Mar 18 04:43:59 2009
New Revision: 755475

URL: http://svn.apache.org/viewvc?rev=755475&view=rev
Log:
Unit test fixes.

Added:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageAlreadyExistsException.java
Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentManager.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentServlet.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/BugReportHandler.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/WeblogEntryPlugin.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/providers/AbstractFileProvider.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/rpc/atom/AtomAPIServlet.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/rss/RSSGenerator.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/search/LuceneSearchProvider.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/VariableManagerTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/diff/ContextualDiffProviderTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/parser/JSPWikiMarkupParserTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/CounterPluginTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/IndexPluginTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/InterWikiLinksPluginTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/PluginManagerTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/RecentChangesPluginTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/ReferredPagesPluginTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/ReferringPagesPluginTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/plugin/UndefinedPagesPluginTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/render/CreoleRendererTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/render/WysiwygEditingRendererTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/ui/migrator/BundleMigratorTest.java
    incubator/jspwiki/trunk/tests/java/org/apache/wiki/util/MailUtilTest.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Wed Mar 18 04:43:59 2009
@@ -1,4 +1,10 @@
-2009-03-26  Andrew Jaquith <ajaquith AT apache DOT org>
+2009-03-18  Andrew Jaquith <ajaquith AT apache DOT org>
+
+        * 3.0.0-svn-85
+        
+        * Lots of unit test and bug fixes.
+        
+2009-03-17  Andrew Jaquith <ajaquith AT apache DOT org>
 
         * 3.0.0-svn-84
 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/PageManager.java Wed Mar 18 04:43:59 2009
@@ -27,6 +27,7 @@
 import org.apache.wiki.api.WikiException;
 import org.apache.wiki.api.WikiPage;
 import org.apache.wiki.content.ContentManager;
+import org.apache.wiki.content.PageAlreadyExistsException;
 import org.apache.wiki.content.PageNotFoundException;
 import org.apache.wiki.content.WikiName;
 import org.apache.wiki.log.Logger;
@@ -181,7 +182,15 @@
         }
         catch( PageNotFoundException e )
         {
-            p = m_engine.getContentManager().addPage( page.getQualifiedName(), ContentManager.JSPWIKI_CONTENT_TYPE );
+            try
+            {
+                p = m_engine.getContentManager().addPage( page.getQualifiedName(), ContentManager.JSPWIKI_CONTENT_TYPE );
+            }
+            catch( PageAlreadyExistsException e1 )
+            {
+                // This should never happen
+                throw new ProviderException( e1.getMessage() );
+            }
         }
         p.setContent(content);
         p.save();

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Wed Mar 18 04:43:59 2009
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "84";
+    public static final String     BUILD         = "85";
     
     /**
      *  This is the generic version string you should use

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java Wed Mar 18 04:43:59 2009
@@ -49,10 +49,7 @@
 import org.apache.wiki.auth.acl.AclManager;
 import org.apache.wiki.auth.acl.DefaultAclManager;
 import org.apache.wiki.auth.authorize.GroupManager;
-import org.apache.wiki.content.ContentManager;
-import org.apache.wiki.content.PageNotFoundException;
-import org.apache.wiki.content.PageRenamer;
-import org.apache.wiki.content.WikiName;
+import org.apache.wiki.content.*;
 import org.apache.wiki.diff.DifferenceManager;
 import org.apache.wiki.event.WikiEngineEvent;
 import org.apache.wiki.event.WikiEventListener;
@@ -409,7 +406,14 @@
             //  Note: May be null, if JSPWiki has been deployed in a WAR file.
             //
             initialize( props );
-            log.info("Root path for this Wiki is: '"+m_rootPath+"'");
+            if ( m_rootPath == null )
+            {
+                log.warn("Root path for this Wiki is null. This is normal if deployed as a WAR or executed in mock context.");
+            }
+            else
+            {
+                log.info("Root path for this Wiki is: '"+m_rootPath+"'");
+            }
         }
         catch( Exception e )
         {
@@ -912,7 +916,15 @@
         }
         catch( PageNotFoundException e )
         {
-            p = createPage( new WikiName(space,m_frontPage) );
+            try
+            {
+                p = createPage( new WikiName(space,m_frontPage) );
+            }
+            catch( PageAlreadyExistsException e1 )
+            {
+                // This should not happen
+                throw new ProviderException( e1.getMessage() );
+            }
         }
         
         return p;
@@ -1874,13 +1886,14 @@
     /**
      *  Creates a new WikiPage object.
      *  
-     *  @param name The WikiName of the object to create
-     *  @return A new WikiPage object.
-     *  @throws ProviderException 
+     *  @param name the WikiName of the object to create
+     *  @return a new WikiPage object
+     *  @throws PageAlreadyExistsException if the page already exists in the repository.
+     *  @throws ProviderException if the backend fails
      *  @since 3.0
      */
     @SuppressWarnings("deprecation")
-    public WikiPage createPage( WikiName name ) throws ProviderException
+    public WikiPage createPage( WikiName name ) throws PageAlreadyExistsException, ProviderException
     {
         return m_contentManager.addPage( name, ContentManager.JSPWIKI_CONTENT_TYPE );
     }
@@ -1888,12 +1901,13 @@
     /**
      *  A shortcut for createPage( WikiName.valueOf(fqn) );
      *  
-     *  @param fqn The fully qualified name of a wikipage.
-     *  @return A new page.
-     *  @throws ProviderException 
+     *  @param fqn the fully qualified name of a wikipage
+     *  @return a new page
+     *  @throws PageAlreadyExistsException if the page already exists in the repository
+     *  @throws ProviderException if the backend fails
      *  @since 3.0
      */
-    public WikiPage createPage( String fqn ) throws ProviderException
+    public WikiPage createPage( String fqn ) throws PageAlreadyExistsException, ProviderException
     {
         return createPage( WikiName.valueOf( fqn ) );
     }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java Wed Mar 18 04:43:59 2009
@@ -45,6 +45,7 @@
 import org.apache.wiki.api.WikiException;
 import org.apache.wiki.api.WikiPage;
 import org.apache.wiki.auth.SessionMonitor;
+import org.apache.wiki.content.PageAlreadyExistsException;
 import org.apache.wiki.content.PageNotFoundException;
 import org.apache.wiki.content.WikiName;
 import org.apache.wiki.log.Logger;
@@ -639,7 +640,15 @@
         catch( PageNotFoundException e )
         {
             page = MarkupParser.cleanLink( page );
-            return m_engine.createPage( WikiName.valueOf( page ) );
+            try
+            {
+                return m_engine.createPage( WikiName.valueOf( page ) );
+            }
+            catch( PageAlreadyExistsException e1 )
+            {
+                // This should not happen
+                throw new ProviderException( e1.getMessage() );
+            }
         }
     }
 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentManager.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentManager.java Wed Mar 18 04:43:59 2009
@@ -402,15 +402,14 @@
     }
 
     /**
-     *  Deletes the given attachment version.
+     *  Deletes the given attachment version. If the attachment is
+     *  not found in the back-end because it does not exist, this method
+     *  completes silently.
      *
      *  @param att The attachment to delete
      *  @throws ProviderException If something goes wrong with the backend.
-     *  If a PageNotFoundException is generated by the ContentManager, it is
-     *  rethrown as a ProviderException
      */
-    public void deleteVersion( WikiPage att )
-        throws ProviderException
+    public void deleteVersion( WikiPage att ) throws ProviderException
     {
         try
         {
@@ -418,20 +417,19 @@
         }
         catch( PageNotFoundException e )
         {
-            throw new ProviderException( e.getMessage() );
+            // No worries
         }
     }
 
     /**
-     *  Deletes all versions of the given attachment.
+     *  Deletes all versions of the given attachment. If the attachment is
+     *  not found in the back-end because it does not exist, this method
+     *  completes silently.
      *  @param att The Attachment to delete.
-     *  @throws ProviderException if something goes wrong with the backend.
-     *  If a PageNotFoundException is generated by the ContentManager, it is
-     *  rethrown as a ProviderException
+     *  @throws ProviderException if something goes wrong with the backend
      */
     // FIXME: Should also use events!
-    public void deleteAttachment( Attachment att )
-        throws ProviderException
+    public void deleteAttachment( Attachment att ) throws ProviderException
     {
         try
         {
@@ -439,7 +437,7 @@
         }
         catch( PageNotFoundException e )
         {
-            throw new ProviderException( e.getMessage() );
+            // No worries
         }
     }
 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentServlet.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentServlet.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentServlet.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/attachment/AttachmentServlet.java Wed Mar 18 04:43:59 2009
@@ -48,6 +48,7 @@
 import org.apache.wiki.api.WikiPage;
 import org.apache.wiki.auth.AuthorizationManager;
 import org.apache.wiki.auth.permissions.PermissionFactory;
+import org.apache.wiki.content.PageAlreadyExistsException;
 import org.apache.wiki.content.PageNotFoundException;
 import org.apache.wiki.content.WikiName;
 import org.apache.wiki.filters.RedirectException;
@@ -58,7 +59,6 @@
 import org.apache.wiki.ui.progress.ProgressItem;
 import org.apache.wiki.util.HttpUtil;
 import org.apache.wiki.util.TextUtil;
-import org.bouncycastle.asn1.ocsp.Request;
 
 
 
@@ -733,7 +733,15 @@
             String contentType = "application/octet-stream"; // FIXME: This is not a good guess
             WikiName path = context.getPage().getQualifiedName().resolve(filename);
             
-            att = m_engine.getContentManager().addPage( path, contentType );
+            try
+            {
+                att = m_engine.getContentManager().addPage( path, contentType );
+            }
+            catch( PageAlreadyExistsException e1 )
+            {
+                // This should not happen
+                throw new ProviderException( e1.getMessage() );
+            }
             created = true;
         }
         att.setSize( contentLength );

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java Wed Mar 18 04:43:59 2009
@@ -754,7 +754,7 @@
         }
         catch( RepositoryException e )
         {
-            throw new ProviderException("Deletion of pages failed.",e);
+            throw new ProviderException( "Deletion of pages failed: " + e.getMessage(), e );
         }
     }
 
@@ -998,9 +998,10 @@
      *  @param path the WikiName
      *  @param contentType the type of content
      *  @return the {@link JCRWikiPage} 
-     *  @throws ProviderException If the backend fails.
+     *  @throws PageAlreadyExistsException if the page already exists in the repository
+     *  @throws ProviderException if the backend fails
      */
-    public JCRWikiPage addPage( WikiName path, String contentType ) throws ProviderException
+    public JCRWikiPage addPage( WikiName path, String contentType ) throws PageAlreadyExistsException, ProviderException
     {
         try
         {

Added: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageAlreadyExistsException.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageAlreadyExistsException.java?rev=755475&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageAlreadyExistsException.java (added)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageAlreadyExistsException.java Wed Mar 18 04:43:59 2009
@@ -0,0 +1,50 @@
+/*
+    JSPWiki - a JSP-based WikiWiki clone.
+
+    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
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "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.      
+ */
+package org.apache.wiki.content;
+
+/**
+ *  Indicates that a new WikiPage or attachment could not be added to the
+ *  content repository at the specified path because it already exists.
+ *  
+ *  @since 3.0
+ */
+public class PageAlreadyExistsException extends Exception
+{
+    private static final long serialVersionUID = 1L;
+
+    /**
+     *  Construct an exception from a String path. 
+     *  @param path the path to the WikiPage, which already exists.
+     */
+    public PageAlreadyExistsException( String path )
+    {
+        super( path );
+    }
+
+    /**
+     *  Construct an exception from a WikiName path. 
+     *  @param path the path to the WikiPage, which already exists.
+     */
+    public PageAlreadyExistsException( WikiName path )
+    {
+        super( path.toString() );
+    }
+}

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/BugReportHandler.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/BugReportHandler.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/BugReportHandler.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/BugReportHandler.java Wed Mar 18 04:43:59 2009
@@ -32,11 +32,13 @@
 import org.apache.wiki.api.PluginException;
 import org.apache.wiki.api.WikiException;
 import org.apache.wiki.api.WikiPage;
+import org.apache.wiki.content.PageAlreadyExistsException;
 import org.apache.wiki.content.WikiName;
 import org.apache.wiki.filters.RedirectException;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
 import org.apache.wiki.parser.MarkupParser;
+import org.apache.wiki.providers.ProviderException;
 
 
 /**
@@ -168,7 +170,15 @@
             String pageName = findNextPage( context, title,
                                             (String)params.get( PARAM_PAGE ) );
 
-            WikiPage newPage = context.getEngine().createPage( WikiName.valueOf(pageName) );
+            WikiPage newPage;
+            try
+            {
+                newPage = context.getEngine().createPage( WikiName.valueOf(pageName) );
+            }
+            catch( PageAlreadyExistsException e )
+            {
+                throw new ProviderException( e.getMessage() );
+            }
             WikiContext newContext = (WikiContext)context.clone();
             newContext.setPage( newPage );
 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/WeblogEntryPlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/WeblogEntryPlugin.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/WeblogEntryPlugin.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/WeblogEntryPlugin.java Wed Mar 18 04:43:59 2009
@@ -26,6 +26,7 @@
 import org.apache.wiki.*;
 import org.apache.wiki.api.PluginException;
 import org.apache.wiki.api.WikiPage;
+import org.apache.wiki.content.PageAlreadyExistsException;
 import org.apache.wiki.content.WikiName;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
@@ -159,7 +160,15 @@
             String name = WeblogPlugin.makeEntryPage( baseName, 
                                                       date, 
                                                       Integer.toString(idx) );
-            WikiPage page = mgr.getEngine().createPage( WikiName.valueOf(name) );
+            WikiPage page;
+            try
+            {
+                page = mgr.getEngine().createPage( WikiName.valueOf(name) );
+            }
+            catch( PageAlreadyExistsException e )
+            {
+                throw new ProviderException( e.getMessage() );
+            }
                                           
             PageLock lock = mgr.getCurrentLock( page );
 

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/providers/AbstractFileProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/providers/AbstractFileProvider.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/providers/AbstractFileProvider.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/providers/AbstractFileProvider.java Wed Mar 18 04:43:59 2009
@@ -25,6 +25,7 @@
 
 import org.apache.wiki.*;
 import org.apache.wiki.api.WikiPage;
+import org.apache.wiki.content.PageAlreadyExistsException;
 import org.apache.wiki.content.WikiName;
 import org.apache.wiki.log.Logger;
 import org.apache.wiki.log.LoggerFactory;
@@ -445,7 +446,15 @@
             return null;
         }
 
-        WikiPage p = m_engine.createPage( WikiName.valueOf( page ) );
+        WikiPage p;
+        try
+        {
+            p = m_engine.createPage( WikiName.valueOf( page ) );
+        }
+        catch( PageAlreadyExistsException e )
+        {
+            throw new ProviderException( e.getMessage() );
+        }
         p.setLastModified( new Date(file.lastModified()) );
 
         return p;

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/rpc/atom/AtomAPIServlet.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/rpc/atom/AtomAPIServlet.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/rpc/atom/AtomAPIServlet.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/rpc/atom/AtomAPIServlet.java Wed Mar 18 04:43:59 2009
@@ -35,6 +35,7 @@
 import org.apache.wiki.*;
 import org.apache.wiki.api.WikiException;
 import org.apache.wiki.api.WikiPage;
+import org.apache.wiki.content.PageAlreadyExistsException;
 import org.apache.wiki.content.PageNotFoundException;
 import org.apache.wiki.content.WikiName;
 import org.apache.wiki.log.Logger;
@@ -148,7 +149,16 @@
             String pageName = plugin.getNewEntryPage( m_engine, blogid );
             String username = author.getName();
 
-            WikiPage entryPage = m_engine.createPage( WikiName.valueOf( pageName ) );
+            WikiPage entryPage;
+            try
+            {
+                entryPage = m_engine.createPage( WikiName.valueOf( pageName ) );
+            }
+            catch( PageAlreadyExistsException e )
+            {
+                // Should not happen
+                throw new ServletException( e.getMessage() );
+            }
             entryPage.setAuthor( username );
 
             WikiContext context = m_engine.getWikiContextFactory().newViewContext( request, response, entryPage );

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/rss/RSSGenerator.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/rss/RSSGenerator.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/rss/RSSGenerator.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/rss/RSSGenerator.java Wed Mar 18 04:43:59 2009
@@ -27,6 +27,7 @@
 import org.apache.wiki.api.WikiPage;
 import org.apache.wiki.attachment.Attachment;
 import org.apache.wiki.auth.permissions.PagePermission;
+import org.apache.wiki.content.PageAlreadyExistsException;
 import org.apache.wiki.content.PageNotFoundException;
 import org.apache.wiki.content.WikiName;
 import org.apache.wiki.log.Logger;
@@ -310,7 +311,23 @@
     public String generate() throws WikiException
     {
         WikiContext context = m_engine.getWikiContextFactory().newContext(null,null,WikiContext.RSS);
-        context.setPage( m_engine.createPage( WikiName.valueOf( "__DUMMY" ) ) );
+        // This is ugly
+        try
+        {
+            context.setPage( m_engine.createPage( WikiName.valueOf( "__DUMMY" ) ) );
+        }
+        catch( PageAlreadyExistsException e )
+        {
+            try
+            {
+                context.setPage( m_engine.getPage( "__DUMMY" ) );
+            }
+            catch( PageNotFoundException e1 )
+            {
+                // This should not happen
+                throw new WikiException( e1.getMessage() );
+            }
+        }
         Feed feed = new RSS10Feed( context );
 
         String result = generateFullWikiRSS( context, feed );

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/search/LuceneSearchProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/search/LuceneSearchProvider.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/search/LuceneSearchProvider.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/search/LuceneSearchProvider.java Wed Mar 18 04:43:59 2009
@@ -49,6 +49,7 @@
 import org.apache.wiki.api.WikiPage;
 import org.apache.wiki.attachment.Attachment;
 import org.apache.wiki.attachment.AttachmentManager;
+import org.apache.wiki.content.PageAlreadyExistsException;
 import org.apache.wiki.content.PageNotFoundException;
 import org.apache.wiki.content.WikiName;
 import org.apache.wiki.log.Logger;
@@ -626,7 +627,17 @@
                 {
                     // No worries!
                     log.error("Lucene found a result page '" + pageName + "' that could not be loaded, removing from Lucene cache");
-                    pageRemoved(m_engine.createPage( WikiName.valueOf( pageName ) ));
+                    try
+                    {
+                        page = m_engine.createPage( WikiName.valueOf( pageName ) );
+                        pageRemoved( page );
+                        m_engine.deletePage( pageName );
+                    }
+                    catch( PageAlreadyExistsException e1 )
+                    {
+                        // This should not happen
+                        throw new ProviderException( e1.getMessage() );
+                    }
                 }
             }
         }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/TestEngine.java Wed Mar 18 04:43:59 2009
@@ -44,6 +44,7 @@
 import org.apache.wiki.auth.SessionMonitor;
 import org.apache.wiki.auth.Users;
 import org.apache.wiki.auth.WikiSecurityException;
+import org.apache.wiki.content.PageAlreadyExistsException;
 import org.apache.wiki.content.PageNotFoundException;
 import org.apache.wiki.content.WikiName;
 import org.apache.wiki.log.Logger;
@@ -309,7 +310,7 @@
      * @param data
      */
     public void addAttachment( String pageName, String attachmentName, byte[] data )
-        throws ProviderException, IOException
+        throws PageAlreadyExistsException, ProviderException, IOException
     {
         Attachment att = getContentManager().addPage( WikiName.valueOf( pageName ).resolve( attachmentName ), "application/octet-stream" );
 
@@ -352,7 +353,15 @@
         }
         catch ( PageNotFoundException e )
         {
-            page = createPage( WikiName.valueOf( pageName ) );
+            try
+            {
+                page = createPage( WikiName.valueOf( pageName ) );
+            }
+            catch( PageAlreadyExistsException e1 )
+            {
+                // This should not happen
+                throw new WikiException( e1.getMessage() );
+            }
         }
         WikiContext context = this.getWikiContextFactory().newViewContext( request, null, page );
         saveText( context, content );
@@ -376,7 +385,16 @@
         }
 
         // Create page and wiki context
-        WikiPage page = createPage( WikiName.valueOf( pageName ) );
+        WikiPage page;
+        try
+        {
+            page = createPage( WikiName.valueOf( pageName ) );
+        }
+        catch( PageAlreadyExistsException e1 )
+        {
+            // This should not happen
+            throw new WikiException( e1.getMessage() );
+        }
         WikiContext context = this.getWikiContextFactory().newViewContext( request, null, page );
         saveText( context, content );
     }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/VariableManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/VariableManagerTest.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/VariableManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/VariableManagerTest.java Wed Mar 18 04:43:59 2009
@@ -62,6 +62,7 @@
 
             m_variableManager = new VariableManager( props );
             testEngine = new TestEngine( props );
+            testEngine.deletePage( PAGE_NAME );
             m_context = testEngine.getWikiContextFactory().newViewContext( testEngine.createPage(WikiName.valueOf(PAGE_NAME)) );
 
         }

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java Wed Mar 18 04:43:59 2009
@@ -25,10 +25,7 @@
 import java.io.*;
 import java.util.*;
 
-import org.apache.wiki.*;
-import org.apache.wiki.api.WikiException;
 import org.apache.wiki.api.WikiPage;
-import org.apache.wiki.attachment.*;
 import org.apache.wiki.content.WikiName;
 import org.apache.wiki.providers.*;
 import org.apache.wiki.util.FileUtil;
@@ -96,7 +93,7 @@
 
         String newdir = tmpdir + File.separator + dirname;
 
-        props.setProperty( AbstractFileProvider.PROP_PAGEDIR, 
+        props.setProperty( WikiEngine.PROP_WORKDIR, 
                            newdir );
 
         m_engine.shutdown();
@@ -111,22 +108,6 @@
         
     }
 
-    public void testNonExistantDirProperty() throws Exception
-    {
-        props.remove( AbstractFileProvider.PROP_PAGEDIR );
-        try
-        {
-            m_engine.shutdown();
-            m_engine = new TestEngine( props );
-
-            fail( "Wiki did not warn about missing property." );
-        }
-        catch( WikiException e )
-        {
-            // This is okay.
-        }
-    }
-
     /**
      *  Check that calling pageExists( String ) works.
      */
@@ -282,6 +263,7 @@
     {
         String src="Foobar. [Foobar].  Frobozz.  [This is a link].";
 
+        m_engine.deletePage( "Test" );
         Object[] result = m_engine.scanWikiLinks( m_engine.createPage( WikiName.valueOf( "Test" ) ), src ).toArray();
         
         assertEquals( "item 0", "Foobar", result[0] );
@@ -934,6 +916,7 @@
     
     public void testChangeNoteOldVersion2() throws Exception
     {
+        m_engine.deletePage( NAME1 );
         WikiPage p = m_engine.createPage( WikiName.valueOf( NAME1 ) );
     
         WikiContext context = m_engine.getWikiContextFactory().newViewContext( p );

Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/diff/ContextualDiffProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/diff/ContextualDiffProviderTest.java?rev=755475&r1=755474&r2=755475&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/diff/ContextualDiffProviderTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/diff/ContextualDiffProviderTest.java Wed Mar 18 04:43:59 2009
@@ -20,11 +20,9 @@
  */
 package org.apache.wiki.diff;
 
-import java.io.IOException;
 import java.util.Properties;
 
 import org.apache.wiki.*;
-import org.apache.wiki.api.WikiException;
 import org.apache.wiki.diff.ContextualDiffProvider;
 
 import junit.framework.Test;
@@ -83,7 +81,7 @@
 
 
 
-    public void testNoChanges() throws IOException, WikiException
+    public void testNoChanges() throws Exception
     {
         diffTest(null, "", "", "");
         diffTest(null, "A", "A", "A");
@@ -96,7 +94,7 @@
 
 
 
-    public void testSimpleInsertions() throws IOException, WikiException
+    public void testSimpleInsertions() throws Exception
     {
         // Ah, the white space trailing an insertion is tacked onto the insertion, this is fair, the
         // alternative would be to greedily take the leading whitespace before the insertion as part
@@ -121,7 +119,7 @@
 
 
 
-    public void testSimpleDeletions() throws IOException, WikiException
+    public void testSimpleDeletions() throws Exception
     {
         // Simple deletes...
         diffTest(null, "A B C", "A C", "A |-B -|C");
@@ -139,7 +137,7 @@
 
 
 
-    public void testContextLimits() throws IOException, WikiException
+    public void testContextLimits() throws Exception
     {
         // No change
         diffTest("1", "A B C D E F G H I", "A B C D E F G H I", "A...");
@@ -163,14 +161,14 @@
                 
     }
 
-    public void testMultiples() throws IOException, WikiException
+    public void testMultiples() throws Exception
     {
         diffTest(null, "A F", "A B C D E F", "A |^B C D E ^|F");
         diffTest(null, "A B C D E F", "A F", "A |-B C D E -|F");
         
     }
 
-    public void testSimpleChanges() throws IOException, WikiException
+    public void testSimpleChanges() throws Exception
     {
         // *changes* are actually an insert and a delete in the output...
 
@@ -204,7 +202,7 @@
      */
     
     private void diffTest(String contextLimit, String oldText, String newText, String expectedDiff)
-        throws IOException, WikiException
+        throws Exception
     {
         ContextualDiffProvider diff = new ContextualDiffProvider();
 
@@ -220,6 +218,7 @@
         m_engine.shutdown();
         m_engine = new TestEngine(props);
         
+        m_engine.deletePage( "Dummy" );
         WikiContext ctx = m_engine.getWikiContextFactory().newViewContext( m_engine.createPage( "Dummy" ) );
         String actualDiff = diff.makeDiffHtml( ctx, oldText, newText);
 



Re: svn commit: r755475 [1/2] - in /incubator/jspwiki/trunk: ./ src/java/org/apache/wiki/ src/java/org/apache/wiki/action/ src/java/org/apache/wiki/attachment/ src/java/org/apache/wiki/content/ src/java/org/apache/wiki/plugin/ src/java/org/apache/wiki/prov...

Posted by Janne Jalkanen <ja...@iki.fi>.
>     incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageAlreadyExistsException.java

Minor point - I would be happier if this extended ProviderException,
just like PageNotFoundException.

/Janne