[exo-jcr-commits] exo-jcr SVN: r1310 - 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 05:00:11 EST 2010


Author: nzamosenchuk
Date: 2010-01-06 05:00:11 -0500 (Wed, 06 Jan 2010)
New Revision: 1310

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: Refactoring of query-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:53:04 UTC (rev 1309)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/functional/WebdavQueryTest.java	2010-01-06 10:00:11 UTC (rev 1310)
@@ -34,6 +34,7 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
+import javax.jcr.query.Query;
 import javax.xml.namespace.QName;
 import javax.xml.stream.FactoryConfigurationError;
 import javax.xml.stream.XMLInputFactory;
@@ -59,7 +60,7 @@
    /**
     * 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 in form of <name><content>
@@ -98,26 +99,14 @@
       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())
-      {
-         HTTPResponse response = conn.sqlQuery(entry.getKey());
-         assertEquals(207, response.getStatusCode());
-         assertResponse(entry.getValue(), response);
-      }
+      assertQuery(conn, sqlCases, Query.SQL);
 
       // map containing test-case: <XPATH query> : <expected nodes>
       Map<String, String[]> xpathCases = new HashMap<String, String[]>();
       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())
-      {
-         HTTPResponse response = conn.xpathQuery(entry.getKey());
-         assertEquals(207, response.getStatusCode());
-         assertResponse(entry.getValue(), response);
-      }
+      assertQuery(conn, xpathCases, Query.XPATH);
       // remove created nodes
       for (Entry<String, String> entry : nodes.entrySet())
       {
@@ -128,7 +117,7 @@
    /**
     * Simple test, searching nodes by given path and concrete name.
     */
-   public void _testPathSearch() throws Exception
+   public void testPathSearch() throws Exception
    {
       String testLocalRootName = "testPathSearch";
       JCRWebdavConnection conn = getConnection();
@@ -151,26 +140,14 @@
          + "[%]/%' 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
-      for (Entry<String, String[]> entry : sqlCases.entrySet())
-      {
-         HTTPResponse response = conn.sqlQuery(entry.getKey());
-         assertEquals(207, response.getStatusCode());
-         assertResponse(entry.getValue(), response);
-      }
+      assertQuery(conn, sqlCases, Query.SQL);
 
       // 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);
-      }
+      assertQuery(conn, xpathCases, Query.XPATH);
 
       conn.removeNode(testLocalRootName);
    }
@@ -213,13 +190,7 @@
          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);
-      }
+      assertQuery(conn, sqlCases, Query.SQL);
 
       // map containing test-case: <XPATH query> : <expected nodes>
       Map<String, String[]> xpathCases = new HashMap<String, String[]>();
@@ -229,13 +200,7 @@
          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);
-      }
+      assertQuery(conn, xpathCases, Query.XPATH);
 
       // remove created nodes
       for (Entry<String, String> entry : nodes.entrySet())
@@ -245,23 +210,39 @@
    }
 
    /**
-    * Checks that response contains expected nodes.
+    * Performs sequence of queries and asserts received results
     * 
-    * @param expected
-    * @param response
+    * @param conn
+    * @param queryCases
+    *          map containing test-case: <query> : <expected nodes>
+    * @param lang
+    *          Query.SQL or Query.XPATH
     * @throws IOException
     * @throws ModuleException
     * @throws XMLStreamException
     * @throws FactoryConfigurationError
     */
-   private void assertResponse(String[] expected, HTTPResponse response) throws IOException, ModuleException,
-      XMLStreamException, FactoryConfigurationError
+   private void assertQuery(JCRWebdavConnection conn, Map<String, String[]> queryCases, String lang)
+      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(Arrays
-         .asList(expected), found));
+      if (lang.equals(Query.SQL) || lang.equals(Query.XPATH))
+      {
+         for (Entry<String, String[]> entry : queryCases.entrySet())
+         {
+            HTTPResponse response =
+               lang.equals(Query.SQL) ? conn.sqlQuery(entry.getKey()) : conn.xpathQuery(entry.getKey());
+            assertEquals(207, response.getStatusCode());
+            List<String> found;
+            assertEquals(207, response.getStatusCode());
+            found = parseNodeNames(response.getData());
+            assertTrue("Lists are not equals:\n*found:\t" + found + "\n*expected:\t" + entry.getValue(), compareLists(
+               Arrays.asList(entry.getValue()), found));
+         }
+      }
+      else
+      {
+         fail("Unsupported query language:" + lang);
+      }
    }
 
    /**



More information about the exo-jcr-commits mailing list