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

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Dec 11 11:34:15 EST 2009


Author: areshetnyak
Date: 2009-12-11 11:34:14 -0500 (Fri, 11 Dec 2009)
New Revision: 1011

Added:
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/functional/
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavAddNodeTest.java
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavRemoveNodeTest.java
Log:
EXOJCR-313 : The tests WebdavAddNodeTest and WebdavRemoveNodeTest.

Added: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java	2009-12-11 16:34:14 UTC (rev 1011)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.cluster;
+
+import org.exoplatform.common.http.client.CookieModule;
+
+import junit.framework.TestCase;
+
+/**
+ * Created by The eXo Platform SAS.
+ * 
+ * <br/>Date: 2009
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a> 
+ * @version $Id$
+ */
+public abstract class BaseClusteringFunctionalTest
+   extends TestCase
+{
+   protected JCRWebdavConnection connection;
+
+   private String host = "localhost";
+
+   private int port = 8080;
+
+   private String realm = "eXo REST services";
+
+   private String user = "root";
+
+   private String password = "exo";
+
+   private String workspacePath = "/rest/jcr/repository/production/";
+   
+   protected String nodeName;
+   
+   /**
+    * {@inheritDoc}
+    */
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      
+      CookieModule.setCookiePolicyHandler(null);
+      connection = new JCRWebdavConnection(host, port, user, password, realm, workspacePath);
+      
+      nodeName = generateUniqueName("removed_node_over_webdav");
+   }
+   
+   public String generateUniqueName(String prefix)
+   {
+      return prefix + "-" + Math.random();
+   }
+   
+   /**
+    * {@inheritDoc}
+    */
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      connection.removeNode(nodeName);
+      connection.stop();
+   }
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java
___________________________________________________________________
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/cluster/JCRWebdavConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java	2009-12-11 16:34:14 UTC (rev 1011)
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.cluster;
+
+import java.io.IOException;
+
+import org.exoplatform.common.http.client.HTTPConnection;
+import org.exoplatform.common.http.client.HTTPResponse;
+import org.exoplatform.common.http.client.HttpHeaderElement;
+import org.exoplatform.common.http.client.HttpOutputStream;
+import org.exoplatform.common.http.client.ModuleException;
+import org.exoplatform.common.http.client.NVPair;
+
+/**
+ * Created by The eXo Platform SAS.
+ * 
+ * <br/>Date: 2009
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a> 
+ * @version $Id$
+ */
+public class JCRWebdavConnection extends HTTPConnection
+{
+   public static final String CONTENT_TYPE = "Content-Type";
+   
+   public static final String CONTENT_LENGTH = "Content-Length";
+   
+   private String realm;
+
+   private String user;
+
+   private String pass;
+
+   private String workspacePath;
+
+   public JCRWebdavConnection(String host, int port, String user, String password, String realm, String workspacePath)
+   {
+      super(host, port);
+
+      this.user = user;
+      this.pass = password;
+      this.realm = realm;
+      this.workspacePath = workspacePath;
+
+      addBasicAuthorization(this.realm, this.user, this.pass);
+   }
+   
+   public void addNode(String name, byte[] data) throws IOException, ModuleException
+   {
+      Put(workspacePath + name, data).getStatusCode();
+   }
+   
+   public void addNode(String name, String nodeType, byte[] data) throws IOException, ModuleException
+   {
+      NVPair[] headers = new NVPair[1];
+      headers[0] = new NVPair("File-NodeType", nodeType);
+      Put(workspacePath + name, data).getStatusCode();
+   }
+   
+   public HTTPResponse addNode(String name, HttpOutputStream stream) throws IOException, ModuleException
+   {
+      return Put(workspacePath + name, stream);
+   }
+   
+   public void removeNode(String name) throws IOException, ModuleException
+   {
+      Delete(workspacePath + name).getStatusCode();
+   }
+   
+   public HTTPResponse getNode(String name) throws IOException, ModuleException
+   {
+      HTTPResponse response = Get(workspacePath + name);
+      response.getStatusCode();
+      return response;
+   }
+   
+   public void addProperty(String nodeName, String property) throws IOException, ModuleException
+   {
+      String xmlBody = "<?xml version='1.0' encoding='utf-8' ?>" +
+      "<D:propertyupdate xmlns:D='DAV:' xmlns:Z='http://www.w3.com/standards/z39.50/'>" +
+         "<D:set>" +
+            "<D:prop>" +
+               "<" + property + ">default value</" + property + ">" +
+            "</D:prop>" +
+         "</D:set>" +
+      "</D:propertyupdate>";
+
+      NVPair[] headers = new NVPair[2];
+      headers[0] = new NVPair(CONTENT_TYPE, "text/xml; charset='utf-8'");
+      headers[1] = new NVPair(CONTENT_LENGTH, Integer.toString(xmlBody.length()));
+
+      ExtensionMethod("PROPPATCH", workspacePath + nodeName, xmlBody.getBytes(), headers).getStatusCode();
+   }
+
+   
+   public void setProperty(String nodeName, String property, String value) throws IOException, ModuleException
+   {
+      String xmlBody = "<?xml version='1.0' encoding='utf-8' ?>" +
+      "<D:propertyupdate xmlns:D='DAV:' xmlns:Z='http://www.w3.com/standards/z39.50/'>" +
+         "<D:set>" +
+            "<D:prop>" +
+               "<" + property + ">" +value + "</" + property + ">" +
+            "</D:prop>" +
+         "</D:set>" +
+      "</D:propertyupdate>";
+
+      NVPair[] headers = new NVPair[2];
+      headers[0] = new NVPair(CONTENT_TYPE, "text/xml; charset='utf-8'");
+      headers[1] = new NVPair(CONTENT_LENGTH, Integer.toString(xmlBody.length()));
+
+      ExtensionMethod("PROPPATCH", workspacePath + nodeName, xmlBody.getBytes(), headers).getStatusCode();
+   }
+   
+   public void removeProperty(String nodeName, String property) throws IOException, ModuleException
+   {
+      String xmlBody = "<?xml version='1.0' encoding='utf-8' ?>" +
+            "<D:propertyupdate xmlns:D='DAV:' xmlns:Z='http://www.w3.com/standards/z39.50/'>" +
+               "<D:remove>" +
+                  "<D:prop><" + property + "/></D:prop>" +
+               "</D:remove>" +
+            "</D:propertyupdate>";
+      
+      NVPair[] headers = new NVPair[2];
+      headers[0] = new NVPair(CONTENT_TYPE, "text/xml; charset='utf-8'");
+      headers[1] = new NVPair(CONTENT_LENGTH, Integer.toString(xmlBody.length()));
+      
+      ExtensionMethod("PROPPATCH", workspacePath + nodeName, xmlBody.getBytes(), headers).getStatusCode();
+   }
+
+}
\ No newline at end of file


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/JCRWebdavConnection.java
___________________________________________________________________
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/cluster/functional/WebdavAddNodeTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavAddNodeTest.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavAddNodeTest.java	2009-12-11 16:34:14 UTC (rev 1011)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.cluster.functional;
+
+import org.exoplatform.common.http.client.HTTPResponse;
+import org.exoplatform.services.jcr.cluster.BaseClusteringFunctionalTest;
+
+/**
+ * Created by The eXo Platform SAS.
+ * 
+ * <br/>Date: 2009
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a> 
+ * @version $Id$
+ */
+public class WebdavAddNodeTest
+   extends BaseClusteringFunctionalTest
+{
+
+   public void testAddNode() throws Exception
+   {
+      // add
+      connection.addNode(nodeName, "_data_".getBytes());
+      
+      // check
+      HTTPResponse response = connection.getNode(nodeName);
+    
+      assertEquals(response.getStatusCode(), 200);
+      assertTrue("_data_".equals(new String(response.getData())));      
+   }
+   
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavAddNodeTest.java
___________________________________________________________________
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/cluster/functional/WebdavRemoveNodeTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavRemoveNodeTest.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavRemoveNodeTest.java	2009-12-11 16:34:14 UTC (rev 1011)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2003-2009 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.cluster.functional;
+
+import org.exoplatform.common.http.client.HTTPResponse;
+import org.exoplatform.services.jcr.cluster.BaseClusteringFunctionalTest;
+
+/**
+ * Created by The eXo Platform SAS.
+ * 
+ * <br/>Date: 2009
+ *
+ * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a> 
+ * @version $Id$
+ */
+public class WebdavRemoveNodeTest
+   extends BaseClusteringFunctionalTest
+{
+   public void testRemoveNode() throws Exception
+   {
+      // add
+      connection.addNode(nodeName, "".getBytes());
+      
+      // remove 
+      connection.removeNode(nodeName);
+      
+      // check
+      HTTPResponse response = connection.getNode(nodeName);
+      
+      assertEquals(response.getStatusCode(), 404);
+   }
+   public WebdavRemoveNodeTest()
+   {
+      // TODO Auto-generated constructor stub
+   }
+   
+   /**
+    * {@inheritDoc}
+    */
+   protected void tearDown() throws Exception
+   {
+      connection.stop();
+   }
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavRemoveNodeTest.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the exo-jcr-commits mailing list