Return-Path: Delivered-To: apmail-incubator-jspwiki-dev-archive@minotaur.apache.org Received: (qmail 44473 invoked from network); 2 May 2009 17:11:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 May 2009 17:11:17 -0000 Received: (qmail 75261 invoked by uid 500); 2 May 2009 17:11:17 -0000 Delivered-To: apmail-incubator-jspwiki-dev-archive@incubator.apache.org Received: (qmail 75244 invoked by uid 500); 2 May 2009 17:11:17 -0000 Mailing-List: contact jspwiki-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jspwiki-dev@incubator.apache.org Delivered-To: mailing list jspwiki-dev@incubator.apache.org Received: (qmail 75234 invoked by uid 99); 2 May 2009 17:11:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 02 May 2009 17:11:17 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of andrew.r.jaquith@gmail.com designates 209.85.217.177 as permitted sender) Received: from [209.85.217.177] (HELO mail-gx0-f177.google.com) (209.85.217.177) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 02 May 2009 17:11:04 +0000 Received: by gxk25 with SMTP id 25so5267827gxk.12 for ; Sat, 02 May 2009 10:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=Et8i1HZ2vDp18lIBsAv2OJtdwKmun+P/0gBhjU9cy9o=; b=ZF/QRHLsXvSJrPuqUGxRBMoW3cbOsusBA+aW2HYmmWARuzJ2qMsIXUVObUUY6j74H0 bss96VCZgO+g3wk8WdFQ6jeeoHNhlZCNMqsf7w73D3gVr1mAbJFGxry9Wa/sHJUzkLGW leg6TzqSEIk5lXTBpAzQzjx9LjNi7PIrU/7Qs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=BcK5fTAvRzVHr1xnAh+eULv9SauZQTyvhEzNWsQ5lkLRzDVJBeKPL/iW7cX2A0lvbz EovdbG6fD2ammVWUMZabDio36qiSbl9d2y1BcKELxO76BywOAnY52t5rczBhyCZoMnKu OstNRS0jQsJwChIW99q97wuZMqIDMLG6YLIwg= MIME-Version: 1.0 Received: by 10.231.19.197 with SMTP id c5mr622859ibb.30.1241284242589; Sat, 02 May 2009 10:10:42 -0700 (PDT) Date: Sat, 2 May 2009 13:10:42 -0400 Message-ID: Subject: Re: svn commit: r770959 [2/2] - in /incubator/jspwiki/trunk: ./ src/java/org/apache/wiki/ src/java/org/apache/wiki/action/ src/java/org/apache/wiki/api/ src/java/org/apache/wiki/auth/ src/java/org/apache/wiki/content/ src/java/org/apache/wiki/event/ From: Andrew Jaquith To: jspwiki-dev@incubator.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Yes, I can break future commits into smaller ones. Generally, the approach I've been taking is to include in a single commit everything I describe in a single bullet. Multiple bullets get multiple commits. In this case, everything seemed to "go together", hence the big commit. But I take your point. As for page renaming -- this seems like it should really be just a specific application of the more general case of JCR node renaming. Logically, the node-renaming code should live in ContentManager, no? That would leave the page-specific aspects in PageRenamer, although it would be smaller and lighter. The page-renaming code (currently parked in ContentManager) has already gotten slimmer because of the movement of re-indexing and re-referencing code into the listener methods of SearchManager and ReferenceManager. That said, I am not really convinced we need a separate PageRenamer class. It's called from exactly one place, RenameActionBean. If we had a decent JCR "prototype method" for renaming nodes in ContentManager that does most of the heavy lifting, we could just do it fairly directly. Andrew On 5/2/09, Janne Jalkanen wrote: > > Request: Could we please have smaller commits with a single feature > only? These massive megacommits are impossible to review... I have no > idea what was really done and why :-(. Offhand, I think I would like > to revert the changes to PageRenamer since I really don't want > ContentManager to become a really massive class it is currently > becoming - page renaming code is fairly heavy and it's better > componentized elsewhere. But because it's one massive commit, I can't > do it simply. > > /Janne > > On 2 May 2009, at 17:15, ajaquith@apache.org wrote: > >> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ >> PageRenamer.java >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageRenamer.java?rev=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ >> PageRenamer.java (original) >> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ >> PageRenamer.java Sat May 2 14:15:13 2009 >> @@ -20,23 +20,8 @@ >> */ >> package org.apache.wiki.content; >> >> -import java.util.Collection; >> -import java.util.Set; >> -import java.util.TreeSet; >> -import java.util.regex.Matcher; >> -import java.util.regex.Pattern; >> - >> -import org.apache.wiki.InternalWikiException; >> import org.apache.wiki.WikiContext; >> -import org.apache.wiki.WikiEngine; >> import org.apache.wiki.api.WikiException; >> -import org.apache.wiki.api.WikiPage; >> -import org.apache.wiki.log.Logger; >> -import org.apache.wiki.log.LoggerFactory; >> -import org.apache.wiki.parser.JSPWikiMarkupParser; >> -import org.apache.wiki.parser.MarkupParser; >> -import org.apache.wiki.providers.ProviderException; >> -import org.apache.wiki.util.TextUtil; >> >> >> >> @@ -49,13 +34,8 @@ >> */ >> public class PageRenamer >> { >> - >> - private static final Logger log = >> LoggerFactory.getLogger( PageRenamer.class ); >> - >> - private boolean m_camelCase = false; >> - >> /** >> - * Renames a page. >> + * Renames a page. Delegates to {@link >> ContentManager#renamePage(WikiContext, String, String, boolean)}. >> * >> * @param context The current context. >> * @param renameFrom The name from which to rename. >> @@ -70,372 +50,7 @@ >> boolean changeReferrers ) >> throws WikiException >> { >> - // >> - // Sanity checks first >> - // >> - if( renameFrom == null || renameFrom.length() == 0 ) >> - { >> - throw new WikiException( "From name may not be null or >> empty" ); >> - } >> - if( renameTo == null || renameTo.length() == 0 ) >> - { >> - throw new WikiException( "To name may not be null or >> empty" ); >> - } >> - >> - // >> - // Clean up the "to" -name so that it does not contain >> anything illegal >> - // >> - >> - renameTo = MarkupParser.cleanLink( renameTo.trim() ); >> - >> - if( renameTo.equals(renameFrom) ) >> - { >> - throw new WikiException( "You cannot rename the page to >> itself" ); >> - } >> - >> - // >> - // Preconditions: "from" page must exist, and "to" page >> must not yet exist. >> - // >> - WikiEngine engine = context.getEngine(); >> - WikiPage fromPage; >> - try >> - { >> - fromPage = engine.getPage( renameFrom ); >> - } >> - catch( PageNotFoundException e ) >> - { >> - throw new WikiException("No such page "+renameFrom, e ); >> - } >> - >> - WikiPage toPage; >> - try >> - { >> - toPage = engine.getPage( renameTo ); >> - if( toPage != null ) >> - { >> - throw new WikiException("Page already exists >> "+renameTo); >> - } >> - } >> - catch( PageNotFoundException e ) >> - { >> - // Good. The page should NOT exist already. >> - } >> - >> - // >> - // Options >> - // >> - >> - m_camelCase = >> TextUtil.getBooleanProperty( engine.getWikiProperties(), >> - >> JSPWikiMarkupParser.PROP_CAMELCASELINKS, >> - m_camelCase ); >> - >> - Set referrers = getReferencesToChange( fromPage, >> engine ); >> - >> - // >> - // Do the actual rename by changing from the frompage to >> the topage, including >> - // all of the attachments >> - // >> - >> - engine.getPageManager().getProvider().movePage( renameFrom, >> renameTo ); >> - /* >> - if( engine.getAttachmentManager().attachmentsEnabled() ) >> - { >> - >> engine >> .getAttachmentManager >> ().getCurrentProvider().moveAttachmentsForPage( renameFrom, >> renameTo ); >> - } >> -*/ >> - // >> - // Add a comment to the page notifying what changed. This >> adds a new revision >> - // to the repo with no actual change. >> - // >> - >> - try >> - { >> - toPage = engine.getPage( renameTo ); >> - } >> - catch( PageNotFoundException e ) >> - { >> - throw new InternalWikiException( "Rename seems to have >> failed for some strange reason - please check logs!" ); >> - } >> - >> - toPage.setAttribute( WikiPage.CHANGENOTE, >> fromPage.getName() + " ==> " + toPage.getName() ); >> - toPage.setAuthor( context.getCurrentUser().getName() ); >> - >> - engine.getPageManager().putPageText( toPage, >> engine.getPureText( toPage ) ); >> - >> - // >> - // Update the references >> - // >> - >> - try >> - { >> - >> engine.getReferenceManager().pageRemoved( fromPage.getPath() ); >> - } >> - catch( PageNotFoundException e ) >> - { >> - // This is fine. >> - } >> - engine.updateReferences( toPage ); >> - >> - // >> - // Update referrers >> - // >> - if( changeReferrers ) >> - { >> - updateReferrers( context, fromPage, toPage, referrers ); >> - } >> - >> - // >> - // re-index the page >> - // >> - engine.getSearchManager().reindexPage(toPage); >> - >> - >> - // >> - // Done, return the new name. >> - // >> - return renameTo; >> - } >> - >> - /** >> - * This method finds all the pages which have anything to do >> with the fromPage and >> - * change any referrers it can figure out in that page. >> - * >> - * @param context WikiContext in which we operate >> - * @param fromPage The old page >> - * @param toPage The new page >> - */ >> - private void updateReferrers( WikiContext context, WikiPage >> fromPage, WikiPage toPage, Setreferrers ) >> - { >> - WikiEngine engine = context.getEngine(); >> - >> - if( referrers.isEmpty() ) return; // No referrers >> - >> - for( WikiPath pageName : referrers ) >> - { >> - // In case the page was just changed from under us, >> let's do this >> - // small kludge. >> - if( pageName.equals( fromPage.getPath() ) ) >> - { >> - pageName = toPage.getPath(); >> - } >> - >> - try >> - { >> - WikiPage p = >> engine.getContentManager().getPage( pageName ); >> - >> - String sourceText = engine.getPureText( p ); >> - >> - String newText = replaceReferrerString( context, >> sourceText, fromPage.getName(), toPage.getName() ); >> - >> - if( m_camelCase ) >> - newText = replaceCCReferrerString( context, >> newText, fromPage.getName(), toPage.getName() ); >> - >> - if( !sourceText.equals( newText ) ) >> - { >> - p.setAttribute( WikiPage.CHANGENOTE, >> fromPage.getName()+" ==> "+toPage.getName() ); >> - >> p.setAuthor( context.getCurrentUser().getName() ); >> - p.setContent( newText ); >> - p.save(); >> - engine.updateReferences( p ); >> - } >> - } >> - catch( PageNotFoundException e ) >> - { >> - // Just continue >> - } >> - catch( ProviderException e ) >> - { >> - // >> - // We fail with an error, but we will try to >> continue to rename >> - // other referrers as well. >> - // >> - log.error("Unable to perform rename.",e); >> - } >> - } >> - } >> - >> - @SuppressWarnings("unchecked") >> - private Set getReferencesToChange( WikiPage fromPage, >> WikiEngine engine ) >> - { >> - Set referrers = new TreeSet(); >> - >> - try >> - { >> - Collection r = >> engine.getReferenceManager().findReferrers( fromPage.getPath() ); >> - if( r != null ) referrers.addAll( r ); >> - /* >> - Collection attachments = >> engine.getAttachmentManager().listAttachments( fromPage ); >> - >> - for( WikiPage att : attachments ) >> - { >> - Collection 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. >> - */ >> - private String replaceCCReferrerString( WikiContext context, >> String sourceText, String from, String to ) >> - { >> - StringBuilder sb = new StringBuilder( sourceText.length() >> +32 ); >> - >> - Pattern linkPattern = Pattern.compile( "\\p{Lu}+\\p{Ll}+\ >> \p{Lu}+[\\p{L}\\p{Digit}]*" ); >> - >> - Matcher matcher = linkPattern.matcher( sourceText ); >> - >> - int start = 0; >> - >> - while( matcher.find(start) ) >> - { >> - String match = matcher.group(); >> - >> - sb.append( sourceText.substring( start, >> matcher.start() ) ); >> - >> - int lastOpenBrace = sourceText.lastIndexOf( '[', >> matcher.start() ); >> - int lastCloseBrace = sourceText.lastIndexOf( ']', >> matcher.start() ); >> - >> - if( match.equals( from ) && lastCloseBrace >= >> lastOpenBrace ) >> - { >> - sb.append( to ); >> - } >> - else >> - { >> - sb.append( match ); >> - } >> - >> - start = matcher.end(); >> - } >> - >> - sb.append( sourceText.substring( start ) ); >> - >> - return sb.toString(); >> - } >> - >> - private String replaceReferrerString( WikiContext context, >> String sourceText, String from, String to ) >> - { >> - 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()); >> - while( matcher.find(start) ) >> - { >> - char charBefore = (char)-1; >> - >> - if( matcher.start() > 0 ) >> - charBefore = sourceText.charAt( matcher.start()-1 ); >> - >> - if( matcher.group(1).length() > 0 || charBefore == '~' >> || charBefore == '[' ) >> - { >> - // >> - // Found an escape character, so I am escaping. >> - // >> - sb.append( sourceText.substring( start, >> matcher.end() ) ); >> - start = matcher.end(); >> - continue; >> - } >> - >> - String text = matcher.group(2); >> - String link = matcher.group(4); >> - String attr = matcher.group(6); >> - >> - /* >> - System.out.println("MATCH="+matcher.group(0)); >> - 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 ); >> - } >> - else >> - { >> - link = replaceSingleLink( context, link, from, to ); >> - >> - // >> - // A very simple substitution, but should work for >> quite a few cases. >> - // >> - text = TextUtil.replaceString( text, from, to ); >> - } >> - >> - // >> - // Construct the new string >> - // >> - sb.append( sourceText.substring( start, >> matcher.start() ) ); >> - sb.append( "["+text ); >> - if( link.length() > 0 ) sb.append( "|" + link ); >> - if( attr.length() > 0 ) sb.append( "|" + attr ); >> - sb.append( "]" ); >> - >> - start = matcher.end(); >> - } >> - >> - sb.append( sourceText.substring( start ) ); >> - >> - return sb.toString(); >> - } >> - >> - /** >> - * This method does a correct replacement of a single link, >> taking into >> - * account anchors and attachments. >> - */ >> - private String replaceSingleLink( WikiContext context, String >> original, String from, String newlink ) >> - { >> - int hash = original.indexOf( '#' ); >> - int slash = original.indexOf( '/' ); >> - String reallink = original; >> - String oldStyleRealLink; >> - >> - if( hash != -1 ) reallink = original.substring( 0, hash ); >> - if( slash != -1 ) reallink = original.substring( 0,slash ); >> - >> - reallink = MarkupParser.cleanLink( reallink ); >> - oldStyleRealLink = MarkupParser.wikifyLink( reallink ); >> - >> - //WikiPage realPage = >> context.getEngine().getPage( reallink ); >> - // WikiPage p2 = context.getEngine().getPage( from ); >> - >> - // System.out.println(" "+reallink+" :: "+ from); >> - // System.out.println(" "+p+" :: "+p2); >> - >> - // >> - // Yes, these point to the same page. >> - // >> - if( reallink.equals(from) || original.equals(from) || >> oldStyleRealLink.equals(from) ) >> - { >> - // >> - // if the original contains blanks, then we should >> introduce a link, for example: [My Page] => [My Page|My Renamed >> Page] >> - int blank = reallink.indexOf( " "); >> - >> - if( blank != -1 ) >> - { >> - return original + "|" + newlink; >> - } >> - >> - return newlink + ((hash > 0) ? >> original.substring( hash ) : "") + ((slash > 0) ? >> original.substring( slash ) : "") ; >> - } >> - >> - return original; >> + ContentManager cm = context.getEngine().getContentManager(); >> + return cm.renamePage( context, renameFrom, renameTo, >> changeReferrers ); >> } >> } >> >> Added: incubator/jspwiki/trunk/src/java/org/apache/wiki/event/ >> ContentEvent.java >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/event/ContentEvent.java?rev=770959&view=auto >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/event/ >> ContentEvent.java (added) >> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/event/ >> ContentEvent.java Sat May 2 14:15:13 2009 >> @@ -0,0 +1,47 @@ >> +package org.apache.wiki.event; >> + >> +import java.io.Serializable; >> + >> +/** >> + * Events fired by {@link org.apache.wiki.content.ContentManager} >> when nodes are >> + * created, saved or deleted. >> + */ >> +public class ContentEvent extends WikiPageEvent >> +{ >> + private static final long serialVersionUID = >> -6577147048708900469L; >> + >> + /** >> + * Indicates that a node has been requested to be deleted, but >> it has not >> + * yet been removed from the repository. >> + */ >> + public static final int NODE_DELETE_REQUEST = 220; >> + >> + /** >> + * Indicates that a node was successfully deleted. >> + */ >> + public static final int NODE_DELETED = 221; >> + >> + /** >> + * Indicates that a node was successfully renamed. >> + */ >> + public static final int NODE_RENAMED = 211; >> + >> + /** >> + * Indicates a node was successfully saved. >> + */ >> + public static final int NODE_SAVED = 201; >> + >> + /** >> + * Constructs an instance of this event. >> + * >> + * @param src the Object that is the source of the event. >> + * @param type the type of the event (see the enumerated int >> values defined >> + * in {@link org.apache.wiki.event.WikiEvent}). >> + * @param pagename the WikiPage being acted upon. >> + * @param args additional arguments passed to the event. >> + */ >> + public ContentEvent( Object src, int type, String pagename, >> Serializable... args ) >> + { >> + super( src, type, pagename, args ); >> + } >> +} >> >> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ >> ReferringPagesPlugin.java >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ReferringPagesPlugin.java?rev=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ >> ReferringPagesPlugin.java (original) >> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ >> ReferringPagesPlugin.java Sat May 2 14:15:13 2009 >> @@ -94,7 +94,7 @@ >> { >> WikiPage page = context.getEngine().getPage( pageName ); >> >> - Collection links = >> refmgr.findReferrers( page.getPath() ); >> + Collection links = >> refmgr.getReferredBy( page.getPath() ); >> String wikitext = ""; >> >> super.initialize( context, params ); >> >> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ >> UndefinedPagesPlugin.java >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UndefinedPagesPlugin.java?rev=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ >> UndefinedPagesPlugin.java (original) >> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ >> UndefinedPagesPlugin.java Sat May 2 14:15:13 2009 >> @@ -24,6 +24,8 @@ >> import java.util.Map; >> import java.util.TreeSet; >> >> +import javax.jcr.RepositoryException; >> + >> import org.apache.wiki.ReferenceManager; >> import org.apache.wiki.WikiContext; >> import org.apache.wiki.api.PluginException; >> @@ -48,7 +50,16 @@ >> throws PluginException >> { >> ReferenceManager refmgr = >> context.getEngine().getReferenceManager(); >> - Collection links = refmgr.findUncreated(); >> + Collection links; >> + try >> + { >> + links = refmgr.findUncreated(); >> + } >> + catch( RepositoryException e ) >> + { >> + e.printStackTrace(); >> + throw new PluginException( "Could not find uncreated >> pages.", e ); >> + } >> >> super.initialize( context, params ); >> >> >> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ >> UnusedPagesPlugin.java >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/UnusedPagesPlugin.java?rev=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ >> UnusedPagesPlugin.java (original) >> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/ >> UnusedPagesPlugin.java Sat May 2 14:15:13 2009 >> @@ -25,6 +25,8 @@ >> import java.util.Map; >> import java.util.TreeSet; >> >> +import javax.jcr.RepositoryException; >> + >> import org.apache.wiki.ReferenceManager; >> import org.apache.wiki.WikiContext; >> import org.apache.wiki.api.PluginException; >> @@ -57,7 +59,16 @@ >> throws PluginException >> { >> ReferenceManager refmgr = >> context.getEngine().getReferenceManager(); >> - Collection links = refmgr.findUnreferenced(); >> + Collection links; >> + try >> + { >> + links = refmgr.findUnreferenced(); >> + } >> + catch( RepositoryException e ) >> + { >> + e.printStackTrace(); >> + throw new PluginException( "Could not find unreferenced >> pages.", e ); >> + } >> // >> // filter out attachments if "excludeattachments" was >> requested: >> // >> >> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/render/ >> RenderingManager.java >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/render/RenderingManager.java?rev=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/render/ >> RenderingManager.java (original) >> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/render/ >> RenderingManager.java Sat May 2 14:15:13 2009 >> @@ -345,7 +345,7 @@ >> m_documentCache.flushPattern( pageName ); >> try >> { >> - Collection referringPages = >> m_engine >> .getReferenceManager().findReferrers( WikiPath.valueOf(pageName) ); >> + Collection referringPages = >> m_engine >> .getReferenceManager().getReferredBy( WikiPath.valueOf(pageName) ); >> >> // >> // Flush also those pages that refer to this >> page (if an nonexistant page >> >> Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/search/ >> SearchManager.java >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java?rev=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/src/java/org/apache/wiki/search/ >> SearchManager.java (original) >> +++ incubator/jspwiki/trunk/src/java/org/apache/wiki/search/ >> SearchManager.java Sat May 2 14:15:13 2009 >> @@ -24,16 +24,14 @@ >> import java.util.*; >> >> import org.apache.commons.lang.time.StopWatch; >> -import org.apache.wiki.*; >> +import org.apache.wiki.InternalWikiException; >> +import org.apache.wiki.NoRequiredPropertyException; >> +import org.apache.wiki.WikiEngine; >> import org.apache.wiki.api.FilterException; >> import org.apache.wiki.api.WikiException; >> import org.apache.wiki.api.WikiPage; >> import org.apache.wiki.content.PageNotFoundException; >> -import org.apache.wiki.event.WikiEvent; >> -import org.apache.wiki.event.WikiEventListener; >> -import org.apache.wiki.event.WikiEventUtils; >> -import org.apache.wiki.event.WikiPageEvent; >> -import org.apache.wiki.filters.BasicPageFilter; >> +import org.apache.wiki.event.*; >> import org.apache.wiki.log.Logger; >> import org.apache.wiki.log.LoggerFactory; >> import org.apache.wiki.modules.InternalModule; >> @@ -53,7 +51,6 @@ >> */ >> >> public class SearchManager >> - extends BasicPageFilter >> implements InternalModule, WikiEventListener >> { >> private static final Logger log = >> LoggerFactory.getLogger(SearchManager.class); >> @@ -70,6 +67,8 @@ >> >> private SearchProvider m_searchProvider = null; >> >> + private WikiEngine m_engine = null; >> + >> /** >> * The name of the JSON object that manages search. >> */ >> @@ -82,15 +81,11 @@ >> * @param properties The list of Properties. >> * @throws WikiException If it cannot be instantiated. >> */ >> - public SearchManager( WikiEngine engine, Properties properties ) >> + public SearchManager() >> throws WikiException >> { >> - initialize( engine, properties ); >> - >> - >> WikiEventUtils.addWikiEventListener(m_engine.getContentManager(), >> - >> WikiPageEvent.PAGE_DELETE_REQUEST, this); >> - >> - JSONRPCManager.registerGlobalObject( JSON_SEARCH, new >> JSONSearch() ); >> + // Do nothing, really >> + super(); >> } >> >> /** >> @@ -220,6 +215,11 @@ >> >> loadSearchProvider(properties); >> >> + // Make sure we catch any page add/save/rename events >> + >> WikiEventManager.addWikiEventListener( engine.getContentManager(), >> this ); >> + >> + JSONRPCManager.registerGlobalObject( JSON_SEARCH, new >> JSONSearch() ); >> + >> try >> { >> m_searchProvider.initialize(engine, properties); >> @@ -295,7 +295,7 @@ >> * >> * @return The current SearchProvider. >> */ >> - public SearchProvider getSearchEngine() >> + protected SearchProvider getSearchProvider() >> { >> return m_searchProvider; >> } >> @@ -322,7 +322,7 @@ >> * Removes the page from the search cache (if any). >> * @param page The page to remove >> */ >> - public void pageRemoved(WikiPage page) >> + private void removePage(WikiPage page) >> { >> try >> { >> @@ -335,35 +335,6 @@ >> } >> >> /** >> - * Reindexes the page. >> - * >> - * @param wikiContext {@inheritDoc} >> - * @param content {@inheritDoc} >> - */ >> - @Override >> - public void postSave( WikiContext wikiContext, String content ) >> - { >> - // >> - // Makes sure that we're indexing the latest version of this >> - // page. >> - // >> - WikiPage p; >> - try >> - { >> - p = m_engine.getPage( wikiContext.getPage().getName() ); >> - reindexPage( p ); >> - } >> - catch( PageNotFoundException e ) >> - { >> - // Swallow quietly; something went wrong but no point >> making fuss about it. >> - } >> - catch( ProviderException e ) >> - { >> - log.info("Could not reindex a page",e); >> - } >> - } >> - >> - /** >> * Forces the reindex of the given page. >> * >> * @param page The page. >> @@ -380,22 +351,55 @@ >> */ >> public void actionPerformed(WikiEvent event) >> { >> - if( (event instanceof WikiPageEvent) && (event.getType() == >> WikiPageEvent.PAGE_DELETE_REQUEST) ) >> + if ( !(event instanceof WikiPageEvent ) ) >> { >> - String pageName = ((WikiPageEvent) event).getPageName(); >> - >> - try >> - { >> - WikiPage p = m_engine.getPage( pageName ); >> - pageRemoved( p ); >> - } >> - catch( PageNotFoundException e ) >> + return; >> + } >> + >> + String pageName = ((WikiPageEvent) event).getPageName(); >> + switch ( event.getType() ) >> + { >> + // If page was deleted, remove it from the index >> + case ( ContentEvent.NODE_DELETE_REQUEST ): >> { >> - throw new InternalWikiException("Page removed >> already!?!"); >> + try >> + { >> + WikiPage p = m_engine.getPage( pageName ); >> + removePage( p ); >> + } >> + catch( PageNotFoundException e ) >> + { >> + throw new InternalWikiException("Page removed >> already!?!"); >> + } >> + catch( ProviderException e ) >> + { >> + log.info( "Could not reindex page " + pageName, >> e ); >> + e.printStackTrace(); >> + } >> } >> - catch( ProviderException e ) >> + >> + // If page was saved, reindex it >> + case ( ContentEvent.NODE_SAVED ): >> { >> - // FIXME: How should it deal with this? >> + // >> + // Makes sure that we're indexing the latest >> version of this >> + // page. >> + // >> + WikiPage p; >> + try >> + { >> + p = m_engine.getPage( pageName ); >> + reindexPage( p ); >> + } >> + catch( PageNotFoundException e ) >> + { >> + // Swallow quietly; something went wrong but no >> point making fuss about it. >> + } >> + catch( ProviderException e ) >> + { >> + log.info( "Could not reindex page " + pageName, >> e ); >> + e.printStackTrace(); >> + } >> } >> } >> } >> >> Added: incubator/jspwiki/trunk/tests/etc/TestMigratorForm.jsp >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/etc/TestMigratorForm.jsp?rev=770959&view=auto >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/tests/etc/TestMigratorForm.jsp (added) >> +++ incubator/jspwiki/trunk/tests/etc/TestMigratorForm.jsp Sat May >> 2 14:15:13 2009 >> @@ -0,0 +1,7 @@ >> +<%@ taglib uri="http://stripes.sourceforge.net/stripes.tld" >> prefix="stripes" %> >> +> beanclass="org.apache.wiki.action.LoginActionBean" event="view" >> id="wikiActionBean" /> >> + >> + >> + >> + >> + >> >> Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/ >> ReferenceManagerTest.java >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/ReferenceManagerTest.java?rev=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/tests/java/org/apache/wiki/ >> ReferenceManagerTest.java (original) >> +++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/ >> ReferenceManagerTest.java Sat May 2 14:15:13 2009 >> @@ -21,62 +21,64 @@ >> >> package org.apache.wiki; >> >> -import java.io.File; >> -import java.util.Collection; >> -import java.util.Iterator; >> -import java.util.Properties; >> -import java.util.Set; >> +import java.util.*; >> + >> +import javax.jcr.Node; >> +import javax.jcr.PathNotFoundException; >> +import javax.jcr.Property; >> +import javax.jcr.Session; >> >> import junit.framework.Test; >> import junit.framework.TestCase; >> import junit.framework.TestSuite; >> >> import org.apache.wiki.api.WikiException; >> +import org.apache.wiki.content.ContentManager; >> import org.apache.wiki.content.WikiPath; >> import org.apache.wiki.providers.ProviderException; >> >> - >> /** >> - * @author Torsten Hildebrandt. >> + * @author Torsten Hildebrandt. >> */ >> public class ReferenceManagerTest extends TestCase >> { >> + private static final WikiPath PATH_FOOBAR = >> WikiPath.valueOf( "Foobar" ); >> + >> + public static void main( String[] args ) >> + { >> + junit.textui.TestRunner.main( new String[] >> { ReferenceManagerTest.class.getName() } ); >> + } >> + >> + public static Test suite() >> + { >> + return new TestSuite( ReferenceManagerTest.class ); >> + } >> + >> Properties props = new Properties(); >> + >> TestEngine engine; >> + >> ReferenceManager mgr; >> - >> + >> public ReferenceManagerTest( String s ) >> { >> super( s ); >> } >> >> - public void setUp() >> - throws Exception >> + public void setUp() throws Exception >> { >> props.load( TestEngine.findTestProperties() ); >> - >> 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(); >> - } >> - >> - engine = new TestEngine(props); >> - >> + >> props.setProperty( "jspwiki.translatorReader.matchEnglishPlurals", >> "true" ); >> + engine = new TestEngine( props ); >> + engine.emptyRepository(); >> + engine.getReferenceManager().rebuild(); >> engine.saveText( "TestPage", "Reference to [Foobar]." ); >> engine.saveText( "Foobar", "Reference to [Foobar2], >> [Foobars], [Foobar]" ); >> >> mgr = engine.getReferenceManager(); >> } >> >> - public void tearDown() >> - throws Exception >> + public void tearDown() throws Exception >> { >> engine.deletePage( "TestPage" ); >> engine.deletePage( "Foobar" ); >> @@ -92,354 +94,620 @@ >> engine.deletePage( "NewBug" ); >> engine.deletePage( "BugOne" ); >> engine.deletePage( "BugTwo" ); >> - >> + >> engine.shutdown(); >> } >> >> - /** Shortcut to help testing. */ >> - private Set findReferrers( String path ) throws >> ProviderException >> - { >> - return mgr.findReferrers( WikiPath.valueOf(path) ); >> - } >> - >> - public void testNonExistant1() >> - throws Exception >> - { >> - Collection c = >> mgr.findReferrers( WikiPath.valueOf("Foobar2") ); >> - >> - assertTrue( c.size() == 1 && >> c.contains( WikiPath.valueOf("Foobar") ) ); >> - } >> - >> - public void testNonExistant2() throws ProviderException >> - { >> - Collection c = findReferrers("TestBug"); >> - >> - assertTrue( c.size() == 0 ); >> - } >> - >> - public void testRemove() >> - throws Exception >> + /** >> + * Tests protected method >> + * {@link ReferenceManager#addReferredBy(WikiPath, List)}, >> which sets inbound >> + * links to a page from multiple sources. The destination page >> exists. >> + * >> + * @throws Exception >> + */ >> + public void testAddReferredBy() throws Exception >> { >> - Collection c = findReferrers("Foobar2"); >> - >> - assertTrue( c.size() == 1 && >> c.contains( WikiPath.valueOf( "Foobar") ) ); >> + WikiPath source = WikiPath.valueOf( "SetReferredBy" ); >> + WikiPath destination1 = WikiPath.valueOf( "PageOne" ); >> + WikiPath destination2 = WikiPath.valueOf( "PageTwo" ); >> + WikiPath destination3 = WikiPath.valueOf( "PageThree" ); >> + >> + List destinations = new ArrayList(); >> + destinations.add( WikiPath.valueOf( "PageOne" ) ); >> + destinations.add( WikiPath.valueOf( "PageTwo" ) ); >> + destinations.add( WikiPath.valueOf( "PageThree" ) ); >> + for ( WikiPath destination : destinations ) >> + { >> + mgr.addReferredBy( destination, source ); >> + } >> >> - engine.deletePage( "Foobar" ); >> - >> - c = findReferrers("Foobar2"); >> - >> - assertNull( c ); >> + List links = mgr.getReferredBy( source ); >> + assertEquals( 0, links.size() ); >> >> - engine.saveText( "Foobar", "[Foobar2]"); >> - >> - c = findReferrers("Foobar2"); >> - >> - assertTrue( c.size() == 1 && c.contains("Foobar") ); >> + links = mgr.getReferredBy( destination1 ); >> + assertEquals( 1, links.size() ); >> + assertTrue( links.contains( source ) ); >> + >> + links = mgr.getReferredBy( destination2 ); >> + assertEquals( 1, links.size() ); >> + assertTrue( links.contains( source ) ); >> + >> + links = mgr.getReferredBy( destination3 ); >> + assertEquals( 1, links.size() ); >> + assertTrue( links.contains( source ) ); >> } >> - >> - public void testUnreferenced() >> - throws Exception >> + >> + /** >> + * Tests low-level method for adding to a multi-valued JCR Node >> property. >> + * @throws Exception >> + */ >> + public void testAddToValues() throws Exception >> { >> - Collection c = mgr.findUnreferenced(); >> - assertTrue( "Unreferenced page not found by >> ReferenceManager", >> - Util.collectionContains( c, "TestPage" )); >> + ContentManager cm = engine.getContentManager(); >> + String jcrPath = ReferenceManager.REFERENCES_ROOT + "/" + >> "TestAddToValues"; >> + Node node; >> + Property prop; >> + Session s = cm.getCurrentSession(); >> + >> + mgr.addToValues( jcrPath, "foo","Value1" ); >> + s.save(); >> + node = cm.getJCRNode( jcrPath ); >> + prop = node.getProperty( "foo" ); >> + assertNotNull( prop.getValues() ); >> + assertEquals( 1, prop.getValues().length ); >> + assertEquals( "Value1", prop.getValues()[0].getString() ); >> + >> + mgr.addToValues( jcrPath, "foo","Value2" ); >> + s.save(); >> + node = cm.getJCRNode( jcrPath ); >> + prop = node.getProperty( "foo" ); >> + assertNotNull( prop.getValues() ); >> + assertEquals( 2, prop.getValues().length ); >> + assertEquals( "Value2", prop.getValues()[1].getString() ); >> + >> + // Add the same Value1 again! >> + mgr.addToValues( jcrPath, "foo","Value1" ); >> + s.save(); >> + node = cm.getJCRNode( jcrPath ); >> + prop = node.getProperty( "foo" ); >> + assertNotNull( prop.getValues() ); >> + assertEquals( 3, prop.getValues().length ); >> + assertEquals( "Value1", prop.getValues()[2].getString() ); >> } >> >> - >> - public void testBecomesUnreferenced() >> - throws Exception >> + public void testBecomesUnreferenced() throws Exception >> { >> engine.saveText( "Foobar2", "[TestPage]" ); >> >> - Collection c = mgr.findUnreferenced(); >> - assertEquals( "Wrong # of orphan pages, stage 1", 0, >> c.size() ); >> + List c = mgr.findUnreferenced(); >> + assertEquals( 0, c.size() ); >> >> engine.saveText( "Foobar2", "norefs" ); >> c = mgr.findUnreferenced(); >> - assertEquals( "Wrong # of orphan pages", 1, c.size() ); >> - >> - Iterator i = c.iterator(); >> - String first = i.next(); >> - assertEquals( "Not correct referrers", "TestPage", first ); >> + assertEquals( 1, c.size() ); >> + assertEquals( "TestPage", c.get( 0 ) ); >> } >> >> - public void testUncreated() >> - throws Exception >> + public void testCircularRefs() throws Exception >> { >> - Collection c = mgr.findUncreated(); >> - >> - assertTrue( c.size()==1 && >> c.iterator().next().equals("Foobar2") ); >> - } >> - >> - public void testReferrers() >> - throws Exception >> - { >> - Collection c = findReferrers( "TestPage" ); >> - assertNull( "TestPage referrers", c ); >> - >> - c = findReferrers( "Foobar" ); >> - assertTrue( "Foobar referrers", c.size()==2 ); >> - >> - c = findReferrers( "Foobar2" ); >> - assertTrue( "Foobar2 referrers", c.size()==1 && ((WikiPath) >> c.iterator().next()).equals("Foobar") ); >> + engine.saveText( "Foobar2", "ref to [TestPage]" ); >> >> - c = findReferrers( "Foobars" ); >> - assertEquals( "Foobars referrers", 2, c.size() ); >> - //assertEquals( "Foobars referrer 'TestPage'", "TestPage", >> (String) c.iterator().next() ); >> + assertEquals( 0, mgr.findUncreated().size() ); >> + assertEquals( 0, mgr.findUnreferenced().size() ); >> } >> >> - public void testRefersTo() >> - throws Exception >> + public void testExtractLinks() 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") ); >> + String src = "Foobar. [Foobar]. Frobozz. [This is a >> link]."; >> + engine.deletePage( "Test" ); >> + engine.saveText( "Test", src ); >> + List results = >> mgr.extractLinks( WikiPath.valueOf( "Test" ) ); >> + >> + assertEquals( 2, results.size() ); >> + assertEquals( "item 0", PATH_FOOBAR, results.get( 0 ) ); >> + assertEquals( "item 1", WikiPath.valueOf( "Main:This is a >> link" ), results.get( 1 ) ); >> } >> >> - /** >> - * Should fail in 2.2.14-beta >> - * @throws Exception >> - */ >> - public void testSingularReferences() >> - throws Exception >> + public void testGetReferredBy() throws Exception >> { >> - engine.saveText( "RandomPage", "FatalBugs" ); >> - engine.saveText( "FatalBugs", "" ); >> - engine.saveText( "BugCommentPreviewDeletesAllComments", >> "FatalBug" ); >> + //engine.saveText( "TestPage", "Reference to [Foobar]." ); >> + //engine.saveText( "Foobar", "Reference to [Foobar2], >> [Foobars], [Foobar]" ); >> >> - Collection c = findReferrers( "FatalBugs" ); >> - >> - assertEquals( "FatalBugs referrers number", 2, c.size() ); >> - } >> + List c = >> mgr.getReferredBy( WikiPath.valueOf( "TestPage" )); >> + assertEquals( 0, c.size() ); >> >> - /** >> - * Is a page recognized as referenced if only plural form >> links exist. >> - */ >> + c = mgr.getReferredBy( WikiPath.valueOf( "Foobar" )); >> + assertEquals( 3, c.size() ); >> >> - // NB: Unfortunately, cleaning out self-references in the case >> there's >> - // a plural and a singular form of the page becomes nigh >> impossible, so we >> - // just don't do it. >> - public void testUpdatePluralOnlyRef() >> - throws Exception >> - { >> - engine.saveText( "TestPage", "Reference to [Foobars]." ); >> - Collection c = mgr.findUnreferenced(); >> - assertTrue( "Foobar unreferenced", c.size()==1 && >> c.iterator().next().equals("TestPage") ); >> + c = mgr.getReferredBy( WikiPath.valueOf( "Foobar2" )); >> + assertEquals( 1, c.size() ); >> + assertEquals( WikiPath.valueOf( "Foobar" ), c.get( 0 ) ); >> >> - Collectionp = findReferrers( "Foobar" ); >> - assertTrue( "Foobar referrers", >> - p.size()==2 ); >> + // The singular 'Foobar' exists, but this variant does not >> + c = mgr.getReferredBy( WikiPath.valueOf( "Foobars" )); >> + assertEquals( 0, c.size() ); >> } >> >> - >> - /** >> - * Opposite to testUpdatePluralOnlyRef(). Is a page with >> plural form recognized as >> - * the page referenced by a singular link. >> - */ >> - >> - public void testUpdateFoobar2s() >> - throws Exception >> + public void testGetRefersTo() throws Exception >> { >> - engine.saveText( "Foobar2s", "qwertz" ); >> - assertTrue( "no uncreated", mgr.findUncreated().size()==0 ); >> + List links; >> >> - Collection c = findReferrers( "Foobar2s" ); >> - assertTrue( "referrers", c!=null && c.size()==1 && >> c.iterator().next().toString().equals("Foobar") ); >> - } >> + links = mgr.getRefersTo( WikiPath.valueOf( "TestPage" ) ); >> + assertEquals( 1, links.size() ); >> + assertTrue( "Does not have Foobar, but it should have", >> links.contains( WikiPath.valueOf( "Foobar" ) ) ); >> >> - public void testUpdateBothExist() >> - throws Exception >> - { >> - engine.saveText( "Foobars", "qwertz" ); >> - Collection c = findReferrers( "Foobars" ); >> - assertEquals( "Foobars referrers", 2, c.size() ); >> - assertTrue( "Foobars referrer is not TestPage", >> c.contains( WikiPath.valueOf( "TestPage" ) ) >> - && c.contains( WikiPath.valueOf( "Foobar") ) ); >> + links = mgr.getRefersTo( WikiPath.valueOf( "Foobar" ) ); >> + assertEquals( 3, links.size() ); >> + assertTrue( "Does not have Foobar, but it should have", >> links.contains( WikiPath.valueOf( "Foobar" ) ) ); // 2 of >> + // these >> + assertTrue( "Does not have Foobar2, but it should have", >> links.contains( WikiPath.valueOf( "Foobar2" ) ) ); // 1 of >> + // these >> + >> + links = mgr.getRefersTo( WikiPath.valueOf( "Foobar2" ) ); >> + assertEquals( 0, links.size() ); >> } >> >> - public void testUpdateBothExist2() >> - throws Exception >> + public void testNonExistant1() throws Exception >> { >> - engine.saveText( "Foobars", "qwertz" ); >> - engine.saveText( "TestPage", "Reference to [Foobar], >> [Foobars]." ); >> - >> - Collection c = findReferrers( "Foobars" ); >> - assertEquals( "Foobars referrers count", 2, c.size() ); >> + Collection c = >> mgr.getReferredBy( WikiPath.valueOf( "Foobar2" ) ); >> >> - assertTrue( "Foobars referrers", >> - c.contains( WikiPath.valueOf( "TestPage" ) ) && >> c.contains( WikiPath.valueOf( "Foobar" ) ) ); >> + assertTrue( c.size() == 1 && >> c.contains( WikiPath.valueOf( "Foobar" ) ) ); >> } >> >> - public void testCircularRefs() >> - throws Exception >> + public void testNonExistant2() throws ProviderException >> { >> - engine.saveText( "Foobar2", "ref to [TestPage]" ); >> - >> - assertTrue( "no uncreated", mgr.findUncreated().size()==0 ); >> - assertTrue( "no unreferenced", >> mgr.findUnreferenced().size()==0 ); >> + Collection c = >> mgr.getReferredBy( WikiPath.valueOf( "TestBug" )); >> + >> + assertTrue( c.size() == 0 ); >> } >> >> - public void testPluralSingularUpdate1() >> - throws Exception >> + public void testPluralSingularUpdate1() throws Exception >> { >> engine.saveText( "BugOne", "NewBug" ); >> engine.saveText( "NewBugs", "foo" ); >> engine.saveText( "OpenBugs", "bar" ); >> - >> + >> engine.saveText( "BugOne", "OpenBug" ); >> - >> - Collection ref = findReferrers( "NewBugs" ); >> - assertNull("newbugs",ref); // No referrers must be found >> >> - ref = findReferrers( "NewBug" ); >> - assertNull("newbug",ref); // No referrers must be found >> + Collection links = >> mgr.getReferredBy( WikiPath.valueOf( "NewBugs" )); >> + assertEquals( "newbugs", links.size() ); // No referrers >> must be found >> + >> + links = mgr.getReferredBy( WikiPath.valueOf( "NewBug" )); >> + assertEquals( "newbug", links.size() ); // No referrers >> must be found >> >> - ref = findReferrers( "OpenBugs" ); >> - assertEquals("openbugs",1,ref.size()); >> - >> assertEquals("openbugs2","BugOne",ref.iterator().next().toString()); >> + links = mgr.getReferredBy( WikiPath.valueOf( "OpenBugs" )); >> + assertEquals( "openbugs", 1, links.size() ); >> + assertEquals( "openbugs2", "BugOne", >> links.iterator().next().toString() ); >> >> - ref = findReferrers( "OpenBug" ); >> - assertEquals("openbug",1,ref.size()); >> - >> assertEquals("openbug2","BugOne",ref.iterator().next().toString()); >> + links = mgr.getReferredBy( WikiPath.valueOf( "OpenBug" )); >> + assertEquals( "openbug", 1, links.size() ); >> + assertEquals( "openbug2", "BugOne", >> links.iterator().next().toString() ); >> >> } >> >> - public void testPluralSingularUpdate2() >> - throws Exception >> + public void testPluralSingularUpdate2() throws Exception >> { >> engine.saveText( "BugOne", "NewBug" ); >> engine.saveText( "NewBug", "foo" ); >> engine.saveText( "OpenBug", "bar" ); >> - >> + >> engine.saveText( "BugOne", "OpenBug" ); >> - >> - Collection ref = findReferrers( "NewBugs" ); >> - assertNull("newbugs",ref); // No referrers must be found >> >> - ref = findReferrers( "NewBug" ); >> - assertNull("newbug",ref); // No referrers must be found >> + Collection links = >> mgr.getReferredBy( WikiPath.valueOf( "NewBugs" )); >> + assertEquals( 0, links.size() ); // No referrers must be >> found >> + >> + links = mgr.getReferredBy( WikiPath.valueOf( "NewBug" )); >> + assertEquals( 0, links.size() ); // No referrers must be >> found >> >> - ref = findReferrers( "OpenBugs" ); >> - assertEquals("openbugs",1,ref.size()); >> - >> assertEquals("openbugs2","BugOne",ref.iterator().next().toString()); >> + links = mgr.getReferredBy( WikiPath.valueOf( "OpenBugs" )); >> + assertEquals( "openbugs", 1, links.size() ); >> + assertEquals( "openbugs2", "BugOne", >> links.iterator().next().toString() ); >> >> - ref = findReferrers( "OpenBug" ); >> - assertEquals("openbug",1,ref.size()); >> - >> assertEquals("openbug2","BugOne",ref.iterator().next().toString()); >> + links = mgr.getReferredBy( WikiPath.valueOf( "OpenBug" )); >> + assertEquals( "openbug", 1, links.size() ); >> + assertEquals( "openbug2", "BugOne", >> links.iterator().next().toString() ); >> >> } >> >> - public void testPluralSingularUpdate3() >> - throws Exception >> + public void testPluralSingularUpdate3() throws Exception >> { >> engine.saveText( "BugOne", "NewBug" ); >> engine.saveText( "BugTwo", "NewBug" ); >> engine.saveText( "NewBugs", "foo" ); >> engine.saveText( "OpenBugs", "bar" ); >> - >> + >> engine.saveText( "BugOne", "OpenBug" ); >> - >> - Collection ref = findReferrers( "NewBugs" ); >> - assertEquals("newbugs",1,ref.size()); >> - >> assertEquals("newbugs2","BugTwo",ref.iterator().next().toString()); >> - >> - ref = findReferrers( "NewBug" ); >> - assertEquals("newbugs",1,ref.size()); >> - >> assertEquals("newbugs2","BugTwo",ref.iterator().next().toString()); >> - >> - ref = findReferrers( "OpenBugs" ); >> - assertEquals("openbugs",1,ref.size()); >> - >> assertEquals("openbugs2","BugOne",ref.iterator().next().toString()); >> - >> - ref = findReferrers( "OpenBug" ); >> - assertEquals("openbug",1,ref.size()); >> - >> assertEquals("openbug2","BugOne",ref.iterator().next().toString()); >> + >> + Collection links = >> mgr.getReferredBy( WikiPath.valueOf( "NewBugs" )); >> + assertEquals( "newbugs", 1, links.size() ); >> + assertEquals( "newbugs2", "BugTwo", >> links.iterator().next().toString() ); >> + >> + links = mgr.getReferredBy( WikiPath.valueOf( "NewBug" )); >> + assertEquals( "newbugs", 1, links.size() ); >> + assertEquals( "newbugs2", "BugTwo", >> links.iterator().next().toString() ); >> + >> + links = mgr.getReferredBy( WikiPath.valueOf( "OpenBugs" )); >> + assertEquals( "openbugs", 1, links.size() ); >> + assertEquals( "openbugs2", "BugOne", >> links.iterator().next().toString() ); >> + >> + links = mgr.getReferredBy( WikiPath.valueOf( "OpenBug" )); >> + assertEquals( "openbug", 1, links.size() ); >> + assertEquals( "openbug2", "BugOne", >> links.iterator().next().toString() ); >> >> } >> >> + public void testRebuild() throws Exception >> + { >> + ContentManager cm = engine.getContentManager(); >> + Node node = >> (Node)cm.getJCRNode( ReferenceManager.REFERENCES_ROOT ); >> + assertNotNull( node ); >> + assertNotSame( 0, node.getNodes().getSize() ); >> + mgr.rebuild(); >> + >> + // Make sure all of the inbound references got deleted >> + node = >> (Node)cm.getJCRNode( ReferenceManager.REFERENCES_ROOT ); >> + assertNotNull( node ); >> + assertEquals( 0, node.getNodes().getSize() ); >> + >> + // Make sure the not-created/not-referenced properties got >> created >> + try >> + { >> + node.getProperty( ReferenceManager.NOT_CREATED ); >> + } >> + catch ( PathNotFoundException e ) >> + { >> + // Excellent! >> + } >> + try >> + { >> + node.getProperty( ReferenceManager.NOT_REFERENCED ); >> + } >> + catch ( PathNotFoundException e ) >> + { >> + // Excellent! >> + } >> + } >> + >> + public void testRemove() throws Exception >> + { >> + Collection c = >> mgr.getReferredBy( WikiPath.valueOf( "Foobar2" )); >> + assertEquals( 1, c.size() ); >> + assertTrue( c.contains( WikiPath.valueOf( "Foobar" ) ) ); >> + >> + engine.deletePage( "Foobar" ); >> + c = mgr.getReferredBy( WikiPath.valueOf("Foobar2" )); >> + assertEquals( 0, c.size() ); >> + >> + engine.saveText( "Foobar", "[Foobar2]" ); >> + c = mgr.getReferredBy( WikiPath.valueOf( "Foobar2" )); >> + assertEquals( 1, c.size() ); >> + assertTrue( c.contains( WikiPath.valueOf( "Foobar" ) ) ); >> + } >> + >> + /** >> + * Tests low-level method for removing items from a multi- >> valued JCR Node property. >> + * @throws Exception >> + */ >> + public void testRemoveAllFromValues() throws Exception >> + { >> + ContentManager cm = engine.getContentManager(); >> + String jcrPath = ReferenceManager.REFERENCES_ROOT + "/" + >> "TestRemoveFromValues"; >> + Node node; >> + Property prop; >> + Session s = cm.getCurrentSession(); >> + >> + mgr.addToValues( jcrPath, "foo","Value1" ); >> + mgr.addToValues( jcrPath, "foo","Value2" ); >> + s.save(); >> + node = cm.getJCRNode( jcrPath ); >> + prop = node.getProperty( "foo" ); >> + assertNotNull( prop.getValues() ); >> + assertEquals( 2, prop.getValues().length ); >> + >> + // Remove the first value >> + mgr.removeAllFromValues( jcrPath, "foo", "Value1" ); >> + s.save(); >> + node = cm.getJCRNode( jcrPath ); >> + prop = node.getProperty( "foo" ); >> + assertNotNull( prop.getValues() ); >> + assertEquals( 1, prop.getValues().length ); >> + assertEquals( "Value2", prop.getValues()[0].getString() ); >> + >> + // Try removing a value that does not exist in the property >> + mgr.removeAllFromValues( jcrPath, "foo", >> "NonExistentValue" ); >> + s.save(); >> + node = cm.getJCRNode( jcrPath ); >> + prop = node.getProperty( "foo" ); >> + assertNotNull( prop.getValues() ); >> + assertEquals( 1, prop.getValues().length ); >> + assertEquals( "Value2", prop.getValues()[0].getString() ); >> + >> + // Remove the last value >> + mgr.removeAllFromValues( jcrPath, "foo", "Value2" ); >> + s.save(); >> + node = cm.getJCRNode( jcrPath ); >> + try >> + { >> + prop = node.getProperty( "foo" ); >> + } >> + catch ( PathNotFoundException e ) >> + { >> + // Good! This is what we expect. >> + } >> + >> + // Add back in the first value, twice >> + mgr.addToValues( jcrPath, "foo","Value1" ); >> + mgr.addToValues( jcrPath, "foo","Value1" ); >> + s.save(); >> + node = cm.getJCRNode( jcrPath ); >> + prop = node.getProperty( "foo" ); >> + assertNotNull( prop.getValues() ); >> + assertEquals( 2, prop.getValues().length ); >> + >> + // Remove the first value -- ALL should be gone now >> + mgr.removeAllFromValues( jcrPath, "foo", "Value1" ); >> + s.save(); >> + node = cm.getJCRNode( jcrPath ); >> + try >> + { >> + prop = node.getProperty( "foo" ); >> + } >> + catch ( PathNotFoundException e ) >> + { >> + // Good! This is what we expect. >> + } >> + } >> + >> + /** >> + * Tests protected method {@link >> ReferenceManager#removeLinks(WikiPath)}, >> + * which removes all outbound links from a page to multiple >> destinations, >> + * and removes all inbound links to the page as well. The >> source page >> + * exists. >> + * >> + * @throws Exception >> + */ >> + public void testRemoveLinks() throws Exception >> + { >> + // Set up some test pages >> + engine.saveText( "RemoveLinks", "Test page." ); >> + engine.saveText( "Destination1", "Test page." ); >> + engine.saveText( "Destination2", "Test page." ); >> + engine.saveText( "Destination3", "Test page." ); >> + >> + // Set source-->dest1,2,3,4 >> + WikiPath source = WikiPath.valueOf( "RemoveLinks" ); >> + List destinations = new ArrayList(); >> + WikiPath destination1 = WikiPath.valueOf( "Destination1" ); >> + WikiPath destination2 = WikiPath.valueOf( "Destination2" ); >> + WikiPath destination3 = WikiPath.valueOf( "Destination3" ); >> + WikiPath destination4 = WikiPath.valueOf( "Destination4" ); >> + destinations.add( destination1 ); >> + destinations.add( destination2 ); >> + destinations.add( destination3 ); >> + destinations.add( destination4 ); >> + mgr.setLinks( source, destinations ); >> + >> + // We should see four outbound links from source-- >> >dest1,2,3,4 >> + assertEquals( 4, mgr.getRefersTo( source ).size() ); >> + assertEquals( 0, mgr.getRefersTo( destination1 ).size() ); >> + assertEquals( 0, mgr.getRefersTo( destination2 ).size() ); >> + assertEquals( 0, mgr.getRefersTo( destination3 ).size() ); >> + assertEquals( 0, mgr.getRefersTo( destination4 ).size() ); >> + >> + // We should see four inbound links dest1,2,3,4<--source >> + assertEquals( 0, mgr.getReferredBy( source ).size() ); >> + assertEquals( 1, mgr.getReferredBy( destination1 ).size() ); >> + assertEquals( 1, mgr.getReferredBy( destination2 ).size() ); >> + assertEquals( 1, mgr.getReferredBy( destination3 ).size() ); >> + assertEquals( 1, mgr.getReferredBy( destination4 ).size() ); >> + >> + // Now, remove all links from the source to dest1,2,3, and >> all inbound links too >> + mgr.removeLinks( source ); >> + assertEquals( 0, mgr.getRefersTo( source ).size() ); >> + assertEquals( 0, mgr.getReferredBy( source ).size() ); >> + assertEquals( 0, mgr.getReferredBy( destination1 ).size() ); >> + assertEquals( 0, mgr.getReferredBy( destination2 ).size() ); >> + assertEquals( 0, mgr.getReferredBy( destination3 ).size() ); >> + assertEquals( 0, mgr.getReferredBy( destination4 ).size() ); >> + assertEquals( 0, mgr.getRefersTo( destination1 ).size() ); >> + assertEquals( 0, mgr.getRefersTo( destination2 ).size() ); >> + assertEquals( 0, mgr.getRefersTo( destination3 ).size() ); >> + assertEquals( 0, mgr.getRefersTo( destination4 ).size() ); >> + } >> + >> public void testSelf() throws WikiException >> { >> engine.saveText( "BugOne", "BugOne" ); >> - Collection ref = findReferrers( "BugOne" ); >> - assertEquals("wrong size",1,ref.size()); >> - assertEquals("ref", "Main:BugOne", >> ref.iterator().next().toString()); >> + Collection ref = >> mgr.getReferredBy( WikiPath.valueOf( "BugOne" )); >> + assertEquals( "wrong size", 1, ref.size() ); >> + assertEquals( "ref", "Main:BugOne", >> ref.iterator().next().toString() ); >> } >> - >> - public static Test suite() >> + >> + /** >> + * Tests protected method {@link >> ReferenceManager#setLinks(WikiPath, List)}, >> + * which sets bi-directional links from a source page to multiple >> + * destinations, and vice-versa. The source and destination >> pages exist. >> + * >> + * @throws Exception >> + */ >> + public void testSetLinks() throws Exception >> { >> - return new TestSuite( ReferenceManagerTest.class ); >> + // Set up some test pages >> + engine.saveText( "SetLinks", "Test page." ); >> + engine.saveText( "Destination1", "Test page." ); >> + engine.saveText( "Destination2", "Test page." ); >> + engine.saveText( "Destination3", "Test page." ); >> + >> + // Set source-->dest1,2,3 >> + WikiPath source = WikiPath.valueOf( "SetLinks" ); >> + List destinations = new ArrayList(); >> + WikiPath destination1 = WikiPath.valueOf( "Destination1" ); >> + WikiPath destination2 = WikiPath.valueOf( "Destination2" ); >> + WikiPath destination3 = WikiPath.valueOf( "Destination3" ); >> + destinations.add( destination1 ); >> + destinations.add( destination2 ); >> + destinations.add( destination3 ); >> + mgr.setLinks( source, destinations ); >> + >> + // We should see three outbound links from source-->dest1,2,3 >> + List links; >> + links = mgr.getRefersTo( source ); >> + assertEquals( 3, links.size() ); >> + assertTrue( links.contains( destination1 ) ); >> + assertTrue( links.contains( destination2 ) ); >> + assertTrue( links.contains( destination3 ) ); >> + >> + // Each dest1,2,3 should NOT have created an inbound link >> to source >> + assertEquals( 0, mgr.getReferredBy( source ).size() ); >> + >> + // Each of the destination pages should have 1 inbound link >> from source >> + links = mgr.getReferredBy( destination1 ); >> + assertEquals( 1, links.size() ); >> + assertTrue( links.contains( source ) ); >> + >> + links = mgr.getReferredBy( destination2 ); >> + assertEquals( 1, links.size() ); >> + assertTrue( links.contains( source ) ); >> + >> + links = mgr.getReferredBy( destination3 ); >> + assertEquals( 1, links.size() ); >> + assertTrue( links.contains( source ) ); >> } >> >> - public static void main(String[] args) >> + /** >> + * Tests protected method >> + * {@link ReferenceManager#setRefersTo(WikiPath, List)}, which >> sets >> + * outbound links from a page to multiple destinatiions. The >> source page >> + * exists. >> + * >> + * @throws Exception >> + */ >> + public void testSetRefersTo() throws Exception >> { >> - junit.textui.TestRunner.main( new String[] >> { ReferenceManagerTest.class.getName() } ); >> + WikiPath source = WikiPath.valueOf( "TestPage" ); >> + List destinations = new ArrayList(); >> + destinations.add( WikiPath.valueOf( "PageOne" ) ); >> + destinations.add( WikiPath.valueOf( "PageTwo" ) ); >> + destinations.add( WikiPath.valueOf( "PageThree" ) ); >> + mgr.setRefersTo( source, destinations ); >> + >> + List links = mgr.getRefersTo( source ); >> + assertEquals( 3, links.size() ); >> + >> assertTrue( links.contains( WikiPath.valueOf( "PageOne" ) ) ); >> + >> assertTrue( links.contains( WikiPath.valueOf( "PageTwo" ) ) ); >> + >> assertTrue( links.contains( WikiPath.valueOf( "PageThree" ) ) ); >> } >> >> + /** >> + * Should fail in 2.2.14-beta >> + * >> + * @throws Exception >> + */ >> + public void testSingularReferences() throws Exception >> + { >> + engine.saveText( "RandomPage", "FatalBugs" ); >> + engine.saveText( "FatalBugs", "" ); >> + engine.saveText( "BugCommentPreviewDeletesAllComments", >> "FatalBug" ); >> + >> + Collection c = >> mgr.getReferredBy( WikiPath.valueOf( "FatalBugs" )); >> + >> + assertEquals( "FatalBugs referrers number", 2, c.size() ); >> + } >> >> + >> + public void testUncreated() throws Exception >> + { >> + List c = mgr.findUncreated(); >> + assertEquals( 1, c.size()); >> + assertEquals( "Main:Foobar2", c.get( 0 ) ); >> + } >> + >> + public void testUnreferenced() throws Exception >> + { >> + List c = mgr.findUnreferenced(); >> + assertEquals( 1, c.size() ); >> + assertEquals( "TestPage", c.get( 0 ) ); >> + } >> + >> + public void testUpdateBothExist() throws Exception >> + { >> + engine.saveText( "Foobars", "qwertz" ); >> + Collection c = >> mgr.getReferredBy( WikiPath.valueOf( "Foobars" )); >> + assertEquals( "Foobars referrers", 2, c.size() ); >> + assertTrue( "Foobars referrer is not TestPage", >> c.contains( WikiPath.valueOf( "TestPage" ) ) >> + && >> c.contains( WikiPath.valueOf( "Foobar" ) ) ); >> + } >> + >> + public void testUpdateBothExist2() throws Exception >> + { >> + engine.saveText( "Foobars", "qwertz" ); >> + engine.saveText( "TestPage", "Reference to [Foobar], >> [Foobars]." ); >> + >> + Collection c = >> mgr.getReferredBy( WikiPath.valueOf( "Foobars" )); >> + assertEquals( "Foobars referrers count", 2, c.size() ); >> + >> + assertTrue( "Foobars referrers", >> c.contains( WikiPath.valueOf( "TestPage" ) ) && >> c.contains( WikiPath.valueOf( "Foobar" ) ) ); >> + } >> + >> /** >> - * Test method: dumps the contents of ReferenceManager link >> lists to stdout. >> - * This method is NOT synchronized, and should be used in testing >> - * with one user, one WikiEngine only. >> + * Opposite to testUpdatePluralOnlyRef(). Is a page with plural >> form >> + * recognized as the page referenced by a singular link. >> */ >> - /* >> - public static String dumpReferenceManager( ReferenceManager rm ) >> + >> + public void testUpdateFoobar2s() throws Exception >> { >> - StringBuffer buf = new StringBuffer(); >> - try >> - { >> - >> buf >> .append >> ( "================================================================ >> \n" ); >> - buf.append( "Referred By list:\n" ); >> - Set keys = rm.getReferredBy().keySet(); >> - Iterator it = keys.iterator(); >> - while( it.hasNext() ) >> - { >> - String key = (String) it.next(); >> - buf.append( key + " referred by: " ); >> - Set refs = (Set)rm.getReferredBy().get( key ); >> - Iterator rit = refs.iterator(); >> - while( rit.hasNext() ) >> - { >> - String aRef = (String)rit.next(); >> - buf.append( aRef + " " ); >> - } >> - buf.append( "\n" ); >> - } >> - >> - >> - >> buf >> .append >> ( "---------------------------------------------------------------- >> \n" ); >> - buf.append( "Refers To list:\n" ); >> - keys = rm.getRefersTo().keySet(); >> - it = keys.iterator(); >> - while( it.hasNext() ) >> - { >> - String key = (String) it.next(); >> - buf.append( key + " refers to: " ); >> - Collection refs = >> (Collection)rm.getRefersTo().get( key ); >> - if(refs != null) >> - { >> - Iterator rit = refs.iterator(); >> - while( rit.hasNext() ) >> - { >> - String aRef = (String)rit.next(); >> - buf.append( aRef + " " ); >> - } >> - buf.append( "\n" ); >> - } >> - else >> - buf.append("(no references)\n"); >> - } >> - >> buf >> .append >> ( "================================================================ >> \n" ); >> - } >> - catch(Exception e) >> - { >> - buf.append("Problem in dump(): " + e + "\n" ); >> - } >> - >> - return( buf.toString() ); >> + engine.saveText( "Foobar2s", "qwertz" ); >> + assertEquals( 0, mgr.findUncreated().size() ); >> + >> + Collection c = >> mgr.getReferredBy( WikiPath.valueOf( "Foobar2s" )); >> + assertTrue( "referrers", c != null && c.size() == 1 && >> c.iterator().next().toString().equals( "Foobar" ) ); >> } >> - */ >> >> -} >> + /** >> + * Is a page recognized as referenced if only plural form links >> exist. >> + */ >> + >> + // NB: Unfortunately, cleaning out self-references in the case >> there's >> + // a plural and a singular form of the page becomes nigh >> impossible, so we >> + // just don't do it. >> + public void testUpdatePluralOnlyRef() throws Exception >> + { >> + engine.saveText( "TestPage", "Reference to [Foobars]." ); >> + List c = mgr.findUnreferenced(); >> + assertEquals( 1, c.size() ); >> + assertEquals( "TestPage", c.get( 0 ) ); >> + >> + Collection p = >> mgr.getReferredBy( WikiPath.valueOf( "Foobar" )); >> + assertTrue( "Foobar referrers", p.size() == 2 ); >> + } >> >> + /** >> + * Test method: dumps the contents of ReferenceManager link >> lists to stdout. >> + * This method is NOT synchronized, and should be used in >> testing with one >> + * user, one WikiEngine only. >> + */ >> + /* >> + * public static String dumpReferenceManager( ReferenceManager >> rm ) { >> + * StringBuffer buf = new StringBuffer(); try { buf.append( >> + * >> "================================================================ >> \n" ); >> + * buf.append( "Referred By list:\n" ); Set keys = >> + * rm.getReferredBy().keySet(); Iterator it = keys.iterator(); >> while( >> + * it.hasNext() ) { String key = (String) it.next(); >> buf.append( key + " >> + * referred by: " ); Set refs = >> (Set)rm.getReferredBy().get( key ); Iterator >> + * rit = refs.iterator(); while( rit.hasNext() ) { String aRef = >> + * (String)rit.next(); buf.append( aRef + " " ); } >> buf.append( "\n" ); } >> + * buf.append( >> + * >> "---------------------------------------------------------------- >> \n" ); >> + * buf.append( "Refers To list:\n" ); keys = >> rm.getRefersTo().keySet(); it = >> + * keys.iterator(); while( it.hasNext() ) { String key = >> (String) it.next(); >> + * buf.append( key + " refers to: " ); Collection refs = >> + * (Collection)rm.getRefersTo().get( key ); if(refs != null) >> { Iterator rit = >> + * refs.iterator(); while( rit.hasNext() ) { String aRef = >> + * (String)rit.next(); buf.append( aRef + " " ); } >> buf.append( "\n" ); } >> + * else buf.append("(no references)\n"); } buf.append( >> + * >> "================================================================ >> \n" ); } >> + * catch(Exception e) { buf.append("Problem in dump(): " + e + >> "\n" ); } >> + * return( buf.toString() ); } >> + */ >> + >> +} >> >> 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=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/tests/java/org/apache/wiki/ >> TestEngine.java (original) >> +++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/ >> TestEngine.java Sat May 2 14:15:13 2009 >> @@ -42,10 +42,8 @@ >> import org.apache.wiki.api.WikiException; >> import org.apache.wiki.api.WikiPage; >> import org.apache.wiki.attachment.Attachment; >> -import org.apache.wiki.auth.AuthenticationManager; >> -import org.apache.wiki.auth.SessionMonitor; >> -import org.apache.wiki.auth.Users; >> -import org.apache.wiki.auth.WikiSecurityException; >> +import org.apache.wiki.auth.*; >> +import org.apache.wiki.auth.user.XMLUserDatabase; >> import org.apache.wiki.content.PageAlreadyExistsException; >> import org.apache.wiki.content.PageNotFoundException; >> import org.apache.wiki.content.WikiPath; >> @@ -449,6 +447,8 @@ >> { >> props.put( AuthenticationManager.PROP_LOGIN_THROTTLING, >> "false" ); >> props.put( WikiEngine.PROP_URLCONSTRUCTOR, >> "org.apache.wiki.url.DefaultURLConstructor" ); >> + props.put( UserManager.PROP_DATABASE, >> "org.apache.wiki.auth.user.XMLUserDatabase" ); >> + props.put(XMLUserDatabase.PROP_USERDATABASE, "tests/etc/ >> userdatabase.xml"); >> return props; >> } >> >> >> 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=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/tests/java/org/apache/wiki/ >> WikiEngineTest.java (original) >> +++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/ >> WikiEngineTest.java Sat May 2 14:15:13 2009 >> @@ -239,18 +239,6 @@ >> assertEquals( "A%E2%89%A2%CE%91.", >> m_engine.encodeName( name ) ); >> } >> >> - public void testReadLinks() >> - throws Exception >> - { >> - String src="Foobar. [Foobar]. Frobozz. [This is a link]."; >> - >> - m_engine.deletePage( "Test" ); >> - Object[] result = >> m_engine >> .scanWikiLinks( m_engine.createPage( WikiPath.valueOf( "Test" ) ), >> src ).toArray(); >> - >> - assertEquals( "item 0", PATH_FOOBAR, result[0] ); >> - assertEquals( "item 1", "Main:This is a link", result[1] ); >> - } >> - >> public void testBeautifyTitle() >> { >> String src = "WikiNameThingy"; >> @@ -713,7 +701,7 @@ >> m_engine.saveText( NAME1, "[Foobar]" ); >> m_engine.getText( NAME1 ); // Ensure that page is cached. >> >> - Collection c = refMgr.findUncreated(); >> + List c = refMgr.findUncreated(); >> assertTrue( "Non-existent reference not detected by >> ReferenceManager", >> Util.collectionContains( c, "Foobar" )); >> >> @@ -754,7 +742,7 @@ >> m_engine.saveText( NAME1, "[Foobar]" ); >> m_engine.getText( NAME1 ); // Ensure that page is cached. >> >> - Collection c = refMgr.findUncreated(); >> + List c = refMgr.findUncreated(); >> assertEquals( "uncreated count", 1, c.size() ); >> assertEquals( "wrong referenced page", "Foobar", >> (String)c.iterator().next() ); >> >> @@ -873,7 +861,7 @@ >> m_engine.saveText( "RenameBugTestPage", "Mary had a little >> generic object" ); >> m_engine.saveText( "OldNameTestPage", "Linked to >> RenameBugTestPage" ); >> >> - Collection pages = >> m_engine >> .getReferenceManager >> ().findReferrers( WikiPath.valueOf("RenameBugTestPage") ); >> + Collection pages = >> m_engine >> .getReferenceManager >> ().getReferredBy( WikiPath.valueOf("RenameBugTestPage") ); >> assertEquals( "has one", "Main:OldNameTestPage", >> pages.iterator().next() ); >> >> WikiContext ctx = >> m_engine >> .getWikiContextFactory >> ().newViewContext( m_engine.getPage("OldNameTestPage") ); >> @@ -883,7 +871,7 @@ >> assertFalse( "did not vanish", >> m_engine.pageExists( "OldNameTestPage") ); >> assertTrue( "did not appear", >> m_engine.pageExists( "NewNameTestPage") ); >> >> - pages = >> m_engine >> .getReferenceManager >> ().findReferrers( WikiPath.valueOf("RenameBugTestPage") ); >> + pages = >> m_engine >> .getReferenceManager >> ().getReferredBy( WikiPath.valueOf("RenameBugTestPage") ); >> >> assertEquals( "wrong # of referrers", 1, pages.size() ); >> >> >> Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/action/ >> RenameActionBeanTest.java >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/action/RenameActionBeanTest.java?rev=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/tests/java/org/apache/wiki/action/ >> RenameActionBeanTest.java (original) >> +++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/action/ >> RenameActionBeanTest.java Sat May 2 14:15:13 2009 >> @@ -151,8 +151,8 @@ >> m_engine.saveText("ReferstoTest", "This page refers to >> [Test].\n"); >> WikiPage referringPage = m_engine.getPage("ReferstoTest"); >> assertNotNull("Did not save page ReferstoTest!", >> referringPage ); >> - >> assertNotNull >> ( m_engine >> .getReferenceManager().findReferrers(WikiPath.valueOf("Test")) ); >> - assertEquals( 1, >> m_engine >> .getReferenceManager >> ().findReferrers(WikiPath.valueOf("Test")).size() ); >> + >> assertNotNull >> ( m_engine >> .getReferenceManager().getReferredBy(WikiPath.valueOf("Test")) ); >> + assertEquals( 1, >> m_engine >> .getReferenceManager >> ().getReferredBy(WikiPath.valueOf("Test")).size() ); >> >> MockRoundtrip trip; >> ValidationErrors errors; >> >> Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ >> PageRenamerTest.java >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/PageRenamerTest.java?rev=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ >> PageRenamerTest.java (original) >> +++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ >> PageRenamerTest.java Sat May 2 14:15:13 2009 >> @@ -21,18 +21,21 @@ >> package org.apache.wiki.content; >> >> import java.util.Collection; >> +import java.util.List; >> import java.util.Properties; >> -import java.util.Set; >> - >> -import org.apache.wiki.*; >> -import org.apache.wiki.api.WikiException; >> -import org.apache.wiki.api.WikiPage; >> -import org.apache.wiki.providers.ProviderException; >> >> import junit.framework.Test; >> import junit.framework.TestCase; >> import junit.framework.TestSuite; >> >> +import org.apache.wiki.TestEngine; >> +import org.apache.wiki.WikiContext; >> +import org.apache.wiki.WikiEngine; >> +import org.apache.wiki.WikiProvider; >> +import org.apache.wiki.api.WikiException; >> +import org.apache.wiki.api.WikiPage; >> +import org.apache.wiki.providers.ProviderException; >> + >> >> public class PageRenamerTest extends TestCase >> { >> @@ -78,9 +81,9 @@ >> m_engine.shutdown(); >> } >> >> - private Set findReferrers(String path) throws >> ProviderException >> + private List findReferrers(String path) throws >> ProviderException >> { >> - return >> m_engine >> .getReferenceManager().findReferrers( WikiPath.valueOf(path) ); >> + return >> m_engine >> .getReferenceManager().getReferredBy( WikiPath.valueOf(path) ); >> } >> >> public void testSimpleRename() >> >> Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/search/ >> SearchManagerTest.java >> URL: >> http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/search/SearchManagerTest.java?rev=770959&r1=770958&r2=770959&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> ====================================================================== >> --- incubator/jspwiki/trunk/tests/java/org/apache/wiki/search/ >> SearchManagerTest.java (original) >> +++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/search/ >> SearchManagerTest.java Sat May 2 14:15:13 2009 >> @@ -73,7 +73,7 @@ >> public void testDefaultProvider() >> { >> assertEquals( "org.apache.wiki.search.LuceneSearchProvider", >> - m_mgr.getSearchEngine().getClass().getName() ); >> + >> m_mgr.getSearchProvider().getClass().getName() ); >> } >> >> public void testSimpleSearch() >> > >