You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2009/05/01 15:38:17 UTC

svn commit: r770676 - in /jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom: LengthTest.java NodeLocalNameTest.java QueryObjectModelFactoryTest.java

Author: jukka
Date: Fri May  1 13:38:16 2009
New Revision: 770676

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

Use the Operator enumeration in a few tests in -core

Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/LengthTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/NodeLocalNameTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/QueryObjectModelFactoryTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/LengthTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/LengthTest.java?rev=770676&r1=770675&r2=770676&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/LengthTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/LengthTest.java Fri May  1 13:38:16 2009
@@ -16,18 +16,20 @@
  */
 package org.apache.jackrabbit.api.jsr283.query.qom;
 
-import org.apache.jackrabbit.test.NotExecutableException;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Calendar;
 
 import javax.jcr.Node;
+import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
-import javax.jcr.PropertyType;
-import javax.jcr.query.QueryResult;
 import javax.jcr.query.InvalidQueryException;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.Calendar;
+import javax.jcr.query.QueryResult;
+
+import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+import org.apache.jackrabbit.test.NotExecutableException;
 
 /**
  * <code>LengthTest</code> performs tests with the Query Object Model length
@@ -130,7 +132,7 @@
         node.save();
 
         String length = String.valueOf(node.getProperty(propertyName1).getLength());
-        executeQuery(propertyName1, JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
+        executeQuery(propertyName1, Operator.EQ, vf.createValue(length));
     }
 
     public void testLengthBinaryLiteral() throws RepositoryException {
@@ -139,7 +141,7 @@
 
         String length = String.valueOf(node.getProperty(propertyName1).getLength());
         InputStream in = new ByteArrayInputStream(length.getBytes());
-        executeQuery(propertyName1, JCR_OPERATOR_EQUAL_TO, vf.createValue(in));
+        executeQuery(propertyName1, Operator.EQ, vf.createValue(in));
     }
 
     public void testLengthDoubleLiteral() throws RepositoryException {
@@ -147,7 +149,7 @@
         node.save();
 
         double length = node.getProperty(propertyName1).getLength();
-        executeQuery(propertyName1, JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
+        executeQuery(propertyName1, Operator.EQ, vf.createValue(length));
     }
 
     public void testLengthDateLiteral() throws RepositoryException {
@@ -156,12 +158,12 @@
 
         Calendar length = Calendar.getInstance();
         length.setTimeInMillis(node.getProperty(propertyName1).getLength());
-        executeQuery(propertyName1, JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
+        executeQuery(propertyName1, Operator.EQ, vf.createValue(length));
     }
 
     public void testLengthBooleanLiteral() throws RepositoryException {
         try {
-            executeQuery(propertyName1, JCR_OPERATOR_EQUAL_TO, vf.createValue(false));
+            executeQuery(propertyName1, Operator.EQ, vf.createValue(false));
             fail("Boolean literal cannot be converted to long");
         } catch (InvalidQueryException e) {
             // expected
@@ -170,7 +172,7 @@
 
     public void testLengthNameLiteral() throws RepositoryException {
         try {
-            executeQuery(propertyName1, JCR_OPERATOR_EQUAL_TO, vf.createValue(
+            executeQuery(propertyName1, Operator.EQ, vf.createValue(
                     propertyName1, PropertyType.NAME));
             fail("Name literal cannot be converted to long");
         } catch (InvalidQueryException e) {
@@ -180,7 +182,7 @@
 
     public void testLengthPathLiteral() throws RepositoryException {
         try {
-            executeQuery(propertyName1, JCR_OPERATOR_EQUAL_TO, vf.createValue(
+            executeQuery(propertyName1, Operator.EQ, vf.createValue(
                     node.getPath(), PropertyType.PATH));
             fail("Path literal cannot be converted to long");
         } catch (InvalidQueryException e) {
@@ -198,7 +200,7 @@
             throw new NotExecutableException("Cannot add mix:referenceable to node");
         }
         try {
-            executeQuery(propertyName1, JCR_OPERATOR_EQUAL_TO, vf.createValue(node));
+            executeQuery(propertyName1, Operator.EQ, vf.createValue(node));
             fail("Reference literal cannot be converted to long");
         } catch (InvalidQueryException e) {
             // expected
@@ -221,27 +223,27 @@
 
     private void checkOperators(String propertyName,
                                 long length) throws RepositoryException {
-        checkLength(propertyName, JCR_OPERATOR_EQUAL_TO, length, true);
-        checkLength(propertyName, JCR_OPERATOR_EQUAL_TO, length - 1, false);
+        checkLength(propertyName, Operator.EQ, length, true);
+        checkLength(propertyName, Operator.EQ, length - 1, false);
 
-        checkLength(propertyName, JCR_OPERATOR_GREATER_THAN, length - 1, true);
-        checkLength(propertyName, JCR_OPERATOR_GREATER_THAN, length, false);
+        checkLength(propertyName, Operator.GT, length - 1, true);
+        checkLength(propertyName, Operator.GT, length, false);
 
-        checkLength(propertyName, JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO, length, true);
-        checkLength(propertyName, JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO, length + 1, false);
+        checkLength(propertyName, Operator.GE, length, true);
+        checkLength(propertyName, Operator.GE, length + 1, false);
 
-        checkLength(propertyName, JCR_OPERATOR_LESS_THAN, length + 1, true);
-        checkLength(propertyName, JCR_OPERATOR_LESS_THAN, length, false);
+        checkLength(propertyName, Operator.LT, length + 1, true);
+        checkLength(propertyName, Operator.LT, length, false);
 
-        checkLength(propertyName, JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO, length, true);
-        checkLength(propertyName, JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO, length - 1, false);
+        checkLength(propertyName, Operator.LE, length, true);
+        checkLength(propertyName, Operator.LE, length - 1, false);
 
-        checkLength(propertyName, JCR_OPERATOR_NOT_EQUAL_TO, length - 1, true);
-        checkLength(propertyName, JCR_OPERATOR_NOT_EQUAL_TO, length, false);
+        checkLength(propertyName, Operator.NE, length - 1, true);
+        checkLength(propertyName, Operator.NE, length, false);
     }
 
     private void checkLength(String propertyName,
-                             String operator,
+                             Operator operator,
                              long length,
                              boolean matches) throws RepositoryException {
         Node[] result;
@@ -254,26 +256,25 @@
     }
 
     private QueryResult executeQuery(String propertyName,
-                                     String operator,
+                                     Operator operator,
                                      long length) throws RepositoryException {
         Value v = vf.createValue(length);
         return executeQuery(propertyName, operator, v);
     }
 
     private QueryResult executeQuery(String propertyName,
-                                     String operator,
+                                     Operator operator,
                                      Value length) throws RepositoryException {
         return qomFactory.createQuery(
                 qomFactory.selector(testNodeType, "s"),
                 qomFactory.and(
                         qomFactory.childNode("s", testRoot),
-                        qomFactory.comparison(
+                        operator.comparison(
+                                qomFactory,
                                 qomFactory.length(
                                         qomFactory.propertyValue(
                                                 "s", propertyName)),
-                                operator,
                                 qomFactory.literal(length))
-
                 ), null, null).execute();
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/NodeLocalNameTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/NodeLocalNameTest.java?rev=770676&r1=770675&r2=770676&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/NodeLocalNameTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/NodeLocalNameTest.java Fri May  1 13:38:16 2009
@@ -16,12 +16,15 @@
  */
 package org.apache.jackrabbit.api.jsr283.query.qom;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
+import java.util.Calendar;
+
 import javax.jcr.Node;
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import javax.jcr.query.Query;
-import java.util.Calendar;
+
+import org.apache.jackrabbit.spi.commons.query.qom.Operator;
 
 /**
  * <code>NodeLocalNameTest</code> checks if conversion of literals is correctly
@@ -53,32 +56,32 @@
 
     public void testStringLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(nodeLocalName);
-        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("[" + nodeLocalName);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(Operator.EQ, 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);
+        Query q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{node1});
     }
 
     public void testDateLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(Calendar.getInstance());
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{});
     }
 
     public void testDoubleLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(Math.PI);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{});
     }
 
@@ -88,37 +91,37 @@
 
     public void testLongLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(283);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{});
     }
 
     public void testBooleanLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(true);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{});
     }
 
     public void testNameLiteral() throws RepositoryException {
         Value literal = superuser.getValueFactory().createValue(
                 nodeLocalName, 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(
                 nodeLocalName, 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);
-        q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{});
 
         literal = superuser.getValueFactory().createValue(
                 nodeName1 + "/" + nodeName1, PropertyType.PATH);
-        q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{});
     }
 
@@ -128,7 +131,7 @@
         }
         node1.save();
         Value literal = superuser.getValueFactory().createValue(node1);
-        Query q = createQuery(JCR_OPERATOR_EQUAL_TO, literal);
+        Query q = createQuery(Operator.EQ, literal);
         checkResult(q.execute(), new Node[]{});
     }
 
@@ -141,36 +144,36 @@
     }
 
     public void testEqualTo() throws RepositoryException {
-        checkOperator(JCR_OPERATOR_EQUAL_TO, false, true, false);
+        checkOperator(Operator.EQ, false, true, false);
     }
 
     public void testGreaterThan() throws RepositoryException {
-        checkOperator(JCR_OPERATOR_GREATER_THAN, true, false, false);
+        checkOperator(Operator.GT, true, false, false);
     }
 
     public void testGreaterThanOrEqualTo() throws RepositoryException {
-        checkOperator(JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO, true, true, false);
+        checkOperator(Operator.GE, true, true, false);
     }
 
     public void testLessThan() throws RepositoryException {
-        checkOperator(JCR_OPERATOR_LESS_THAN, false, false, true);
+        checkOperator(Operator.LT, false, false, true);
     }
 
     public void testLessThanOrEqualTo() throws RepositoryException {
-        checkOperator(JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO, false, true, true);
+        checkOperator(Operator.LE, false, true, true);
     }
 
     public void testLike() throws RepositoryException {
-        checkOperator(JCR_OPERATOR_LIKE, false, true, false);
+        checkOperator(Operator.LIKE, 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)
@@ -180,9 +183,8 @@
         checkOperatorSingleLiteral(createLexicographicallyGreater(nodeLocalName), operator, matchesGreater);
     }
 
-    private void checkOperatorSingleLiteral(String literal,
-                                            String operator,
-                                            boolean matches)
+    private void checkOperatorSingleLiteral(
+            String literal, Operator operator, boolean matches)
             throws RepositoryException {
         Value value = superuser.getValueFactory().createValue(literal);
         Query q = createQuery(operator, value);
@@ -201,17 +203,16 @@
         return tmp.toString();
     }
 
-    private Query createQuery(String operator, Value literal)
+    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.nodeLocalName("s"),
-                                operator,
-                                qomFactory.literal(literal)
-                        )
+                                qomFactory.literal(literal))
                 ), null, null);
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/QueryObjectModelFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/QueryObjectModelFactoryTest.java?rev=770676&r1=770675&r2=770676&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/QueryObjectModelFactoryTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/api/jsr283/query/qom/QueryObjectModelFactoryTest.java Fri May  1 13:38:16 2009
@@ -54,6 +54,8 @@
 import javax.jcr.query.qom.StaticOperand;
 import javax.jcr.query.qom.UpperCase;
 
+import org.apache.jackrabbit.spi.commons.query.qom.Operator;
+
 /**
  * <code>QueryObjectModelFactoryTest</code> tests all methods on the
  * {@link QueryObjectModelFactory}.
@@ -86,24 +88,11 @@
     private static final String FULLTEXT_SEARCH_EXPR = "foo -bar";
 
     /**
-     * Set of all possible operators.
-     */
-    private static final Set<String> OPERATORS = new HashSet<String>();
-
-    /**
      * Set of all possible join types.
      */
     private static final Set<String> JOIN_TYPES = new HashSet<String>();
 
     static {
-        OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO);
-        OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN);
-        OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO);
-        OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN);
-        OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO);
-        OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_LIKE);
-        OPERATORS.add(QueryObjectModelConstants.JCR_OPERATOR_NOT_EQUAL_TO);
-
         JOIN_TYPES.add(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER);
         JOIN_TYPES.add(QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER);
         JOIN_TYPES.add(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER);
@@ -214,8 +203,8 @@
     public void testComparison() throws RepositoryException {
         PropertyValue op1 = qomFactory.propertyValue(SELECTOR_NAME1, propertyName1);
         BindVariableValue op2 = qomFactory.bindVariable(VARIABLE_NAME);
-        for (String operator : OPERATORS) {
-            Comparison comp = qomFactory.comparison(op1, operator, op2);
+        for (Operator operator : Operator.values()) {
+            Comparison comp = operator.comparison(qomFactory, op1, op2);
             assertTrue("Not a PropertyValue operand", comp.getOperand1() instanceof PropertyValue);
             assertTrue("Not a BindVariableValue operand", comp.getOperand2() instanceof BindVariableValue);
             assertEquals("Wrong operator", operator, comp.getOperator());