jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r770697 - in /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit: api/jsr283/query/qom/BindVariableValueTest.java api/jsr283/query/qom/NodeNameTest.java core/query/UpperLowerCaseQueryTest.java
Date Fri, 01 May 2009 14:45:34 GMT
Author: jukka
Date: Fri May  1 14:45:34 2009
New Revision: 770697

URL: http://svn.apache.org/viewvc?rev=770697&view=rev
Log:
JCR-2094: Use an enumeration for QOM operators

Updated more test cases to use the Operator enumeration. This works around the problems caused
by the incorrect QOM constants in JCR 2.0 PFD.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/BindVariableValueTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/NodeNameTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/BindVariableValueTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/BindVariableValueTest.java?rev=770697&r1=770696&r2=770697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/BindVariableValueTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/BindVariableValueTest.java
Fri May  1 14:45:34 2009
@@ -21,6 +21,9 @@
 import javax.jcr.ValueFactory;
 import javax.jcr.Value;
 import javax.jcr.query.Query;
+
+import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+
 import java.util.Calendar;
 
 /**
@@ -49,9 +52,9 @@
                 qomFactory.selector(testNodeType, "s"),
                 qomFactory.and(
                         qomFactory.childNode("s", testRoot),
-                        qomFactory.comparison(
+                        Operator.EQ.comparison(
+                                qomFactory,
                                 qomFactory.propertyValue("s", propertyName1),
-                                JCR_OPERATOR_EQUAL_TO,
                                 qomFactory.bindVariable("v")
                         )
                 ), null, null);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/NodeNameTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/NodeNameTest.java?rev=770697&r1=770696&r2=770697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/NodeNameTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/NodeNameTest.java
Fri May  1 14:45:34 2009
@@ -22,6 +22,9 @@
 import javax.jcr.PropertyType;
 import javax.jcr.query.Query;
 import javax.jcr.query.InvalidQueryException;
+
+import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+
 import java.util.Calendar;
 
 /**
@@ -45,14 +48,14 @@
 
     public void testStringLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(nodeName1);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{node1});
     }
 
     public void testStringLiteralInvalidName() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue("[" + nodeName1);
         try {
-            createQuery(JCR_OPERATOR_EQUAL_TO, literal).execute();
+            createQuery(Operator.EQ, literal).execute();
             fail("NodeName comparison with STRING that cannot be converted to NAME must fail
with InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
@@ -62,14 +65,14 @@
     public void testBinaryLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(
                 nodeName1, PropertyType.BINARY);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{node1});
     }
 
     public void testDateLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(Calendar.getInstance());
         try {
-            createQuery(JCR_OPERATOR_EQUAL_TO, literal).execute();
+            createQuery(Operator.EQ, literal).execute();
             fail("NodeName comparison with DATE must fail with InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
@@ -79,7 +82,7 @@
     public void testDoubleLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(Math.PI);
         try {
-            createQuery(JCR_OPERATOR_EQUAL_TO, literal).execute();
+            createQuery(Operator.EQ, literal).execute();
             fail("NodeName comparison with DOUBLE must fail with InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
@@ -93,7 +96,7 @@
     public void testLongLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(283);
         try {
-            createQuery(JCR_OPERATOR_EQUAL_TO, literal).execute();
+            createQuery(Operator.EQ, literal).execute();
             fail("NodeName comparison with LONG must fail with InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
@@ -103,7 +106,7 @@
     public void testBooleanLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(true);
         try {
-            createQuery(JCR_OPERATOR_EQUAL_TO, literal).execute();
+            createQuery(Operator.EQ, literal).execute();
             fail("NodeName comparison with BOOLEAN must fail with InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
@@ -113,20 +116,20 @@
     public void testNameLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(
                 nodeName1, PropertyType.NAME);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{node1});
     }
 
     public void testPathLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(
                 nodeName1, PropertyType.PATH);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{node1});
 
         literal = superuser.getValueFactory().createValue(
                 node1.getPath(), PropertyType.PATH);
         try {
-            createQuery(JCR_OPERATOR_EQUAL_TO, literal).execute();
+            createQuery(Operator.EQ, literal).execute();
             fail("NodeName comparison with absolute PATH must fail with InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
@@ -135,7 +138,7 @@
         literal = superuser.getValueFactory().createValue(
                 nodeName1 + "/" + nodeName1, PropertyType.PATH);
         try {
-            createQuery(JCR_OPERATOR_EQUAL_TO, literal).execute();
+            createQuery(Operator.EQ, literal).execute();
             fail("NodeName comparison with PATH length >1 must fail with InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
@@ -149,7 +152,7 @@
         node1.save();
         Value literal = superuser.getValueFactory().createValue(node1);
         try {
-            createQuery(JCR_OPERATOR_EQUAL_TO, literal).execute();
+            createQuery(Operator.EQ, literal).execute();
             fail("NodeName comparison with REFERENCE must fail with InvalidQueryException");
         } catch (InvalidQueryException e) {
             // expected
@@ -174,16 +177,16 @@
     }
 
     public void testEqualTo() throws RepositoryException {
-        checkOperator(JCR_OPERATOR_EQUAL_TO, false, true, false);
+        checkOperator(Operator.EQ, false, true, false);
     }
 
     public void testNotEqualTo() throws RepositoryException {
-        checkOperator(JCR_OPERATOR_NOT_EQUAL_TO, true, false, true);
+        checkOperator(Operator.NE, true, false, true);
     }
 
     //------------------------------< helper >----------------------------------
 
-    private void checkOperator(String operator,
+    private void checkOperator(Operator operator,
                                boolean matchesLesser,
                                boolean matchesEqual,
                                boolean matchesGreater)
@@ -194,7 +197,7 @@
     }
 
     private void checkOperatorSingleLiteral(String literal,
-                                            String operator,
+                                            Operator operator,
                                             boolean matches)
             throws RepositoryException {
         Value value = superuser.getValueFactory().createValue(literal);
@@ -214,14 +217,14 @@
         return tmp.toString();
     }
 
-    private Query createQuery(String operator, Value literal) throws RepositoryException
{
+    private Query createQuery(Operator operator, Value literal) throws RepositoryException
{
         return qomFactory.createQuery(
                 qomFactory.selector(testNodeType, "s"),
                 qomFactory.and(
                         qomFactory.childNode("s", testRoot),
-                        qomFactory.comparison(
+                        operator.comparison(
+                                qomFactory,
                                 qomFactory.nodeName("s"),
-                                operator,
                                 qomFactory.literal(literal)
                         )
                 ), null, null);

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java?rev=770697&r1=770696&r2=770697&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/UpperLowerCaseQueryTest.java
Fri May  1 14:45:34 2009
@@ -16,9 +16,7 @@
  */
 package org.apache.jackrabbit.core.query;
 
-import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Random;
 import java.util.Set;
 
@@ -29,6 +27,8 @@
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.qom.QueryObjectModelConstants;
 
+import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+
 /**
  * <code>UpperLowerCaseQueryTest</code> tests the functions fn:lower-case() and
  * fn:upper-case() in XPath, LOWER() and UPPER() in SQL and UpperCase and
@@ -36,44 +36,28 @@
  */
 public class UpperLowerCaseQueryTest extends AbstractQueryTest implements QueryObjectModelConstants
{
 
-    /**
-     * Maps operator strings to QueryObjectModelConstants.
-     */
-    private static final Map<String, String> OPERATORS =
-        new HashMap<String, String>();
-
-    static {
-        OPERATORS.put("=", JCR_OPERATOR_EQUAL_TO);
-        OPERATORS.put(">", JCR_OPERATOR_GREATER_THAN);
-        OPERATORS.put(">=", JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO);
-        OPERATORS.put("<", JCR_OPERATOR_LESS_THAN);
-        OPERATORS.put("<=", JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO);
-        OPERATORS.put("like", JCR_OPERATOR_LIKE);
-        OPERATORS.put("!=", JCR_OPERATOR_NOT_EQUAL_TO);
-    }
-
     public void testEqualsGeneralComparison() throws RepositoryException {
         check(new String[]{"foo", "Foo", "fOO", "FOO", "fooBar", "fo", "fooo"},
-                "=",
+                Operator.EQ,
                 "foo",
                 new boolean[]{true, true, true, true, false, false, false});
-        check(new String[]{"foo"}, "=", "", new boolean[]{false});
-        check(new String[]{""}, "=", "", new boolean[]{true});
+        check(new String[]{"foo"}, Operator.EQ, "", new boolean[]{false});
+        check(new String[]{""}, Operator.EQ, "", new boolean[]{true});
     }
 
     public void testGreaterThanGeneralComparison() throws RepositoryException {
         // check edges
         check(new String[]{"foo", "FOO", "FoO", "fOo", "FON", "fon", "fo", "FO"},
-                ">",
+                Operator.GT,
                 "foo",
                 new boolean[]{false, false, false, false, false, false, false, false});
         check(new String[]{"foo ", "FOOa", "FoOO", "fOo1", "FOp", "foP", "fp", "g", "G"},
-                ">",
+                Operator.GT,
                 "foo",
                 new boolean[]{true, true, true, true, true, true, true, true, true});
         // check combinations
         check(new String[]{"foo", "fooo", "FooO", "fo", "FON", "fon"},
-                ">",
+                Operator.GT,
                 "foo",
                 new boolean[]{false, true, true, false, false, false});
     }
@@ -81,16 +65,16 @@
     public void testLessThanGeneralComparison() throws RepositoryException {
         // check edges
         check(new String[]{"foo", "FOO", "FoO", "fOo", "foOo", "foo ", "fooa", "fop"},
-                "<",
+                Operator.LT,
                 "foo",
                 new boolean[]{false, false, false, false, false, false, false, false});
         check(new String[]{"fo", "FOn", "FoN", "fO", "FO1", "fn", "fN", "E", "e"},
-                "<",
+                Operator.LT,
                 "foo",
                 new boolean[]{true, true, true, true, true, true, true, true, true});
         // check combinations
         check(new String[]{"foo", "fooo", "FooO", "fo", "FON", "fon"},
-                "<",
+                Operator.LT,
                 "foo",
                 new boolean[]{false, false, false, true, true, true});
     }
@@ -98,16 +82,16 @@
     public void testGreaterEqualsGeneralComparison() throws RepositoryException {
         // check edges
         check(new String[]{"fo", "FO", "Fon", "fONo", "FON", "fO", "fo", "FO"},
-                ">=",
+                Operator.GE,
                 "foo",
                 new boolean[]{false, false, false, false, false, false, false, false});
         check(new String[]{"foo", "FoO", "FoOO", "fOo1", "FOp", "foP", "fp", "g", "G"},
-                ">=",
+                Operator.GE,
                 "foo",
                 new boolean[]{true, true, true, true, true, true, true, true, true});
         // check combinations
         check(new String[]{"foo", "fooo", "FOo", "fo", "FON", "fon"},
-                ">=",
+                Operator.GE,
                 "foo",
                 new boolean[]{true, true, true, false, false, false});
     }
@@ -115,16 +99,16 @@
     public void testLessEqualsGeneralComparison() throws RepositoryException {
         // check edges
         check(new String[]{"fooo", "FOoo", "Fop", "fOpo", "FOP", "fOo ", "fp", "G"},
-                "<=",
+                Operator.LE,
                 "foo",
                 new boolean[]{false, false, false, false, false, false, false, false});
         check(new String[]{"foo", "FoO", "Foo", "fOn", "FO", "fo", "f", "E", "e"},
-                "<=",
+                Operator.LE,
                 "foo",
                 new boolean[]{true, true, true, true, true, true, true, true, true});
         // check combinations
         check(new String[]{"foo", "fo", "FOo", "fop", "FOP", "fooo"},
-                "<=",
+                Operator.LE,
                 "foo",
                 new boolean[]{true, true, true, false, false, false});
     }
@@ -132,35 +116,35 @@
     public void testNotEqualsGeneralComparison() throws RepositoryException {
         // check edges
         check(new String[]{"fooo", "FOoo", "Fop", "fOpo", "FOP", "fOo ", "fp", "G", ""},
-                "!=",
+                Operator.NE,
                 "foo",
                 new boolean[]{true, true, true, true, true, true, true, true, true});
         check(new String[]{"foo", "FoO", "Foo", "foO", "FOO"},
-                "!=",
+                Operator.NE,
                 "foo",
                 new boolean[]{false, false, false, false, false});
         // check combinations
         check(new String[]{"foo", "fo", "FOo", "fop", "FOP", "fooo"},
-                "!=",
+                Operator.NE,
                 "foo",
                 new boolean[]{false, true, false, true, true, true});
     }
 
     public void testLikeComparison() throws RepositoryException {
         check(new String[]{"foo", "Foo", "fOO", "FO "},
-                "like",
+                Operator.LIKE,
                 "fo_",
                 new boolean[]{true, true, true, true});
         check(new String[]{"foo", "Foo", "fOO", "FOO"},
-                "like",
+                Operator.LIKE,
                 "f_o",
                 new boolean[]{true, true, true, true});
         check(new String[]{"foo", "Foo", "fOO", " OO"},
-                "like",
+                Operator.LIKE,
                 "_oo",
                 new boolean[]{true, true, true, true});
         check(new String[]{"foo", "Foa", "fOO", "FO", "foRm", "fPo", "fno", "FPo", "Fno"},
-                "like",
+                Operator.LIKE,
                 "fo%",
                 new boolean[]{true, true, true, true, true, false, false, false, false});
     }
@@ -190,25 +174,25 @@
                 values[n] = value;
             }
             pattern += "%";
-            check(values, "like", pattern, matches);
+            check(values, Operator.LIKE, pattern, matches);
         }
     }
 
     public void testRangeWithEmptyString() throws RepositoryException {
         check(new String[]{" ", "a", "A", "1", "3", "!", "@"},
-                ">",
+                Operator.GT,
                 "",
                 new boolean[]{true, true, true, true, true, true, true});
         check(new String[]{"", "a", "A", "1", "3", "!", "@"},
-                ">=",
+                Operator.GE,
                 "",
                 new boolean[]{true, true, true, true, true, true, true});
         check(new String[]{"", "a", "A", "1", "3", "!", "@"},
-                "<",
+                Operator.LT,
                 "",
                 new boolean[]{false, false, false, false, false, false, false});
         check(new String[]{"", "a", "A", "1", "3", "!", "@"},
-                "<=",
+                Operator.LE,
                 "",
                 new boolean[]{true, false, false, false, false, false, false});
     }
@@ -238,7 +222,7 @@
 
     //----------------------------< internal >----------------------------------
 
-    private void check(String[] values, String operation, String queryTerm, boolean[] matches)
+    private void check(String[] values, Operator operator, String queryTerm, boolean[] matches)
             throws RepositoryException {
         if (values.length != matches.length) {
             throw new IllegalArgumentException("values and matches must have same length");
@@ -273,25 +257,18 @@
         testRootNode.save();
 
         Node[] nodes = matchingNodes.toArray(new Node[matchingNodes.size()]);
-        String sqlOperation = operation;
-        if (operation.equals("!=")) {
-            sqlOperation = "<>";
-        }
 
         // run queries with lower-case
-        String xpath = testPath;
-        if (operation.equals("like")) {
-            xpath += "/*[jcr:like(fn:lower-case(@" + propertyName1 +
-                    "), '" + queryTerm.toLowerCase() + "')]";
-        } else {
-            xpath += "/*[fn:lower-case(@" + propertyName1 +
-                    ") " + operation + " '" + queryTerm.toLowerCase() + "']";
-        }
-        executeXPathQuery(xpath, nodes);
-
-        String sql = "select * from nt:base where jcr:path like '" +
-                testRoot + "/%' and LOWER(" + propertyName1 + ") " +
-                sqlOperation + " '" + queryTerm.toLowerCase() + "'";
+        String xpath = operator.formatXpath(
+                "fn:lower-case(@" + propertyName1 + ")",
+                "'" + queryTerm.toLowerCase() + "'");
+        executeXPathQuery(testPath + "/*[" + xpath + "]", nodes);
+
+        String sql = "select * from nt:base where "
+            + "jcr:path like '" + testRoot + "/%' and "
+            + operator.formatSql(
+                    "LOWER(" + propertyName1 + ")",
+                    "'" + queryTerm.toLowerCase() + "'");
         executeSQLQuery(sql, nodes);
 
         QueryResult result = qomFactory.createQuery(
@@ -301,7 +278,7 @@
                         qomFactory.comparison(
                                 qomFactory.lowerCase(
                                         qomFactory.propertyValue("s", propertyName1)),
-                                getOperatorForString(operation),
+                                operator.toString(),
                                 qomFactory.literal(
                                         superuser.getValueFactory().createValue(
                                                 queryTerm.toLowerCase()))
@@ -310,29 +287,26 @@
         checkResult(result, nodes);
 
         // run queries with upper-case
-        xpath = testPath;
-        if (operation.equals("like")) {
-            xpath += "/*[jcr:like(fn:upper-case(@" + propertyName1 +
-                    "), '" + queryTerm.toUpperCase() + "')]";
-        } else {
-            xpath += "/*[fn:upper-case(@" + propertyName1 +
-                    ") " + operation + " '" + queryTerm.toUpperCase() + "']";
-        }
-        executeXPathQuery(xpath, nodes);
-
-        sql = "select * from nt:base where jcr:path like '" +
-                testRoot + "/%' and UPPER(" + propertyName1 + ") " +
-                sqlOperation + " '" + queryTerm.toUpperCase() + "'";
+        xpath = operator.formatXpath(
+                "fn:upper-case(@" + propertyName1 + ")",
+                "'" + queryTerm.toUpperCase() + "'");
+        executeXPathQuery(testPath + "/*[" + xpath + "]", nodes);
+
+        sql = "select * from nt:base where "
+            + "jcr:path like '" + testRoot + "/%' and "
+            + operator.formatSql(
+                    "UPPER(" + propertyName1 + ")",
+                    "'" + queryTerm.toUpperCase() + "'");
         executeSQLQuery(sql, nodes);
 
         result = qomFactory.createQuery(
                 qomFactory.selector(testNodeType, "s"),
                 qomFactory.and(
                         qomFactory.childNode("s", testRoot),
-                        qomFactory.comparison(
+                        operator.comparison(
+                                qomFactory,
                                 qomFactory.upperCase(
                                         qomFactory.propertyValue("s", propertyName1)),
-                                getOperatorForString(operation),
                                 qomFactory.literal(
                                         superuser.getValueFactory().createValue(
                                                 queryTerm.toUpperCase()))
@@ -345,7 +319,4 @@
         return pool.charAt(random.nextInt(pool.length()));
     }
 
-    protected static String getOperatorForString(String operator) {
-        return OPERATORS.get(operator);
-    }
 }



Mime
View raw message