jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r794294 - in /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query: AbstractQueryTest.java QueryResultNodeIteratorTest.java SQLJcrPathTest.java SQLPathTest.java
Date Wed, 15 Jul 2009 15:00:52 GMT
Author: reschke
Date: Wed Jul 15 15:00:52 2009
New Revision: 794294

URL: http://svn.apache.org/viewvc?rev=794294&view=rev
Log:
JCR-2208: make SQL query tests abort with NotExecutableException if Query.SQL is not supported

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/QueryResultNodeIteratorTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/SQLJcrPathTest.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=794294&r1=794293&r2=794294&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
Wed Jul 15 15:00:52 2009
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.apache.jackrabbit.test.api.util.ISO9075;
 
+import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.RowIterator;
 import javax.jcr.query.Query;
@@ -126,13 +127,14 @@
      * @throws RepositoryException
      * @see #createQuery(String, String)
      */
-    protected Query createQuery(Statement statement) throws RepositoryException {
+    protected Query createQuery(Statement statement)
+        throws RepositoryException, NotExecutableException {
         return createQuery(statement.getStatement(), statement.getLanguage());
     }
 
     /**
      * Creates a {@link Query} for the given statement in the requested
-     * language
+     * language, treating optional languages gracefully
      *
      * @param statement the query should be created for
      * @param language  query language to be used for Query creation
@@ -140,10 +142,24 @@
      *
      * @throws RepositoryException
      */
-    protected Query createQuery(String statement, String language) throws RepositoryException
{
+    protected Query createQuery(String statement, String language)
+        throws RepositoryException, NotExecutableException {
         log.println("Creating query: " + statement);
-        return superuser.getWorkspace().getQueryManager().createQuery(statement,
-                language);
+        try {
+            return qm.createQuery(statement, language);
+        }
+        catch (InvalidQueryException ex) {
+            
+            // if language is optional and not reported as "supported" -> 
+            // demote to NotExecutableException
+            
+            if (! isSupportedLanguage(language) && ! Query.JCR_SQL2.equals(language))
{
+                throw new NotExecutableException("Repository does not support " + language
+ " query syntax");
+            }
+            else {
+                throw ex;
+            }
+        }
     }
 
     /**
@@ -155,7 +171,8 @@
      * @throws RepositoryException
      * @see #execute(String, String)
      */
-    protected QueryResult execute(Statement statement) throws RepositoryException {
+    protected QueryResult execute(Statement statement)
+        throws RepositoryException, NotExecutableException {
         return execute(statement.getStatement(), statement.getLanguage());
     }
 
@@ -170,7 +187,7 @@
      * @throws RepositoryException
      */
     protected QueryResult execute(String statement, String language)
-            throws RepositoryException {
+            throws RepositoryException, NotExecutableException {
         Query query = createQuery(statement, language);
         return query.execute();
     }
@@ -298,10 +315,11 @@
      * @param session the session to use for the query.
      * @param sql the sql query.
      * @param nodes the expected result nodes.
+     * @throws NotExecutableException 
      */
     protected void executeSqlQuery(Session session, String sql, Node[] nodes)
-            throws RepositoryException {
-        QueryResult res = session.getWorkspace().getQueryManager().createQuery(sql, Query.SQL).execute();
+            throws RepositoryException, NotExecutableException {
+        QueryResult res = createQuery(sql, Query.SQL).execute();
         checkResult(res, nodes);
     }
 

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/QueryResultNodeIteratorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/QueryResultNodeIteratorTest.java?rev=794294&r1=794293&r2=794294&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/QueryResultNodeIteratorTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/QueryResultNodeIteratorTest.java
Wed Jul 15 15:00:52 2009
@@ -71,7 +71,7 @@
     /**
      * Tests the method <code>NodeIterator.getPosition()</code>.
      */
-    public void testGetPosition() throws RepositoryException {
+    public void testGetPosition() throws RepositoryException, NotExecutableException {
         QueryResult rs = execute(xpathRoot + "//*", Query.XPATH);
 
         // getPosition initially returns 0
@@ -89,8 +89,9 @@
     /**
      * Tests the method <code>NodeIterator.getPosition()</code> on an empty
      * <code>NodeIterator</code>.
+     * @throws NotExecutableException 
      */
-    public void testGetPositionEmptyIterator() throws RepositoryException {
+    public void testGetPositionEmptyIterator() throws RepositoryException, NotExecutableException
{
         QueryResult rs = execute(xpathRoot + "/" + nodeName4, Query.XPATH);
 
         NodeIterator it = rs.getNodes();
@@ -103,8 +104,9 @@
      * Tests if a {@link java.util.NoSuchElementException} is thrown when {@link
      * javax.jcr.NodeIterator#nextNode()} is called and there are no more nodes
      * available.
+     * @throws NotExecutableException 
      */
-    public void testNoSuchElementException() throws RepositoryException {
+    public void testNoSuchElementException() throws RepositoryException, NotExecutableException
{
         NodeIterator it = execute(xpathRoot + "//*", Query.XPATH).getNodes();
         while (it.hasNext()) {
             it.nextNode();
@@ -119,8 +121,9 @@
 
     /**
      * Tests if {@link javax.jcr.NodeIterator#skip(long)} works correctly.
+     * @throws NotExecutableException 
      */
-    public void testSkip() throws RepositoryException {
+    public void testSkip() throws RepositoryException, NotExecutableException {
         String query = xpathRoot + "//*";
         QueryResult rs = execute(query, Query.XPATH);
         NodeIterator it = rs.getNodes();

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/SQLJcrPathTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/SQLJcrPathTest.java?rev=794294&r1=794293&r2=794294&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/SQLJcrPathTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/SQLJcrPathTest.java
Wed Jul 15 15:00:52 2009
@@ -66,7 +66,7 @@
         String queryStatement = "select * from " + nodeTypeName;
 
         // execute the search query
-        Query query = session.getWorkspace().getQueryManager().createQuery(queryStatement,
Query.SQL);
+        Query query = super.createQuery(queryStatement, Query.SQL);
         QueryResult result = query.execute();
 
         assertTrue("jcr:path must be present in query result row",

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=794294&r1=794293&r2=794294&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
Wed Jul 15 15:00:52 2009
@@ -21,6 +21,9 @@
 import javax.jcr.NodeIterator;
 import javax.jcr.Session;
 import javax.jcr.util.TraversingItemVisitor;
+
+import org.apache.jackrabbit.test.NotExecutableException;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -66,8 +69,9 @@
 
     /**
      * Tests if &lt;somepath>/% returns the descendants of &lt;somepath>.
+     * @throws NotExecutableException 
      */
-    public void testDescendantTestRoot() throws RepositoryException {
+    public void testDescendantTestRoot() throws RepositoryException, NotExecutableException
{
         String sql = getStatement(testRoot + "/%");
         executeSqlQuery(session, sql, getDescendants(testRootNode));
     }
@@ -75,8 +79,9 @@
     /**
      * Tests if &lt;somepath>/% returns no nodes if node at &lt;somepath>
      * is a leaf.
+     * @throws NotExecutableException 
      */
-    public void testDescendantLeaf() throws RepositoryException {
+    public void testDescendantLeaf() throws RepositoryException, NotExecutableException {
         // find leaf
         Node leaf = testRootNode;
         while (leaf.hasNodes()) {
@@ -90,8 +95,9 @@
      * 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 
      */
-    public void testDescendantSelfTestRoot() throws RepositoryException {
+    public void testDescendantSelfTestRoot() throws RepositoryException, NotExecutableException
{
         // get first node which is two levels deeper than node at testroot
         Node n = null;
         for (NodeIterator it = testRootNode.getNodes(); it.hasNext();) {
@@ -118,8 +124,9 @@
 
     /**
      * Tests if /% AND NOT /%/% returns the child nodes of the root node.
+     * @throws NotExecutableException 
      */
-    public void testChildAxisRoot() throws RepositoryException {
+    public void testChildAxisRoot() throws RepositoryException, NotExecutableException {
         String sql = getStatement("/%");
         sql += " AND NOT " + jcrPath + " LIKE '/%/%'";
         Node[] nodes = toArray(session.getRootNode().getNodes());
@@ -129,8 +136,9 @@
     /**
      * Tests if &lt;somepath>/% AND NOT &lt;somepath>/%/% returns the child
      * nodes of node at &lt;somepath>.
+     * @throws NotExecutableException 
      */
-    public void testChildAxisTestRoot() throws RepositoryException {
+    public void testChildAxisTestRoot() throws RepositoryException, NotExecutableException
{
         String sql = getStatement(testRoot + "/%");
         sql += " AND NOT " + jcrPath + " LIKE '" + testRoot + "/%/%'";
         Node[] nodes = toArray(testRootNode.getNodes());
@@ -140,8 +148,9 @@
     /**
      * Tests if &lt;somepath>/% AND NOT &lt;somepath>/%/% returns no nodes
      * if the node at &lt;somepath> is a leaf.
+     * @throws NotExecutableException 
      */
-    public void testChildAxisLeaf() throws RepositoryException {
+    public void testChildAxisLeaf() throws RepositoryException, NotExecutableException {
         // find leaf
         Node leaf = testRootNode;
         while (leaf.hasNodes()) {



Mime
View raw message