jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r792142 [22/35] - in /jackrabbit/sandbox/JCR-1456: ./ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/ jackrabbit-core/ jackrabbit-core/src/main/java/org/apache/jackrab...
Date Wed, 08 Jul 2009 13:57:46 GMT
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/TestAll.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/TestAll.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/TestAll.java Wed Jul  8 13:57:13 2009
@@ -57,6 +57,7 @@
         suite.addTestSuite(GetPersistentQueryPathTest.class);
         suite.addTestSuite(GetStatementTest.class);
         suite.addTestSuite(GetSupportedQueryLanguagesTest.class);
+        suite.addTestSuite(CreateQueryTest.class);
 
         suite.addTestSuite(QueryResultNodeIteratorTest.class);
         suite.addTestSuite(GetPropertyNamesTest.class);
@@ -68,6 +69,15 @@
         suite.addTestSuite(OrderByLongTest.class);
         suite.addTestSuite(OrderByMultiTypeTest.class);
         suite.addTestSuite(OrderByStringTest.class);
+        suite.addTestSuite(OrderByLengthTest.class);
+        suite.addTestSuite(OrderByLocalNameTest.class);
+        suite.addTestSuite(OrderByNameTest.class);
+        suite.addTestSuite(OrderByLowerCaseTest.class);
+        suite.addTestSuite(OrderByUpperCaseTest.class);
+        suite.addTestSuite(OrderByDecimalTest.class);
+        suite.addTestSuite(OrderByURITest.class);
+        suite.addTestSuite(SetLimitTest.class);
+        suite.addTestSuite(SetOffsetTest.class);
 
         return suite;
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathDocOrderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathDocOrderTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathDocOrderTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathDocOrderTest.java Wed Jul  8 13:57:13 2009
@@ -53,14 +53,12 @@
      * For configuration description see {@link XPathDocOrderTest}.
      */
     public void testDocOrderPositionFunction() throws Exception {
-        StringBuffer tmp = new StringBuffer("/");
-        tmp.append(jcrRoot).append(testRoot).append("/*");
-        tmp.append("[position()=2]");
+        String xpath = xpathRoot + "/*[position()=2]";
         String resultPath = "";
         for (NodeIterator nodes = testRootNode.getNodes(); nodes.hasNext() && nodes.getPosition() < 2;) {
             resultPath = nodes.nextNode().getPath();
         }
-        docOrderTest(new Statement(tmp.toString(), Query.XPATH), resultPath);
+        docOrderTest(new Statement(xpath, Query.XPATH), resultPath);
     }
 
     /**
@@ -70,14 +68,12 @@
      * For configuration description see {@link XPathDocOrderTest}.
      */
     public void testDocOrderPositionIndex() throws Exception {
-        StringBuffer tmp = new StringBuffer("/");
-        tmp.append(jcrRoot).append(testRoot).append("/*");
-        tmp.append("[2]");
+        String xpath = xpathRoot + "/*[2]";
         String resultPath = "";
         for (NodeIterator nodes = testRootNode.getNodes(); nodes.hasNext() && nodes.getPosition() < 2;) {
             resultPath = nodes.nextNode().getPath();
         }
-        docOrderTest(new Statement(tmp.toString(), Query.XPATH), resultPath);
+        docOrderTest(new Statement(xpath, Query.XPATH), resultPath);
     }
 
     /**
@@ -86,14 +82,12 @@
      * For configuration description see {@link XPathDocOrderTest}.
      */
     public void testDocOrderLastFunction() throws Exception {
-        StringBuffer tmp = new StringBuffer("/");
-        tmp.append(jcrRoot).append(testRoot).append("/*");
-        tmp.append("[position()=last()]");
+        String xpath = xpathRoot + "/*[position()=last()]";
         String resultPath = "";
         for (NodeIterator nodes = testRootNode.getNodes(); nodes.hasNext();) {
             resultPath = nodes.nextNode().getPath();
         }
-        docOrderTest(new Statement(tmp.toString(), Query.XPATH), resultPath);
+        docOrderTest(new Statement(xpath, Query.XPATH), resultPath);
     }
 
     /**
@@ -102,11 +96,9 @@
      * For configuration description see {@link XPathDocOrderTest}.
      */
     public void testDocOrderFirstFunction() throws Exception {
-        StringBuffer tmp = new StringBuffer("/");
-        tmp.append(jcrRoot).append(testRoot).append("/*");
-        tmp.append("[first()]");
+        String xpath = xpathRoot + "/*[first()]";
         String resultPath = testRootNode.getNodes().nextNode().getPath();
-        docOrderTest(new Statement(tmp.toString(), Query.XPATH), resultPath);
+        docOrderTest(new Statement(xpath, Query.XPATH), resultPath);
     }
 
     //-----------------------------< internal >---------------------------------

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathJcrPathTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathJcrPathTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathJcrPathTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathJcrPathTest.java Wed Jul  8 13:57:13 2009
@@ -43,7 +43,7 @@
     protected void setUp() throws Exception {
         isReadOnly = true;
         super.setUp();
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
         testRootNode = session.getRootNode().getNode(testPath);
     }
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathOrderByTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathOrderByTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathOrderByTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathOrderByTest.java Wed Jul  8 13:57:13 2009
@@ -44,13 +44,8 @@
     protected void setUp() throws Exception {
         isReadOnly = true;
         super.setUp();
-        StringBuffer tmp = new StringBuffer("/");
-        tmp.append(jcrRoot).append(testRoot);
-        tmp.append("/*[@");
-        tmp.append(propertyName1);
-        tmp.append("] order by @");
-        tmp.append(propertyName1);
-        baseStatement = tmp.toString();
+        baseStatement =
+            xpathRoot + "/*[@" + propertyName1 + "] order by @" + propertyName1;
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/XPathQueryLevel2Test.java Wed Jul  8 13:57:13 2009
@@ -129,11 +129,9 @@
      *         and excluding with a word
      */
     private Statement getFullTextStatement() {
-        StringBuffer tmp = new StringBuffer("/");
-        tmp.append(jcrRoot).append(testRoot);
-        tmp.append("/*[").append(jcrContains);
-        tmp.append("(., '\"quick brown\" -cat')]");
-        return new Statement(tmp.toString(), Query.XPATH);
+        String xpath =
+            xpathRoot + "/*[" + jcrContains + "(., '\"quick brown\" -cat')]";
+        return new Statement(xpath, Query.XPATH);
     }
 
     /**
@@ -141,24 +139,20 @@
      *         property
      */
     private Statement getMultiValueStatement() {
-        StringBuffer tmp = new StringBuffer("/");
-        tmp.append(jcrRoot).append(testRoot);
-        tmp.append("/*[@").append(propertyName2).append(" = 'two'");
-        tmp.append(" and @").append(propertyName1).append(" = 'existence']");
-        return new Statement(tmp.toString(), Query.XPATH);
+        String xpath =
+            xpathRoot + "/*[@" + propertyName2 + " = 'two' and @"
+            + propertyName1 + " = 'existence']";
+        return new Statement(xpath, Query.XPATH);
     }
 
     /**
      * @return Statement selecting nodes by its range in {@link #propertyName1}
      */
     private Statement getRangeStatement() {
-        StringBuffer tmp = new StringBuffer("/");
-        tmp.append(jcrRoot).append(testRoot);
-        tmp.append("/*[@");
-        tmp.append(propertyName1);
-        tmp.append(" <= 'b' and @");
-        tmp.append(propertyName1);
-        tmp.append(" > 'a']");
-        return new Statement(tmp.toString(), Query.XPATH);
+        String xpath =
+            xpathRoot + "/*[@" + propertyName1 + " <= 'b' and @"
+            + propertyName1 + " > 'a']";
+        return new Statement(xpath, Query.XPATH);
     }
-}
\ No newline at end of file
+
+}

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractJoinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractJoinTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractJoinTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractJoinTest.java Wed Jul  8 13:57:13 2009
@@ -23,6 +23,7 @@
 import javax.jcr.query.qom.Join;
 import javax.jcr.query.qom.JoinCondition;
 import javax.jcr.query.qom.QueryObjectModel;
+import javax.jcr.query.qom.QueryObjectModelConstants;
 
 /**
  * <code>AbstractJoinTest</code> provides utility methods for join related
@@ -44,14 +45,14 @@
      * The selector names for the join.
      */
     protected static final String[] SELECTOR_NAMES = new String[]{LEFT, RIGHT};
-
-    // Constants broken in JCR 2.0 PFD
-    // TODO remove when API is fixed
-    protected static String JCR_JOIN_TYPE_LEFT_OUTER = "{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter";
-    protected static String JCR_JOIN_TYPE_RIGHT_OUTER = "{http://www.jcp.org/jcr/1.0}joinTypeRightOuter";
     
     //--------------------------< utilities >-----------------------------------
 
+    protected void checkQOM(QueryObjectModel qom, Node[][] nodes)
+            throws RepositoryException {
+        checkQOM(qom, SELECTOR_NAMES, nodes);
+    }
+
     protected void checkResult(QueryResult result, Node[][] nodes)
             throws RepositoryException {
         checkResult(result, SELECTOR_NAMES, nodes);
@@ -70,23 +71,23 @@
             throws RepositoryException {
         // only consider nodes under test root
         Constraint constraint;
-        if (JCR_JOIN_TYPE_LEFT_OUTER.equals(joinType)) {
-            constraint = qomFactory.descendantNode(LEFT, testRoot);
+        if (QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER.equals(joinType)) {
+            constraint = qf.descendantNode(LEFT, testRoot);
         } else {
-            constraint = qomFactory.descendantNode(RIGHT, testRoot);
+            constraint = qf.descendantNode(RIGHT, testRoot);
         }
 
         if (left != null) {
-            constraint = qomFactory.and(constraint, left);
+            constraint = qf.and(constraint, left);
         }
         if (right != null) {
-            constraint = qomFactory.and(constraint, right);
+            constraint = qf.and(constraint, right);
         }
-        Join join = qomFactory.join(
-                qomFactory.selector(testNodeType, LEFT),
-                qomFactory.selector(testNodeType, RIGHT),
+        Join join = qf.join(
+                qf.selector(testNodeType, LEFT),
+                qf.selector(testNodeType, RIGHT),
                 joinType,
                 condition);
-        return qomFactory.createQuery(join, constraint, null, null);
+        return qf.createQuery(join, constraint, null, null);
     }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractQOMTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractQOMTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractQOMTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractQOMTest.java Wed Jul  8 13:57:13 2009
@@ -19,36 +19,24 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.query.Query;
-import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.Row;
 import javax.jcr.query.RowIterator;
-import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.qom.QueryObjectModel;
 
 import org.apache.jackrabbit.test.api.query.AbstractQueryTest;
 
 /**
  * <code>AbstractQOMTest</code> is a base class for test cases on the JQOM.
  */
-public class AbstractQOMTest extends AbstractQueryTest {
-
-    // Constants broken in JCR 2.0 PFD
-    // TODO remove when API is fixed
-    protected static String JCR_OPERATOR_EQUAL_TO = "{http://www.jcp.org/jcr/1.0}operatorEqualTo";
-    protected static String JCR_OPERATOR_NOT_EQUAL_TO = "{http://www.jcp.org/jcr/1.0}operatorNotEqualTo";
-
-    protected QueryObjectModelFactory qomFactory;
-
-    protected void setUp() throws Exception {
-        super.setUp();
-        QueryManager qm = superuser.getWorkspace().getQueryManager();
-        qomFactory = qm.getQOMFactory();
-    }
+public abstract class AbstractQOMTest extends AbstractQueryTest {
 
     /**
      * Binds the given <code>value</code> to the variable named
@@ -66,6 +54,85 @@
         q.bindValue(var, value);
     }
 
+    protected void checkResultOrder(QueryObjectModel qom,
+                                    String[] selectorNames,
+                                    Node[][] nodes)
+            throws RepositoryException {
+        checkResultOrder(qom.execute(), selectorNames, nodes);
+        checkResultOrder(qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute(),
+                selectorNames, nodes);
+    }
+
+    protected void checkResultOrder(QueryResult result,
+                                    String[] selectorNames,
+                                    Node[][] nodes)
+            throws RepositoryException {
+        // collect rows
+        List expectedPaths = new ArrayList();
+        log.println("expected:");
+        for (int i = 0; i < nodes.length; i++) {
+            StringBuffer aggregatedPaths = new StringBuffer();
+            for (int j = 0; j < nodes[i].length; j++) {
+                aggregatedPaths.append(getPath(nodes[i][j]));
+                aggregatedPaths.append("|");
+            }
+            expectedPaths.add(aggregatedPaths.toString());
+            log.println(aggregatedPaths.toString());
+        }
+
+        List resultPaths = new ArrayList();
+        log.println("result:");
+        for (RowIterator it = result.getRows(); it.hasNext();) {
+            Row r = it.nextRow();
+            StringBuffer aggregatedPaths = new StringBuffer();
+            for (int i = 0; i < selectorNames.length; i++) {
+                aggregatedPaths.append(getPath(r.getNode(selectorNames[i])));
+                aggregatedPaths.append("|");
+            }
+            resultPaths.add(aggregatedPaths.toString());
+            log.println(aggregatedPaths.toString());
+        }
+
+        assertEquals("wrong result order", expectedPaths, resultPaths);
+    }
+
+    /**
+     * Checks the query object model by executing it directly and matching the
+     * result against the given <code>nodes</code>. Then the QOM is executed
+     * again using {@link QueryObjectModel#getStatement()} with {@link
+     * Query#JCR_SQL2}.
+     *
+     * @param qom   the query object model to check.
+     * @param nodes the result nodes.
+     * @throws RepositoryException if an error occurs while executing the
+     *                             query.
+     */
+    protected void checkQOM(QueryObjectModel qom, Node[] nodes)
+            throws RepositoryException {
+        checkResult(qom.execute(), nodes);
+        checkResult(qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute(), nodes);
+    }
+
+    /**
+     * Checks the query object model by executing it directly and matching the
+     * result against the given <code>nodes</code>. Then the QOM is executed
+     * again using {@link QueryObjectModel#getStatement()} with
+     * {@link Query#JCR_SQL2}.
+     *
+     * @param qom           the query object model to check.
+     * @param selectorNames the selector names of the qom.
+     * @param nodes         the result nodes.
+     * @throws RepositoryException if an error occurs while executing the
+     *                             query.
+     */
+    protected void checkQOM(QueryObjectModel qom,
+                            String[] selectorNames,
+                            Node[][] nodes) throws RepositoryException {
+        checkResult(qom.execute(), selectorNames, nodes);
+        checkResult(qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute(),
+                selectorNames, nodes);
+    }
+
     protected void checkResult(QueryResult result,
                                String[] selectorNames,
                                Node[][] nodes)
@@ -125,4 +192,27 @@
             return "";
         }
     }
+
+    /**
+     * Calls back the <code>callable</code> first with the <code>qom</code> and
+     * then a JCR_SQL2 query created from {@link QueryObjectModel#getStatement()}.
+     *
+     * @param qom      a query object model.
+     * @param callable the callback.
+     * @throws RepositoryException if an error occurs.
+     */
+    protected void forQOMandSQL2(QueryObjectModel qom, Callable callable)
+            throws RepositoryException {
+        List queries = new ArrayList();
+        queries.add(qom);
+        queries.add(qm.createQuery(qom.getStatement(), Query.JCR_SQL2));
+        for (Iterator it = queries.iterator(); it.hasNext();) {
+            callable.call((Query) it.next());
+        }
+    }
+
+    protected interface Callable {
+
+        public Object call(Query query) throws RepositoryException;
+    }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java Wed Jul  8 13:57:13 2009
@@ -17,12 +17,16 @@
 package org.apache.jackrabbit.test.api.query.qom;
 
 import java.util.Calendar;
+import java.math.BigDecimal;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
-import javax.jcr.ValueFactory;
+import javax.jcr.PropertyType;
 import javax.jcr.query.Query;
+import javax.jcr.query.qom.QueryObjectModelConstants;
+
+import org.apache.jackrabbit.test.NotExecutableException;
 
 /**
  * <code>BindVariableValueTest</code>...
@@ -39,34 +43,43 @@
 
     private static final Calendar DATE_VALUE = Calendar.getInstance();
 
-    private Query query;
+    private static final BigDecimal DECIMAL_VALUE = new BigDecimal(LONG_VALUE);
+
+    private static final String URI_VALUE = "http://example.com/";
 
-    private ValueFactory vf;
+    private Query qomQuery;
+
+    private Query sqlQuery;
 
     protected void setUp() throws Exception {
         super.setUp();
-        vf = superuser.getValueFactory();
-        query = qomFactory.createQuery(
-                qomFactory.selector(testNodeType, "s"),
-                qomFactory.and(
-                        qomFactory.childNode("s", testRoot),
-                        qomFactory.comparison(
-                                qomFactory.propertyValue("s", propertyName1),
-                                AbstractQOMTest.JCR_OPERATOR_EQUAL_TO,
-                                qomFactory.bindVariable("v")
+        qomQuery = qf.createQuery(
+                qf.selector(testNodeType, "s"),
+                qf.and(
+                        qf.childNode("s", testRoot),
+                        qf.comparison(
+                                qf.propertyValue("s", propertyName1),
+                                QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
+                                qf.bindVariable("v")
                         )
                 ), null, null);
+        sqlQuery = qm.createQuery(qomQuery.getStatement(), Query.JCR_SQL2);
     }
 
     protected void tearDown() throws Exception {
-        vf = null;
-        query = null;
+        qomQuery = null;
         super.tearDown();
     }
 
     public void testIllegalArgumentException() throws RepositoryException {
         try {
-            bindVariableValue(query, "x", vf.createValue(STRING_VALUE));
+            bindVariableValue(qomQuery, "x", vf.createValue(STRING_VALUE));
+            fail("Query.bindValue() must throw IllegalArgumentException for unknown variable name");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        try {
+            bindVariableValue(sqlQuery, "x", vf.createValue(STRING_VALUE));
             fail("Query.bindValue() must throw IllegalArgumentException for unknown variable name");
         } catch (IllegalArgumentException e) {
             // expected
@@ -76,93 +89,147 @@
     public void testString() throws RepositoryException {
         Node n = testRootNode.addNode(nodeName1, testNodeType);
         n.setProperty(propertyName1, STRING_VALUE);
-        testRootNode.save();
+        superuser.save();
+
+        bindVariableValue(qomQuery, "v", vf.createValue(STRING_VALUE));
+        checkResult(qomQuery.execute(), new Node[]{n});
 
-        bindVariableValue(query, "v", vf.createValue(STRING_VALUE));
-        checkResult(query.execute(), new Node[]{n});
+        bindVariableValue(sqlQuery, "v", vf.createValue(STRING_VALUE));
+        checkResult(sqlQuery.execute(), new Node[]{n});
     }
 
     public void testDate() throws RepositoryException {
         Node n = testRootNode.addNode(nodeName1, testNodeType);
         n.setProperty(propertyName1, DATE_VALUE);
-        testRootNode.save();
+        superuser.save();
 
-        bindVariableValue(query, "v", vf.createValue(DATE_VALUE));
-        checkResult(query.execute(), new Node[]{n});
+        bindVariableValue(sqlQuery, "v", vf.createValue(DATE_VALUE));
+        checkResult(sqlQuery.execute(), new Node[]{n});
+
+        bindVariableValue(qomQuery, "v", vf.createValue(DATE_VALUE));
+        checkResult(qomQuery.execute(), new Node[]{n});
     }
 
     public void testLong() throws RepositoryException {
         Node n = testRootNode.addNode(nodeName1, testNodeType);
         n.setProperty(propertyName1, LONG_VALUE);
-        testRootNode.save();
+        superuser.save();
+
+        bindVariableValue(qomQuery, "v", vf.createValue(LONG_VALUE));
+        checkResult(qomQuery.execute(), new Node[]{n});
 
-        bindVariableValue(query, "v", vf.createValue(LONG_VALUE));
-        checkResult(query.execute(), new Node[]{n});
+        bindVariableValue(sqlQuery, "v", vf.createValue(LONG_VALUE));
+        checkResult(sqlQuery.execute(), new Node[]{n});
     }
 
     public void testDouble() throws RepositoryException {
         Node n = testRootNode.addNode(nodeName1, testNodeType);
         n.setProperty(propertyName1, DOUBLE_VALUE);
-        testRootNode.save();
+        superuser.save();
 
-        bindVariableValue(query, "v", vf.createValue(DOUBLE_VALUE));
-        checkResult(query.execute(), new Node[]{n});
+        bindVariableValue(qomQuery, "v", vf.createValue(DOUBLE_VALUE));
+        checkResult(qomQuery.execute(), new Node[]{n});
+
+        bindVariableValue(sqlQuery, "v", vf.createValue(DOUBLE_VALUE));
+        checkResult(sqlQuery.execute(), new Node[]{n});
     }
 
     public void testBoolean() throws RepositoryException {
         Node n = testRootNode.addNode(nodeName1, testNodeType);
         n.setProperty(propertyName1, BOOLEAN_VALUE);
-        testRootNode.save();
+        superuser.save();
+
+        bindVariableValue(qomQuery, "v", vf.createValue(BOOLEAN_VALUE));
+        checkResult(qomQuery.execute(), new Node[]{n});
 
-        bindVariableValue(query, "v", vf.createValue(BOOLEAN_VALUE));
-        checkResult(query.execute(), new Node[]{n});
+        bindVariableValue(sqlQuery, "v", vf.createValue(BOOLEAN_VALUE));
+        checkResult(sqlQuery.execute(), new Node[]{n});
     }
 
     public void testName() throws RepositoryException {
-        Value name = vf.createValue(STRING_VALUE);
+        Value name = vf.createValue(STRING_VALUE, PropertyType.NAME);
         Node n = testRootNode.addNode(nodeName1, testNodeType);
         n.setProperty(propertyName1, name);
-        testRootNode.save();
+        superuser.save();
+
+        bindVariableValue(qomQuery, "v", name);
+        checkResult(qomQuery.execute(), new Node[]{n});
 
-        bindVariableValue(query, "v", name);
-        checkResult(query.execute(), new Node[]{n});
+        bindVariableValue(sqlQuery, "v", name);
+        checkResult(sqlQuery.execute(), new Node[]{n});
     }
 
     public void testPath() throws RepositoryException {
         Node n = testRootNode.addNode(nodeName1, testNodeType);
-        Value path = vf.createValue(n.getPath());
+        Value path = vf.createValue(n.getPath(), PropertyType.PATH);
         n.setProperty(propertyName1, path);
-        testRootNode.save();
+        superuser.save();
 
-        bindVariableValue(query, "v", path);
-        checkResult(query.execute(), new Node[]{n});
+        bindVariableValue(qomQuery, "v", path);
+        checkResult(qomQuery.execute(), new Node[]{n});
+
+        bindVariableValue(sqlQuery, "v", path);
+        checkResult(sqlQuery.execute(), new Node[]{n});
     }
 
-    public void testReference() throws RepositoryException {
+    public void testReference() throws RepositoryException,
+            NotExecutableException {
         Node n = testRootNode.addNode(nodeName1, testNodeType);
-        testRootNode.save();
+        superuser.save();
 
-        if (!n.isNodeType(mixReferenceable)) {
-            n.addMixin(mixReferenceable);
-            n.save();
-        }
+        ensureMixinType(n, mixReferenceable);
+        superuser.save();
         n.setProperty(propertyName1, n);
-        n.save();
+        superuser.save();
 
 
-        bindVariableValue(query, "v", vf.createValue(n));
-        checkResult(query.execute(), new Node[]{n});
+        bindVariableValue(qomQuery, "v", vf.createValue(n));
+        checkResult(qomQuery.execute(), new Node[]{n});
+
+        bindVariableValue(sqlQuery, "v", vf.createValue(n));
+        checkResult(sqlQuery.execute(), new Node[]{n});
     }
 
-    public void testWeakReference() throws RepositoryException {
-        // TODO
+    public void testWeakReference() throws RepositoryException,
+            NotExecutableException {
+        Node n = testRootNode.addNode(nodeName1, testNodeType);
+        superuser.save();
+
+        ensureMixinType(n, mixReferenceable);
+        superuser.save();
+        n.setProperty(propertyName1, vf.createValue(n, true));
+        superuser.save();
+
+        bindVariableValue(qomQuery, "v", vf.createValue(n, true));
+        checkResult(qomQuery.execute(), new Node[]{n});
+
+        bindVariableValue(sqlQuery, "v", vf.createValue(n, true));
+        checkResult(sqlQuery.execute(), new Node[]{n});
     }
 
     public void testURI() throws RepositoryException {
-        // TODO
+        Value value = vf.createValue(URI_VALUE, PropertyType.URI);
+        Node n = testRootNode.addNode(nodeName1, testNodeType);
+        n.setProperty(propertyName1, value);
+        superuser.save();
+
+        bindVariableValue(qomQuery, "v", value);
+        checkResult(qomQuery.execute(), new Node[]{n});
+
+        bindVariableValue(sqlQuery, "v", value);
+        checkResult(sqlQuery.execute(), new Node[]{n});
     }
 
     public void testDecimal() throws RepositoryException {
-        // TODO
+        Value value = vf.createValue(DECIMAL_VALUE);
+        Node n = testRootNode.addNode(nodeName1, testNodeType);
+        n.setProperty(propertyName1, value);
+        superuser.save();
+
+        bindVariableValue(qomQuery, "v", value);
+        checkResult(qomQuery.execute(), new Node[]{n});
+
+        bindVariableValue(sqlQuery, "v", value);
+        checkResult(sqlQuery.execute(), new Node[]{n});
     }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeJoinConditionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeJoinConditionTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeJoinConditionTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeJoinConditionTest.java Wed Jul  8 13:57:13 2009
@@ -39,25 +39,25 @@
         super.setUp();
         n1 = testRootNode.addNode(nodeName1, testNodeType);
         n2 = n1.addNode(nodeName2, testNodeType);
-        n2.addMixin(mixReferenceable);
-        testRootNode.save();
+        ensureMixinType(n2, mixReferenceable);
+        superuser.save();
     }
 
     public void testInnerJoin() throws RepositoryException {
-        JoinCondition c = qomFactory.childNodeJoinCondition(LEFT, RIGHT);
+        JoinCondition c = qf.childNodeJoinCondition(LEFT, RIGHT);
         QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, c);
-        checkResult(qom.execute(), new Node[][]{{n2, n1}});
+        checkQOM(qom, new Node[][]{{n2, n1}});
     }
 
     public void testRightOuterJoin() throws RepositoryException {
-        JoinCondition c = qomFactory.childNodeJoinCondition(LEFT, RIGHT);
-        QueryObjectModel qom = createQuery(AbstractJoinTest.JCR_JOIN_TYPE_RIGHT_OUTER, c);
-        checkResult(qom.execute(), new Node[][]{{n2, n1}, {null, n2}});
+        JoinCondition c = qf.childNodeJoinCondition(LEFT, RIGHT);
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER, c);
+        checkQOM(qom, new Node[][]{{n2, n1}, {null, n2}});
     }
 
     public void testLeftOuterJoin() throws RepositoryException {
-        JoinCondition c = qomFactory.childNodeJoinCondition(LEFT, RIGHT);
-        QueryObjectModel qom = createQuery(AbstractJoinTest.JCR_JOIN_TYPE_LEFT_OUTER, c);
+        JoinCondition c = qf.childNodeJoinCondition(LEFT, RIGHT);
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER, c);
         List result = new ArrayList();
         result.add(new Node[]{n2, n1});
         if (testRootNode.isNodeType(testNodeType)) {
@@ -65,6 +65,6 @@
         } else {
             result.add(new Node[]{n1, null});
         }
-        checkResult(qom.execute(), (Node[][]) result.toArray(new Node[result.size()][]));
+        checkQOM(qom, (Node[][]) result.toArray(new Node[result.size()][]));
     }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeTest.java Wed Jul  8 13:57:13 2009
@@ -25,43 +25,45 @@
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.query.Query;
 import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.qom.QueryObjectModel;
 
 /**
- * <code>ChildNodeTest</code>...
+ * <code>ChildNodeTest</code> contains test cases that cover the QOM ChildNode
+ * condition.
  */
 public class ChildNodeTest extends AbstractQOMTest {
 
     public void testChildNode() throws RepositoryException {
         Node n = testRootNode.addNode(nodeName1, testNodeType);
-        testRootNode.save();
+        superuser.save();
 
-        Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                qomFactory.childNode("s", testRoot), null, null);
-        checkResult(q.execute(), new Node[]{n});
+        QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
+                qf.childNode("s", testRoot), null, null);
+        checkQOM(qom, new Node[]{n});
     }
 
     public void testChildNodes() throws RepositoryException {
         Node n1 = testRootNode.addNode(nodeName1, testNodeType);
         Node n2 = testRootNode.addNode(nodeName2, testNodeType);
         Node n3 = testRootNode.addNode(nodeName3, testNodeType);
-        testRootNode.save();
+        superuser.save();
 
-        Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                qomFactory.childNode("s", testRoot), null, null);
-        checkResult(q.execute(), new Node[]{n1, n2, n3});
+        QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
+                qf.childNode("s", testRoot), null, null);
+        checkQOM(qom, new Node[]{n1, n2, n3});
     }
 
     public void testPathDoesNotExist() throws RepositoryException {
-        Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                qomFactory.childNode("s", testRoot + "/" + nodeName1),
+        QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
+                qf.childNode("s", testRoot + "/" + nodeName1),
                 null, null);
-        checkResult(q.execute(), new Node[]{});
+        checkQOM(qom, new Node[]{});
     }
 
     public void testChildNodesDoNotMatchSelector()
             throws RepositoryException, NotExecutableException {
         testRootNode.addNode(nodeName1, testNodeType);
-        testRootNode.save();
+        superuser.save();
 
         NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
         NodeTypeIterator it = ntMgr.getPrimaryNodeTypes();
@@ -70,9 +72,10 @@
             NodeType nt = it.nextNodeType();
             if (!testNt.isNodeType(nt.getName())) {
                 // perform test
-                Query q = qomFactory.createQuery(qomFactory.selector(nt.getName(), "s"),
-                        qomFactory.childNode("s", testRoot), null, null);
-                checkResult(q.execute(), new Node[]{});
+                QueryObjectModel qom = qf.createQuery(
+                        qf.selector(nt.getName(), "s"),
+                        qf.childNode("s", testRoot), null, null);
+                checkQOM(qom, new Node[]{});
                 return;
             }
         }
@@ -82,36 +85,60 @@
 
     public void testRelativePath() throws RepositoryException {
         try {
-            Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                    qomFactory.childNode("s", testPath), null, null);
+            Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+                    qf.childNode("s", testPath), null, null);
             q.execute();
             fail("ChildNode with relative path argument must throw InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
         }
+        try {
+            String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+                    "ISCHILDNODE(s, [" + testPath + "])";
+            qm.createQuery(stmt, Query.JCR_SQL2).execute();
+            fail("ISCHILDNODE() with relative path argument must throw InvalidQueryException");
+        } catch (InvalidQueryException e) {
+            // expected
+        }
     }
 
     public void testSyntacticallyInvalidPath() throws RepositoryException {
+        String invalidPath = testRoot + "/" + nodeName1 + "[";
         try {
-            Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                    qomFactory.childNode("s", testRoot + "/" + nodeName1 + "["),
+            Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+                    qf.childNode("s", invalidPath),
                     null, null);
             q.execute();
             fail("ChildNode with syntactically invalid path argument must throw InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
         }
+        try {
+            String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+                    "ISCHILDNODE(s, [" + invalidPath + "])";
+            qm.createQuery(stmt, Query.JCR_SQL2).execute();
+            fail("ISCHILDNODE() with syntactically invalid path argument must throw InvalidQueryException");
+        } catch (InvalidQueryException e) {
+            // expected
+        }
     }
 
     public void testNotASelectorName() throws RepositoryException {
         try {
-            Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                    qomFactory.childNode("x", testRoot), null, null);
+            Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+                    qf.childNode("x", testRoot), null, null);
             q.execute();
-            fail("ChildNode with an invalid selector name must throw InvalidQueryException");
+            fail("ChildNode with an unknown selector name must throw InvalidQueryException");
+        } catch (InvalidQueryException e) {
+            // expected
+        }
+        try {
+            String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+                    "ISCHILDNODE(x, [" + testRoot + "])";
+            qm.createQuery(stmt, Query.JCR_SQL2).execute();
+            fail("ISCHILDNODE() with an unknown selector name must throw InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
         }
     }
-
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeJoinConditionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeJoinConditionTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeJoinConditionTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeJoinConditionTest.java Wed Jul  8 13:57:13 2009
@@ -39,25 +39,25 @@
         super.setUp();
         n1 = testRootNode.addNode(nodeName1, testNodeType);
         n2 = n1.addNode(nodeName2, testNodeType);
-        n2.addMixin(mixReferenceable);
-        testRootNode.save();
+        ensureMixinType(n2, mixReferenceable);
+        superuser.save();
     }
 
     public void testInnerJoin() throws RepositoryException {
-        JoinCondition c = qomFactory.descendantNodeJoinCondition(LEFT, RIGHT);
+        JoinCondition c = qf.descendantNodeJoinCondition(LEFT, RIGHT);
         QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, c);
-        checkResult(qom.execute(), new Node[][]{{n2, n1}});
+        checkQOM(qom, new Node[][]{{n2, n1}});
     }
 
     public void testRightOuterJoin() throws RepositoryException {
-        JoinCondition c = qomFactory.descendantNodeJoinCondition(LEFT, RIGHT);
-        QueryObjectModel qom = createQuery(AbstractJoinTest.JCR_JOIN_TYPE_RIGHT_OUTER, c);
-        checkResult(qom.execute(), new Node[][]{{n2, n1}, {null, n2}});
+        JoinCondition c = qf.descendantNodeJoinCondition(LEFT, RIGHT);
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER, c);
+        checkQOM(qom, new Node[][]{{n2, n1}, {null, n2}});
     }
 
     public void testLeftOuterJoin() throws RepositoryException {
-        JoinCondition c = qomFactory.descendantNodeJoinCondition(LEFT, RIGHT);
-        QueryObjectModel qom = createQuery(AbstractJoinTest.JCR_JOIN_TYPE_LEFT_OUTER, c);
+        JoinCondition c = qf.descendantNodeJoinCondition(LEFT, RIGHT);
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER, c);
         List result = new ArrayList();
         result.add(new Node[]{n2, n1});
         // for each ancestor-or-self of testRootNode check
@@ -79,6 +79,6 @@
             // n1 not yet covered
             result.add(new Node[]{n1, null});
         }
-        checkResult(qom.execute(), (Node[][]) result.toArray(new Node[result.size()][]));
+        checkQOM(qom, (Node[][]) result.toArray(new Node[result.size()][]));
     }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeTest.java Wed Jul  8 13:57:13 2009
@@ -25,43 +25,45 @@
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.query.Query;
 import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.qom.QueryObjectModel;
 
 /**
- * <code>DescendantNodeTest</code>...
+ * <code>DescendantNodeTest</code> contains test cases related to QOM
+ * DescendantNode constraints.
  */
 public class DescendantNodeTest extends AbstractQOMTest {
 
     public void testDescendantNode() throws RepositoryException {
         Node n = testRootNode.addNode(nodeName1, testNodeType);
-        testRootNode.save();
+        superuser.save();
 
-        Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                qomFactory.descendantNode("s", testRoot), null, null);
-        checkResult(q.execute(), new Node[]{n});
+        QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
+                qf.descendantNode("s", testRoot), null, null);
+        checkQOM(qom, new Node[]{n});
     }
 
     public void testDescendantNodes() throws RepositoryException {
         Node n1 = testRootNode.addNode(nodeName1, testNodeType);
         Node n2 = testRootNode.addNode(nodeName2, testNodeType);
         Node n21 = n2.addNode(nodeName1, testNodeType);
-        testRootNode.save();
+        superuser.save();
 
-        Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                qomFactory.descendantNode("s", testRoot), null, null);
-        checkResult(q.execute(), new Node[]{n1, n2, n21});
+        QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
+                qf.descendantNode("s", testRoot), null, null);
+        checkQOM(qom, new Node[]{n1, n2, n21});
     }
 
     public void testPathDoesNotExist() throws RepositoryException {
-        Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                qomFactory.descendantNode("s", testRoot + "/" + nodeName1),
+        QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
+                qf.descendantNode("s", testRoot + "/" + nodeName1),
                 null, null);
-        checkResult(q.execute(), new Node[]{});
+        checkQOM(qom, new Node[]{});
     }
 
     public void testDescendantNodesDoNotMatchSelector()
             throws RepositoryException, NotExecutableException {
         testRootNode.addNode(nodeName1, testNodeType);
-        testRootNode.save();
+        superuser.save();
 
         NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
         NodeTypeIterator it = ntMgr.getPrimaryNodeTypes();
@@ -70,9 +72,9 @@
             NodeType nt = it.nextNodeType();
             if (!testNt.isNodeType(nt.getName())) {
                 // perform test
-                Query q = qomFactory.createQuery(qomFactory.selector(nt.getName(), "s"),
-                        qomFactory.descendantNode("s", testRoot), null, null);
-                checkResult(q.execute(), new Node[]{});
+                QueryObjectModel qom = qf.createQuery(qf.selector(nt.getName(), "s"),
+                        qf.descendantNode("s", testRoot), null, null);
+                checkQOM(qom, new Node[]{});
                 return;
             }
         }
@@ -82,33 +84,57 @@
 
     public void testRelativePath() throws RepositoryException {
         try {
-            Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                    qomFactory.descendantNode("s", testPath), null, null);
+            Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+                    qf.descendantNode("s", testPath), null, null);
             q.execute();
             fail("DescendantNode with relative path argument must throw InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
         }
+        try {
+            String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+                    "ISDESCENDANTNODE(s, [" + testPath + "])";
+            qm.createQuery(stmt, Query.JCR_SQL2).execute();
+            fail("ISDESCENDANTNODE() with relative path argument must throw InvalidQueryException");
+        } catch (InvalidQueryException e) {
+            // expected
+        }
     }
 
     public void testSyntacticallyInvalidPath() throws RepositoryException {
+        String invalidPath = testRoot + "/" + nodeName1 + "[";
         try {
-            Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                    qomFactory.descendantNode("s", testRoot + "/" + nodeName1 +
-                    "["), null, null);
+            Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+                    qf.descendantNode("s", invalidPath), null, null);
             q.execute();
             fail("DescendantNode with syntactically invalid path argument must throw InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
         }
+        try {
+            String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+                    "ISDESCENDANTNODE(s, [" + invalidPath + "])";
+            qm.createQuery(stmt, Query.JCR_SQL2).execute();
+            fail("ISDESCENDANTNODE() with syntactically invalid path argument must throw InvalidQueryException");
+        } catch (InvalidQueryException e) {
+            // expected
+        }
     }
 
     public void testNotASelectorName() throws RepositoryException {
         try {
-            Query q = qomFactory.createQuery(qomFactory.selector(testNodeType, "s"),
-                    qomFactory.descendantNode("x", testRoot), null, null);
+            Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+                    qf.descendantNode("x", testRoot), null, null);
             q.execute();
-            fail("DescendantNode with an invalid selector name must throw InvalidQueryException");
+            fail("DescendantNode with an unknown selector name must throw InvalidQueryException");
+        } catch (InvalidQueryException e) {
+            // expected
+        }
+        try {
+            String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+                    "ISDESCENDANTNODE(x, [" + testRoot + "])";
+            qm.createQuery(stmt, Query.JCR_SQL2).execute();
+            fail("ISDESCENDANTNODE() with an unknown selector name must throw InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
         }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/EquiJoinConditionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/EquiJoinConditionTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/EquiJoinConditionTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/EquiJoinConditionTest.java Wed Jul  8 13:57:13 2009
@@ -41,50 +41,50 @@
         n2 = n1.addNode(nodeName2, testNodeType);
         n2.setProperty(propertyName1, value);
         n2.setProperty(propertyName2, value);
-        n2.addMixin(mixReferenceable);
-        testRootNode.save();
+        ensureMixinType(n2, mixReferenceable);
+        superuser.save();
     }
 
     public void testInnerJoin1() throws RepositoryException {
-        JoinCondition c = qomFactory.equiJoinCondition(
+        JoinCondition c = qf.equiJoinCondition(
                 LEFT, propertyName1, RIGHT, propertyName2);
         QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, c);
-        checkResult(qom.execute(), new Node[][]{{n1, n2}, {n2, n2}});
+        checkQOM(qom, new Node[][]{{n1, n2}, {n2, n2}});
     }
 
     public void testInnerJoin2() throws RepositoryException {
-        JoinCondition c = qomFactory.equiJoinCondition(
+        JoinCondition c = qf.equiJoinCondition(
                 LEFT, propertyName2, RIGHT, propertyName1);
         QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, c);
-        checkResult(qom.execute(), new Node[][]{{n2, n1}, {n2, n2}});
+        checkQOM(qom, new Node[][]{{n2, n1}, {n2, n2}});
     }
 
     public void testRightOuterJoin1() throws RepositoryException {
-        JoinCondition c = qomFactory.equiJoinCondition(
+        JoinCondition c = qf.equiJoinCondition(
                 LEFT, propertyName1, RIGHT, propertyName2);
-        QueryObjectModel qom = createQuery(AbstractJoinTest.JCR_JOIN_TYPE_RIGHT_OUTER, c);
-        checkResult(qom.execute(), new Node[][]{{null, n1}, {n1, n2}, {n2, n2}});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER, c);
+        checkQOM(qom, new Node[][]{{null, n1}, {n1, n2}, {n2, n2}});
     }
 
     public void testRightOuterJoin2() throws RepositoryException {
-        JoinCondition c = qomFactory.equiJoinCondition(
+        JoinCondition c = qf.equiJoinCondition(
                 LEFT, propertyName2, RIGHT, propertyName1);
-        QueryObjectModel qom = createQuery(AbstractJoinTest.JCR_JOIN_TYPE_RIGHT_OUTER, c);
-        checkResult(qom.execute(), new Node[][]{{n2, n1}, {n2, n2}});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER, c);
+        checkQOM(qom, new Node[][]{{n2, n1}, {n2, n2}});
     }
 
     public void testLeftOuterJoin1() throws RepositoryException {
-        JoinCondition c = qomFactory.equiJoinCondition(
+        JoinCondition c = qf.equiJoinCondition(
                 LEFT, propertyName1, RIGHT, propertyName2);
-        QueryObjectModel qom = createQuery(AbstractJoinTest.JCR_JOIN_TYPE_LEFT_OUTER, c);
-        checkResult(qom.execute(), new Node[][]{{n1, n2}, {n2, n2}});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER, c);
+        checkQOM(qom, new Node[][]{{n1, n2}, {n2, n2}});
     }
 
 
     public void testLeftOuterJoin2() throws RepositoryException {
-        JoinCondition c = qomFactory.equiJoinCondition(
+        JoinCondition c = qf.equiJoinCondition(
                 LEFT, propertyName2, RIGHT, propertyName1);
-        QueryObjectModel qom = createQuery(AbstractJoinTest.JCR_JOIN_TYPE_LEFT_OUTER, c);
-        checkResult(qom.execute(), new Node[][]{{n1, null}, {n2, n1}, {n2, n2}});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER, c);
+        checkQOM(qom, new Node[][]{{n1, null}, {n2, n1}, {n2, n2}});
     }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java Wed Jul  8 13:57:13 2009
@@ -21,15 +21,17 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
-import javax.jcr.ValueFactory;
 import javax.jcr.PropertyType;
+import javax.jcr.Binary;
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.Query;
 import javax.jcr.query.qom.QueryObjectModelConstants;
+import javax.jcr.query.qom.QueryObjectModel;
 
 import java.io.ByteArrayInputStream;
-import java.io.InputStream;
 import java.util.Calendar;
+import java.math.BigDecimal;
 
 /**
  * <code>LengthTest</code> performs tests with the Query Object Model length
@@ -39,131 +41,145 @@
 
     private Node node;
 
-    private ValueFactory vf;
 
     protected void setUp() throws Exception {
         super.setUp();
         node = testRootNode.addNode(nodeName1, testNodeType);
-        testRootNode.save();
-        vf = superuser.getValueFactory();
+        superuser.save();
     }
 
     protected void tearDown() throws Exception {
         node = null;
-        vf = null;
         super.tearDown();
     }
 
     public void testStringLength() throws RepositoryException {
         node.setProperty(propertyName1, "abc");
-        node.save();
+        superuser.save();
         checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
     
     public void testBinaryLength() throws RepositoryException {
         byte[] data = "abc".getBytes();
-        node.setProperty(propertyName1, new ByteArrayInputStream(data));
-        node.save();
+        Binary b = vf.createBinary(new ByteArrayInputStream(data));
+        try {
+            node.setProperty(propertyName1, b);
+        } finally {
+            b.dispose();
+        }
+        superuser.save();
         checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
 
     public void testLongLength() throws RepositoryException {
         node.setProperty(propertyName1, 123);
-        node.save();
+        superuser.save();
         checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
 
     public void testDoubleLength() throws RepositoryException {
         node.setProperty(propertyName1, Math.PI);
-        node.save();
+        superuser.save();
         checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
 
     public void testDateLength() throws RepositoryException {
         node.setProperty(propertyName1, Calendar.getInstance());
-        node.save();
+        superuser.save();
         checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
 
     public void testBooleanLength() throws RepositoryException {
         node.setProperty(propertyName1, false);
-        node.save();
+        superuser.save();
         checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
 
     public void testNameLength() throws RepositoryException {
-        // TODO
+        node.setProperty(propertyName1, vf.createValue(node.getName(), PropertyType.NAME));
+        superuser.save();
+        checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
 
     public void testPathLength() throws RepositoryException {
-        // TODO
+        node.setProperty(propertyName1, vf.createValue(node.getPath(), PropertyType.PATH));
+        superuser.save();
+        checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
 
     public void testReferenceLength() throws RepositoryException, NotExecutableException {
-        try {
-            if (!node.isNodeType(mixReferenceable)) {
-                node.addMixin(mixReferenceable);
-                node.save();
-            }
-        } catch (RepositoryException e) {
-            throw new NotExecutableException("Cannot add mix:referenceable to node");
-        }
+        ensureMixinType(node, mixReferenceable);
+        superuser.save();
         node.setProperty(propertyName1, node);
-        node.save();
+        superuser.save();
         checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
 
-    public void testWeakReferenceLength() throws RepositoryException {
-        // TODO
+    public void testWeakReferenceLength()
+            throws RepositoryException, NotExecutableException {
+        ensureMixinType(node, mixReferenceable);
+        superuser.save();
+        node.setProperty(propertyName1, vf.createValue(node, true));
+        superuser.save();
+        checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
 
     public void testURILength() throws RepositoryException {
-        // TODO
+        node.setProperty(propertyName1, vf.createValue("http://example.com", PropertyType.URI));
+        superuser.save();
+        checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
 
     public void testDecimalLength() throws RepositoryException {
-        // TODO
+        node.setProperty(propertyName1, new BigDecimal(123));
+        superuser.save();
+        checkOperators(propertyName1, node.getProperty(propertyName1).getLength());
     }
 
     //------------------------< conversion tests >------------------------------
 
     public void testLengthStringLiteral() throws RepositoryException {
         node.setProperty(propertyName1, "abc");
-        node.save();
+        superuser.save();
 
         String length = String.valueOf(node.getProperty(propertyName1).getLength());
-        executeQuery(propertyName1, AbstractQOMTest.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
+        executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
     }
 
     public void testLengthBinaryLiteral() throws RepositoryException {
         node.setProperty(propertyName1, "abc");
-        node.save();
+        superuser.save();
 
         String length = String.valueOf(node.getProperty(propertyName1).getLength());
-        InputStream in = new ByteArrayInputStream(length.getBytes());
-        executeQuery(propertyName1, AbstractQOMTest.JCR_OPERATOR_EQUAL_TO, vf.createValue(in));
+        Binary b = vf.createBinary(new ByteArrayInputStream(length.getBytes()));
+        try {
+            executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
+                    vf.createValue(b));
+        } finally {
+            b.dispose();
+        }
     }
 
     public void testLengthDoubleLiteral() throws RepositoryException {
         node.setProperty(propertyName1, "abc");
-        node.save();
+        superuser.save();
 
         double length = node.getProperty(propertyName1).getLength();
-        executeQuery(propertyName1, AbstractQOMTest.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
+        executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
     }
 
     public void testLengthDateLiteral() throws RepositoryException {
         node.setProperty(propertyName1, "abc");
-        node.save();
+        superuser.save();
 
         Calendar length = Calendar.getInstance();
         length.setTimeInMillis(node.getProperty(propertyName1).getLength());
-        executeQuery(propertyName1, AbstractQOMTest.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
+        executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
     }
 
     public void testLengthBooleanLiteral() throws RepositoryException {
         try {
-            executeQuery(propertyName1, AbstractQOMTest.JCR_OPERATOR_EQUAL_TO, vf.createValue(false));
+            executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(false));
             fail("Boolean literal cannot be converted to long");
         } catch (InvalidQueryException e) {
             // expected
@@ -172,7 +188,7 @@
 
     public void testLengthNameLiteral() throws RepositoryException {
         try {
-            executeQuery(propertyName1, AbstractQOMTest.JCR_OPERATOR_EQUAL_TO, vf.createValue(
+            executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(
                     propertyName1, PropertyType.NAME));
             fail("Name literal cannot be converted to long");
         } catch (InvalidQueryException e) {
@@ -182,7 +198,7 @@
 
     public void testLengthPathLiteral() throws RepositoryException {
         try {
-            executeQuery(propertyName1, AbstractQOMTest.JCR_OPERATOR_EQUAL_TO, vf.createValue(
+            executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(
                     node.getPath(), PropertyType.PATH));
             fail("Path literal cannot be converted to long");
         } catch (InvalidQueryException e) {
@@ -191,40 +207,51 @@
     }
 
     public void testLengthReferenceLiteral() throws RepositoryException, NotExecutableException {
+        ensureMixinType(node, mixReferenceable);
+        superuser.save();
         try {
-            if (!node.isNodeType(mixReferenceable)) {
-                node.addMixin(mixReferenceable);
-                node.save();
-            }
-        } catch (RepositoryException e) {
-            throw new NotExecutableException("Cannot add mix:referenceable to node");
-        }
-        try {
-            executeQuery(propertyName1, AbstractQOMTest.JCR_OPERATOR_EQUAL_TO, vf.createValue(node));
+            executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(node));
             fail("Reference literal cannot be converted to long");
         } catch (InvalidQueryException e) {
             // expected
         }
     }
 
-    public void testLengthWeakReferenceLiteral() throws RepositoryException {
-        // TODO
+    public void testLengthWeakReferenceLiteral() throws RepositoryException, NotExecutableException {
+        ensureMixinType(node, mixReferenceable);
+        superuser.save();
+        try {
+            executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(node, true));
+            fail("Reference literal cannot be converted to long");
+        } catch (InvalidQueryException e) {
+            // expected
+        }
     }
 
     public void testLengthURILiteral() throws RepositoryException {
-        // TODO
+        try {
+            executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
+                    vf.createValue(node.getPath(), PropertyType.URI));
+            fail("URI literal cannot be converted to long");
+        } catch (InvalidQueryException e) {
+            // expected
+        }
     }
 
     public void testLengthDecimalLiteral() throws RepositoryException {
-        // TODO
+        node.setProperty(propertyName1, "abc");
+        superuser.save();
+
+        BigDecimal length = new BigDecimal(node.getProperty(propertyName1).getLength());
+        executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
     }
 
     //------------------------< internal helpers >------------------------------
 
     private void checkOperators(String propertyName,
                                 long length) throws RepositoryException {
-        checkLength(propertyName, AbstractQOMTest.JCR_OPERATOR_EQUAL_TO, length, true);
-        checkLength(propertyName, AbstractQOMTest.JCR_OPERATOR_EQUAL_TO, length - 1, false);
+        checkLength(propertyName, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, length, true);
+        checkLength(propertyName, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, length - 1, false);
 
         checkLength(propertyName, QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN, length - 1, true);
         checkLength(propertyName, QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN, length, false);
@@ -238,44 +265,53 @@
         checkLength(propertyName, QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO, length, true);
         checkLength(propertyName, QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO, length - 1, false);
 
-        checkLength(propertyName, AbstractQOMTest.JCR_OPERATOR_NOT_EQUAL_TO, length - 1, true);
-        checkLength(propertyName, AbstractQOMTest.JCR_OPERATOR_NOT_EQUAL_TO, length, false);
+        checkLength(propertyName, QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO, length - 1, true);
+        checkLength(propertyName, QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO, length, false);
     }
 
     private void checkLength(String propertyName,
                              String operator,
                              long length,
                              boolean matches) throws RepositoryException {
-        Node[] result;
+        Node[] expected;
         if (matches) {
-            result = new Node[]{node};
+            expected = new Node[]{node};
         } else {
-            result = new Node[0];
+            expected = new Node[0];
+        }
+        QueryResult[] results = executeQueries(propertyName, operator, length);
+        for (int i = 0; i < results.length; i++) {
+            checkResult(results[i], expected);
         }
-        checkResult(executeQuery(propertyName, operator, length), result);
     }
 
-    private QueryResult executeQuery(String propertyName,
-                                     String operator,
-                                     long length) throws RepositoryException {
+    private QueryResult[] executeQueries(String propertyName,
+                                         String operator,
+                                         long length)
+            throws RepositoryException {
         Value v = vf.createValue(length);
-        return executeQuery(propertyName, operator, v);
+        return executeQueries(propertyName, operator, v);
     }
 
-    private QueryResult executeQuery(String propertyName,
-                                     String operator,
-                                     Value length) throws RepositoryException {
-        return qomFactory.createQuery(
-                qomFactory.selector(testNodeType, "s"),
-                qomFactory.and(
-                        qomFactory.childNode("s", testRoot),
-                        qomFactory.comparison(
-                                qomFactory.length(
-                                        qomFactory.propertyValue(
+    private QueryResult[] executeQueries(String propertyName,
+                                         String operator,
+                                         Value length)
+            throws RepositoryException {
+        QueryObjectModel qom = qf.createQuery(
+                qf.selector(testNodeType, "s"),
+                qf.and(
+                        qf.childNode("s", testRoot),
+                        qf.comparison(
+                                qf.length(
+                                        qf.propertyValue(
                                                 "s", propertyName)),
                                 operator,
-                                qomFactory.literal(length))
+                                qf.literal(length))
 
-                ), null, null).execute();
+                ), null, null);
+        QueryResult[] results = new QueryResult[2];
+        results[0] = qom.execute();
+        results[1] = qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute();
+        return results;
     }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeLocalNameTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeLocalNameTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeLocalNameTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeLocalNameTest.java Wed Jul  8 13:57:13 2009
@@ -22,13 +22,16 @@
 import javax.jcr.PropertyType;
 import javax.jcr.query.Query;
 import javax.jcr.query.qom.QueryObjectModelConstants;
+import javax.jcr.query.qom.QueryObjectModel;
 
 import java.util.Calendar;
+import java.math.BigDecimal;
+
+import org.apache.jackrabbit.test.NotExecutableException;
 
 /**
  * <code>NodeLocalNameTest</code> checks if conversion of literals is correctly
  * performed and operators work as specified.
- * TODO: assumes https://jsr-283.dev.java.net/issues/show_bug.cgi?id=483 gets resolved as initially proposed
  */
 public class NodeLocalNameTest extends AbstractQOMTest {
 
@@ -39,7 +42,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         node1 = testRootNode.addNode(nodeName1, testNodeType);
-        testRootNode.save();
+        superuser.save();
         int colon = nodeName1.indexOf(':');
         if (colon != -1) {
             nodeLocalName = nodeName1.substring(colon + 1);
@@ -55,95 +58,103 @@
 
     public void testStringLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(nodeLocalName);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
         checkResult(q.execute(), new Node[]{node1});
     }
 
     public void testStringLiteralInvalidName() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue("[" + nodeLocalName);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
         checkResult(q.execute(), new Node[]{});
     }
 
     public void testBinaryLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(
                 nodeLocalName, PropertyType.BINARY);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
-        checkResult(q.execute(), new Node[]{node1});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{node1});
     }
 
     public void testDateLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(Calendar.getInstance());
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
-        checkResult(q.execute(), new Node[]{});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{});
     }
 
     public void testDoubleLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(Math.PI);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
-        checkResult(q.execute(), new Node[]{});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{});
     }
 
     public void testDecimalLiteral() throws RepositoryException {
-        // TODO must not match node
+        Value literal = superuser.getValueFactory().createValue(new BigDecimal(283));
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{});
     }
 
     public void testLongLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(283);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
-        checkResult(q.execute(), new Node[]{});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{});
     }
 
     public void testBooleanLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(true);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
-        checkResult(q.execute(), new Node[]{});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{});
     }
 
     public void testNameLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(
                 nodeLocalName, PropertyType.NAME);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
-        checkResult(q.execute(), new Node[]{node1});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{node1});
     }
 
     public void testPathLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(
                 nodeLocalName, PropertyType.PATH);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
-        checkResult(q.execute(), new Node[]{node1});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{node1});
 
         literal = superuser.getValueFactory().createValue(
                 node1.getPath(), PropertyType.PATH);
-        q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
-        checkResult(q.execute(), new Node[]{});
+        qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{});
 
         literal = superuser.getValueFactory().createValue(
                 nodeName1 + "/" + nodeName1, PropertyType.PATH);
-        q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
-        checkResult(q.execute(), new Node[]{});
+        qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{});
     }
 
-    public void testReferenceLiteral() throws RepositoryException {
-        if (!node1.isNodeType(mixReferenceable)) {
-            node1.addMixin(mixReferenceable);
-        }
-        node1.save();
+    public void testReferenceLiteral() throws RepositoryException,
+            NotExecutableException {
+        ensureMixinType(node1, mixReferenceable);
+        superuser.save();
         Value literal = superuser.getValueFactory().createValue(node1);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
-        checkResult(q.execute(), new Node[]{});
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{});
     }
 
-    public void testWeakReferenceLiteral() throws RepositoryException {
-        // TODO must not match node
+    public void testWeakReferenceLiteral() throws RepositoryException,
+            NotExecutableException {
+        ensureMixinType(node1, mixReferenceable);
+        superuser.save();
+        Value literal = superuser.getValueFactory().createValue(node1, true);
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{});
     }
 
     public void testURILiteral() throws RepositoryException {
-        // TODO must not match node
+        Value literal = superuser.getValueFactory().createValue("http://example.com", PropertyType.URI);
+        QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkQOM(qom, new Node[]{});
     }
 
     public void testEqualTo() throws RepositoryException {
-        checkOperator(AbstractQOMTest.JCR_OPERATOR_EQUAL_TO, false, true, false);
+        checkOperator(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, false, true, false);
     }
 
     public void testGreaterThan() throws RepositoryException {
@@ -167,7 +178,7 @@
     }
 
     public void testNotEqualTo() throws RepositoryException {
-        checkOperator(AbstractQOMTest.JCR_OPERATOR_NOT_EQUAL_TO, true, false, true);
+        checkOperator(QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO, true, false, true);
     }
 
     //------------------------------< helper >----------------------------------
@@ -187,8 +198,8 @@
                                             boolean matches)
             throws RepositoryException {
         Value value = superuser.getValueFactory().createValue(literal);
-        Query q = createQuery(operator, value);
-        checkResult(q.execute(), matches ? new Node[]{node1} : new Node[0]);
+        QueryObjectModel qom = createQuery(operator, value);
+        checkQOM(qom, matches ? new Node[]{node1} : new Node[0]);
     }
 
     private String createLexicographicallyGreater(String name) {
@@ -203,16 +214,16 @@
         return tmp.toString();
     }
 
-    private Query createQuery(String operator, Value literal)
+    private QueryObjectModel createQuery(String operator, Value literal)
             throws RepositoryException {
-        return qomFactory.createQuery(
-                qomFactory.selector(testNodeType, "s"),
-                qomFactory.and(
-                        qomFactory.childNode("s", testRoot),
-                        qomFactory.comparison(
-                                qomFactory.nodeLocalName("s"),
+        return qf.createQuery(
+                qf.selector(testNodeType, "s"),
+                qf.and(
+                        qf.childNode("s", testRoot),
+                        qf.comparison(
+                                qf.nodeLocalName("s"),
                                 operator,
-                                qomFactory.literal(literal)
+                                qf.literal(literal)
                         )
                 ), null, null);
     }



Mime
View raw message