jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1406669 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilder.java test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilderTest.java
Date Wed, 07 Nov 2012 15:15:20 GMT
Author: mduerig
Date: Wed Nov  7 15:15:19 2012
New Revision: 1406669

URL: http://svn.apache.org/viewvc?rev=1406669&view=rev
Log:
OAK-429: MemoryPropertyBuilder.assignFrom leads to ClassCastException on getPropertyState
with date properties

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilder.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilderTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilder.java?rev=1406669&r1=1406668&r2=1406669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilder.java
Wed Nov  7 15:15:19 2012
@@ -223,11 +223,21 @@ public class MemoryPropertyBuilder<T> im
             setName(property.getName());
             if (property.isArray()) {
                 isArray = true;
-                setValues((Iterable<T>) property.getValue(type.getArrayType()));
+                if (type == Type.DATE) {
+                    setValues((Iterable<T>) property.getValue(Type.STRINGS));
+                }
+                else {
+                    setValues((Iterable<T>) property.getValue(type.getArrayType()));
+                }
             }
             else {
                 isArray = false;
-                setValue(property.getValue(type));
+                if (type == Type.DATE) {
+                    setValue((T) property.getValue(Type.STRING));
+                }
+                else {
+                    setValue(property.getValue(type));
+                }
             }
         }
         return this;

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilderTest.java?rev=1406669&r1=1406668&r2=1406669&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilderTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/memory/MemoryPropertyBuilderTest.java
Wed Nov  7 15:15:19 2012
@@ -73,6 +73,29 @@ public class MemoryPropertyBuilderTest {
     }
 
     @Test
+    public void testDateProperty() {
+        PropertyBuilder<String> builder = MemoryPropertyBuilder.array(Type.DATE);
+        String date1 = "1970-01-01T00:00:00.000Z";
+        String date2 = "1971-01-01T00:00:00.000Z";
+        builder.setName("foo")
+                .addValue(date1)
+                .addValue(date2);
+        assertEquals(MultiLongPropertyState.createDateProperty("foo", Arrays.asList(date1,
date2)),
+                builder.getPropertyState());
+
+        builder.setScalar();
+        try {
+            builder.getPropertyState();
+        }
+        catch (IllegalStateException expected) {
+        }
+
+        builder.removeValue(date1);
+        assertEquals(LongPropertyState.createDateProperty("foo", date2),
+                builder.getPropertyState());
+    }
+
+    @Test
     public void testAssignFromLong() {
         PropertyState source = LongPropertyState.createLongProperty("foo", 42L);
         PropertyBuilder<String> builder = MemoryPropertyBuilder.scalar(Type.STRING);
@@ -90,6 +113,15 @@ public class MemoryPropertyBuilderTest {
                 builder.getPropertyState());
     }
 
+    @Test
+    public void testAssignFromDate() {
+        String date = "1970-01-01T00:00:00.000Z";
+        PropertyState source = LongPropertyState.createDateProperty("foo", date);
+        PropertyBuilder<String> builder = MemoryPropertyBuilder.scalar(Type.DATE);
+        builder.assignFrom(source);
+        assertEquals(source, builder.getPropertyState());
+    }
+
     @Test(expected = NumberFormatException.class)
     public void testAssignFromStringNumberFormatException() {
         PropertyState source = StringPropertyState.stringProperty("foo", "bar");
@@ -116,6 +148,16 @@ public class MemoryPropertyBuilderTest {
     }
 
     @Test
+    public void testAssignFromDates() {
+        String date1 = "1970-01-01T00:00:00.000Z";
+        String date2 = "1971-01-01T00:00:00.000Z";
+        PropertyState source = MultiLongPropertyState.createDateProperty("foo", Arrays.asList(date1,
date2));
+        PropertyBuilder<String> builder = MemoryPropertyBuilder.scalar(Type.DATE);
+        builder.assignFrom(source);
+        assertEquals(source, builder.getPropertyState());
+    }
+
+    @Test
     public void testAssignInvariant() {
         PropertyState source = MultiStringPropertyState.stringProperty("source", Arrays.asList("1",
"2", "3"));
         PropertyBuilder<String> builder = MemoryPropertyBuilder.scalar(Type.STRING);



Mime
View raw message