jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r797417 - /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java
Date Fri, 24 Jul 2009 11:02:33 GMT
Author: stefan
Date: Fri Jul 24 11:02:33 2009
New Revision: 797417

URL: http://svn.apache.org/viewvc?rev=797417&view=rev
Log:
JCR-2085: test case (TCK) maintenance for JCR 2.0

added Node.getReferences(String) tests


Modified:
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java?rev=797417&r1=797416&r2=797417&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java
Fri Jul 24 11:02:33 2009
@@ -24,6 +24,8 @@
 import javax.jcr.PropertyIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
+import java.util.Set;
+import java.util.HashSet;
 
 /**
  * <code>ReferencesTest</code> contains the test cases for the references.
@@ -111,6 +113,88 @@
     }
 
     /**
+     * Tests Node.getReferences(String)
+     */
+    public void testGetReferencesWithName() throws RepositoryException, NotExecutableException
{
+        Node n1 = testRootNode.addNode(nodeName1, testNodeType);
+        ensureMixinType(n1, mixReferenceable);
+
+        // with some impls. the mixin type has only affect upon save
+        testRootNode.save();
+
+        // make sure the node is now referenceable
+        assertTrue("test node should be mix:referenceable", n1.isNodeType(mixReferenceable));
+
+        // create references:
+        // n2.p1 -> n1
+        // n2.p2 -> n1
+        // n3.p1 -> n1
+        Node n2 = testRootNode.addNode(nodeName2, testNodeType);
+        Node n3 = testRootNode.addNode(nodeName3, testNodeType);
+
+        Value[] values = new Value[]{superuser.getValueFactory().createValue(n1)};
+
+        // abort test if the repository does not allow setting
+        // reference properties on this node
+        ensureCanSetProperty(n2, propertyName1, values);
+        ensureCanSetProperty(n2, propertyName2, values);
+        ensureCanSetProperty(n1, propertyName1, values);
+
+        Property p1 = n2.setProperty(propertyName1, values);
+        Property p2 = n2.setProperty(propertyName2, values);
+        Property p3 = n3.setProperty(propertyName1, n1);
+        testRootNode.save();
+
+        // get references with name propertyName1
+        // (should return p1 and p3))
+        PropertyIterator iter = n1.getReferences(propertyName1);
+        Set results = new HashSet();
+        while (iter.hasNext()) {
+            results.add(iter.nextProperty().getPath());
+        }
+        assertEquals("wrong number of references reported", 2, results.size());
+        assertTrue("missing reference property: " + p1.getPath(), results.contains(p1.getPath()));
+        assertTrue("missing reference property: " + p3.getPath(), results.contains(p3.getPath()));
+
+        // get references with name propertyName2
+        // (should return p2))
+        iter = n1.getReferences(propertyName2);
+        results.clear();
+        while (iter.hasNext()) {
+            results.add(iter.nextProperty().getPath());
+        }
+        assertEquals("wrong number of references reported", 1, results.size());
+        assertTrue("missing reference property: " + p2.getPath(), results.contains(p2.getPath()));
+
+        // remove reference n3.p1 -> n1
+        testRootNode.getNode(nodeName3).getProperty(propertyName1).remove();
+        testRootNode.save();
+
+        // get references with name propertyName1
+        // (should return p1))
+        iter = n1.getReferences(propertyName1);
+        results.clear();
+        while (iter.hasNext()) {
+            results.add(iter.nextProperty().getPath());
+        }
+        assertEquals("wrong number of references reported", 1, results.size());
+        assertTrue("missing reference property: " + p1.getPath(), results.contains(p1.getPath()));
+
+        // remove reference n2.p1 -> n1
+        p1.remove();
+        testRootNode.save();
+
+        // get references with name propertyName1
+        // (should nothing))
+        iter = n1.getReferences(propertyName1);
+        results.clear();
+        while (iter.hasNext()) {
+            results.add(iter.nextProperty().getPath());
+        }
+        assertEquals("wrong number of references reported", 0, results.size());
+    }
+
+    /**
      * Tests Property.getNode();
      */
     public void testReferenceTarget() throws RepositoryException, NotExecutableException
{



Mime
View raw message