jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r784163 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbi...
Date Fri, 12 Jun 2009 15:49:58 GMT
Author: mreutegg
Date: Fri Jun 12 15:49:58 2009
New Revision: 784163

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

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeNameOperand.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java?rev=784163&r1=784162&r2=784163&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
Fri Jun 12 15:49:58 2009
@@ -27,6 +27,8 @@
 
 import java.util.regex.Pattern;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
 
 import javax.jcr.PropertyType;
 import javax.jcr.Value;
@@ -272,6 +274,21 @@
                 c2 = v2.getDecimal();
                 break;
             case PropertyType.NAME:
+                if (v2.getType() == PropertyType.URI) {
+                    String s = v2.getString();
+                    if (s.startsWith("./")) {
+                        s = s.substring(2);
+                    }
+                    // need to decode
+                    try {
+                        c2 = URLDecoder.decode(s, "UTF-8");
+                    } catch (UnsupportedEncodingException e) {
+                        throw new RepositoryException(e);
+                    }
+                } else {
+                    c2 = v2.getString();
+                }
+                break;
             case PropertyType.PATH:
             case PropertyType.REFERENCE:
             case PropertyType.WEAKREFERENCE:

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java?rev=784163&r1=784162&r2=784163&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/ConstraintBuilder.java
Fri Jun 12 15:49:58 2009
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.core.query.lucene.constraint;
 
 import java.util.Map;
+import java.net.URLDecoder;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -252,11 +253,19 @@
                 case PropertyType.URI:
                     // make sure static value is valid NAME
                     try {
-                            vf.createValue(staticValue.getString(), PropertyType.NAME);
+                        String s = staticValue.getString();
+                        if (staticValue.getType() == PropertyType.URI) {
+                            if (s.startsWith("./")) {
+                                s = s.substring(2);
+                            }
+                            // need to decode
+                            s = URLDecoder.decode(s, "UTF-8");
+                        }
+                        vf.createValue(s, PropertyType.NAME);
                     } catch (ValueFormatException e) {
                             throw new InvalidQueryException("Value " +
                                 staticValue.getString() +
-                                " cannot be converted into STRING");
+                                " cannot be converted into NAME");
                     }
                     break;
                 // the following types cannot be converted to NAME

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeNameOperand.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeNameOperand.java?rev=784163&r1=784162&r2=784163&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeNameOperand.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/constraint/NodeNameOperand.java
Fri Jun 12 15:49:58 2009
@@ -20,6 +20,7 @@
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
+import javax.jcr.PropertyType;
 
 import org.apache.jackrabbit.core.query.lucene.ScoreNode;
 import org.apache.jackrabbit.core.query.lucene.Util;
@@ -44,7 +45,7 @@
         try {
             SessionImpl session = context.getSession();
             String name = session.getNodeById(sn.getNodeId()).getName();
-            return new Value[]{session.getValueFactory().createValue(name)};
+            return new Value[]{session.getValueFactory().createValue(name, PropertyType.NAME)};
         } catch (RepositoryException e) {
             throw Util.createIOException(e);
         }

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java?rev=784163&r1=784162&r2=784163&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java
Fri Jun 12 15:49:58 2009
@@ -20,11 +20,13 @@
 import javax.jcr.Value;
 import javax.jcr.Node;
 import javax.jcr.PropertyType;
+import javax.jcr.ValueFactory;
 import javax.jcr.query.Query;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.qom.QueryObjectModelConstants;
 
 import java.util.Calendar;
+import java.math.BigDecimal;
 
 /**
  * <code>NodeNameTest</code> checks if conversion of literals is correctly
@@ -34,10 +36,13 @@
 
     private Node node1;
 
+    private ValueFactory vf;
+
     protected void setUp() throws Exception {
         super.setUp();
         node1 = testRootNode.addNode(nodeName1, testNodeType);
-        testRootNode.save();
+        superuser.save();
+        vf = superuser.getValueFactory();
     }
 
     protected void tearDown() throws Exception {
@@ -46,13 +51,13 @@
     }
 
     public void testStringLiteral() throws RepositoryException {
-        Value literal = superuser.getValueFactory().createValue(nodeName1);
+        Value literal = vf.createValue(nodeName1);
         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("[" + nodeName1);
+        Value literal = vf.createValue("[" + nodeName1);
         try {
             createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
             fail("NodeName comparison with STRING that cannot be converted to NAME must fail
with InvalidQueryException");
@@ -62,14 +67,14 @@
     }
 
     public void testBinaryLiteral() throws RepositoryException {
-        Value literal = superuser.getValueFactory().createValue(
+        Value literal = vf.createValue(
                 nodeName1, PropertyType.BINARY);
         Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
         checkResult(q.execute(), new Node[]{node1});
     }
 
     public void testDateLiteral() throws RepositoryException {
-        Value literal = superuser.getValueFactory().createValue(Calendar.getInstance());
+        Value literal = vf.createValue(Calendar.getInstance());
         try {
             createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
             fail("NodeName comparison with DATE must fail with InvalidQueryException");
@@ -79,7 +84,7 @@
     }
 
     public void testDoubleLiteral() throws RepositoryException {
-        Value literal = superuser.getValueFactory().createValue(Math.PI);
+        Value literal = vf.createValue(Math.PI);
         try {
             createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
             fail("NodeName comparison with DOUBLE must fail with InvalidQueryException");
@@ -89,11 +94,17 @@
     }
 
     public void testDecimalLiteral() throws RepositoryException {
-        // TODO must throw InvalidQueryException
+        Value literal = vf.createValue(new BigDecimal(283));
+        try {
+            createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
+            fail("NodeName comparison with DECIMAL must fail with InvalidQueryException");
+        } catch (InvalidQueryException e) {
+            // expected
+        }
     }
 
     public void testLongLiteral() throws RepositoryException {
-        Value literal = superuser.getValueFactory().createValue(283);
+        Value literal = vf.createValue(283);
         try {
             createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
             fail("NodeName comparison with LONG must fail with InvalidQueryException");
@@ -103,7 +114,7 @@
     }
 
     public void testBooleanLiteral() throws RepositoryException {
-        Value literal = superuser.getValueFactory().createValue(true);
+        Value literal = vf.createValue(true);
         try {
             createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
             fail("NodeName comparison with BOOLEAN must fail with InvalidQueryException");
@@ -113,20 +124,17 @@
     }
 
     public void testNameLiteral() throws RepositoryException {
-        Value literal = superuser.getValueFactory().createValue(
-                nodeName1, PropertyType.NAME);
+        Value literal = vf.createValue(nodeName1, PropertyType.NAME);
         Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
         checkResult(q.execute(), new Node[]{node1});
     }
 
     public void testPathLiteral() throws RepositoryException {
-        Value literal = superuser.getValueFactory().createValue(
-                nodeName1, PropertyType.PATH);
+        Value literal = vf.createValue(nodeName1, PropertyType.PATH);
         Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
         checkResult(q.execute(), new Node[]{node1});
 
-        literal = superuser.getValueFactory().createValue(
-                node1.getPath(), PropertyType.PATH);
+        literal = vf.createValue(node1.getPath(), PropertyType.PATH);
         try {
             createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
             fail("NodeName comparison with absolute PATH must fail with InvalidQueryException");
@@ -134,8 +142,7 @@
             // expected
         }
 
-        literal = superuser.getValueFactory().createValue(
-                nodeName1 + "/" + nodeName1, PropertyType.PATH);
+        literal = vf.createValue(nodeName1 + "/" + nodeName1, PropertyType.PATH);
         try {
             createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
             fail("NodeName comparison with PATH length >1 must fail with InvalidQueryException");
@@ -148,8 +155,8 @@
         if (!node1.isNodeType(mixReferenceable)) {
             node1.addMixin(mixReferenceable);
         }
-        node1.save();
-        Value literal = superuser.getValueFactory().createValue(node1);
+        superuser.save();
+        Value literal = vf.createValue(node1);
         try {
             createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
             fail("NodeName comparison with REFERENCE must fail with InvalidQueryException");
@@ -159,7 +166,17 @@
     }
 
     public void testWeakReferenceLiteral() throws RepositoryException {
-        // TODO: must throw InvalidQueryException
+        if (!node1.isNodeType(mixReferenceable)) {
+            node1.addMixin(mixReferenceable);
+        }
+        superuser.save();
+        Value literal = vf.createValue(node1, true);
+        try {
+            createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
+            fail("NodeName comparison with WEAKREFERENCE must fail with InvalidQueryException");
+        } catch (InvalidQueryException e) {
+            // expected
+        }
     }
 
     /**
@@ -172,7 +189,17 @@
      * thrown.
      */
     public void testURILiteral() throws RepositoryException {
-        // TODO
+        Value literal = vf.createValue("./" + nodeName1, PropertyType.URI);
+        Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+        checkResult(q.execute(), new Node[]{node1});
+
+        literal = vf.createValue("http://example.com", PropertyType.URI);
+        try {
+            createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal).execute();
+            fail("NodeName comparison with URI that cannot be converted to NAME must fail
with InvalidQueryException");
+        } catch (InvalidQueryException e) {
+            // expected
+        }
     }
 
     public void testEqualTo() throws RepositoryException {
@@ -199,7 +226,7 @@
                                             String operator,
                                             boolean matches)
             throws RepositoryException {
-        Value value = superuser.getValueFactory().createValue(literal);
+        Value value = vf.createValue(literal);
         Query q = createQuery(operator, value);
         checkResult(q.execute(), matches ? new Node[]{node1} : new Node[0]);
     }



Mime
View raw message