jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r784117 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java
Date Fri, 12 Jun 2009 13:40:05 GMT
Author: mreutegg
Date: Fri Jun 12 13:40:05 2009
New Revision: 784117

URL: http://svn.apache.org/viewvc?rev=784117&view=rev
Log:
JCR-2085: test case (TCK) maintenance for JCR 2.0
- length tests for DECIMAL, URI and WEAKREFERENCE

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java?rev=784117&r1=784116&r2=784117&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/LengthOperand.java
Fri Jun 12 13:40:05 2009
@@ -19,12 +19,15 @@
 import java.io.IOException;
 
 import javax.jcr.Value;
-import javax.jcr.ValueFactory;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.core.query.lucene.ScoreNode;
 import org.apache.jackrabbit.core.query.lucene.Util;
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.value.InternalValue;
+import org.apache.jackrabbit.core.value.ValueFactoryImpl;
+import org.apache.jackrabbit.spi.QValueFactory;
 
 /**
  * <code>LengthOperand</code> implements a length operand.
@@ -55,11 +58,25 @@
         if (ps == null) {
             return EMPTY;
         } else {
-            ValueFactory vf = context.getSession().getValueFactory();
+            ValueFactoryImpl vf = (ValueFactoryImpl) context.getSession().getValueFactory();
+            QValueFactory qvf = vf.getQValueFactory();
             InternalValue[] values = ps.getValues();
             Value[] lengths = new Value[values.length];
             for (int i = 0; i < lengths.length; i++) {
-                lengths[i] = vf.createValue(Util.getLength(values[i]));
+                long len;
+                int type = values[i].getType();
+                try {
+                    if (type == PropertyType.NAME) {
+                        len = vf.createValue(qvf.create(values[i].getName())).getString().length();
+                    } else if (type == PropertyType.PATH) {
+                        len = vf.createValue(qvf.create(values[i].getPath())).getString().length();
+                    } else {
+                        len = Util.getLength(values[i]);
+                    }
+                } catch (RepositoryException e) {
+                    throw Util.createIOException(e);
+                }
+                lengths[i] = vf.createValue(len);
             }
             return lengths;
         }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java?rev=784117&r1=784116&r2=784117&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java
Fri Jun 12 13:40:05 2009
@@ -23,13 +23,14 @@
 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.qom.QueryObjectModelConstants;
 
 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
@@ -44,7 +45,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         node = testRootNode.addNode(nodeName1, testNodeType);
-        testRootNode.save();
+        superuser.save();
         vf = superuser.getValueFactory();
     }
 
@@ -56,80 +57,104 @@
 
     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();
+                superuser.save();
             }
         } catch (RepositoryException e) {
             throw new NotExecutableException("Cannot add mix:referenceable to node");
         }
         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 {
+        try {
+            if (!node.isNodeType(mixReferenceable)) {
+                node.addMixin(mixReferenceable);
+                superuser.save();
+            }
+        } catch (RepositoryException e) {
+            throw new NotExecutableException("Cannot add mix:referenceable to node");
+        }
+        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, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
@@ -137,16 +162,21 @@
 
     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, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(in));
+        Binary b = vf.createBinary(new ByteArrayInputStream(length.getBytes()));
+        try {
+            executeQuery(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, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
@@ -154,7 +184,7 @@
 
     public void testLengthDateLiteral() throws RepositoryException {
         node.setProperty(propertyName1, "abc");
-        node.save();
+        superuser.save();
 
         Calendar length = Calendar.getInstance();
         length.setTimeInMillis(node.getProperty(propertyName1).getLength());
@@ -194,7 +224,7 @@
         try {
             if (!node.isNodeType(mixReferenceable)) {
                 node.addMixin(mixReferenceable);
-                node.save();
+                superuser.save();
             }
         } catch (RepositoryException e) {
             throw new NotExecutableException("Cannot add mix:referenceable to node");
@@ -207,16 +237,39 @@
         }
     }
 
-    public void testLengthWeakReferenceLiteral() throws RepositoryException {
-        // TODO
+    public void testLengthWeakReferenceLiteral() throws RepositoryException, NotExecutableException
{
+        try {
+            if (!node.isNodeType(mixReferenceable)) {
+                node.addMixin(mixReferenceable);
+                superuser.save();
+            }
+        } catch (RepositoryException e) {
+            throw new NotExecutableException("Cannot add mix:referenceable to node");
+        }
+        try {
+            executeQuery(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 {
+            executeQuery(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());
+        executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
     }
 
     //------------------------< internal helpers >------------------------------



Mime
View raw message