[exo-jcr-commits] exo-jcr SVN: r1307 - 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
Wed Jan 6 04:39:03 EST 2010


Author: nzamosenchuk
Date: 2010-01-06 04:39:03 -0500 (Wed, 06 Jan 2010)
New Revision: 1307

Modified:
   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 property-constraint search test.

Modified: 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	2010-01-06 09:00:54 UTC (rev 1306)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java	2010-01-06 09:39:03 UTC (rev 1307)
@@ -50,43 +50,47 @@
  */
 public class WebdavQueryTest extends BaseClusteringFunctionalTest
 {
+   public static final String MIME_TEXT_PLAIN = "text/plain";
 
+   public static final String MIME_TEXT_PATCH = "text/x-patch";
+
+   public static final String MIME_TEXT_HTML = "text/html";
+
    /**
-    * Fulltext queries
+    * Full-text query tests
     */
-   public void testFullTextSearch() throws Exception
+   public void _testFullTextSearch() throws Exception
    {
       JCRWebdavConnection conn = getConnection();
-      // Nodes with some text, with unique words in each one.
-      Map<String, String> expected = new HashMap<String, String>();
-      expected
+      // Nodes with some text, with unique words in each one in form of <name><content>
+      Map<String, String> nodes = new HashMap<String, String>();
+      nodes
          .put(
             "JCR_Overview",
             "A JCR is a type of Object Database tailored to the storage, searching, and retrieval of hierarchical data. The JCR API grew o"
                + "ut of the needs of content management systems, which require storage of documents and other binary objects with associated me"
                + "tadata; however, the API is applicable to many additional types of application. In addition to object storage, the JCR provid"
                + "es: APIs for versioning of data; transactions; observation of changes in data; and import or export of data to XML in a standard way.");
-      expected
+      nodes
          .put(
             "JCR_Structure",
             "The data in a JCR consists of a tree of Nodes with associated Properties. Data is stored in the Properties, which may hold simple "
                + "values such as numbers and strings or binary data of arbitrary length. Nodes may optionally have one or more types associated with"
                + " them which dictate the kinds of properties, number and type of child nodes, and certain behavioral characteristics of the nodes. API");
 
-      expected
+      nodes
          .put(
             "JCR_Queries",
             "A JCR can be queried with XPathQuery, can export portions of its tree to XML in two standard formats and can import hierarchies directly"
                + " from XML. A JCR may optionally support a standardized form of SQL for queries. The Apache Jackrabbit reference implementation of "
                + "JCR also supports the integration of the Apache Lucene search engine to give full text searches of data in the repository.");
 
-      expected.put("JCR_Impl",
+      nodes.put("JCR_Impl",
          "eXo Platform JCR implementation on the company wiki. eXo Platform 2 article on theserverside");
-
       // add nodes
-      for (Entry<String, String> entry : expected.entrySet())
+      for (Entry<String, String> entry : nodes.entrySet())
       {
-         conn.addNode(entry.getKey(), entry.getValue().getBytes(), "text/plain");
+         conn.addNode(entry.getKey(), entry.getValue().getBytes(), MIME_TEXT_PLAIN);
       }
 
       // map containing test-case: <SQL query> : <expected nodes>
@@ -94,7 +98,6 @@
       sqlCases.put("SELECT * FROM nt:base WHERE CONTAINS(*,'tailored')", new String[]{"JCR_Overview"});
       sqlCases.put("SELECT * FROM nt:base WHERE CONTAINS(*,'XPathQuery')", new String[]{"JCR_Queries"});
       sqlCases.put("SELECT * FROM nt:resource WHERE CONTAINS(*,'API')", new String[]{"JCR_Structure", "JCR_Overview"});
-
       // SQL
       for (Entry<String, String[]> entry : sqlCases.entrySet())
       {
@@ -108,7 +111,6 @@
       xpathCases.put("//element(*, nt:base)[jcr:contains(.,'tailored')]", new String[]{"JCR_Overview"});
       xpathCases.put("//element(*, nt:base)[jcr:contains(.,'XPathQuery')]", new String[]{"JCR_Queries"});
       xpathCases.put("//element(*, nt:resource)[jcr:contains(.,'API')]", new String[]{"JCR_Structure", "JCR_Overview"});
-
       // XPATH
       for (Entry<String, String[]> entry : xpathCases.entrySet())
       {
@@ -117,18 +119,18 @@
          assertResponse(entry.getValue(), response);
       }
       // remove created nodes
-      for (Entry<String, String> entry : expected.entrySet())
+      for (Entry<String, String> entry : nodes.entrySet())
       {
          conn.removeNode(entry.getKey());
       }
    }
 
    /**
-    * Simple test, searching nodes by given path 
+    * Simple test, searching nodes by given path and concrete name.
     */
-   public void testPathSearch() throws Exception
+   public void _testPathSearch() throws Exception
    {
-      String testLocalRootName = "testSimpleGetAll";
+      String testLocalRootName = "testPathSearch";
       JCRWebdavConnection conn = getConnection();
       conn.addDir(testLocalRootName);
       List<String> expected = new ArrayList<String>();
@@ -143,20 +145,108 @@
       {
          conn.addNode(testLocalRootName + "/" + name, "_data_".getBytes());
       }
+      // map containing test-case: <SQL query> : <expected nodes>
+      Map<String, String[]> sqlCases = new HashMap<String, String[]>();
+      sqlCases.put("SELECT * FROM nt:base WHERE jcr:path LIKE '/" + testLocalRootName
+         + "[%]/%' AND NOT jcr:path LIKE '/" + testLocalRootName + "[%]/%/%' ", expected.toArray(new String[expected
+         .size()]));
+      sqlCases.put("SELECT * FROM nt:base WHERE fn:name() = 'exoString'", new String[]{"exoString"});
       // SQL
-      HTTPResponse response =
-         conn.sqlQuery("SELECT * FROM nt:base WHERE jcr:path LIKE '/" + testLocalRootName
-            + "[%]/%' AND NOT jcr:path LIKE '/" + testLocalRootName + "[%]/%/%' ");
-      assertEquals(207, response.getStatusCode());
-      assertResponse(expected, response);
-      // XPath
-      response = conn.xpathQuery("/jcr:root/" + testLocalRootName + "/ element(*, nt:base)");
-      assertEquals(207, response.getStatusCode());
-      assertResponse(expected, response);
+      for (Entry<String, String[]> entry : sqlCases.entrySet())
+      {
+         HTTPResponse response = conn.sqlQuery(entry.getKey());
+         assertEquals(207, response.getStatusCode());
+         assertResponse(entry.getValue(), response);
+      }
+
+      // map containing test-case: <XPATH query> : <expected nodes>
+      Map<String, String[]> xpathCases = new HashMap<String, String[]>();
+      xpathCases.put("/jcr:root/" + testLocalRootName + "/ element(*, nt:base)", expected.toArray(new String[expected
+         .size()]));
+      xpathCases.put("//element(*,nt:file)[fn:name() = 'exoString']", new String[]{"exoString"});
+      // XPATH
+      for (Entry<String, String[]> entry : xpathCases.entrySet())
+      {
+         HTTPResponse response = conn.xpathQuery(entry.getKey());
+         assertEquals(207, response.getStatusCode());
+         assertResponse(entry.getValue(), response);
+      }
+
       conn.removeNode(testLocalRootName);
    }
 
    /**
+    * Test, searching over the repository nodes with concrete value of concrete property.
+    * jcr:mimeType is used for querying purposes. 
+    */
+   public void testPropertyValueSearch() throws Exception
+   {
+      JCRWebdavConnection conn = getConnection();
+      // Nodes with concrete mimetype in form of <name><content>
+      Map<String, String> nodes = new HashMap<String, String>();
+      // text/plain
+      nodes.put("TextDescription", MIME_TEXT_PLAIN);
+      nodes.put("SmallNote", MIME_TEXT_PLAIN);
+      nodes.put("CalendarMemo", MIME_TEXT_PLAIN);
+      nodes.put("GetThisDone", MIME_TEXT_PLAIN);
+      // text/patch
+      nodes.put("CriticalPath", MIME_TEXT_PATCH);
+      nodes.put("BrokenPatch", MIME_TEXT_PATCH);
+      // text/html
+      nodes.put("FirstPage", MIME_TEXT_HTML);
+      nodes.put("AboutGateIn", MIME_TEXT_HTML);
+      nodes.put("LicenseAgreement", MIME_TEXT_HTML);
+      nodes.put("HomePage", MIME_TEXT_HTML);
+      nodes.put("StrangePage", MIME_TEXT_HTML);
+
+      // add nodes
+      for (Entry<String, String> entry : nodes.entrySet())
+      {
+         conn.addNode(entry.getKey(), "content".getBytes(), entry.getValue());
+      }
+
+      // map containing test-case: <SQL query> : <expected nodes>
+      Map<String, String[]> sqlCases = new HashMap<String, String[]>();
+      sqlCases.put("SELECT * FROM nt:resource WHERE jcr:mimeType ='" + MIME_TEXT_PLAIN + "'", getNodesByMime(nodes,
+         MIME_TEXT_PLAIN));
+      sqlCases.put("SELECT * FROM nt:resource WHERE jcr:mimeType ='" + MIME_TEXT_HTML + "'", getNodesByMime(nodes,
+         MIME_TEXT_HTML));
+      sqlCases.put("SELECT * FROM nt:resource WHERE jcr:mimeType LIKE 'text%'", nodes.keySet().toArray(
+         new String[nodes.size()]));
+      // SQL
+      for (Entry<String, String[]> entry : sqlCases.entrySet())
+      {
+         HTTPResponse response = conn.sqlQuery(entry.getKey());
+         assertEquals(207, response.getStatusCode());
+         assertResponse(entry.getValue(), response);
+      }
+
+      // map containing test-case: <XPATH query> : <expected nodes>
+      Map<String, String[]> xpathCases = new HashMap<String, String[]>();
+      xpathCases.put("//element(*,nt:resource)[@jcr:mimeType='" + MIME_TEXT_PLAIN + "']", getNodesByMime(nodes,
+         MIME_TEXT_PLAIN));
+      xpathCases.put("//element(*,nt:resource)[@jcr:mimeType='" + MIME_TEXT_HTML + "']", getNodesByMime(nodes,
+         MIME_TEXT_HTML));
+      xpathCases.put("//element(*,nt:resource)[jcr:like(@jcr:mimeType, 'text%')]", nodes.keySet().toArray(
+         new String[nodes.size()]));
+      // XPATH
+      for (Entry<String, String[]> entry : xpathCases.entrySet())
+      {
+         HTTPResponse response = conn.xpathQuery(entry.getKey());
+         assertEquals(207, response.getStatusCode());
+         assertResponse(entry.getValue(), response);
+      }
+
+      // remove created nodes
+      for (Entry<String, String> entry : nodes.entrySet())
+      {
+         conn.removeNode(entry.getKey());
+      }
+   }
+
+   /**
+    * Checks that response contains expected nodes.
+    * 
     * @param expected
     * @param response
     * @throws IOException
@@ -164,28 +254,35 @@
     * @throws XMLStreamException
     * @throws FactoryConfigurationError
     */
-   private void assertResponse(Collection<String> expected, HTTPResponse response) throws IOException, ModuleException,
+   private void assertResponse(String[] expected, HTTPResponse response) throws IOException, ModuleException,
       XMLStreamException, FactoryConfigurationError
    {
       List<String> found;
       assertEquals(207, response.getStatusCode());
       found = parseNodeNames(response.getData());
-      assertTrue("Lists are not equals:\n*found:\t" + found + "\n*expected:\t" + expected,
-         compareLists(expected, found));
+      assertTrue("Lists are not equals:\n*found:\t" + found + "\n*expected:\t" + expected, compareLists(Arrays
+         .asList(expected), found));
    }
 
    /**
-    * @param expected
-    * @param response
-    * @throws IOException
-    * @throws ModuleException
-    * @throws XMLStreamException
-    * @throws FactoryConfigurationError
+    * Given map nodesMap should contain entry: <nodeName>:<mime-type>, this method returns array with names of 
+    * nodes that are only of given mime-type.
+    * 
+    * @param nodesMap
+    * @param mime
+    * @return
     */
-   private void assertResponse(String[] expected, HTTPResponse response) throws IOException, ModuleException,
-      XMLStreamException, FactoryConfigurationError
+   private String[] getNodesByMime(Map<String, String> nodesMap, String mime)
    {
-      assertResponse(Arrays.asList(expected), response);
+      List<String> filteredNodes = new ArrayList<String>();
+      for (Entry<String, String> entry : nodesMap.entrySet())
+      {
+         if (entry.getValue().equals(mime))
+         {
+            filteredNodes.add(entry.getKey());
+         }
+      }
+      return filteredNodes.toArray(new String[filteredNodes.size()]);
    }
 
    /**
@@ -207,9 +304,6 @@
    /**
     * Extracts names of nodes from response XML
     * 
-    * TODO: fix
-    * /!\ Method accumulates nodes in SET, because of https://jira.jboss.org/jira/browse/EXOJCR-364 /!\
-    * 
     * @param data
     * @return
     * @throws XMLStreamException



More information about the exo-jcr-commits mailing list