jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r158068 - in incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api: NodeTest.java PropertyTest.java TestAll.java nodetype/PropertyDefTest.java
Date Fri, 18 Mar 2005 13:43:08 GMT
Author: mreutegg
Date: Fri Mar 18 05:43:07 2005
New Revision: 158068

URL: http://svn.apache.org/viewcvs?view=rev&rev=158068
Log:
Additional test cases for Node.isSame(), property definition checks and Property.isSame().

Added:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyTest.java 
 (with props)
Modified:
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeTest.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java
    incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/PropertyDefTest.java

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeTest.java?view=diff&r1=158067&r2=158068
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/NodeTest.java Fri Mar
18 05:43:07 2005
@@ -758,6 +758,34 @@
     }
 
     /**
+     * Tests if <code>Item.isSame(Item otherItem)</code> will return true when
+     * two <code>Node</code> objects representing the same actual repository
+     * item have been retrieved through two different sessions and one has been
+     * modified.
+     */
+    public void testIsSameMustNotCompareStates()
+            throws RepositoryException {
+
+        // create a node and save it
+        Node testNode1 = testRootNode.addNode(nodeName1, testNodeType);
+        testRootNode.save();
+
+        // accuire the same node with a different session
+        Session session = helper.getReadOnlySession();
+        try {
+            Node testNode2 = (Node) session.getItem(testNode1.getPath());
+
+            // add a property and do not save it so property is different in testNode2
+            testNode1.setProperty(propertyName1, "value1");
+
+            assertTrue("Two references of same node should return true for Node1.isSame(Node2)",
+                    testNode1.isSame(testNode2));
+        } finally {
+            session.logout();
+        }
+    }
+
+    /**
      * Checks if {@link Node#isModified()} works correcty for unmodified and
      * modified nodes.
      */

Added: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyTest.java?view=auto&rev=158068
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyTest.java (added)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyTest.java Fri
Mar 18 05:43:07 2005
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.test.api;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Session;
+
+/**
+ * <code>PropertyTest</code> contains all test cases for the
+ * <code>javax.jcr.Property</code> that are related to writing, modifing or
+ * deleting properties (level 2 of the specification).
+ *
+ * @tck.config nodetype name of a node type. The node at <code>testroot</code>
+ * must allow child nodes with this node.
+ * @tck.config nodename1 name of a child node at <code>testroot</code>.
+ * @tck.config propertyname1 name of a string property in
+ * <code>nodetype</code>.
+ * 
+ * @test
+ * @sources PropertyTest.java
+ * @executeClass org.apache.jackrabbit.test.api.PropertyTest
+ * @keywords level2
+ */
+public class PropertyTest extends AbstractJCRTest {
+
+    /**
+     * Tests if <code>Item.isSame(Item otherItem)</code> will return true when
+     * two <code>Property</code> objects representing the same actual repository
+     * item have been retrieved through two different sessions and one has been
+     * modified.
+     */
+    public void testIsSameMustNotCompareStates()
+            throws RepositoryException {
+
+        // create a node, add a property and save it
+        Node testNode1 = testRootNode.addNode(nodeName1, testNodeType);
+        Property prop1 = testNode1.setProperty(propertyName1, "value1");
+        testRootNode.save();
+
+        // accuire the same property through a different session
+        Session session = helper.getSuperuserSession();
+        try {
+            Property prop2 = (Property) session.getItem(prop1.getPath());
+
+            // change the value of prop2
+            prop2.setValue("value2");
+
+            assertTrue("Two references of same property must return true for " +
+                    "property1.isSame(property2)", prop1.isSame(prop2));
+        } finally {
+            session.logout();
+        }
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/PropertyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java?view=diff&r1=158067&r2=158068
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/TestAll.java Fri Mar
18 05:43:07 2005
@@ -74,6 +74,7 @@
         suite.addTestSuite(NodeTest.class);
         suite.addTestSuite(NodeUUIDTest.class);
         suite.addTestSuite(NodeOrderableChildNodesTest.class);
+        suite.addTestSuite(PropertyTest.class);
 
         suite.addTestSuite(SetValueBinaryTest.class);
         suite.addTestSuite(SetValueBooleanTest.class);

Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/PropertyDefTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/PropertyDefTest.java?view=diff&r1=158067&r2=158068
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/PropertyDefTest.java
(original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/test/api/nodetype/PropertyDefTest.java
Fri Mar 18 05:43:07 2005
@@ -26,8 +26,7 @@
 import javax.jcr.PropertyType;
 import javax.jcr.Value;
 import javax.jcr.NodeIterator;
-import javax.jcr.Property;
-import javax.jcr.PathNotFoundException;
+import javax.jcr.NamespaceException;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeType;
@@ -278,6 +277,8 @@
                                 assertTrue("Value constraint does not match " +
                                         "the pattern of PropertyType.NAME",
                                         matcher.matches());
+
+                                checkPrefix(constraints[j]);
                                 break;
 
                             case PropertyType.PATH:
@@ -285,6 +286,11 @@
                                 assertTrue("Value constraint does not match " +
                                         "the pattern of PropertyType.PATH",
                                         matcher.matches());
+
+                                String elems[] = constraints[j].split("/");
+                                for (int k = 0; k < elems.length; k++) {
+                                    checkPrefix(elems[k]);
+                                }
                                 break;
 
                             case PropertyType.REFERENCE:
@@ -293,6 +299,8 @@
                                 assertTrue("Value constraint does not match " +
                                         "the pattern of PropertyType.REFERENCE",
                                         matcher.matches());
+
+                                checkPrefix(constraints[j]);
                                 break;
 
                             case PropertyType.BOOLEAN:
@@ -340,6 +348,8 @@
         }
     }
 
+    // ---------------------------------< internal >----------------------------
+
     /**
      * Traverses the node hierarchy and applies
      * {@link #checkMandatoryConstraint(javax.jcr.Node, javax.jcr.nodetype.NodeType)}
@@ -379,12 +389,15 @@
                 foundMandatoryProperty = true;
                 String name = propDef.getName();
 
+                assertTrue("Node instance does not contain value for mandatory property.",
node.hasProperty(name));
+                // todo check back with latest spec!
+                /*
                 try {
                     Property p = node.getProperty(name);
                     if (propDef.isMultiple()) {
                         // empty array fails
-                        assertFalse("A mandatory and multiple property " +
-                                "must not be empty.",
+                        assertFalse("The mandatory and multiple property " + p.getName()
+
+                                " must not be empty.",
                                 p.getValues().length == 0);
                     } else {
                         // empty value fails
@@ -394,7 +407,26 @@
                 } catch (PathNotFoundException e) {
                     fail("Mandatory property " + name + " does not exist.");
                 }
+                */
             }
         }
     }
-}
\ No newline at end of file
+
+    /**
+     * Checks for NAME, PATH and REFERENCE constraint values if the constraint
+     * is reflecting the namespace mapping in the current <code>Session</code>
+     *
+     * @throws NamespaceException if the prefix of name is not a registered
+     *                            namespace prefix
+     */
+    private void checkPrefix(String name)
+            throws NamespaceException, RepositoryException {
+
+        if (name.indexOf(":") != -1) {
+            String prefix = name.split(":")[0];
+
+            // NamespaceException is thrown if fails
+            session.getNamespaceURI(prefix);
+        }
+    }
+}



Mime
View raw message