jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1359213 - in /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query: AbstractQueryTest.java SQLPathTest.java
Date Mon, 09 Jul 2012 15:13:22 GMT
Author: thomasm
Date: Mon Jul  9 15:13:22 2012
New Revision: 1359213

URL: http://svn.apache.org/viewvc?rev=1359213&view=rev
Log:
JCR-3376 TCK: SQLPathTest.testChildAxisRoot expects root node not in result

Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/SQLPathTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java?rev=1359213&r1=1359212&r2=1359213&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/AbstractQueryTest.java
Mon Jul  9 15:13:22 2012
@@ -159,14 +159,12 @@ public abstract class AbstractQueryTest 
      */
     protected Query createQuery(Session session, String statement, String language) throws
RepositoryException, NotExecutableException {
         log.println("Creating query: " + statement);
-        
+
         // check for unsupported query languages early
         if (! isSupportedLanguage(language) && !Query.JCR_SQL2.equals(language))
{
             throw new NotExecutableException("Repository does not support " + language +
" query syntax");
         }
-        else {
-            return session.getWorkspace().getQueryManager().createQuery(statement, language);
-        }
+        return session.getWorkspace().getQueryManager().createQuery(statement, language);
     }
 
     /**
@@ -308,13 +306,26 @@ public abstract class AbstractQueryTest 
      * the specified <code>nodes</code>.
      * @param session the session to use for the query.
      * @param xpath the xpath query.
-     * @param nodes the expected result nodes.
-     * @throws NotExecutableException 
+     * @param expectedNodes the expected nodes.
+     * @throws NotExecutableException
      */
-    protected void executeXPathQuery(Session session, String xpath, Node[] nodes)
+    protected void executeXPathQuery(Session session, String xpath, Node[] expectedNodes)
             throws RepositoryException, NotExecutableException {
         QueryResult res = createQuery(session, xpath, qsXPATH).execute();
-        checkResult(res, nodes);
+        checkResult(res, expectedNodes, null);
+    }
+
+    /**
+     * Executes the <code>sql</code> query and checks the results against
+     * the specified <code>nodes</code>.
+     * @param session the session to use for the query.
+     * @param sql the sql query.
+     * @param expectedNodes the expected nodes.
+     * @throws NotExecutableException
+     */
+    protected void executeSqlQuery(Session session, String sql, Node[] expectedNodes)
+            throws RepositoryException, NotExecutableException {
+    		executeSqlQuery(session, sql, expectedNodes, null);
     }
 
     /**
@@ -322,43 +333,69 @@ public abstract class AbstractQueryTest 
      * the specified <code>nodes</code>.
      * @param session the session to use for the query.
      * @param sql the sql query.
-     * @param nodes the expected result nodes.
-     * @throws NotExecutableException 
+     * @param requiredNodes the nodes that need to be in the result set
+     * 		(null if no node is required).
+     * @param optionalNodes the nodes that may be in the result set
+     * 		(null if no node is optional).
+     * @throws NotExecutableException
      */
-    protected void executeSqlQuery(Session session, String sql, Node[] nodes)
+    protected void executeSqlQuery(Session session, String sql, Node[] requiredNodes, Node[]
optionalNodes)
             throws RepositoryException, NotExecutableException {
         QueryResult res = createQuery(session, sql, qsSQL).execute();
-        checkResult(res, nodes);
+        checkResult(res, requiredNodes, optionalNodes);
     }
 
     /**
      * Checks if the result set contains exactly the <code>nodes</code>.
      * @param result the query result.
-     * @param nodes the expected nodes in the result set.
+     * @param expectedNodes the expected nodes.
      */
-    protected void checkResult(QueryResult result, Node[] nodes)
+    protected void checkResult(QueryResult result, Node[] expectedNodes)
+    			throws RepositoryException {
+    		checkResult(result, expectedNodes, null);
+	}
+
+    /**
+     * Checks if the result set contains exactly the <code>nodes</code>.
+     * @param result the query result.
+     * @param requiredNodes the nodes that need to be in the result set
+     * 		(null if no node is required).
+     * @param optionalNodes the nodes that may be in the result set
+     * 		(null if no node is optional).
+     */
+    protected void checkResult(QueryResult result, Node[] requiredNodes, Node[] optionalNodes)
             throws RepositoryException {
         // collect paths
-        Set<String> expectedPaths = new HashSet<String>();
-        for (int i = 0; i < nodes.length; i++) {
-            expectedPaths.add(nodes[i].getPath());
-        }
+        Set<String> requiredPaths = getPathSet(requiredNodes);
+        Set<String> optionalPaths = getPathSet(optionalNodes);
         Set<String> resultPaths = new HashSet<String>();
         for (NodeIterator it = result.getNodes(); it.hasNext();) {
             resultPaths.add(it.nextNode().getPath());
         }
-        // check if all expected are in result
-        for (Iterator<String> it = expectedPaths.iterator(); it.hasNext();) {
+        // check if all required nodes are in result
+        for (Iterator<String> it = requiredPaths.iterator(); it.hasNext();) {
             String path = it.next();
             assertTrue(path + " is not part of the result set", resultPaths.contains(path));
         }
         // check result does not contain more than expected
         for (Iterator<String> it = resultPaths.iterator(); it.hasNext();) {
             String path = it.next();
-            assertTrue(path + " is not expected to be part of the result set", expectedPaths.contains(path));
+            if (!optionalPaths.contains(path)) {
+            		assertTrue(path + " is not expected to be part of the result set", requiredPaths.contains(path));
+            }
         }
     }
 
+    private static HashSet<String> getPathSet(Node[] nodes) throws RepositoryException
{
+    		HashSet<String> paths = new HashSet<String>();
+    		if (nodes != null) {
+    	        for (int i = 0; i < nodes.length; i++) {
+    	        		paths.add(nodes[i].getPath());
+        		}
+    		}
+    		return paths;
+    }
+
     /**
      * Returns the nodes in <code>it</code> as an array of Nodes.
      * @param it the NodeIterator.
@@ -383,9 +420,7 @@ public abstract class AbstractQueryTest 
         if (!needsEscaping) {
             return identifier;
         }
-        else {
-            return '"' + identifier + '"';
-        }
+        return '"' + identifier + '"';
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/SQLPathTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/SQLPathTest.java?rev=1359213&r1=1359212&r2=1359213&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/SQLPathTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/SQLPathTest.java
Mon Jul  9 15:13:22 2012
@@ -69,7 +69,7 @@ public class SQLPathTest extends Abstrac
 
     /**
      * Tests if &lt;somepath>/% returns the descendants of &lt;somepath>.
-     * @throws NotExecutableException 
+     * @throws NotExecutableException
      */
     public void testDescendantTestRoot() throws RepositoryException, NotExecutableException
{
         String sql = getStatement(testRoot + "/%");
@@ -79,7 +79,7 @@ public class SQLPathTest extends Abstrac
     /**
      * Tests if &lt;somepath>/% returns no nodes if node at &lt;somepath>
      * is a leaf.
-     * @throws NotExecutableException 
+     * @throws NotExecutableException
      */
     public void testDescendantLeaf() throws RepositoryException, NotExecutableException {
         // find leaf
@@ -95,7 +95,7 @@ public class SQLPathTest extends Abstrac
      * Tests if &lt;somepath>/%/&lt;nodename> OR &lt;somepath>/&lt;nodename>
      * returns nodes with name &lt;nodename> which are descendants of
      * node at <code>testroot</code>.
-     * @throws NotExecutableException 
+     * @throws NotExecutableException
      */
     public void testDescendantSelfTestRoot() throws RepositoryException, NotExecutableException
{
         // get first node which is two levels deeper than node at testroot
@@ -124,19 +124,23 @@ public class SQLPathTest extends Abstrac
 
     /**
      * Tests if /% AND NOT /%/% returns the child nodes of the root node.
-     * @throws NotExecutableException 
+     * @throws NotExecutableException
      */
     public void testChildAxisRoot() throws RepositoryException, NotExecutableException {
         String sql = getStatement("/%");
         sql += " AND NOT " + jcrPath + " LIKE '/%/%'";
         Node[] nodes = toArray(session.getRootNode().getNodes());
-        executeSqlQuery(session, sql, nodes);
+        // optionally, the result may include the root node -
+        // the specification allows to not return it even if using jcr:path LIKE '/%'
+        // see also the JCR 1.0 specification, section 8.5.2.2 ("Pseudo-property jcr:path")
+        Node[] optional = { session.getRootNode() };
+        executeSqlQuery(session, sql, nodes, optional);
     }
 
     /**
      * Tests if &lt;somepath>/% AND NOT &lt;somepath>/%/% returns the child
      * nodes of node at &lt;somepath>.
-     * @throws NotExecutableException 
+     * @throws NotExecutableException
      */
     public void testChildAxisTestRoot() throws RepositoryException, NotExecutableException
{
         String sql = getStatement(testRoot + "/%");
@@ -148,7 +152,7 @@ public class SQLPathTest extends Abstrac
     /**
      * Tests if &lt;somepath>/% AND NOT &lt;somepath>/%/% returns no nodes
      * if the node at &lt;somepath> is a leaf.
-     * @throws NotExecutableException 
+     * @throws NotExecutableException
      */
     public void testChildAxisLeaf() throws RepositoryException, NotExecutableException {
         // find leaf



Mime
View raw message