Author: jalkanen
Date: Wed Jul 22 17:58:35 2009
New Revision: 796818
URL: http://svn.apache.org/viewvc?rev=796818&view=rev
Log:
Versioning implemented; tests were upgraded to conform to the API, and some
obsolete tests were removed from WikiEngineTest.
Added:
incubator/jspwiki/trunk/src/WebContent/WEB-INF/lib/priha-0.1.21.jar (with
props)
Removed:
incubator/jspwiki/trunk/src/WebContent/WEB-INF/lib/priha-0.1.17.jar
Modified:
incubator/jspwiki/trunk/ChangeLog
incubator/jspwiki/trunk/doc/README - JCR Changes.txt
incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/search/SearchManager.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java
Modified: incubator/jspwiki/trunk/ChangeLog
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=796818&r1=796817&r2=796818&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Wed Jul 22 17:58:35 2009
@@ -1,3 +1,12 @@
+2009-07-22 Janne Jalkanen <[email protected]>
+
+ * 3.0.0-svn-133
+
+ * First implementation of versioning implemented. Almost all
+ of the WikiEngine unit tests now run, though some of the old ones
+ were removed. Please see doc/README - JCR Changes.txt for details
+ about the versioning implementation.
+
2009-06-07 Janne Jalkanen <[email protected]>
* 3.0.0-svn-132
Modified: incubator/jspwiki/trunk/doc/README - JCR Changes.txt
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/doc/README%20-%20JCR%20Changes.txt?rev=796818&r1=796817&r2=796818&view=diff
==============================================================================
--- incubator/jspwiki/trunk/doc/README - JCR Changes.txt (original)
+++ incubator/jspwiki/trunk/doc/README - JCR Changes.txt Wed Jul 22 17:58:35
2009
@@ -89,5 +89,39 @@
Versioning
==========
-TBD, this has not yet been decided.
-
\ No newline at end of file
+While JSR-170 offers a comprehensive versioning API, there are some reasons
+why it is not used in JSPWiki.
+
+* There is no import/export support for version histories. There is an
+ export mechanism, but a version history cannot be imported, since /jcr:system
+ is unmodifiable. There is no support for playing back version changes either,
+ since the jcr:created property cannot be set when a Node is added.
+* JCR versioning always concerns the entire subtree and all the subproperties.
+ Considering that one of the goals of 3.0 is to allow subpages, this is not
+ a desired outcome.
+* JCR versioning assumes that prior to any change, checkout() is called to
+ give ownership to a particular Session. Now, this is difficult to set up
+ in the existing JSPWiki API without modifying it too radically.
+
+Therefore, JSPWiki manages its own versions. The versioning structure looks
like this:
+
+* WikiPage
++--- wiki:versions
+ +--- 1
+ +--- <copy of all properties>
+ +--- jcr:uuid (autogenerated; unique for each version)
+ +--- wiki:version (integer, 1)
+ +--- 2
+ +--- 3
++--- <properties>
++--- jcr:uuid
++--- wiki:version (integer,4)
+
+Upon save(), the following happens:
+* The <properties> are copied using a secondary Session to the wiki:versions/4
directory
+* wiki:version is bumped (to 5)
+* The Node.save() operation is called on the new wikipage.
+
+TBD: This keeps a dual copy of the latest version!
+TBD: How to optimize the storage of the binaries, if only properties change?
We could
+ of course just rely on the storage to optimize this...
\ No newline at end of file
Added: incubator/jspwiki/trunk/src/WebContent/WEB-INF/lib/priha-0.1.21.jar
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/WEB-INF/lib/priha-0.1.21.jar?rev=796818&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/jspwiki/trunk/src/WebContent/WEB-INF/lib/priha-0.1.21.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java?rev=796818&r1=796817&r2=796818&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java Wed Jul
22 17:58:35 2009
@@ -60,6 +60,8 @@
private static final String ATTR_CONTENT = "wiki:content";
+ public static final String ATTR_VERSION = "wiki:version";
+
public static final String CONTENTTYPE = "wiki:contentType";
@@ -111,6 +113,12 @@
m_path = name;
}
+ /**
+ * Returns the JCR Node which backs this WikiPage implementation.
+ *
+ * @return The JCR Node
+ * @throws RepositoryException If the page cannot be located.
+ */
public Node getJCRNode() throws RepositoryException
{
return m_engine.getContentManager().getJCRNode(m_jcrPath);
@@ -275,8 +283,17 @@
*/
public int getVersion()
{
- return -1;
- //return getJCRNode().getBaseVersion().
+ try
+ {
+ return (int) getJCRNode().getProperty( ATTR_VERSION ).getLong();
+ }
+ catch( PathNotFoundException e )
+ {}
+ catch( RepositoryException e )
+ {
+ // FIXME: SHould really throw something else.
+ }
+ return 0;
}
/* (non-Javadoc)
@@ -580,6 +597,10 @@
}
}
+ /**
+ * Returns the parent page of this subpage. If this is not a subpage,
+ * it will simply throw a PageNotFoundException.
+ */
public WikiPage getParent() throws PageNotFoundException, ProviderException
{
return m_engine.getContentManager().getPage( m_path.getParent() );
@@ -595,12 +616,20 @@
return m_path.getName();
}
+ public boolean isLatest() throws RepositoryException
+ {
+ // TODO: This is a bit kludgish, but works.
+ return getJCRNode().getPath().indexOf( "/wiki:versions/" ) == -1;
+ }
+
+ /** @deprecated */
public boolean isCacheable()
{
// TODO Auto-generated method stub
return false;
}
+ /** @deprecated */
public void setCacheable( boolean value )
{
// TODO Auto-generated method stub
@@ -626,6 +655,9 @@
return true;
}
+ /**
+ * {...@inheritdoc}
+ */
public List<WikiPage> getChildren() throws ProviderException
{
ArrayList<WikiPage> pages = new ArrayList<WikiPage>();
@@ -636,7 +668,16 @@
while( iter.hasNext() )
{
- pages.add( new JCRWikiPage( m_engine, iter.nextNode() ) );
+ Node n = iter.nextNode();
+
+ //
+ // We will not count any page which has a namespace as
+ // a child of this WikiPage.
+ //
+ if( n.getName().indexOf( ':' ) == -1 )
+ {
+ pages.add( new JCRWikiPage( m_engine, iter.nextNode() ) );
+ }
}
}
catch( PathNotFoundException e )
@@ -650,5 +691,43 @@
return pages;
}
+
+ // FIXME: This is really slow. I mean, really, really slow, especially
+ // if you call it repeatedly.
+ public JCRWikiPage getPredecessor() throws ProviderException,
PageNotFoundException
+ {
+ List<WikiPage> versions = m_engine.getVersionHistory( getName() );
+
+ int thisVersion = getVersion();
+
+ WikiPage p = null;
+
+ for( int i = 0; i < versions.size(); i++ )
+ {
+ if( versions.get( i ).getVersion() == thisVersion )
+ {
+ break;
+ }
+ p = versions.get( i );
+ }
+
+ if( p == null )
+ throw new PageNotFoundException("No predecessor");
+
+ return (JCRWikiPage)p;
+ }
+
+ public JCRWikiPage getCurrentVersion() throws ProviderException
+ {
+ try
+ {
+ return (JCRWikiPage) m_engine.getPage( getPath() );
+ }
+ catch( PageNotFoundException e )
+ {
+ throw new ProviderException("version cannot access current page -
this can be serious",e);
+ }
+ }
+
}
\ No newline at end of file
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=796818&r1=796817&r2=796818&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Wed Jul 22
17:58:35 2009
@@ -77,7 +77,7 @@
* <p>
* If the build identifier is empty, it is not added.
*/
- public static final String BUILD = "132";
+ public static final String BUILD = "133";
/**
* This is the generic version string you should use
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java?rev=796818&r1=796817&r2=796818&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java
(original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java Wed Jul
22 17:58:35 2009
@@ -286,4 +286,5 @@
* @throws ProviderException If the attachmentness cannot be determined.
*/
public boolean isAttachment() throws ProviderException;
+
}
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=796818&r1=796817&r2=796818&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 Jul 22 17:58:35 2009
@@ -28,12 +28,12 @@
import java.util.*;
import javax.jcr.*;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
-import javax.jcr.version.Version;
-import javax.jcr.version.VersionHistory;
-import javax.jcr.version.VersionIterator;
+import javax.jcr.version.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -102,6 +102,8 @@
public class ContentManager implements WikiEventListener
{
+ private static final String WIKI_VERSIONS = "wiki:versions";
+
/**
* The name of the default WikiSpace.
*/
@@ -330,17 +332,114 @@
}
/**
- * Saves a WikiPage to the repository.
- * @param page the page to save
+ * Creates a new version of the given page.
+ *
+ * @param page
+ * @throws RepositoryException
+ */
+ private void checkin( String path, int currentVersion ) throws
RepositoryException
+ {
+ Session copierSession = null;
+
+ try
+ {
+ copierSession = m_sessionManager.newSession();
+
+ // If the item does not exist yet, there is nothing to copy.
+ if( !copierSession.itemExists( path ) ) return;
+
+ Node nd = (Node)copierSession.getItem( path );
+ Node versions;
+
+ if( !nd.hasNode( WIKI_VERSIONS ) )
+ {
+ versions = nd.addNode( WIKI_VERSIONS );
+ }
+ else
+ {
+ versions = nd.getNode( WIKI_VERSIONS );
+ }
+
+ Node newVersion = versions.addNode( Integer.toString(
currentVersion ) );
+
+ newVersion.addMixin( "mix:referenceable" );
+
+ copyProperties( nd, newVersion );
+
+ copierSession.save();
+ }
+ finally
+ {
+ if( copierSession != null ) copierSession.logout();
+ }
+
+ }
+
+ private void copyProperties( Node source, Node dest )
+ throws
RepositoryException,
+
ValueFormatException,
+ VersionException,
+ LockException,
+
ConstraintViolationException
+ {
+ for( PropertyIterator pi = source.getProperties(); pi.hasNext(); )
+ {
+ Property p = pi.nextProperty();
+
+ int opp = p.getDefinition().getOnParentVersion();
+
+ //
+ // This should prevent us from copying stuff which is set by
+ // the repository.
+ //
+ // FIXME: The jcr:uuid check is a Priha 0.1.21-specific hack - I
have
+ // no idea why it's giving the wrong OnParentVersionAction.
+ if( opp == OnParentVersionAction.COPY && !p.getName().equals(
"jcr:uuid" ))
+ {
+// System.out.println(" Copying "+p.getName());
+ if( p.getDefinition().isMultiple() )
+ dest.setProperty( p.getName(), p.getValues() );
+ else
+ dest.setProperty( p.getName(), p.getValue() );
+ }
+// else System.out.println(" Skipping "+p.getName());
+ }
+ }
+
+ /**
+ * Saves a WikiPage to the repository and creates a new version.
+ * Sets the following attributes:
+ * <ul>
+ * <li>wiki:created
+ * <li>wiki:version
+ * </ul>
+ *
+ * @param page the page to save
*/
public void save( WikiPage page ) throws RepositoryException
{
WikiPath path = page.getPath();
Node nd = getJCRNode( getJCRPath( path ) );
+
+ int version = page.getVersion();
+
+ nd.setProperty( JCRWikiPage.ATTR_VERSION, version+1 );
+
+ if( !nd.hasProperty( "wiki:created" ) )
+ {
+ nd.setProperty( "wiki:created", Calendar.getInstance() );
+ }
+
if( nd.isNew() )
+ {
+ // New node, so nothing to check in
nd.getParent().save();
+ }
else
+ {
+ checkin( getJCRPath( path ), version );
nd.save();
+ }
fireEvent( ContentEvent.NODE_SAVED, page.getName(), NO_ARGS );
}
@@ -462,7 +561,8 @@
Node n = ni.nextNode();
// Hack to make sure we don't add the space root node.
- if( !isSpaceRoot(n) )
+ // or any of the special child nodes that have a namespace
+ if( !isSpaceRoot(n) && n.getPath().indexOf( ':' ) == -1 )
{
WikiPage page = new JCRWikiPage( getEngine(), n );
if ( !results.contains( page ) )
@@ -717,32 +817,28 @@
throws ProviderException, PageNotFoundException
{
List<WikiPage> result = new ArrayList<WikiPage>();
- JCRWikiPage base = getPage(path);
try
{
- Node baseNode = base.getJCRNode();
+ Node base = getJCRNode( getJCRPath(path) );
- VersionHistory vh = baseNode.getVersionHistory();
-
- for( VersionIterator vi = vh.getAllVersions(); vi.hasNext(); )
+ if( base.hasNode( WIKI_VERSIONS ) )
{
- Version v = vi.nextVersion();
-
- result.add( new JCRWikiPage(m_engine,v) );
+ Node versionHistory = base.getNode( WIKI_VERSIONS );
+
+ for( NodeIterator ni = versionHistory.getNodes();
ni.hasNext(); )
+ {
+ Node v = ni.nextNode();
+
+ result.add( new JCRWikiPage(m_engine,path,v) );
+ }
}
- }
- catch( PathNotFoundException e )
- {
- throw new PageNotFoundException(path);
+
+ result.add( new JCRWikiPage(m_engine,base) );
}
catch( RepositoryException e )
{
- throw new ProviderException("Unable to get version history",e);
- }
- catch( WikiException e )
- {
- throw new ProviderException("Unable to get version history",e);
+ throw new ProviderException("Failure in trying to get version
history",e);
}
return result;
@@ -872,26 +968,56 @@
}
/**
- * Deletes only a specific version of a WikiPage.
+ * Deletes only a specific version of a WikiPage. No need to call
page.save()
+ * after this.
+ * <p>
+ * If this is the only version of the page, then the entire page will be
+ * deleted.
*
* @param page The page to delete.
* @throws ProviderException if the page fails
* @return True, if the page existed and was actually deleted, and false
if the page did
* not exist.
*/
- // TODO: The event which gets fired suggests that this actually a whole
page delete event
+ // TODO: Should fire proper events
public boolean deleteVersion( WikiPage page )
throws ProviderException
{
- fireEvent( ContentEvent.NODE_DELETE_REQUEST, page.getName(), NO_ARGS );
+ //fireEvent( ContentEvent.NODE_DELETE_REQUEST, page.getName(), NO_ARGS
);
JCRWikiPage jcrPage = (JCRWikiPage)page;
+
try
{
- jcrPage.getJCRNode().remove();
- jcrPage.save();
+ if( jcrPage.isLatest() )
+ {
+ // ..--p8mmmfpppppppppcccc0i9u8ioakkkcnnnnr njv,vv,vb
+
+ try
+ {
+ JCRWikiPage pred = jcrPage.getPredecessor();
+
+ restore( pred );
+ }
+ catch( PageNotFoundException e )
+ {
+ deletePage( page );
+ }
+ catch( PageAlreadyExistsException e )
+ {
+ // SHould never happen, so this is quite problematic
+ throw new ProviderException( "Page which was already
removed still exists?", e );
+ }
+
+ }
+ else
+ {
+ jcrPage.getJCRNode().remove();
+
+ jcrPage.getJCRNode().getParent().save();
+ }
- fireEvent( ContentEvent.NODE_DELETED, page.getName(), NO_ARGS );
+ //fireEvent( ContentEvent.NODE_DELETED, page.getName(), NO_ARGS );
return true;
}
@@ -905,6 +1031,30 @@
}
}
+ private void restore( JCRWikiPage page ) throws ProviderException,
RepositoryException, PageAlreadyExistsException
+ {
+ JCRWikiPage original = page.getCurrentVersion();
+ WikiPath path = original.getPath();
+ String contentType = page.getContentType();
+
+ Node origNode = original.getJCRNode();
+
+ for( PropertyIterator pi = origNode.getProperties(); pi.hasNext(); )
+ {
+ Property p = pi.nextProperty();
+
+ // TODO: Again, strange Priha-specific hack for 0.1.21
+ if( !p.getDefinition().isProtected() &&
!p.getName().equals("jcr:uuid") )
+ p.remove();
+ }
+
+ origNode.save();
+
+ copyProperties( page.getJCRNode(), origNode );
+
+ origNode.save();
+ }
+
/**
* Deletes an entire page, all versions, all traces. If the page did not
* exist, will just exit quietly and return false.
@@ -919,26 +1069,10 @@
{
fireEvent( ContentEvent.NODE_DELETE_REQUEST, page.getName(), NO_ARGS );
- VersionHistory vh;
try
{
Node nd = ((JCRWikiPage)page).getJCRNode();
- // Remove version history
- if( nd.isNodeType( "mix:versionable" ) )
- {
- vh = nd.getVersionHistory();
-
- for( VersionIterator iter = vh.getAllVersions();
iter.hasNext(); )
- {
- Version v = iter.nextVersion();
-
- v.remove();
- v.save();
- }
- vh.save();
- }
-
// Remove the node itself.
nd.remove();
@@ -1434,38 +1568,28 @@
{
try
{
- JCRWikiPage page = null;
Session session = m_sessionManager.getSession();
- Node nd = session.getRootNode().getNode( getJCRPath(path) );
-
- try
- {
- VersionHistory vh = nd.getVersionHistory();
+ Node original = session.getRootNode().getNode( getJCRPath(path) );
- Version v = vh.getVersion( Integer.toString( version ) );
+ Property p = original.getProperty( "wiki:version" );
- page = new JCRWikiPage(m_engine, v);
- }
- catch( UnsupportedRepositoryOperationException e )
- {
- // No version history yet
-
- if( version == WikiProvider.LATEST_VERSION || version == 1)
- page = new JCRWikiPage( m_engine, nd );
- else
- throw new PageNotFoundException("Version "+version+" of
page "+path+" does not exist!");
- }
+ if( p.getLong() == version || version ==
WikiProvider.LATEST_VERSION )
+ return new JCRWikiPage( m_engine, original );
- return page;
+ Node versionHistory = original.getNode( WIKI_VERSIONS );
+
+ Node v = versionHistory.getNode( Integer.toString( version ) );
+
+ return new JCRWikiPage( m_engine, path, v );
}
catch( PathNotFoundException e )
{
- throw new PageNotFoundException( path );
+ throw new PageNotFoundException("No such version "+version+"
exists for path "+path);
}
catch( RepositoryException e )
{
- throw new ProviderException( "Unable to get a page", e );
+ throw new ProviderException( "Repository failed", e );
}
}
@@ -1624,7 +1748,7 @@
Session session = m_currentSession.get();
if(session == null)
{
- session = m_repository.login(m_workspaceName);
+ session = newSession();
m_currentSession.set(session);
return m_trueOwner;
}
@@ -1632,6 +1756,20 @@
}
/**
+ * Creates a new Session object always which you will need to
manually logout().
+ *
+ * @return A new Session object.
+ * @throws LoginException
+ * @throws RepositoryException
+ */
+ public Session newSession() throws LoginException, RepositoryException
+ {
+ Session session = m_repository.login(m_workspaceName);
+
+ return session;
+ }
+
+ /**
* Closes the current session, if this caller is the owner. Must be
called
* in your finally- block.
*
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=796818&r1=796817&r2=796818&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
Wed Jul 22 17:58:35 2009
@@ -367,7 +367,7 @@
}
catch( PageNotFoundException e )
{
- throw new InternalWikiException("Page removed already!?!");
+ throw new InternalWikiException("Page removed already!?!
Page="+pageName);
}
catch( ProviderException e )
{
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=796818&r1=796817&r2=796818&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
(original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java Wed
Jul 22 17:58:35 2009
@@ -26,6 +26,7 @@
import java.util.*;
import org.apache.wiki.api.WikiPage;
+import org.apache.wiki.content.PageNotFoundException;
import org.apache.wiki.content.WikiPath;
import org.apache.wiki.providers.*;
import org.apache.wiki.util.FileUtil;
@@ -647,8 +648,6 @@
*/
public void testDeleteVersion() throws Exception
{
- props.setProperty( "jspwiki.pageProvider", "VersioningFileProvider" );
-
m_engine.shutdown();
m_engine = new TestEngine( props );
m_engine.saveText( NAME1, "Test1" );
@@ -659,7 +658,12 @@
m_engine.deleteVersion( page );
- assertNull( "got page", m_engine.getPage( NAME1, 3 ) );
+ try
+ {
+ WikiPage p = m_engine.getPage( NAME1, 3 );
+ fail("got page");
+ }
+ catch(PageNotFoundException e) {} // Expected
String content = m_engine.getText( NAME1, WikiProvider.LATEST_VERSION
);
@@ -668,139 +672,30 @@
public void testDeleteVersion2() throws Exception
{
- props.setProperty( "jspwiki.pageProvider",
"VersioningFileProvider" );
-
- m_engine.shutdown();
- m_engine = new TestEngine( props );
- m_engine.saveText( NAME1, "Test1" );
- m_engine.saveText( NAME1, "Test2" );
- m_engine.saveText( NAME1, "Test3" );
-
- WikiPage page = m_engine.getPage( NAME1, 1 );
-
- m_engine.deleteVersion( page );
-
- assertNull( "got page", m_engine.getPage( NAME1, 1 ) );
+ m_engine.shutdown();
+ m_engine = new TestEngine( props );
+ m_engine.saveText( NAME1, "Test1" );
+ m_engine.saveText( NAME1, "Test2" );
+ m_engine.saveText( NAME1, "Test3" );
- String content = m_engine.getText( NAME1,
WikiProvider.LATEST_VERSION );
+ WikiPage page = m_engine.getPage( NAME1, 1 );
- assertEquals( "content", "Test3", content.trim() );
+ m_engine.deleteVersion( page );
- assertEquals( "content1", "", m_engine.getText( NAME1, 1 ).trim()
);
+ try
+ {
+ m_engine.getPage( NAME1, 1 );
+ fail("Got page!");
}
-
-
- /**
- * Assumes that CachingProvider is in use.
- */
- public void testExternalModificationRefs()
- throws Exception
- {
- ReferenceManager refMgr = m_engine.getReferenceManager();
-
- m_engine.saveText( NAME1, "[Foobar]" );
- m_engine.getText( NAME1 ); // Ensure that page is cached.
-
- List<WikiPath> c = refMgr.findUncreated();
- assertTrue( "Non-existent reference not detected by ReferenceManager",
- c.contains( WikiPath.valueOf( "Foobar" ) ) );
-
- Thread.sleep( 2000L ); // Wait two seconds for filesystem granularity
-
- String files = props.getProperty( AbstractFileProvider.PROP_PAGEDIR );
-
- File saved = new File( files, NAME1+".txt" );
-
- assertTrue( "No file!", saved.exists() );
-
- FileWriter out = new FileWriter( saved );
- FileUtil.copyContents( new StringReader("[Puppaa]"), out );
- out.close();
-
- Thread.sleep( 2000L*PAGEPROVIDER_RESCAN_PERIOD ); // Wait five seconds
for CachingProvider to wake up.
-
- String text = m_engine.getText( NAME1 );
-
- assertEquals( "wrong contents", "[Puppaa]", text );
-
- c = refMgr.findUncreated();
+ catch( PageNotFoundException e ) {} // Expected
- assertTrue( "Non-existent reference after external page change " +
- "not detected by ReferenceManager",
- c.contains( WikiPath.valueOf( "Puppaa" ) ) );
- }
-
-
- /**
- * Assumes that CachingProvider is in use.
- */
- public void testExternalModificationRefsDeleted()
- throws Exception
- {
- ReferenceManager refMgr = m_engine.getReferenceManager();
-
- m_engine.saveText( NAME1, "[Foobar]" );
- m_engine.getText( NAME1 ); // Ensure that page is cached.
-
- List<WikiPath> c = refMgr.findUncreated();
- assertEquals( "uncreated count", 1, c.size() );
- assertEquals( "wrong referenced page", WikiPath.valueOf( "Foobar" ),
c.iterator().next() );
-
- Thread.sleep( 2000L ); // Wait two seconds for filesystem granularity
-
- String files = props.getProperty( AbstractFileProvider.PROP_PAGEDIR );
-
- File saved = new File( files, NAME1+".txt" );
-
- assertTrue( "No file!", saved.exists() );
-
- saved.delete();
-
- assertFalse( "File not deleted!", saved.exists() );
-
- Thread.sleep( 2000L*PAGEPROVIDER_RESCAN_PERIOD ); // Wait five seconds
for CachingProvider to catch up.
-
- WikiPage p = m_engine.getPage( NAME1 );
-
- assertNull( "Got page!", p );
-
- String text = m_engine.getText( NAME1 );
-
- assertEquals( "wrong contents", "", text );
-
- c = refMgr.findUncreated();
- assertEquals( "NEW: uncreated count", 0, c.size() );
- }
-
- /**
- * Assumes that CachingProvider is in use.
- */
- public void testExternalModification()
- throws Exception
- {
- m_engine.saveText( NAME1, "Foobar" );
-
- m_engine.getText( NAME1 ); // Ensure that page is cached.
-
- Thread.sleep( 2000L ); // Wait two seconds for filesystem granularity
-
- String files = props.getProperty( AbstractFileProvider.PROP_PAGEDIR );
-
- File saved = new File( files, NAME1+".txt" );
+ String content = m_engine.getText( NAME1, WikiProvider.LATEST_VERSION
);
- assertTrue( "No file!", saved.exists() );
+ assertEquals( "content", "Test3", content.trim() );
- FileWriter out = new FileWriter( saved );
- FileUtil.copyContents( new StringReader("Puppaa"), out );
- out.close();
-
- // Wait for the caching provider to notice a refresh.
- Thread.sleep( 2000L*PAGEPROVIDER_RESCAN_PERIOD );
-
- // Trim - engine.saveText() may append a newline.
- String text = m_engine.getText( NAME1 ).trim();
- assertEquals( "wrong contents", "Puppaa", text );
+ assertEquals( "content1", "", m_engine.getText( NAME1, 1 ).trim() );
}
+
/**
* Tests BugReadingOfVariableNotWorkingForOlderVersions
Modified:
incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java?rev=796818&r1=796817&r2=796818&view=diff
==============================================================================
---
incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java
(original)
+++
incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/ContentManagerTest.java
Wed Jul 22 17:58:35 2009
@@ -132,6 +132,60 @@
assertEquals( 2, allPages.size() );
}
+ public void testVersions() throws Exception
+ {
+ String content = "Test Content";
+
+ WikiPage page = m_mgr.addPage( WikiPath.valueOf("TestPage"),
ContentManager.JSPWIKI_CONTENT_TYPE );
+
+ page.setContent( content );
+
+ page.save();
+
+ page.setContent( "New Test Content" );
+
+ page.save();
+
+ page.setContent( "Even newer Test Content" );
+
+ page.save();
+
+ assertEquals( "origpage version", 3, page.getVersion() );
+
+ WikiPage p2 = m_mgr.getPage( WikiPath.valueOf("TestPage") );
+
+ assertEquals( "fetched page version", 3, p2.getVersion() );
+
+ assertEquals( "content", "Even newer Test Content",
p2.getContentAsString() );
+
+ assertEquals( "content type", ContentManager.JSPWIKI_CONTENT_TYPE,
p2.getContentType() );
+
+ // Test get version
+
+ p2 = m_mgr.getPage( WikiPath.valueOf("TestPage"), 1 );
+
+ assertEquals( "v1 content", "Test Content", p2.getContentAsString() );
+ assertEquals( "v1 version", 1, p2.getVersion() );
+
+ assertFalse( "content",
page.getContentAsString().equals(p2.getContentAsString()));
+ assertFalse( "uuid", page.getAttribute( "jcr:uuid" ).equals(
p2.getAttribute( "jcr:uuid" )));
+
+ p2 = m_mgr.getPage( WikiPath.valueOf("TestPage"), 2 );
+
+ assertEquals( "v2 content", "New Test Content",
p2.getContentAsString() );
+ assertEquals( "v2 version", 2, p2.getVersion() );
+
+ p2 = m_mgr.getPage( WikiPath.valueOf("TestPage"), 3 );
+
+ assertEquals( "v3 content", "Even newer Test Content",
p2.getContentAsString() );
+ assertEquals( "v3 version", 3, p2.getVersion() );
+
+ p2 = m_mgr.getPage( WikiPath.valueOf("TestPage"), -1 );
+
+ assertEquals( "v3 content", "Even newer Test Content",
p2.getContentAsString() );
+ assertEquals( "v3 version", 3, p2.getVersion() );
+}
+
public static Test suite()
{
return new TestSuite( ContentManagerTest.class );