[exo-jcr-commits] exo-jcr SVN: r1280 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jan 4 11:02:20 EST 2010


Author: nzamosenchuk
Date: 2010-01-04 11:02:20 -0500 (Mon, 04 Jan 2010)
New Revision: 1280

Added:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java
Log:
EXOJCR-340: Added simple query tests for clustered environment.

Added: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java	2010-01-04 16:02:20 UTC (rev 1280)
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2010 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.cluster.functional;
+
+import org.exoplatform.common.http.client.HTTPResponse;
+import org.exoplatform.services.jcr.cluster.BaseClusteringFunctionalTest;
+import org.exoplatform.services.jcr.cluster.JCRWebdavConnection;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+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;
+
+/**
+ * Class contains set of query tests for clustered environment
+ * 
+ * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: WebdavQueryTest.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class WebdavQueryTest extends BaseClusteringFunctionalTest
+{
+
+   public void testSimpleGetAllSql() throws Exception
+   {
+      String testLocalRootName = "node";
+      JCRWebdavConnection conn = getConnection();
+      conn.addDir(testLocalRootName);
+      List<String> expected = new ArrayList<String>();
+      expected.add("exo_String");
+      expected.add("exo_Boolean");
+      expected.add("exo_Integer");
+      expected.add("exo_Long");
+      expected.add("exo_Float");
+      expected.add("exo_Double");
+
+      for (String name : expected)
+      {
+         conn.addNode(testLocalRootName + "/" + name, "_data_".getBytes());
+         System.out.println("added: " + name);
+      }
+
+      HTTPResponse response =
+         conn.sqlQuery("SELECT * FROM nt:base WHERE jcr:path LIKE '/" + testLocalRootName + "[%]/%'");
+      assertEquals(207, response.getStatusCode());
+      List<String> found = parseNodeNames(response.getData());
+      assertTrue("Some nodes not found", assertLists(expected, found));
+      conn.removeNode(testLocalRootName);
+   }
+
+   /**
+    * Extracts names of nodes from response XML
+    * 
+    * TODO: fix
+    * /!\ During parsing method accumulates nodes in SET, because of https://jira.jboss.org/jira/browse/EXOJCR-364 /!\
+    * 
+    * @param data
+    * @return
+    * @throws XMLStreamException
+    * @throws FactoryConfigurationError
+    * @throws IOException
+    */
+   public List<String> parseNodeNames(byte[] data) throws XMLStreamException, FactoryConfigurationError, IOException
+   {
+      // flag, that notifies when parser is inside <D:displayname></D:displayname> 
+      boolean displayName = false;
+      Set<String> nodes = new HashSet<String>();
+      InputStream input = new ByteArrayInputStream(data);
+      XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(input);
+      QName name = QName.valueOf("{DAV:}displayname");
+      try
+      {
+         while (reader.hasNext())
+         {
+            int eventCode = reader.next();
+            switch (eventCode)
+            {
+               case StartElement.START_ELEMENT : {
+                  // if {DAV:}displayname opening element 
+                  if (reader.getName().equals(name))
+                  {
+                     displayName = true;
+                  }
+                  break;
+               }
+               case StartElement.CHARACTERS : {
+                  if (displayName)
+                  {
+                     // currently reader is inside <D:displayname>nodeName</D:displayname>
+                     // adding name to list if not empty
+                     String nodeName = reader.getText();
+                     if (nodeName != null && !nodeName.equals(""))
+                     {
+                        nodes.add(nodeName);
+                     }
+                  }
+                  break;
+               }
+               default : {
+                  displayName = false;
+                  break;
+               }
+            }
+         }
+      }
+      finally
+      {
+         reader.close();
+         input.close();
+      }
+      return new ArrayList<String>(nodes);
+   }
+
+   /**
+    * returns true if lists are equals (order doesn't matter)
+    * 
+    * @param expected
+    * @param found
+    * @return
+    */
+   public boolean assertLists(List<String> expected, List<String> found)
+   {
+      if (expected == null || found == null)
+      {
+         return false;
+      }
+      return expected.containsAll(found) && found.containsAll(expected);
+   }
+}


Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the exo-jcr-commits mailing list