[exo-jcr-commits] exo-jcr SVN: r876 - in jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr: lab and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Nov 26 06:13:27 EST 2009


Author: nzamosenchuk
Date: 2009-11-26 06:13:27 -0500 (Thu, 26 Nov 2009)
New Revision: 876

Added:
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/AbstractRestartTest.java
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestLockCleanup.java
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestVersionHistory.java
Removed:
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockCleanupOnRestart.java
Log:
EXOJCR-199: Added restart test on Versioning and moved Lock properties cleanup.

Deleted: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockCleanupOnRestart.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockCleanupOnRestart.java	2009-11-26 11:04:06 UTC (rev 875)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/api/lock/TestLockCleanupOnRestart.java	2009-11-26 11:13:27 UTC (rev 876)
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.jcr.api.lock;
-
-import org.exoplatform.services.jcr.JcrAPIBaseTest;
-import org.exoplatform.services.jcr.impl.core.NodeImpl;
-import org.hsqldb.DatabaseManager;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-
-import javax.jcr.PathNotFoundException;
-
-/**
- * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
- * @version $Id$
- *
- */
-public class TestLockCleanupOnRestart extends JcrAPIBaseTest
-{
-
-   /*
-    * This test should be performed manually because it requires JCR tearDown and startup without
-    * cleaning it's content. BEFORE TESTING UNCOMMENT TEST BODY and TEAR DOWN 
-    * 
-    * To check whether lock-properties are deleted as expected, first run:
-    *    >mvn clean test -Dtest=org.exoplatform.services.jcr.api.lock.TestLockCleanupOnRestart
-    * then (without clean!) :
-    *    >mvn test -Dtest=org.exoplatform.services.jcr.api.lock.TestLockCleanupOnRestart
-    */
-
-   private static String testNodeName = "LockIt";
-
-   public void testLockCleanUp() throws Exception
-   {
-//      log.info("/!\\ This test should be executed twice ('mvn clean test "
-//         + "-Dtest=...' and then without 'clean') and separately from other tests /!\\");
-//      NodeImpl node;
-//      try
-//      {
-//         node = (NodeImpl)root.getNode(testNodeName);
-//         log.info("Node \"/LockIt\" found, this is correct SECOND run.");
-//      }
-//      catch (PathNotFoundException e)
-//      {
-//         node = (NodeImpl)root.addNode(testNodeName);
-//         node.addMixin("mix:lockable");
-//         log.info("Node \"/LockIt\" not found, this is probably FIRST run. If not, "
-//            + "ensure that \"clean\" is not invoked in \"maven test\"!");
-//      }
-//      session.save();
-//      // locking the node with open-scoped deep lock.
-//      // no exception should be thrown
-//      try
-//      {
-//         node.lock(true, false);
-//         // ok!
-//      }
-//      catch (Exception e)
-//      {
-//         fail("Unexpected exception" + e.getStackTrace());
-//      }
-   }
-
-//   @Override
-//   protected void tearDown() throws Exception
-//   {
-//      // super.tearDown in not invoked to prevent DB cleaning
-//      // shutdown HSSQLDB :)
-//      for (Object uri : DatabaseManager.getDatabaseURIs())
-//      {
-//         try
-//         {
-//            Connection c = DriverManager.getConnection("jdbc:hsqldb:" + uri.toString(), "sa", "");
-//            c.createStatement().execute("SHUTDOWN");
-//         }
-//         catch (Throwable e)
-//         {
-//         }
-//      }
-//   }
-}

Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/AbstractRestartTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/AbstractRestartTest.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/AbstractRestartTest.java	2009-11-26 11:13:27 UTC (rev 876)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.lab.restart;
+
+import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.hsqldb.DatabaseManager;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import javax.jcr.PathNotFoundException;
+
+/**
+ * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id$
+ *
+ */
+public abstract class AbstractRestartTest extends JcrAPIBaseTest
+{
+   protected boolean firstRun = true;
+
+   private final String runNodeName = "SecondRun";
+
+   @Override
+   public void setUp() throws Exception
+   {
+      super.setUp();
+      try
+      {
+         root.getNode(runNodeName);
+         // node exists, it means than this is second run
+         firstRun = false;
+      }
+      catch (PathNotFoundException e)
+      {
+         root.addNode(runNodeName);
+      }
+      session.save();
+      if (firstRun)
+      {
+         log.info("/!\\ This is FIRST run");
+      }
+      else
+      {
+         log.info("/!\\ This is SECOND run");
+      }
+   }
+
+   public boolean isFirstRun()
+   {
+      return firstRun;
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      // super.tearDown in not invoked to prevent DB cleaning
+      // shutdown HSSQLDB :)
+      if (firstRun)
+      {
+         for (Object uri : DatabaseManager.getDatabaseURIs())
+         {
+            try
+            {
+               Connection c = DriverManager.getConnection("jdbc:hsqldb:" + uri.toString(), "sa", "");
+               c.createStatement().execute("SHUTDOWN");
+            }
+            catch (Throwable e)
+            {
+            }
+         }
+      }
+      else
+      {
+         super.tearDown();
+      }
+
+   }
+
+}
\ No newline at end of file


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/AbstractRestartTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestLockCleanup.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestLockCleanup.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestLockCleanup.java	2009-11-26 11:13:27 UTC (rev 876)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.lab.restart;
+
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+
+/**
+ * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id$
+ *
+ */
+public class TestLockCleanup extends AbstractRestartTest
+{
+
+   /*
+    * This test should be performed manually because it requires JCR tearDown and startup without
+    * cleaning it's content. 
+    * 
+    * To check whether lock-properties are deleted as expected, first run:
+    *    >mvn clean test -Dtest=org.exoplatform.services.jcr.lab.restart.TestLockCleanup
+    * then (without clean!) :
+    *    >mvn test -Dtest=org.exoplatform.services.jcr.lab.restart.TestLockCleanup
+    */
+
+   private static String testNodeName = "LockIt";
+
+   public void testLockCleanUp() throws Exception
+   {
+      log.info("/!\\ This test should be executed twice ('mvn clean test "
+         + "-Dtest=...' and then without 'clean') and separately from other tests /!\\");
+      NodeImpl node;
+      if (!isFirstRun())
+      {
+         node = (NodeImpl)root.getNode(testNodeName);
+         log.info("Node \"/LockIt\" found, this is correct SECOND run.");
+      }
+      else
+      {
+         node = (NodeImpl)root.addNode(testNodeName);
+         node.addMixin("mix:lockable");
+         log.info("Node \"/LockIt\" not found, this is probably FIRST run. If not, "
+            + "ensure that \"clean\" is not invoked in \"maven test\"!");
+      }
+      session.save();
+      // locking the node with open-scoped deep lock.
+      // no exception should be thrown
+      try
+      {
+         node.lock(true, false);
+         // ok!
+      }
+      catch (Exception e)
+      {
+         fail("Unexpected exception" + e.getStackTrace());
+      }
+   }
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestLockCleanup.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestVersionHistory.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestVersionHistory.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestVersionHistory.java	2009-11-26 11:13:27 UTC (rev 876)
@@ -0,0 +1,268 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.lab.restart;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
+
+/**
+ * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id$
+ *
+ */
+public class TestVersionHistory extends AbstractRestartTest
+{
+
+   /*
+    * This test should be performed manually because it requires JCR tearDown and startup without
+    * cleaning it's content. 
+    * 
+    * For the first run:
+    *    >mvn clean test -Dtest=org.exoplatform.services.jcr.lab.restart.TestVersionHistory
+    * then (without clean!) :
+    *    >mvn test -Dtest=org.exoplatform.services.jcr.lab.restart.TestVersionHistory
+    */
+
+   private Node testVersionable = null;
+
+   public void testVersionHistory() throws Exception
+   {
+      if (isFirstRun())
+      {
+         // prepare phase
+         Node testRoot = root.addNode("testRoot");
+         testVersionable = testRoot.addNode("testVersionable", "nt:unstructured");
+         testVersionable.addMixin("mix:versionable");
+         root.save();
+
+         // testVersionable = versionableNode; // it's nt:folder
+
+         VersionHistory vHistory = testVersionable.getVersionHistory();
+
+         // Creating nodes: n1, n2
+         Node n1 = testVersionable.addNode("n1");
+         Node n2 = testVersionable.addNode("n2");
+         testVersionable.save();
+         Version ver1 = testVersionable.checkin(); // v1
+         vHistory.addVersionLabel(ver1.getName(), "ver.1", false);
+         testVersionable.checkout();
+
+         // sameNameSibs nodes
+         // Creating nodes: n1[2], n1[3], n1[4]
+         Node snsN1_2 = testVersionable.addNode("n1");
+         Node snsN1_3 = testVersionable.addNode("n1");
+         Node snsN1_4 = testVersionable.addNode("n1");
+
+         // Creating node: n3
+         Node n3 = testVersionable.addNode("n3");
+         testVersionable.save();
+         Version ver2 = testVersionable.checkin(); // v2
+         vHistory.addVersionLabel(ver2.getName(), "ver.2", false);
+         testVersionable.checkout();
+
+         // Creating node: n4
+         Node n4 = testVersionable.addNode("n4");
+         testVersionable.save();
+         Version ver3 = testVersionable.checkin(); // v3
+         vHistory.addVersionLabel(ver3.getName(), "ver.3", false);
+         vHistory.addVersionLabel(ver3.getName(), "version 3.0", false);
+         testVersionable.checkout();
+
+         // Creating node: n5
+         Node n5 = testVersionable.addNode("n5");
+         testVersionable.save();
+         Version ver4 = testVersionable.checkin(); // v4
+         vHistory.addVersionLabel(ver4.getName(), "ver.4", false);
+         testVersionable.checkout();
+
+         if (log.isDebugEnabled())
+            log.debug("===== init =====");
+         checkItemsExisted(new String[]{n1.getPath(), snsN1_2.getPath(), snsN1_3.getPath(), snsN1_4.getPath(),
+            n2.getPath(), n3.getPath(), n4.getPath(), n5.getPath()}, null);
+         checkVersionHistory(testVersionable, 4);
+
+      }
+      else
+      {
+         // test phase
+         Node testRoot = root.getNode("testRoot");
+         testVersionable = testRoot.getNode("testVersionable");
+         VersionHistory vHistory = testVersionable.getVersionHistory();
+         Node n1 = testVersionable.getNode("n1");
+         Node n2 = testVersionable.getNode("n2");
+         Node n3 = testVersionable.getNode("n3");
+         Node n4 = testVersionable.getNode("n4");
+         Node n5 = testVersionable.getNode("n5");
+
+         Node snsN1_2 = testVersionable.getNode("n1[2]");
+         Node snsN1_3 = testVersionable.getNode("n1[3]");
+         Node snsN1_4 = testVersionable.getNode("n1[4]");
+
+         Version ver1 = vHistory.getVersionByLabel("ver.1");
+
+         // removing nodes: n2, n4
+         n2.remove();
+         n4.remove();
+         testVersionable.save();
+         if (log.isDebugEnabled())
+            log.debug("===== ver.1 before restore =====");
+         checkItemsExisted(new String[]{n1.getPath(), snsN1_2.getPath(), snsN1_3.getPath(), snsN1_4.getPath(),
+            n3.getPath(), n5.getPath()}, new String[]{n2.getPath(), n4.getPath()});
+         checkVersionHistory(testVersionable, 4);
+
+         // RESTORE ver.1 and n1, n2 will be restored
+         testVersionable.restore(ver1, true);
+         if (log.isDebugEnabled())
+            log.debug("===== ver.1 after restore =====");
+         checkItemsExisted(new String[]{n1.getPath(), n2.getPath()}, new String[]{snsN1_2.getPath(), snsN1_3.getPath(),
+            snsN1_4.getPath(), n3.getPath(), n4.getPath(), n5.getPath()});
+         checkVersionHistory(testVersionable, 4);
+
+      }
+   }
+
+   protected void checkVersionHistory(Node versionable, int versionCount) throws RepositoryException
+   {
+
+      VersionHistory vHistory = versionable.getVersionHistory();
+      Version rootVersion = vHistory.getRootVersion();
+      if (log.isDebugEnabled())
+         log.debug("rootVersion " + rootVersion.getPath());
+      Version baseVersion = versionable.getBaseVersion();
+      if (log.isDebugEnabled())
+         log.debug("baseVersion " + baseVersion.getPath());
+
+      BaseVersionFinder baseVersionFinder = new BaseVersionFinder(baseVersion);
+
+      List<Value> refs = traverseVersionSubTree(rootVersion, baseVersionFinder, vHistory, "  --");
+      if (refs.size() != versionCount)
+      {
+         fail("Version history contains not all versions for node " + versionable.getPath() + ", expected:"
+            + versionCount + " was:" + refs.size());
+      }
+      if (!baseVersionFinder.isBaseVersionFound())
+      {
+         fail("Base version not founded in version history tree for node " + versionable.getPath()
+            + ", but exists if call versionable.getBaseVersion() " + baseVersion.getPath());
+      }
+   }
+
+   class BaseVersionFinder
+   {
+
+      private Version baseVersion = null;
+
+      private boolean baseVersionFound = false;
+
+      BaseVersionFinder(Version baseVersion)
+      {
+         this.baseVersion = baseVersion;
+      }
+
+      public Version getBaseVersion()
+      {
+         return baseVersion;
+      }
+
+      public boolean check(Version someVersion) throws RepositoryException
+      {
+
+         if (baseVersionFound)
+            return false;
+
+         baseVersionFound = baseVersion.isSame(someVersion);
+         return baseVersionFound;
+      }
+
+      public boolean isBaseVersionFound()
+      {
+         return baseVersionFound;
+      }
+   }
+
+   protected List<Value> traverseVersionSubTree(Version ver, BaseVersionFinder baseVersionFinder,
+      VersionHistory vHistory, String outPrefix) throws RepositoryException
+   {
+
+      List<Value> successorsRefs = new ArrayList<Value>();
+      String vlInfo = "";
+      String[] versionLabels = vHistory.getVersionLabels(ver);
+      for (String vl : versionLabels)
+      {
+         vlInfo += (vlInfo.length() > 0 ? ", " + vl : vl);
+      }
+      if (baseVersionFinder.check(ver))
+      {
+         // this is a base version
+         vlInfo = (vlInfo.length() > 0 ? " [" + vlInfo + "]" : "") + " >>>Base version<<<  ";
+      }
+      else
+      {
+         vlInfo = (vlInfo.length() > 0 ? " [" + vlInfo + "]" : "");
+      }
+      if (log.isDebugEnabled())
+         log.debug(outPrefix + " " + ver.getName() + vlInfo);
+      Value[] versionSuccessors = getSucessors(ver);
+      if (versionSuccessors != null)
+      {
+         for (Value sv : versionSuccessors)
+         {
+            Version successor = (Version)session.getNodeByUUID(sv.getString());
+            if (successor != null)
+            {
+               successorsRefs.add(sv);
+               List<Value> successorSuccessors =
+                  traverseVersionSubTree(successor, baseVersionFinder, vHistory, "  " + outPrefix);
+               if (successorSuccessors != null)
+               {
+                  successorsRefs.addAll(successorSuccessors);
+               }
+            }
+            else
+            {
+               fail("No item for successor UUID " + sv.getString());
+            }
+         }
+      }
+      return successorsRefs;
+   }
+
+   protected Value[] getSucessors(Version ver) throws RepositoryException
+   {
+      try
+      {
+         Property successors = ver.getProperty("jcr:successors");
+         return successors.getValues();
+      }
+      catch (PathNotFoundException e)
+      {
+         // fail("Property jcr:successors must exists for " + vp);
+         return null;
+      }
+   }
+
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/lab/restart/TestVersionHistory.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the exo-jcr-commits mailing list