jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r779657 - in /jackrabbit/trunk/jackrabbit-spi-commons/src: main/java/org/apache/jackrabbit/spi/commons/value/ValueFormat.java test/java/org/apache/jackrabbit/spi/commons/value/ValueFormatTest.java
Date Thu, 28 May 2009 16:43:32 GMT
Author: angela
Date: Thu May 28 16:43:32 2009
New Revision: 779657

URL: http://svn.apache.org/viewvc?rev=779657&view=rev
Log:
JCR-1609  new Property Types

update ValueFormat and add trivial tests for new property types.
add TODO for binary conversion that still uses the deprecated getStream method

Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/ValueFormat.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/value/ValueFormatTest.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/ValueFormat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/ValueFormat.java?rev=779657&r1=779656&r2=779657&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/ValueFormat.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/ValueFormat.java
Thu May 28 16:43:32 2009
@@ -50,6 +50,7 @@
         } else if (jcrValue instanceof QValueValue) {
             return ((QValueValue)jcrValue).getQValue();
         } else if (jcrValue.getType() == PropertyType.BINARY) {
+            // TODO: jsr 283 binary property conversion
             try {
                 return factory.create(jcrValue.getStream());
             } catch (IOException e) {
@@ -61,6 +62,8 @@
             return factory.create(jcrValue.getDouble());
         } else if (jcrValue.getType() == PropertyType.LONG) {
             return factory.create(jcrValue.getLong());
+        } else if (jcrValue.getType() == PropertyType.DECIMAL) {
+            return factory.create(jcrValue.getDecimal());
         } else {
             return getQValue(jcrValue.getString(), jcrValue.getType(), resolver, factory);
         }
@@ -107,8 +110,11 @@
             case PropertyType.BOOLEAN:
             case PropertyType.DOUBLE:
             case PropertyType.LONG:
+            case PropertyType.DECIMAL:
             case PropertyType.DATE:
             case PropertyType.REFERENCE:
+            case PropertyType.WEAKREFERENCE:
+            case PropertyType.URI:
                 qValue = factory.create(jcrValue, propertyType);
                 break;
             case PropertyType.BINARY:
@@ -146,6 +152,8 @@
             switch (propertyType) {
                 case PropertyType.STRING:
                 case PropertyType.REFERENCE:
+                case PropertyType.WEAKREFERENCE:
+                case PropertyType.URI:
                     jcrValue = factory.createValue(qualifiedValue.getString(), propertyType);
                     break;
                 case PropertyType.PATH:
@@ -160,6 +168,7 @@
                     jcrValue = factory.createValue(qualifiedValue.getBoolean());
                     break;
                 case PropertyType.BINARY:
+                    // TODO: jsr 283 binary handling
                     jcrValue = factory.createValue(qualifiedValue.getStream());
                     break;
                 case PropertyType.DATE:
@@ -171,6 +180,9 @@
                 case PropertyType.LONG:
                     jcrValue = factory.createValue(qualifiedValue.getLong());
                     break;
+                case PropertyType.DECIMAL:
+                    jcrValue = factory.createValue(qualifiedValue.getDecimal());
+                    break;
                 default:
                     throw new RepositoryException("illegal internal value type");
             }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/value/ValueFormatTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/value/ValueFormatTest.java?rev=779657&r1=779656&r2=779657&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/value/ValueFormatTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/value/ValueFormatTest.java
Thu May 28 16:43:32 2009
@@ -36,8 +36,12 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.PropertyType;
 import javax.jcr.ValueFactory;
+import javax.jcr.Value;
 import java.util.List;
 import java.util.ArrayList;
+import java.math.BigDecimal;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 /**
  * <code>ValueFormatTest</code>...
@@ -90,4 +94,35 @@
         }
     }
 
+    public void testDecimal() throws RepositoryException {
+        BigDecimal bd = new BigDecimal(Double.MIN_VALUE);
+
+        Value v = vFactory.createValue(bd);
+        QValue qv = qvFactory.create(bd);
+
+        assertEquals(v, ValueFormat.getJCRValue(qv, resolver, vFactory));
+        assertEquals(qv, ValueFormat.getQValue(v, resolver, qvFactory));
+    }
+
+    public void testURI() throws RepositoryException, URISyntaxException {
+        URI uri = new URI("http://jackrabbit.apache.org");
+
+        Value v = vFactory.createValue("http://jackrabbit.apache.org", PropertyType.URI);
+        QValue qv = qvFactory.create(uri);
+
+        assertEquals(v, ValueFormat.getJCRValue(qv, resolver, vFactory));
+        assertEquals(qv, ValueFormat.getQValue(v, resolver, qvFactory));
+        assertEquals(qv, ValueFormat.getQValue("http://jackrabbit.apache.org", PropertyType.URI,
resolver, qvFactory));
+    }
+
+    public void testWeakReferences() throws RepositoryException {
+        String reference = UUID.randomUUID().toString();
+
+        Value v = vFactory.createValue(reference, PropertyType.WEAKREFERENCE);
+        QValue qv = qvFactory.create(reference, PropertyType.WEAKREFERENCE);
+
+        assertEquals(v, ValueFormat.getJCRValue(qv, resolver, vFactory));
+        assertEquals(qv, ValueFormat.getQValue(v, resolver, qvFactory));
+        assertEquals(qv, ValueFormat.getQValue(reference, PropertyType.WEAKREFERENCE, resolver,
qvFactory));        
+    }
 }
\ No newline at end of file



Mime
View raw message