You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Marcel Reutegger (JIRA)" <ji...@apache.org> on 2006/08/02 15:06:14 UTC

[jira] Commented: (JCR-502) TCK: SetPropertyCalendarTest compares Calendar objects

    [ http://issues.apache.org/jira/browse/JCR-502?page=comments#action_12425220 ] 
            
Marcel Reutegger commented on JCR-502:
--------------------------------------

I agree with you that the test cases should not compare Calendar instances because the specification only defines value equality on Value instances and not their representations in basic Java types.

However I do think that Value.equals(Object) should work and indicate true when the Calendar instance which is passed to setProperty() goes through the ValueFactory. IMO a repository implementation must not change the time zone part of a Calendar because this results in a different Calendar. If an implementation normalizes a calendar it should at least do it consistent when using the ValueFactory.

I therefore propose to change the test cases the following way:

Index: java/org/apache/jackrabbit/test/api/SetPropertyCalendarTest.java
===================================================================
--- java/org/apache/jackrabbit/test/api/SetPropertyCalendarTest.java	(revision 424965)
+++ java/org/apache/jackrabbit/test/api/SetPropertyCalendarTest.java	(working copy)
@@ -19,6 +19,7 @@
 import org.apache.jackrabbit.test.AbstractJCRTest;
 
 import javax.jcr.Node;
+import javax.jcr.ValueFactory;
 
 import java.util.Calendar;
 import java.util.GregorianCalendar;
@@ -36,12 +37,15 @@
 
     private Node testNode;
 
+    private ValueFactory vFactory;
+
     private Calendar c1 = new GregorianCalendar(2005, 1, 10, 14, 8, 56);
     private Calendar c2 = new GregorianCalendar(1945, 1, 6, 16, 20, 0);
 
     protected void setUp() throws Exception {
         super.setUp();
         testNode = testRootNode.addNode(nodeName1, testNodeType);
+        vFactory = superuser.getValueFactory();
     }
 
     /**
@@ -52,8 +56,8 @@
         testNode.setProperty(propertyName1, c1);
         superuser.save();
         assertEquals("Setting property with Node.setProperty(String, Calendar) and Session.save() not working",
-                c1,
-                testNode.getProperty(propertyName1).getDate());
+                vFactory.createValue(c1),
+                testNode.getProperty(propertyName1).getValue());
     }
 
     /**
@@ -66,8 +70,8 @@
         testNode.setProperty(propertyName1, c2);
         superuser.save();
         assertEquals("Modifying property with Node.setProperty(String, Calendar) and Session.save() not working",
-                c2,
-                testNode.getProperty(propertyName1).getDate());
+                vFactory.createValue(c2),
+                testNode.getProperty(propertyName1).getValue());
     }
 
     /**
@@ -78,8 +82,8 @@
         testNode.setProperty(propertyName1, c1);
         testRootNode.save();
         assertEquals("Setting property with Node.setProperty(String, Calendar) and parentNode.save() not working",
-                c1,
-                testNode.getProperty(propertyName1).getDate());
+                vFactory.createValue(c1),
+                testNode.getProperty(propertyName1).getValue());
     }
 
     /**
@@ -92,8 +96,8 @@
         testNode.setProperty(propertyName1, c2);
         testRootNode.save();
         assertEquals("Modifying property with Node.setProperty(String, Calendar) and parentNode.save() not working",
-                c2,
-                testNode.getProperty(propertyName1).getDate());
+                vFactory.createValue(c2),
+                testNode.getProperty(propertyName1).getValue());
     }
 
     /**


WDYT?

> TCK: SetPropertyCalendarTest compares Calendar objects
> ------------------------------------------------------
>
>                 Key: JCR-502
>                 URL: http://issues.apache.org/jira/browse/JCR-502
>             Project: Jackrabbit
>          Issue Type: Bug
>          Components: test
>            Reporter: David Pitfield
>
> SetPropertyCalendarTest# testNewCalendarPropertySession
> SetPropertyCalendarTest# testModifyCalendarPropertySession
> SetPropertyCalendarTest# testNewCalendarPropertyParent
> SetPropertyCalendarTest# testModifyCalendarPropertyParent
> Tests compare Calendar objects.  Calendar.equals(Object) is a stronger test than JSR-170 specifies for Value.equals(Object), leading to false failures.  For the purpose of these tests, even Value.equals(Object) is too strong an equality test, since some repositories may normalize date/time values across a save/read roundtrip (for example, converting "Z" to "+00:00", or adding/removing trailing zeros in fractional seconds).
> Proposal: compare the getTimeInMillis() values.
> --- SetPropertyCalendarTest.java        (revision 422074)
> +++ SetPropertyCalendarTest.java        (working copy)
> @@ -52,8 +52,8 @@
>          testNode.setProperty(propertyName1, c1);
>          superuser.save();
>          assertEquals("Setting property with Node.setProperty(String, Calendar) and Session.save() not working",
> -                c1,
> -                testNode.getProperty(propertyName1).getDate());
> +                c1.getTimeInMillis(),
> +                testNode.getProperty(propertyName1).getDate().getTimeInMillis());
>      }
>   
>      /**
> @@ -66,8 +66,8 @@
>          testNode.setProperty(propertyName1, c2);
>          superuser.save();
>          assertEquals("Modifying property with Node.setProperty(String, Calendar) and Session.save() not working",
> -                c2,
> -                testNode.getProperty(propertyName1).getDate());
> +                c2.getTimeInMillis(),
> +                testNode.getProperty(propertyName1).getDate().getTimeInMillis());
>      }
>   
>      /**
> @@ -78,8 +78,8 @@
>          testNode.setProperty(propertyName1, c1);
>          testRootNode.save();
>          assertEquals("Setting property with Node.setProperty(String, Calendar) and parentNode.save() not working",
> -                c1,
> -                testNode.getProperty(propertyName1).getDate());
> +                c1.getTimeInMillis(),
> +                testNode.getProperty(propertyName1).getDate().getTimeInMillis());
>      }
>   
>      /**
> @@ -92,8 +92,8 @@
>          testNode.setProperty(propertyName1, c2);
>          testRootNode.save();
>          assertEquals("Modifying property with Node.setProperty(String, Calendar) and parentNode.save() not working",
> -                c2,
> -                testNode.getProperty(propertyName1).getDate());
> +                c2.getTimeInMillis(),
> +                testNode.getProperty(propertyName1).getDate().getTimeInMillis());
>      }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira