[exo-jcr-commits] exo-jcr SVN: r1246 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster: functional and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Dec 29 11:45:44 EST 2009


Author: areshetnyak
Date: 2009-12-29 11:45:43 -0500 (Tue, 29 Dec 2009)
New Revision: 1246

Modified:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavCreatePropertyTest.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavLockNodeTest.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavMoveNodeTest.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavRemovePropertyTest.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavSetPropertyTest.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavVersionTest.java
Log:
EXOJCR-330 : The functional cluster tests was changed.

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java	2009-12-29 16:23:38 UTC (rev 1245)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java	2009-12-29 16:45:43 UTC (rev 1246)
@@ -20,11 +20,19 @@
 
 import org.exoplatform.services.jcr.cluster.JCRWebdavConnection;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.Random;
 
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.events.StartElement;
+
 /**
  * Created by The eXo Platform SAS.
  * 
@@ -33,20 +41,21 @@
  * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a> 
  * @version $Id$
  */
-public abstract class BaseClusteringFunctionalTest extends TestCase
+public abstract class BaseClusteringFunctionalTest
+   extends TestCase
 {
-   
+
    private String realm = "eXo REST services";
 
    private String workspacePath = "/rest/jcr/repository/production/";
 
-   private JCRWebdavConnection[] connections = new JCRWebdavConnection[] {
-            new JCRWebdavConnection("localhost", 8080, "root", "exo", realm, workspacePath)/*,
-            new JCRWebdavConnection("localhost", 8082, "root", "exo", realm, workspacePath),
-            new JCRWebdavConnection("localhost", 8083, "root", "exo", realm, workspacePath),
-            new JCRWebdavConnection("localhost", 8084, "root", "exo", realm, workspacePath)*/
+   private JCRWebdavConnection[] connections = new JCRWebdavConnection[]
+   {new JCRWebdavConnection("localhost", 8080, "root", "exo", realm, workspacePath)/*,
+                                                                                   new JCRWebdavConnection("localhost", 8082, "root", "exo", realm, workspacePath),
+                                                                                   new JCRWebdavConnection("localhost", 8083, "root", "exo", realm, workspacePath),
+                                                                                   new JCRWebdavConnection("localhost", 8084, "root", "exo", realm, workspacePath)*/
    };
-   
+
    protected String nodeName;
 
    /**
@@ -74,12 +83,12 @@
       connections[0].removeNode(nodeName);
       connections[0].stop();
    }
-   
+
    protected JCRWebdavConnection[] getConnections()
    {
       return connections;
    }
-   
+
    protected JCRWebdavConnection getConnection()
    {
       return connections[(int) (Math.random() * 100) % connections.length];
@@ -111,4 +120,52 @@
       testFile.deleteOnExit(); // delete on test exit
       return testFile;
    }
+
+   protected String getPropertyValue(byte[] responseData, String propertyName) throws XMLStreamException,
+            FactoryConfigurationError, IOException
+   {
+      InputStream input = new ByteArrayInputStream(responseData);
+
+      XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(input);
+
+      boolean valueIsFound = false;
+
+      String propertyValue = null;
+
+      try
+      {
+         while (reader.hasNext())
+         {
+            int eventCode = reader.next();
+
+            switch (eventCode)
+            {
+
+               case StartElement.START_ELEMENT : {
+
+                  if (propertyName.equals(reader.getName()))
+                  {
+                     valueIsFound = true;
+                  }
+                  break;
+               }
+
+               case StartElement.CHARACTERS : {
+                  if (valueIsFound)
+                  {
+                     propertyValue = reader.getText();
+                  }
+                  break;
+               }
+            }
+         }
+      }
+      finally
+      {
+         reader.close();
+         input.close();
+      }
+
+      return propertyValue;
+   }
 }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavCreatePropertyTest.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavCreatePropertyTest.java	2009-12-29 16:23:38 UTC (rev 1245)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavCreatePropertyTest.java	2009-12-29 16:45:43 UTC (rev 1246)
@@ -40,14 +40,13 @@
       
       conn.addNode(nodeName, "nt:untstructured","".getBytes());
       conn.addProperty(nodeName, property);
-      conn.setProperty(nodeName, property, "prop_value");
       
       // check is property exist
       for (JCRWebdavConnection connection : getConnections())
       {
          HTTPResponse response = connection.getProperty(nodeName, property);
          assertEquals(207, response.getStatusCode());
-         assertTrue("_data_".equals(new String(response.getData())));
+         assertEquals("value", getPropertyValue(response.getData(), "D:testProp"));
       }
       
    }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavLockNodeTest.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavLockNodeTest.java	2009-12-29 16:23:38 UTC (rev 1245)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavLockNodeTest.java	2009-12-29 16:45:43 UTC (rev 1246)
@@ -16,6 +16,7 @@
  */
 package org.exoplatform.services.jcr.cluster.functional;
 
+import org.exoplatform.common.http.HTTPStatus;
 import org.exoplatform.common.http.client.HTTPResponse;
 import org.exoplatform.services.jcr.cluster.BaseClusteringFunctionalTest;
 import org.exoplatform.services.jcr.cluster.JCRWebdavConnection;
@@ -42,26 +43,26 @@
       conn.addNode(nodeName + "/" + lockedNodeName, "".getBytes());
       
       // lock
-      String lockToken =  conn.lock(nodeName);
+      String lockToken =  conn.lock(nodeName + "/" + lockedNodeName);
       
       // check
       for (JCRWebdavConnection connection : getConnections()) 
       {
-         HTTPResponse response = connection.addNode(nodeName + "/" + "subnode", "should not be added".getBytes());
-         
-         assertEquals(403, response.getStatusCode());
+         HTTPResponse response = connection.removeNode(nodeName + "/" + lockedNodeName);
+         assertEquals(HTTPStatus.LOCKED, response.getStatusCode());
       }
       
       // unloc
-      conn.unlock(nodeName, lockToken);
+      conn.unlock(nodeName + "/" + lockedNodeName, lockToken);
       
+      HTTPResponse resp = getConnection().removeNode(nodeName + "/" + lockedNodeName);
+      assertEquals(HTTPStatus.NO_CONTENT, resp.getStatusCode());
+      
       // ckeck
       for (JCRWebdavConnection connection : getConnections()) 
       {
-         HTTPResponse response = connection.addNode(nodeName + "/" + "subnode", "should be added".getBytes());
-         
-         assertEquals(200, response.getStatusCode());
-         assertTrue("should be added".equals(new String(response.getData())));
+         HTTPResponse response = connection.getNode(nodeName + "/" + lockedNodeName);
+         assertEquals(HTTPStatus.NOT_FOUND, response.getStatusCode());
       }
    }
 }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavMoveNodeTest.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavMoveNodeTest.java	2009-12-29 16:23:38 UTC (rev 1245)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavMoveNodeTest.java	2009-12-29 16:45:43 UTC (rev 1246)
@@ -49,8 +49,8 @@
       // move node
       conn = getConnection();
       
-      HTTPResponse response = conn.Move(nodeName, newNodeName);
-      response.getStatusCode();
+      HTTPResponse response = conn.moveNode(nodeName, newNodeName);
+      assertEquals(201, response.getStatusCode());
 
       // check is node not exist
       for (JCRWebdavConnection connection : getConnections()) 

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavRemovePropertyTest.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavRemovePropertyTest.java	2009-12-29 16:23:38 UTC (rev 1245)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavRemovePropertyTest.java	2009-12-29 16:45:43 UTC (rev 1246)
@@ -16,6 +16,7 @@
  */
 package org.exoplatform.services.jcr.cluster.functional;
 
+import org.exoplatform.common.http.client.HTTPResponse;
 import org.exoplatform.services.jcr.cluster.BaseClusteringFunctionalTest;
 import org.exoplatform.services.jcr.cluster.JCRWebdavConnection;
 
@@ -39,12 +40,20 @@
       conn.setProperty(nodeName, "D:testProp", "the_value");
       
       //check
+      for (JCRWebdavConnection connection : getConnections())
+      {
+         HTTPResponse response = connection.getProperty(nodeName, "D:testProp");
+         assertEquals(207, response.getStatusCode());
+      }
       
-      
       //remove
       conn.removeProperty(nodeName, "D:testProp");
       
       //check
-      
+      for (JCRWebdavConnection connection : getConnections())
+      {
+         HTTPResponse response = connection.getProperty(nodeName, "D:testProp");
+         assertEquals(404, response.getStatusCode());
+      } 
    }
 }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavSetPropertyTest.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavSetPropertyTest.java	2009-12-29 16:23:38 UTC (rev 1245)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavSetPropertyTest.java	2009-12-29 16:45:43 UTC (rev 1246)
@@ -16,6 +16,7 @@
  */
 package org.exoplatform.services.jcr.cluster.functional;
 
+import org.exoplatform.common.http.client.HTTPResponse;
 import org.exoplatform.services.jcr.cluster.BaseClusteringFunctionalTest;
 import org.exoplatform.services.jcr.cluster.JCRWebdavConnection;
 
@@ -33,18 +34,28 @@
    public void testSetProperty() throws Exception
    {
       JCRWebdavConnection conn = getConnection();
-      
+
       // prepare
       conn.addNode(nodeName, "nt:untstructured", "".getBytes());
       conn.addProperty(nodeName, "D:testProp");
-      
+
       // check
-      
-      
+      for (JCRWebdavConnection connection : getConnections())
+      {
+         HTTPResponse response = connection.getProperty(nodeName, "D:testProp");
+         assertEquals(207, response.getStatusCode());
+      }
+
       // set property
-      conn.setProperty(nodeName, "D:testProp", "testValue");
-      
-      
+      conn.setProperty(nodeName, "D:testProp", "testValue_new");
+
       // check
+      for (JCRWebdavConnection connection : getConnections())
+      {
+         HTTPResponse response = connection.getProperty(nodeName, "D:testProp");
+         assertEquals(207, response.getStatusCode());
+
+         assertEquals("testValue_new", getPropertyValue(response.getData(), "D:testProp"));
+      }
    }
 }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavVersionTest.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavVersionTest.java	2009-12-29 16:23:38 UTC (rev 1245)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavVersionTest.java	2009-12-29 16:45:43 UTC (rev 1246)
@@ -50,27 +50,51 @@
          assertTrue("v1".equals(new String(response.getData())));
       }
       
+      // create version
+      conn.checkOut(nodeName);
+      conn.addNode(nodeName, "v2".getBytes());
       conn.checkIn(nodeName);
-      conn.addNode(nodeName, "v2".getBytes());
+      
+      // create version      
       conn.checkOut(nodeName);
+      conn.addNode(nodeName, "v3".getBytes());
+      conn.checkIn(nodeName);
       
+      // create version
+      conn.checkOut(nodeName);
+      conn.addNode(nodeName, "v4".getBytes());
+      conn.checkIn(nodeName);
+      
       // check
       for (JCRWebdavConnection connection : getConnections())
       {
          HTTPResponse response = connection.getNode(nodeName);
          assertEquals(200, response.getStatusCode());
-         assertTrue("v2".equals(new String(response.getData())));
+         assertTrue("v4".equals(new String(response.getData())));
       }
       
-      // restore
-      conn.restore(nodeName, "1");
-      
-      //check
+      //check v1
       for (JCRWebdavConnection connection : getConnections())
       {
-         HTTPResponse response = connection.getNode(nodeName);
+         HTTPResponse response = connection.restore(nodeName, "1");
          assertEquals(200, response.getStatusCode());
          assertTrue("v1".equals(new String(response.getData())));
       }
+      
+      //check v2
+      for (JCRWebdavConnection connection : getConnections())
+      {
+         HTTPResponse response = connection.restore(nodeName, "2");
+         assertEquals(200, response.getStatusCode());
+         assertTrue("v2".equals(new String(response.getData())));
+      }
+      
+      //check v2
+      for (JCRWebdavConnection connection : getConnections())
+      {
+         HTTPResponse response = connection.restore(nodeName, "3");
+         assertEquals(200, response.getStatusCode());
+         assertTrue("v3".equals(new String(response.getData())));
+      }
    }
 }



More information about the exo-jcr-commits mailing list