jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r792142 [19/35] - in /jackrabbit/sandbox/JCR-1456: ./ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/ jackrabbit-api/src/main/java/org/apache/jackrabbit/api/security/ jackrabbit-core/ jackrabbit-core/src/main/java/org/apache/jackrab...
Date Wed, 08 Jul 2009 13:57:46 GMT
Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java Wed Jul  8 13:57:13 2009
@@ -18,12 +18,15 @@
 
 import org.apache.jackrabbit.test.NotExecutableException;
 
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+
+import javax.jcr.Binary;
 import javax.jcr.PropertyType;
-import javax.jcr.Value;
 import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
-import java.io.InputStream;
-import java.io.IOException;
 
 /**
  * Tests a binary property. If the workspace does not contain a node with a
@@ -89,6 +92,42 @@
     }
 
     /**
+     * Tests that when Binary.getStream() is called a second time a new stream
+     * object is returned.
+     */
+    public void testSameStreamJcr2() throws RepositoryException, IOException {
+        Value val = PropertyUtil.getValue(prop);
+        Binary bin = val.getBinary();
+        try {
+            InputStream in = bin.getStream();
+            InputStream in2 = bin.getStream();
+            try {
+                assertNotSame("Value.getStream() called on a new value " +
+                        "object should return a different Stream object.", in, in2);
+                //check if both streams can be read independently but contain the same bytes
+                int n,n2;
+                while ((n = in.read()) != -1) {
+                    n2 = in2.read();
+                    assertEquals("streams from the same binary object should have identical content", n, n2);
+                }
+                assertEquals("streams from the same binary object should have identical content", -1, in2.read());
+            } finally {
+                // cleaning up
+                try {
+                    in.close();
+                } catch (IOException ignore) {}
+                if (in2 != in) {
+                    try {
+                        in2.close();
+                    } catch (IOException ignore) {}
+                }
+            }
+        } finally {
+            bin.dispose();
+        }
+    }
+
+    /**
      * Tests the failure of calling Property.getStream() on a multivalue
      * property.
      */
@@ -110,6 +149,22 @@
     }
 
     /**
+     * Tests the failure of calling Property.getBinary() on a multivalue
+     * property.
+     */
+    public void testMultiValueJcr2() throws RepositoryException, IOException {
+        if (multiple) {
+            try {
+                prop.getBinary();
+                fail("Calling getStream() on a multivalue property " +
+                        "should throw a ValueFormatException.");
+            } catch (ValueFormatException vfe) {
+                // ok
+            }
+        }
+    }
+
+    /**
      * Tests that Property.getStream() delivers the same as Value.getStream().
      * We check this by reading each byte of the two streams and assuring that
      * they are equal.
@@ -145,6 +200,40 @@
     }
 
     /**
+     * Tests that Value.getStream() delivers the same as Value.getBinary.getStream().
+     * We check this by reading each byte of the two streams and assuring that
+     * they are equal.
+     */
+    public void testValueJcr2() throws IOException, RepositoryException {
+        Value val = PropertyUtil.getValue(prop);
+        InputStream in = val.getStream();
+        Binary bin = val.getBinary();
+        try {
+            InputStream in2 = bin.getStream();
+            try {
+                int b = in.read();
+                while (b != -1) {
+                    int b2 = in2.read();
+                    assertEquals("Value.getStream() and Value.getBinary().getStream() " +
+                            "return different values.", b, b2);
+                    b = in.read();
+                }
+                assertEquals("Value.getStream() and Value.getBinary().getStream() " +
+                        "return different values.", -1, in2.read());
+            } finally {
+                try {
+                    in.close();
+                } catch (IOException ignore) {}
+                try {
+                    in2.close();
+                } catch (IOException ignore) {}
+            }
+        } finally {
+            bin.dispose();
+        }
+    }
+
+    /**
      * Tests conversion from Binary type to Boolean type. This is done via
      * String conversion.
      */
@@ -295,6 +384,25 @@
     }
 
     /**
+     * Tests the Binary.getSize() method.
+     */
+    public void testGetLengthJcr2() throws RepositoryException {
+        Value val = PropertyUtil.getValue(prop);
+        Binary binary = val.getBinary();
+        long length;
+        try {
+            length = binary.getSize();
+        } finally {
+            binary.dispose();
+        }
+        long bytes = PropertyUtil.countBytes(prop.getValue());
+        if (bytes != -1) {
+            assertEquals("Binary.getSize() returns wrong number of bytes.",
+                    bytes, length);
+        }
+    }
+
+    /**
      * Tests the Property.getLengths() method. The test is successful, if either
      * -1 is returned
      */
@@ -319,4 +427,55 @@
             }
         }
     }
+
+    /**
+     * Tests the Binary.read() method.
+     */
+    public void testRandomAccess() throws RepositoryException, IOException {
+        Value val = PropertyUtil.getValue(prop);
+        Binary bin = val.getBinary();
+        try {
+            byte[] buf = new byte[0x1000];
+
+            //verify that reading behind EOF returns -1
+            assertEquals("reading behind EOF must return -1", -1, bin.read(buf, bin.getSize()));
+
+            //read content using Binary.read()
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            for (int cnt, pos = 0; (cnt = bin.read(buf, pos)) > 0; pos += cnt) {
+                out.write(buf, 0, cnt);
+            }
+            byte[] content = out.toByteArray();
+            assertEquals("unexpected content length", bin.getSize(), content.length);
+
+            //verify against stream
+            InputStream in = val.getStream();
+            try {
+                int k = 0;
+                for (int b; (b = in.read()) != -1; k++) {
+                    assertEquals("Value.getStream().read() and Value.getBinary().read() " +
+                            "return different values.", (byte) b, content[k]);
+                }
+                assertEquals("unexpected content length", k, content.length);
+            } finally {
+                try {
+                    in.close();
+                } catch (IOException ignore) {}
+            }
+
+            //verify random access
+            buf = new byte[1];
+            assertTrue("unexpected result of Value.getBinary.read()", -1 != bin.read(buf, 0));
+            assertEquals("unexpected result of Value.getBinary.read()", content[0], buf[0]);
+            if (content.length > 0) {
+                assertTrue("unexpected result of Value.getBinary.read()", -1 != bin.read(buf, content.length - 1));
+                assertEquals("unexpected result of Value.getBinary.read()", content[content.length - 1], buf[0]);
+                assertTrue("unexpected result of Value.getBinary.read()", -1 != bin.read(buf, 0));
+                assertEquals("unexpected result of Value.getBinary.read()", content[0], buf[0]);
+            }
+        } finally {
+            bin.dispose();
+        }
+    }
+    
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/CheckPermissionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/CheckPermissionTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/CheckPermissionTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/CheckPermissionTest.java Wed Jul  8 13:57:13 2009
@@ -43,7 +43,7 @@
         testRootNode.addNode(nodeName2, testNodeType);
         superuser.save();
 
-        Session readOnly = helper.getReadOnlySession();
+        Session readOnly = getHelper().getReadOnlySession();
         try {
             permissionCheckReadOnly(readOnly);
             permissionCheckReadWrite(superuser);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ExportDocViewTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ExportDocViewTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ExportDocViewTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ExportDocViewTest.java Wed Jul  8 13:57:13 2009
@@ -121,7 +121,7 @@
 
     protected void setUp() throws Exception {
         isReadOnly = true;
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
         workspace = session.getWorkspace();
         nsr = workspace.getNamespaceRegistry();
         file = File.createTempFile("docViewExportTest", ".xml");

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ExportSysViewTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ExportSysViewTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ExportSysViewTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ExportSysViewTest.java Wed Jul  8 13:57:13 2009
@@ -58,7 +58,7 @@
 
     protected void setUp() throws Exception {
         isReadOnly = true;
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
         file = File.createTempFile("SysViewExportTest", ".xml");
 
         super.setUp();

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ImpersonateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ImpersonateTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ImpersonateTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ImpersonateTest.java Wed Jul  8 13:57:13 2009
@@ -45,7 +45,7 @@
         // impersonate to read-only user
         Session session;
         try {
-            session = superuser.impersonate(helper.getReadOnlyCredentials());
+            session = superuser.impersonate(getHelper().getReadOnlyCredentials());
         } catch (LoginException e) {
             throw new NotExecutableException("impersonate threw LoginException");
         }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NamespaceRegistryReadMethodsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NamespaceRegistryReadMethodsTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NamespaceRegistryReadMethodsTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NamespaceRegistryReadMethodsTest.java Wed Jul  8 13:57:13 2009
@@ -55,7 +55,7 @@
     public void setUp() throws Exception {
         isReadOnly = true;
         super.setUp();
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
         Workspace ws = session.getWorkspace();
         nsr = ws.getNamespaceRegistry();
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NamespaceRemappingTest.java Wed Jul  8 13:57:13 2009
@@ -16,20 +16,23 @@
  */
 package org.apache.jackrabbit.test.api;
 
-import org.apache.jackrabbit.test.AbstractJCRTest;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
 
-import javax.jcr.Session;
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.RepositoryException;
 import javax.jcr.NamespaceException;
+import javax.jcr.NamespaceRegistry;
 import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.nodetype.NodeType;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Arrays;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
 
 /**
- * <code>NamespaceRemappingTest</code> tests transient namespace remapping.
+ * Test cases for JSR 283 sections 3.5.2 Session-Local Mappings and
+ * 5.11 Namespace Mapping and the related namespace mapping methods
+ * in {@link Session}.
  *
  * @test
  * @sources NamespaceRemappingTest.java
@@ -54,7 +57,7 @@
     protected void setUp() throws Exception {
         isReadOnly = true;
         super.setUp();
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
         nsr = session.getWorkspace().getNamespaceRegistry();
     }
 
@@ -99,55 +102,211 @@
     }
 
     /**
-     * Tests if the remapping is cleared in a new session object
-     */
-    public void testRemapClearing() throws RepositoryException {
-        // find an unused prefix
-        String testPrefix = getUnusedPrefix();
-        // remap jcr prefix
-        session.setNamespacePrefix(testPrefix, NS_JCR_URI);
-        session.logout();
+     * Test case for the automatic generation of a new local prefix for a
+     * registered namespace URI that doesn't have a local mapping, as specified
+     * in section 3.5.2 Session-Local Mappings:
+     *
+     * <blockquote>
+     * If a JCR method returns a name from the repository with a namespace URI
+     * for which no local mapping exists, a prefix is created automatically
+     * and a mapping between that prefix and the namespace URI in question is
+     * added to the set of local mappings. The new prefix must differ from
+     * those already present among the set of local mappings.
+     * </blockquote>
+     */
+    public void testAutomaticNewLocalPrefix() throws RepositoryException {
+        Set prefixes =
+            new HashSet(Arrays.asList(session.getNamespacePrefixes()));
+        prefixes.remove(session.getNamespacePrefix(NS_JCR_URI));
+        prefixes.remove(session.getNamespacePrefix(NS_NT_URI));
+
+        // Remove the local mapping of NS_JCR_URI
+        // NOTE: JCR 1.0 repositories will throw an exception on this
+        String before = session.getNamespacePrefix(NS_JCR_URI);
+        session.setNamespacePrefix(before, NS_NT_URI);
+
+        // Have the repository come up with a new prefix for this namespace
+        String name =
+            session.getProperty("/{" + NS_JCR_URI + "}primaryType").getName();
+        int colon = name.indexOf(':');
+        String after = name.substring(0, colon);
+
+        assertFalse(
+                "Automatically created new local prefix of a namespace"
+                + " must be different from the prefix that removed the mapping",
+                after.equals(before));
+
+        assertFalse(
+                "Automatically created new local prefix of a namespace"
+                + " must be different from those already present",
+                prefixes.contains(after));
 
-        session = helper.getReadOnlySession();
         try {
-            session.getNamespaceURI(testPrefix);
-            fail("Must throw a NamespaceException on unknown prefix.");
-        } catch (NamespaceException nse) {
-            // correct
+            assertEquals(
+                    "The local namespace mappings must match the"
+                    + " automatically created new prefix of a namespace",
+                    after, session.getNamespacePrefix(NS_JCR_URI));
+        } catch (NamespaceException e) {
+            fail("Automatically created new prefix must be included in"
+                    + " the set of local namespace mappings");
         }
     }
 
     /**
-     * Tests if a remapping to "xml" fails correctly
-     */
-    public void testXmlRemapping() throws RepositoryException {
+     * Test case for the unknown prefix behaviour specified in
+     * section 3.5.2 Session-Local Mappings:
+     * 
+     * <blockquote>
+     * If a JCR method is passed a name or path containing a prefix which
+     * does not exist in the local mapping an exception is thrown.
+     * </blockquote>
+     */
+    public void testExceptionOnUnknownPrefix() throws RepositoryException {
+        // Change the local prefix of of NS_JCR_URI
+        // NOTE: JCR 1.0 repositories will throw an exception on this
+        String before = session.getNamespacePrefix(NS_JCR_URI);
+        String after = before + "-changed";
+        session.setNamespacePrefix(after, NS_JCR_URI);
+
+        // Try to use the changed prefix
         try {
-            session.setNamespacePrefix("xml", NS_JCR_URI);
-            fail("Remapping a namespace uri to 'xml' must not be possible");
-        } catch (NamespaceException nse) {
-            // correct
+            session.propertyExists("/" + before + ":primaryType");
+            fail("A path with an unknown prefix must cause"
+                    + " an exception to be thrown");
+        } catch (RepositoryException expected) {
+        }
+    }
+
+    /**
+     * Test case for the initial set of local namespace mappings as specified
+     * in section 3.5.2 Session-Local Mappings:
+     *
+     * <blockquote> 
+     * When a new session is acquired, the mappings present in the persistent
+     * namespace registry are copied to the local namespace mappings of that
+     * session.
+     * </blockquote>
+     */
+    public void testInitialLocalNamespaceMappings() throws RepositoryException {
+        String[] uris = nsr.getURIs();
+        for (int i = 0; i < uris.length; i++) {
+            assertEquals(
+                    "The initial local namespace prefix of \""
+                    + uris[i] + "\" must match the persistent registry mapping",
+                    nsr.getPrefix(uris[i]),
+                    session.getNamespacePrefix(uris[i]));
+            
         }
+    }
+
+    /**
+     * Test case for the scope of the local namespace mappings as specified
+     * in section 3.5.2 Session-Local Mappings:
+     *
+     * <blockquote> 
+     * The resulting mapping table applies only within the scope of that session
+     * </blockquote>
+     *
+     * <p>
+     * Also specified in the javadoc of
+     * {@link Session#setNamespacePrefix(String, String)}:
+     *
+     * <blockquote>
+     * The remapping only affects operations done through this
+     * <code>Session</code>. To clear all remappings, the client must
+     * acquire a new <code>Session</code>.
+     * </blockquote>
+     */
+    public void testScopeOfLocalNamepaceMappings() throws RepositoryException {
+        String before = session.getNamespacePrefix(NS_JCR_URI);
+        String after = before + "-changed";
+
+        // Change the prefix of a well-known namespace
+        session.setNamespacePrefix(after, NS_JCR_URI);
+        assertEquals(after, session.getNamespacePrefix(NS_JCR_URI));
+
+        // Check whether the mapping affects another session
+        Session another = getHelper().getReadOnlySession();
         try {
-            session.setNamespacePrefix("xmlfoo", NS_JCR_URI);
-            fail("Remapping a namespace uri to 'xmlfoo' must not be possible");
-        } catch (NamespaceException nse) {
-            // correct
+            assertEquals(
+                    "Local namespace changes must not affect other sessions",
+                    before, another.getNamespacePrefix(NS_JCR_URI));
+        } finally {
+            another.logout();
         }
     }
 
     /**
-     * tests that when a prefix which is mapped to a URI yet globally registered
-     * this prefix cannot be remapped to another URI with
-     * session.setNamespacePrefix()
+     * Test case for the exception clauses of section 5.11 Namespace Mapping:
+     *
+     * <blockquote>
+     * However, the method will throw an exception if
+     * <ul>
+     * <li>the specified prefix begins with the characters “xml”
+     *     (in any combination of case) or,</li>
+     * <li>the specified prefix is the empty string or,</li>
+     * <li>the specified namespace URI is the empty string.</li>
+     * </blockquote>
+     *
+     * <p>
+     * Also specified in the javadoc for throwing a {@link NamespaceException}
+     * from {@link Session#setNamespacePrefix(String, String)}:
+     *
+     * <blockquote>
+     * if an attempt is made to map a namespace URI to a prefix beginning
+     * with the characters "<code>xml</code>" (in any combination of case)
+     * or if an attempt is made to map either the empty prefix or the empty
+     * namespace (i.e., if either <code>prefix</code> or  <code>uri</code>
+     * are the empty string).
+     * </blockquote>
+     *
+     * <p>
+     * Section 3.2 Names also contains extra constraints on the prefix and
+     * namespace URI syntax:
+     *
+     * <blockquote><pre>
+     * Namespace   ::= EmptyString | Uri
+     * EmptyString ::= The empty string
+     * Uri         ::= A URI, as defined in Section 3 in
+     *                 http://tools.ietf.org/html/rfc3986#section-3
+     * Prefix      ::= Any string that matches the NCName production in
+     *                 http://www.w3.org/TR/REC-xml-names
+     * </blockquote>
+     *
+     * <p>
+     * It is unspecified whether an implementation should actually enforce
+     * these constraints, so for now this test case <em>does not</em>
+     * check this behaviour.
+     */
+    public void testExceptionsFromRemapping() throws RepositoryException {
+        // Remapping to "xml..." in any combination of case must fail
+        assertSetNamespacePrefixFails("xml",    NS_JCR_URI);
+        assertSetNamespacePrefixFails("xmlfoo", NS_JCR_URI);
+        assertSetNamespacePrefixFails("XML",    NS_JCR_URI);
+        assertSetNamespacePrefixFails("XMLFOO", NS_JCR_URI);
+        assertSetNamespacePrefixFails("Xml",    NS_JCR_URI);
+        assertSetNamespacePrefixFails("XmlFoo", NS_JCR_URI);
+
+        // Remapping the empty prefix or empty URI must fail
+        assertSetNamespacePrefixFails("", NS_JCR_URI);
+        assertSetNamespacePrefixFails("prefix", "");
+    }
+
+    /**
+     * Checks that a {@link Session#setNamespacePrefix(String, String)}
+     * call with the given arguments throws a {@link NamespaceException}.
+     *
+     * @param prefix namespace prefix
+     * @param uri namespace URI
+     * @throws RepositoryException if another error occurs
      */
-    public void testNamespaceException() throws RepositoryException {
-        String testURI = getUnusedURI();
-        String prefix = session.getNamespacePrefix(NS_JCR_URI);
+    private void assertSetNamespacePrefixFails(String prefix, String uri)
+            throws RepositoryException {
         try {
-            session.setNamespacePrefix(prefix, testURI);
-            fail("NamespaceRegistry must not register a URI with an already assign prefix");
-        } catch (NamespaceException nse) {
-            // ok
+            session.setNamespacePrefix(prefix, uri);
+            fail("Setting a local namespace mapping from \""
+                    + prefix + "\" to \"" + uri + "\" must fail");
+        } catch (NamespaceException expected) {
         }
     }
 
@@ -225,19 +384,4 @@
         return prefix + count;
     }
 
-    /**
-     * Returns a namespace uri that is not in use.
-     *
-     * @return a namespace uri that is not in use.
-     */
-    private String getUnusedURI() throws RepositoryException {
-        Set uris = new HashSet();
-        uris.addAll(Arrays.asList(nsr.getURIs()));
-        String uri = "http://www.unknown-company.com/namespace";
-        int count = 0;
-        while (uris.contains(uri + count)) {
-            count++;
-        }
-        return uri + count;
-    }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeAddMixinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeAddMixinTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeAddMixinTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeAddMixinTest.java Wed Jul  8 13:57:13 2009
@@ -103,6 +103,60 @@
         }
     }
 
+    /**
+     * Test if adding the same mixin twice works as expected.
+     * 
+     * @throws RepositoryException
+     * @throws NotExecutableException
+     * @since JCR 2.0
+     */
+    public void testAddMixinTwice() throws RepositoryException, NotExecutableException {
+        Session session = testRootNode.getSession();
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        node.addMixin(mixinName);
+        // adding again must succeed
+        node.addMixin(mixinName);
+
+        session.save();
+        
+        node.addMixin(mixinName);
+        assertFalse(node.isModified());
+    }
+
+    /**
+     * Test if adding an inherited mixin type has no effect.
+     * 
+     * @throws RepositoryException
+     * @since JCR 2.0
+     */
+    public void testAddInheritedMixin() throws RepositoryException, NotExecutableException {
+        Session session = testRootNode.getSession();
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        session.save();
+
+        String inheritedMixin = null;
+
+        NodeType nt = node.getPrimaryNodeType();
+        NodeType[] superTypes = nt.getSupertypes();
+        for (int i = 0; i < superTypes.length && inheritedMixin == null; i++) {
+            if (superTypes[i].isMixin()) {
+                inheritedMixin = superTypes[i].getName();
+            }
+        }
+
+        if (inheritedMixin != null) {
+            node.addMixin(inheritedMixin);
+            assertFalse(node.isModified());
+        } else {
+            throw new NotExecutableException("Primary node type does not have a mixin supertype");
+        }
+    }
 
     /**
      * Tests if <code>Node.addMixin(String mixinName)</code> throws a
@@ -125,14 +179,7 @@
         // create a node that is lockable
         Node node = testRootNode.addNode(nodeName1, testNodeType);
         // or try to make it lockable if it is not
-        if (!node.isNodeType(mixLockable)) {
-            if (node.canAddMixin(mixLockable)) {
-                node.addMixin(mixLockable);
-            } else {
-                throw new NotExecutableException("Node " + nodeName1 + " is not lockable and does not " +
-                        "allow to add mix:lockable");
-            }
-        }
+        ensureMixinType(node, mixLockable);
         testRootNode.save();
 
         String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
@@ -144,7 +191,7 @@
         String pathRelToRoot = node.getPath().substring(1);
 
         // access node through another session to lock it
-        Session session2 = helper.getSuperuserSession();
+        Session session2 = getHelper().getSuperuserSession();
         try {
             Node node2 = session2.getRootNode().getNode(pathRelToRoot);
             node2.lock(true, true);
@@ -187,14 +234,7 @@
         // create a node that is versionable
         Node node = testRootNode.addNode(nodeName1, testNodeType);
         // or try to make it versionable if it is not
-        if (!node.isNodeType(mixVersionable)) {
-            if (node.canAddMixin(mixVersionable)) {
-                node.addMixin(mixVersionable);
-            } else {
-                throw new NotExecutableException("Node " + nodeName1 + " is not versionable and does not " +
-                        "allow to add mix:versionable");
-            }
-        }
+        ensureMixinType(node, mixVersionable);
         testRootNode.save();
 
         String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
@@ -225,9 +265,7 @@
 
         // get session an create default node
         Node node = testRootNode.addNode(nodeName1, testNodeType);
-        if (needsMixin(node, mixReferenceable)) {
-            node.addMixin(mixReferenceable);
-        }
+        ensureMixinType(node, mixReferenceable);
         // implementation specific: mixin may take effect only upon save
         testRootNode.save();
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeCanAddMixinTest.java Wed Jul  8 13:57:13 2009
@@ -25,6 +25,7 @@
 import javax.jcr.Repository;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.NodeType;
 
 /**
  * <code>NodeCanAddMixinTest</code> contains the test cases for the method
@@ -53,14 +54,7 @@
         // create a node that is lockable
         Node node = testRootNode.addNode(nodeName1, testNodeType);
         // or try to make it lockable if it is not
-        if (!node.isNodeType(mixLockable)) {
-            if (node.canAddMixin(mixLockable)) {
-                node.addMixin(mixLockable);
-            } else {
-                throw new NotExecutableException("Node " + nodeName1 + " is not lockable and does not " +
-                        "allow to add mix:lockable");
-            }
-        }
+        ensureMixinType(node, mixLockable);
         testRootNode.save();
 
         String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
@@ -72,7 +66,7 @@
         String pathRelToRoot = node.getPath().substring(1);
 
         // access node through another session to lock it
-        Session session2 = helper.getSuperuserSession();
+        Session session2 = getHelper().getSuperuserSession();
         try {
             Node node2 = session2.getRootNode().getNode(pathRelToRoot);
             node2.lock(true, true);
@@ -104,14 +98,7 @@
         // create a node that is versionable
         Node node = testRootNode.addNode(nodeName1, testNodeType);
         // or try to make it versionable if it is not
-        if (!node.isNodeType(mixVersionable)) {
-            if (node.canAddMixin(mixVersionable)) {
-                node.addMixin(mixVersionable);
-            } else {
-                throw new NotExecutableException("Node " + nodeName1 + " is not versionable and does not " +
-                        "allow to add mix:versionable");
-            }
-        }
+        ensureMixinType(node, mixVersionable);
         testRootNode.save();
 
         String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
@@ -146,4 +133,53 @@
         }
     }
 
+       /**
+     * Test if adding the same mixin twice would be allowed.
+     *
+     * @throws RepositoryException
+     * @throws NotExecutableException
+     * @since JCR 2.0
+     */
+    public void testAddMixinTwice() throws RepositoryException, NotExecutableException {
+        Session session = testRootNode.getSession();
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
+
+        if (mixinName == null) {
+            throw new NotExecutableException("No testable mixin node type found");
+        }
+
+        assertTrue(node.canAddMixin(mixinName));
+        node.addMixin(mixinName);
+        // adding again must be possible (though it has no effect)
+        assertTrue(node.canAddMixin(mixinName));
+
+        session.save();
+
+        // adding again must be possible (though it has no effect)
+        assertTrue(node.canAddMixin(mixinName));
+    }
+
+    /**
+     * Test if an inherited mixin could be added.
+     *
+     * @throws RepositoryException
+     * @since JCR 2.0
+     */
+    public void testAddInheritedMixin() throws RepositoryException {
+        Session session = testRootNode.getSession();
+        Node node = testRootNode.addNode(nodeName1, testNodeType);
+        session.save();
+
+        NodeType nt = node.getPrimaryNodeType();
+        NodeType[] superTypes = nt.getSupertypes();
+        for (int i = 0; i < superTypes.length; i++) {
+            if (superTypes[i].isMixin()) {
+                String mixinName = superTypes[i].getName();
+                // adding again must be possible (though it has no effect)
+                assertTrue(node.canAddMixin(mixinName));
+            }
+        }
+    }
+
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeDiscoveringNodeTypesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeDiscoveringNodeTypesTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeDiscoveringNodeTypesTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeDiscoveringNodeTypesTest.java Wed Jul  8 13:57:13 2009
@@ -56,7 +56,7 @@
         isReadOnly = true;
         super.setUp();
 
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
         testRootNode = session.getRootNode().getNode(testPath);
         NodeIterator nodes = testRootNode.getNodes();
         try {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeMixinUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeMixinUtil.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeMixinUtil.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeMixinUtil.java Wed Jul  8 13:57:13 2009
@@ -21,6 +21,9 @@
 import javax.jcr.Node;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeIterator;
+import javax.jcr.nodetype.NodeType;
+import java.util.List;
+import java.util.Arrays;
 
 /**
  * Utility class to locate mixins in the NodeTyeManager.
@@ -46,6 +49,20 @@
         return null;
     }
 
+    public static String getNotAssignedMixinName(Session session, Node node) throws RepositoryException {
+        NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
+        NodeTypeIterator mixins = manager.getMixinNodeTypes();
+        List existingMixins = Arrays.asList(node.getMixinNodeTypes());
+
+        while (mixins.hasNext()) {
+            NodeType nt = mixins.nextNodeType();
+            if (!existingMixins.contains(nt)) {
+                return nt.getName();
+            }
+        }
+        return null;
+    }
+
     /**
      * @return a string that is not the name of a mixin type
      */

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeReadMethodsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeReadMethodsTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeReadMethodsTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeReadMethodsTest.java Wed Jul  8 13:57:13 2009
@@ -32,6 +32,7 @@
 import javax.jcr.PropertyType;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import java.util.ArrayList;
+import java.util.List;
 import java.util.NoSuchElementException;
 
 /**
@@ -65,7 +66,7 @@
         isReadOnly = true;
         super.setUp();
 
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
 
         testRootNode = session.getRootNode().getNode(testPath);
         NodeIterator nodes = testRootNode.getNodes();
@@ -229,7 +230,7 @@
      */
     public void testIsSame() throws RepositoryException {
         // access same node through different session
-        Session s = helper.getReadOnlySession();
+        Session s = getHelper().getReadOnlySession();
         try {
             Item otherTestNode = s.getRootNode().getNode(testPath);
             assertTrue("isSame(Item item) must return true for the same " +
@@ -432,6 +433,152 @@
     }
 
     /**
+     * Test getNodes(String[] namePattern) with all possible patterns. Tested
+     * node: root
+     * @throws NotExecutableException is thrown when root node has no sub
+     * nodes.
+     */
+    public void testGetNodesNamePatternArray()
+            throws NotExecutableException, RepositoryException {
+
+        // get root node and build an ArrayList of its sub nodes
+        Node node = testRootNode;
+        if (!node.hasNodes()) {
+            throw new NotExecutableException("Workspace does not have sufficient content for this test. " +
+                    "Root node must have at least one child node.");
+        }
+        NodeIterator allNodesIt = node.getNodes();
+        ArrayList allNodes = new ArrayList();
+        while (allNodesIt.hasNext()) {
+            Node n = allNodesIt.nextNode();
+            allNodes.add(n);
+        }
+
+        // test if an empty NodeIterator is returned
+        // when the pattern is not matching any child node
+        String pattern0 = "";
+        NodeIterator nodes0 = node.getNodes(new String[] { pattern0 });
+        try {
+            nodes0.nextNode();
+            fail("An empty NodeIterator must be returned if pattern does" +
+                    "not match any child node.");
+        } catch (NoSuchElementException e) {
+            // success
+        }
+
+        // all further tests are using root's first sub node
+        Node firstNode = (Node) allNodes.get(0);
+
+        // test pattern "*"
+        String pattern1 = "*";
+        String assertString1 = "node.getNodes(\"" + pattern1 + "\"): ";
+        NodeIterator nodes1 = node.getNodes(new String[] { pattern1 });
+        // test if the number of found nodes is correct
+        assertEquals(assertString1 + "number of nodes found: ",
+                allNodes.size(),
+                getSize(nodes1));
+
+        // test pattern "nodeName"
+        String pattern2 = firstNode.getName();
+        String assertString2 = "node.getNodes(\"" + pattern2 + "\"): ";
+        // test if the names of the found nodes are matching the pattern
+        NodeIterator nodes2 = node.getNodes(new String[] { pattern2 });
+        while (nodes2.hasNext()) {
+            Node n = nodes2.nextNode();
+            assertEquals(assertString2 + "name comparison failed: ",
+                    firstNode.getName(),
+                    n.getName());
+        }
+        // test if the number of found nodes is correct
+        int numExpected2 = 0;
+        for (int i = 0; i < allNodes.size(); i++) {
+            Node n = (Node) allNodes.get(i);
+            if (n.getName().equals(firstNode.getName())) {
+                numExpected2++;
+            }
+        }
+        assertEquals(assertString2 + "number of nodes found: ",
+                numExpected2,
+                getSize(nodes2));
+
+
+        // test pattern "nodeName|nodeName"
+        String pattern3 = firstNode.getName() + "|" + firstNode.getName();
+        String assertString3 = "node.getNodes(\"" + pattern3 + "\"): ";
+        // test if the names of the found nodes are matching the pattern
+        NodeIterator nodes3 = node.getNodes(pattern3);
+        while (nodes3.hasNext()) {
+            Node n = nodes3.nextNode();
+            assertEquals(assertString2 + "name comparison failed: ",
+                    firstNode.getName(),
+                    n.getName());
+        }
+        // test if the number of found nodes is correct
+        int numExpected3 = 0;
+        for (int i = 0; i < allNodes.size(); i++) {
+            Node n = (Node) allNodes.get(i);
+            if (n.getName().equals(firstNode.getName())) {
+                numExpected3++;
+            }
+        }
+        assertEquals(assertString3 + "number of nodes found: ",
+                numExpected3,
+                getSize(nodes3));
+
+
+        // test pattern "nodeName", "nodeName"
+        String pattern4 = firstNode.getName() + "," + firstNode.getName();
+        String assertString4 = "node.getNodes(\"" + pattern4 + "\"): ";
+        // test if the names of the found nodes are matching the pattern
+        NodeIterator nodes4 = node.getNodes(new String[] { firstNode.getName(), firstNode.getName() });
+        while (nodes4.hasNext()) {
+            Node n = nodes4.nextNode();
+            assertEquals(assertString2 + "name comparison failed: ",
+                    firstNode.getName(),
+                    n.getName());
+        }
+        // test if the number of found nodes is correct
+        int numExpected4 = 0;
+        for (int i = 0; i < allNodes.size(); i++) {
+            Node n = (Node) allNodes.get(i);
+            if (n.getName().equals(firstNode.getName())) {
+                numExpected4++;
+            }
+        }
+        assertEquals(assertString4 + "number of nodes found: ",
+                numExpected4,
+                getSize(nodes4));
+
+
+        // test pattern "*odeNam*"
+        if (firstNode.getName().length() > 2) {
+            String name = firstNode.getName();
+            String shortenName = name.substring(1, name.length() - 1);
+            String pattern5 = "*" + shortenName + "*";
+            String assertString5 = "node.getNodes(\"" + pattern5 + "\"): ";
+            // test if the names of the found nodes are matching the pattern
+            NodeIterator nodes5 = node.getNodes(new String[] { pattern5 });
+            while (nodes5.hasNext()) {
+                Node n = nodes5.nextNode();
+                assertTrue(assertString5 + "name comparison failed: *" +
+                        shortenName + "* not found in " + n.getName(),
+                        n.getName().indexOf(shortenName) != -1);
+            }
+            // test if the number of found nodes is correct
+            int numExpected5 = 0;
+            for (int i = 0; i < allNodes.size(); i++) {
+                Node n = (Node) allNodes.get(i);
+                if (n.getName().indexOf(shortenName) != -1) {
+                    numExpected5++;
+                }
+            }
+            assertEquals(assertString5 + "number of nodes found: ",
+                    numExpected5,
+                    getSize(nodes5));
+        }
+    }
+
+    /**
      * Test if getProperty(String relPath) returns the correct node and if a
      * PathNotFoundException is thrown when property at relPath does not exist
      */
@@ -600,6 +747,137 @@
     }
 
     /**
+     * Test getProperties(String[] namePattern) with all possible patterns. 
+     * @throws NotExecutableException is thrown when root node has no properties.
+     */
+    public void testGetPropertiesNamePatternArray()
+            throws NotExecutableException, RepositoryException {
+
+        // get root node and build an ArrayList of its sub nodes
+        Node node = testRootNode;
+        if (!node.hasProperties()) {
+            fail("Root node must always have at least one property: jcr:primaryType");
+        }
+        PropertyIterator allPropertiesIt = node.getProperties();
+        List allProperties = new ArrayList();
+        StringBuffer notExistingPropertyName = new StringBuffer();
+        while (allPropertiesIt.hasNext()) {
+            Property p = allPropertiesIt.nextProperty();
+            allProperties.add(p);
+            notExistingPropertyName.append(p.getName() + "X");
+        }
+
+        // all tests are running using root's first property
+        Property firstProperty = (Property) allProperties.get(0);
+
+        // test: getProperties("*")
+        String pattern1 = "*";
+        String assertString1 = "node.getProperties(\"" + pattern1 + "\"): ";
+        PropertyIterator properties1 = node.getProperties(new String[] { pattern1 });
+        assertEquals(assertString1 + "number of properties found: ",
+                allProperties.size(),
+                getSize(properties1));
+
+        // test: getProperties("propertyName")
+        String pattern2 = firstProperty.getName();
+        String assertString2 = "node.getProperties(\"" + pattern2 + "\"): ";
+        // test if the names of the found properties are matching the pattern
+        PropertyIterator properties2 = node.getProperties(new String[] { pattern2 });
+        while (properties2.hasNext()) {
+            Property p = properties2.nextProperty();
+            assertEquals(assertString2 + "name comparison failed: ",
+                    firstProperty.getName(),
+                    p.getName());
+        }
+        // test if the number of found properties is correct
+        int numExpected2 = 0;
+        for (int i = 0; i < allProperties.size(); i++) {
+            Property p = (Property) allProperties.get(i);
+            if (p.getName().equals(firstProperty.getName())) {
+                numExpected2++;
+            }
+        }
+        assertEquals(assertString2 + "number of properties found: ",
+                numExpected2,
+                getSize(properties2));
+
+
+        // test: getProperties("propertyName|propertyName")
+        String pattern3 = firstProperty.getName() + "|" + firstProperty.getName();
+        String assertString3 = "node.getProperties(\"" + pattern3 + "\"): ";
+        // test if the names of the found properties are matching the pattern
+        PropertyIterator properties3 = node.getProperties(new String[] { pattern3 });
+        while (properties3.hasNext()) {
+            Property p = properties3.nextProperty();
+            assertEquals(assertString2 + "name comparison failed: ",
+                    firstProperty.getName(),
+                    p.getName());
+        }
+        // test if the number of found properties is correct
+        int numExpected3 = 0;
+        for (int i = 0; i < allProperties.size(); i++) {
+            Property p = (Property) allProperties.get(i);
+            if (p.getName().equals(firstProperty.getName())) {
+                numExpected3++;
+            }
+        }
+        assertEquals(assertString3 + "number of properties found: ",
+                numExpected3,
+                getSize(properties3));
+
+        // test: getProperties("propertyName", "propertyName")
+        String pattern4 = firstProperty.getName() + "," + firstProperty.getName();
+        String assertString4 = "node.getProperties(\"" + pattern4 + "\"): ";
+        // test if the names of the found properties are matching the pattern
+        PropertyIterator properties4 = node.getProperties(new String[] { firstProperty.getName(), firstProperty.getName() });
+        while (properties4.hasNext()) {
+            Property p = properties4.nextProperty();
+            assertEquals(assertString2 + "name comparison failed: ",
+                    firstProperty.getName(),
+                    p.getName());
+        }
+        // test if the number of found properties is correct
+        int numExpected4 = 0;
+        for (int i = 0; i < allProperties.size(); i++) {
+            Property p = (Property) allProperties.get(i);
+            if (p.getName().equals(firstProperty.getName())) {
+                numExpected4++;
+            }
+        }
+        assertEquals(assertString4 + "number of properties found: ",
+                numExpected4,
+                getSize(properties4));
+
+        // test: getProperties("*opertyNam*")
+        if (firstProperty.getName().length() > 2) {
+            String name = firstProperty.getName();
+            String shortenName = name.substring(1, name.length() - 1);
+            String pattern5 = "*" + shortenName + "*";
+            String assertString5 = "node.getProperties(\"" + pattern5 + "\"): ";
+            // test if the names of the found properties are matching the pattern
+            PropertyIterator properties5 = node.getProperties(new String[] { pattern5 });
+            while (properties5.hasNext()) {
+                Property p = properties5.nextProperty();
+                assertTrue(assertString5 + "name comparison failed: *" +
+                        shortenName + "* not found in " + p.getName(),
+                        p.getName().indexOf(shortenName) != -1);
+            }
+            // test if the number of found properties is correct
+            int numExpected5 = 0;
+            for (int i = 0; i < allProperties.size(); i++) {
+                Property p = (Property) allProperties.get(i);
+                if (p.getName().indexOf(shortenName) != -1) {
+                    numExpected5++;
+                }
+            }
+            properties5 = node.getProperties(pattern5);
+            assertEquals(assertString5 + "number of properties found: ",
+                    numExpected5,
+                    getSize(properties5));
+        }
+    }
+
+    /**
      * Test if getPrimaryItem returns the primary item as defined in the primary
      * node type. Therefor a node with a primary item is located recursively in
      * the entire repository. A NotExecutableException is thrown when no such

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeRemoveMixinTest.java Wed Jul  8 13:57:13 2009
@@ -112,7 +112,8 @@
         node.addMixin(mixinName);
         testRootNode.save();
 
-        String notAssignedMixin = NodeMixinUtil.getAddableMixinName(session, node);
+
+        String notAssignedMixin = NodeMixinUtil.getNotAssignedMixinName(session, node);
         if (notAssignedMixin == null) {
             throw new NotExecutableException("No testable mixin node type found");
         }
@@ -148,14 +149,7 @@
         // create a node that is lockable
         Node node = testRootNode.addNode(nodeName1, testNodeType);
         // or try to make it lockable if it is not
-        if (!node.isNodeType(mixLockable)) {
-            if (node.canAddMixin(mixLockable)) {
-                node.addMixin(mixLockable);
-            } else {
-                throw new NotExecutableException("Node " + nodeName1 + " is not lockable and does not " +
-                        "allow to add mix:lockable");
-            }
-        }
+        ensureMixinType(node, mixLockable);
         testRootNode.save();
 
         String mixinName = NodeMixinUtil.getAddableMixinName(session, node);
@@ -170,7 +164,7 @@
         String pathRelToRoot = node.getPath().substring(1);
 
         // access node through another session to lock it
-        Session session2 = helper.getSuperuserSession();
+        Session session2 = getHelper().getSuperuserSession();
         try {
             Node node2 = session2.getRootNode().getNode(pathRelToRoot);
             node2.lock(true, true);
@@ -213,14 +207,7 @@
         // create a node that is versionable
         Node node = testRootNode.addNode(nodeName1, testNodeType);
         // or try to make it versionable if it is not
-        if (!node.isNodeType(mixVersionable)) {
-            if (node.canAddMixin(mixVersionable)) {
-                node.addMixin(mixVersionable);
-            } else {
-                throw new NotExecutableException("Node " + nodeName1 + " is not versionable and does not " +
-                        "allow to add mix:versionable");
-            }
-        }
+        ensureMixinType(node, mixVersionable);
         testRootNode.save();
 
         String mixinName = NodeMixinUtil.getAddableMixinName(session, node);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeTest.java Wed Jul  8 13:57:13 2009
@@ -55,7 +55,7 @@
         super.setUp();
 
         // login to second workspace
-        superuserW2 = helper.getSuperuserSession(workspaceName);
+        superuserW2 = getHelper().getSuperuserSession(workspaceName);
     }
 
     /**
@@ -470,7 +470,7 @@
         defaultRootNode.save();
 
         // use a different session to verify if the node is there
-        Session session = helper.getReadOnlySession();
+        Session session = getHelper().getReadOnlySession();
         try {
             testNode = (Node) session.getItem(testNode.getPath());
         } finally {
@@ -494,7 +494,7 @@
         superuser.save();
 
         // use a different session to verify if the node is there
-        Session session = helper.getReadOnlySession();
+        Session session = getHelper().getReadOnlySession();
         try {
             testNode = (Node) session.getItem(testNode.getPath());
         } finally {
@@ -558,7 +558,7 @@
         superuser.save();
 
         // get the node with session 2
-        Session testSession = helper.getReadWriteSession();
+        Session testSession = getHelper().getReadWriteSession();
         try {
             Node defaultTestNodeSession2 = (Node) testSession.getItem(defaultTestNode.getPath());
 
@@ -657,21 +657,14 @@
         // create a node that is lockable
         Node node = testRootNode.addNode(nodeName1, testNodeType);
         // or try to make it lockable if it is not
-        if (!node.isNodeType(mixLockable)) {
-            if (node.canAddMixin(mixLockable)) {
-                node.addMixin(mixLockable);
-            } else {
-                throw new NotExecutableException("Node " + nodeName1 + " is not lockable and does not " +
-                        "allow to add mix:lockable");
-            }
-        }
+        ensureMixinType(node, mixLockable);
         testRootNode.save();
 
         // remove first slash of path to get rel path to root
         String pathRelToRoot = node.getPath().substring(1);
 
         // access node through another session to lock it
-        Session session2 = helper.getSuperuserSession();
+        Session session2 = getHelper().getSuperuserSession();
         try {
             Node node2 = session2.getRootNode().getNode(pathRelToRoot);
             node2.lock(true, true);
@@ -705,14 +698,7 @@
         // create a node that is lockable
         Node node = testRootNode.addNode(nodeName1, testNodeType);
         // or try to make it lockable if it is not
-        if (!node.isNodeType(mixLockable)) {
-            if (node.canAddMixin(mixLockable)) {
-                node.addMixin(mixLockable);
-            } else {
-                throw new NotExecutableException("Node " + nodeName1 + " is not lockable and does not " +
-                        "allow to add mix:lockable");
-            }
-        }
+        ensureMixinType(node, mixLockable);
         // create a child node
         Node subNode = node.addNode(nodeName2, testNodeType);
         testRootNode.save();
@@ -721,7 +707,7 @@
         // remove first slash of path to get rel path to root
         String pathRelToRoot = node.getPath().substring(1);
         // access node through another session to lock it
-        Session session2 = helper.getSuperuserSession();
+        Session session2 = getHelper().getSuperuserSession();
         try {
             Node node2 = session2.getRootNode().getNode(pathRelToRoot);
             node2.lock(true, true);
@@ -797,7 +783,7 @@
         testRootNode.save();
 
         // accuire the same node with a different session
-        Session session = helper.getReadOnlySession();
+        Session session = getHelper().getReadOnlySession();
         try {
             Node testNode2 = (Node) session.getItem(testNode1.getPath());
 
@@ -916,7 +902,7 @@
         testNode1Session1.addNode(nodeName2, testNodeType);
 
         // get session 2
-        Session session2 = helper.getReadWriteSession();
+        Session session2 = getHelper().getReadWriteSession();
 
         try {
             // get the second node
@@ -975,7 +961,7 @@
         testNode1Session1.addNode(nodeName2, testNodeType);
 
         // get session 2
-        Session session2 = helper.getReadWriteSession();
+        Session session2 = getHelper().getReadWriteSession();
 
         try {
             // get the second node
@@ -1030,7 +1016,7 @@
         nodeSession1.addNode(nodeName2, testNodeType);
 
         // get the new node with a different session
-        Session testSession = helper.getReadWriteSession();
+        Session testSession = getHelper().getReadWriteSession();
         try {
             Node nodeSession2 = (Node) testSession.getItem(nodeSession1.getPath());
 
@@ -1091,7 +1077,7 @@
         defaultRootNode.save();
 
         // get the new node with a different session
-        Session testSession = helper.getReadOnlySession();
+        Session testSession = getHelper().getReadOnlySession();
         try {
             testSession.getItem(testNode.getPath());
         } finally {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeUUIDTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeUUIDTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeUUIDTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/NodeUUIDTest.java Wed Jul  8 13:57:13 2009
@@ -122,7 +122,7 @@
         superuser.save();
 
         // get the moving node with session 2
-        Session testSession = helper.getReadWriteSession();
+        Session testSession = getHelper().getReadWriteSession();
         try {
             Node refTargetNodeSession2 = (Node) testSession.getItem(refTargetNode.getPath());
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyReadMethodsTest.java Wed Jul  8 13:57:13 2009
@@ -57,7 +57,7 @@
         isReadOnly = true;
         super.setUp();
 
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
         testRootNode = session.getRootNode().getNode(testPath);
 
         PropertyIterator properties = testRootNode.getProperties();
@@ -176,6 +176,14 @@
     }
 
     /**
+     * Tests if isMultiple() is consistent with PropertyDefinition.isMultiple().
+     */
+    public void testIsMultiple() throws RepositoryException {
+        assertEquals("Property.isMultiple() must be consistent with PropertyDefinition.isMultiple()",
+                property.isMultiple(), property.getDefinition().isMultiple());
+    }
+
+    /**
      * Tests if isNode() returns false
      */
     public void testIsNode() {
@@ -189,7 +197,7 @@
      */
     public void testIsSame() throws RepositoryException {
         // access same property through different session
-        Session otherSession = helper.getReadOnlySession();
+        Session otherSession = getHelper().getReadOnlySession();
         try {
             Property otherProperty = otherSession.getRootNode().getNode(testPath).getProperty(property.getName());
             assertTrue("isSame must return true for the same " +

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyTest.java Wed Jul  8 13:57:13 2009
@@ -58,7 +58,7 @@
         testRootNode.save();
 
         // accuire the same property through a different session
-        Session session = helper.getSuperuserSession();
+        Session session = getHelper().getSuperuserSession();
         try {
             Property prop2 = session.getProperty(prop1.getPath());
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyTypeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyTypeTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyTypeTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/PropertyTypeTest.java Wed Jul  8 13:57:13 2009
@@ -52,7 +52,7 @@
      * the workspace starting at {@link #testRoot}.
      */
     public void testType() throws RepositoryException {
-        Session session = helper.getReadOnlySession();
+        Session session = getHelper().getReadOnlySession();
         try {
             Node root = session.getRootNode().getNode(testPath);
             typeCheckChildren(root);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferenceableRootNodesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferenceableRootNodesTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferenceableRootNodesTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferenceableRootNodesTest.java Wed Jul  8 13:57:13 2009
@@ -48,8 +48,8 @@
         isReadOnly = true;
         super.setUp();
 
-        session = helper.getReadOnlySession();
-        sessionW2 = helper.getReadOnlySession(workspaceName);
+        session = getHelper().getReadOnlySession();
+        sessionW2 = getHelper().getReadOnlySession(workspaceName);
 
         String wspName = session.getWorkspace().getName();
         boolean sameWsp = (wspName == null) ? workspaceName == null : wspName.equals(workspaceName);

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ReferencesTest.java Wed Jul  8 13:57:13 2009
@@ -40,9 +40,7 @@
      */
     public void testReferences() throws RepositoryException, NotExecutableException {
         Node n1 = testRootNode.addNode(nodeName1, testNodeType);
-        if (needsMixin(n1, mixReferenceable)) {
-            n1.addMixin(mixReferenceable);
-        }
+        ensureMixinType(n1, mixReferenceable);
 
         // with some impls. the mixin type has only affect upon save
         testRootNode.save();
@@ -117,9 +115,7 @@
      */
     public void testReferenceTarget() throws RepositoryException, NotExecutableException {
         Node n1 = testRootNode.addNode(nodeName1, testNodeType);
-        if (needsMixin(n1, mixReferenceable)) {
-            n1.addMixin(mixReferenceable);
-        }
+        ensureMixinType(n1, mixReferenceable);
 
         // with some impls. the mixin type has only affect upon save
         testRootNode.save();
@@ -146,13 +142,9 @@
      */
     public void testAlterReference() throws RepositoryException, NotExecutableException {
         Node n1 = testRootNode.addNode(nodeName1, testNodeType);
-        if (needsMixin(n1, mixReferenceable)) {
-            n1.addMixin(mixReferenceable);
-        }
+        ensureMixinType(n1, mixReferenceable);
         Node n2 = testRootNode.addNode(nodeName2, testNodeType);
-        if (needsMixin(n2, mixReferenceable)) {
-            n2.addMixin(mixReferenceable);
-        }
+        ensureMixinType(n2, mixReferenceable);
 
         // with some impls. the mixin type has only affect upon save
         testRootNode.save();
@@ -206,4 +198,24 @@
             fail("too many referers: " + iter.nextProperty().getPath());
         }
     }
+
+    public void testNonReferenceable() throws RepositoryException, NotExecutableException {
+        Node nonReferenceable = null;
+        if (testRootNode.isNodeType(mixReferenceable)) {
+            Node child = testRootNode.addNode(nodeName1, testNodeType);
+            superuser.save();
+            if (!child.isNodeType(mixReferenceable)) {
+                nonReferenceable = child;
+            }
+        } else {
+            nonReferenceable = testRootNode;
+        }
+
+        if (nonReferenceable == null) {
+            throw new NotExecutableException("Test node is referenceable.");
+        }
+
+        // getReferences must return an empty iterator and must not throw.        
+        assertFalse(nonReferenceable.getReferences().hasNext());
+    }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RepositoryDescriptorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RepositoryDescriptorTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RepositoryDescriptorTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RepositoryDescriptorTest.java Wed Jul  8 13:57:13 2009
@@ -65,7 +65,7 @@
     protected void setUp() throws Exception {
         isReadOnly = true;
         super.setUp();
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RepositoryLoginTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RepositoryLoginTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RepositoryLoginTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RepositoryLoginTest.java Wed Jul  8 13:57:13 2009
@@ -45,9 +45,9 @@
         isReadOnly = true;
         super.setUp();
 
-        credentials = helper.getReadOnlyCredentials();
+        credentials = getHelper().getReadOnlyCredentials();
         workspaceName = superuser.getWorkspace().getName();
-        repository = helper.getRepository();
+        repository = getHelper().getRepository();
     }
 
     /**
@@ -58,7 +58,7 @@
     public void testNoSuchWorkspaceException()
             throws RepositoryException {
 
-        Session session = helper.getReadOnlySession();
+        Session session = getHelper().getReadOnlySession();
         String name;
         try {
             name = getNonExistingWorkspaceName(session);
@@ -68,7 +68,7 @@
         }
 
         try {
-            session = helper.getRepository().login(credentials, name);
+            session = getHelper().getRepository().login(credentials, name);
             fail("login with a not available workspace name must throw a " +
                     "NoSuchWorkspaceException");
         } catch (NoSuchWorkspaceException e) {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RootNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RootNodeTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RootNodeTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/RootNodeTest.java Wed Jul  8 13:57:13 2009
@@ -45,7 +45,7 @@
     protected void setUp() throws Exception {
         isReadOnly = true;
         super.setUp();
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
         rootNode = session.getRootNode();
     }
 

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationContext.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationContext.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationContext.java Wed Jul  8 13:57:13 2009
@@ -17,8 +17,12 @@
 package org.apache.jackrabbit.test.api;
 
 import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.RepositoryStub;
+import org.apache.jackrabbit.test.NotExecutableException;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.Session;
 
 /**
  * Encapsulates the various properties that are needed for a serialization test
@@ -32,6 +36,13 @@
     public String sourceFolderName;
     public String targetFolderName;
     public String rootNodeName;
+    public String nodeName1;
+    public String nodeName2;
+    public String nodeName3;
+    public String testNodeType;
+    public String propertyName1;
+    public String jcrPrimaryType;
+    public String mixReferenceable;
 
     public String propertyValueMayChange;
     public String propertySkipped;
@@ -58,7 +69,8 @@
     public String referenceTestProperty;
     public String multiValueTestProperty;
 
-    public SerializationContext(AbstractJCRTest test) throws RepositoryException {
+    public SerializationContext(AbstractJCRTest test, Session session)
+            throws RepositoryException {
         // creates a serialization context based on a test class
         baseTest = test;
 
@@ -67,6 +79,13 @@
         sourceFolderName = get("sourceFolderName");
         targetFolderName = get("targetFolderName");
         rootNodeName = get("rootNodeName");
+        nodeName1 = get(RepositoryStub.PROP_NODE_NAME1);
+        nodeName2 = get(RepositoryStub.PROP_NODE_NAME2);
+        nodeName3 = get(RepositoryStub.PROP_NODE_NAME3);
+        testNodeType = get(RepositoryStub.PROP_NODETYPE);
+        propertyName1 = get(RepositoryStub.PROP_PROP_NAME1);
+        jcrPrimaryType = session.getNamespacePrefix(AbstractJCRTest.NS_JCR_URI) + ":primaryType";
+        mixReferenceable = session.getNamespacePrefix(AbstractJCRTest.NS_MIX_URI) + ":referenceable";
 
         propertyValueMayChange = " " + get("propertyValueMayChange") + " ";
         propertySkipped = " " + get("propertySkipped") + " ";
@@ -101,4 +120,28 @@
         return value;
     }
 
+    public void log(String message) {
+        baseTest.log.println(message);
+    }
+
+    /**
+     * Ensures that the given <code>node</code> is of the given mixin type.
+     *
+     * @param node  a node.
+     * @param mixin the name of a mixin type.
+     * @throws NotExecutableException if the node is not of type mixin and the
+     *                                mixin cannot be added.
+     * @throws RepositoryException    if an error occurs.
+     */
+    protected void ensureMixinType(Node node, String mixin)
+            throws NotExecutableException, RepositoryException {
+        if (!node.isNodeType(mixin)) {
+            if (node.canAddMixin(mixin)) {
+                node.addMixin(mixin);
+            } else {
+                throw new NotExecutableException(node.getPath() +
+                        " does not support adding " + mixin);
+            }
+        }
+    }
 }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SerializationTest.java Wed Jul  8 13:57:13 2009
@@ -81,7 +81,7 @@
             file = File.createTempFile("serializationTest", ".xml");
             log.print("Tempfile: " + file.getAbsolutePath());
 
-            SerializationContext sc = new SerializationContext(this);
+            SerializationContext sc = new SerializationContext(this, session);
             treeComparator = new TreeComparator(sc, session);
             treeComparator.createComplexTree(treeComparator.WORKSPACE);
         }
@@ -103,9 +103,6 @@
             session.logout();
             session = null;
         }
-        if (treeComparator != null) {
-            treeComparator.tearDown();
-        }
         workspace = null;
         super.tearDown();
     }
@@ -123,13 +120,7 @@
      */
     protected Node initVersioningException(boolean returnParent) throws RepositoryException, NotExecutableException, IOException {
         Node vNode = testRootNode.addNode(nodeName1, testNodeType);
-        if (!vNode.isNodeType(mixVersionable)) {
-            if (vNode.canAddMixin(mixVersionable)) {
-                vNode.addMixin(mixVersionable);
-            } else {
-                throw new NotExecutableException("NodeType: " + testNodeType + " is not versionable");
-            }
-        }
+        ensureMixinType(vNode, mixVersionable);
         Node vChild = vNode.addNode(nodeName2, testNodeType);
         session.save();
         vNode.checkin();
@@ -215,7 +206,7 @@
         if (isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
             //A LockException is thrown if a lock prevents the addition of the subtree.
             Node lNode = testRootNode.addNode(nodeName1);
-            lNode.addMixin(mixLockable);
+            ensureMixinType(lNode, mixLockable);
             testRootNode.save();
             Lock lock = lNode.lock(true, true);
             session.removeLockToken(lock.getLockToken());   //remove the token, so the lock is for me, too
@@ -525,7 +516,7 @@
         session.logout();
         superuser = null; //so tearDown won't fail
 
-        session = helper.getReadWriteSession();
+        session = getHelper().getReadWriteSession();
         treeComparator.setSession(session);
         treeComparator.compare(treeComparator.CHECK_EMPTY);
     }
@@ -548,7 +539,7 @@
         session.logout();
         superuser = null; //so tearDown won't fail
 
-        session = helper.getReadWriteSession();
+        session = getHelper().getReadWriteSession();
         treeComparator.setSession(session);
         treeComparator.compare(treeComparator.CHECK_EMPTY);
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionReadMethodsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionReadMethodsTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionReadMethodsTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionReadMethodsTest.java Wed Jul  8 13:57:13 2009
@@ -50,7 +50,7 @@
     protected void setUp() throws Exception {
         isReadOnly = true;
         super.setUp();
-        session = helper.getReadOnlySession();
+        session = getHelper().getReadOnlySession();
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionRemoveItemTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionRemoveItemTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionRemoveItemTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionRemoveItemTest.java Wed Jul  8 13:57:13 2009
@@ -44,7 +44,7 @@
 
         adminSession = superuser;
 
-        readOnlySession = helper.getReadOnlySession();
+        readOnlySession = getHelper().getReadOnlySession();
 
         removeNode = testRootNode.addNode(nodeName1, testNodeType);
         testRootNode.save();
@@ -91,20 +91,14 @@
     }
 
     public void testRemoveLockedNode() throws RepositoryException, NotExecutableException {
-        if (!removeNode.isNodeType(mixLockable)) {
-            if (removeNode.canAddMixin(mixLockable)) {
-                removeNode.addMixin(mixLockable);
-                removeNode.save();
-            } else {
-                throw new NotExecutableException("Cannot make test node lockable.");
-            }
-        }
+        ensureMixinType(removeNode, mixLockable);
+        removeNode.save();
 
         // make sure the test node is locked.
         removeNode.lock(true, true);
         Session testSession = null;
         try {
-            testSession = (Session) helper.getReadWriteSession();
+            testSession = getHelper().getReadWriteSession();
             // removal of the locked node is a alteration of the parent, which
             // isn't locked -> must succeed.
             testSession.removeItem(nPath);
@@ -123,21 +117,15 @@
         Property childP = removeNode.setProperty(propertyName2, v);
         removeNode.save();
 
-        if (!removeNode.isNodeType(mixLockable)) {
-            if (removeNode.canAddMixin(mixLockable)) {
-                removeNode.addMixin(mixLockable);
-                removeNode.save();
-            } else {
-                throw new NotExecutableException("Cannot make test node lockable.");
-            }
-        }
+        ensureMixinType(removeNode, mixLockable);
+        removeNode.save();
 
         // make sure the test node is locked.
         removeNode.lock(true, true);
         Session testSession = null;
 
         try {
-            testSession = (Session) helper.getReadWriteSession();
+            testSession = getHelper().getReadWriteSession();
             try {
                 testSession.removeItem(childN.getPath());
                 testSession.save();
@@ -167,14 +155,8 @@
         Property childP = removeNode.setProperty(propertyName2, v);
         removeNode.save();
 
-        if (!removeNode.isNodeType(mixVersionable)) {
-            if (removeNode.canAddMixin(mixVersionable)) {
-                removeNode.addMixin(mixVersionable);
-                removeNode.save();
-            } else {
-                throw new NotExecutableException("Cannot make test node versionable.");
-            }
-        }
+        ensureMixinType(removeNode, mixVersionable);
+        removeNode.save();
 
         removeNode.checkin();
         try {

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionTest.java?rev=792142&r1=792141&r2=792142&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionTest.java (original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SessionTest.java Wed Jul  8 13:57:13 2009
@@ -259,14 +259,7 @@
         // create a node that is lockable
         Node lockableNode = testRootNode.addNode(nodeName1, testNodeType);
         // or try to make it lockable if it is not
-        if (!lockableNode.isNodeType(mixLockable)) {
-            if (lockableNode.canAddMixin(mixLockable)) {
-                lockableNode.addMixin(mixLockable);
-            } else {
-                throw new NotExecutableException("Node " + nodeName1 + " is not lockable and does not " +
-                        "allow to add mix:lockable");
-            }
-        }
+        ensureMixinType(lockableNode, mixLockable);
 
         // add a sub node (the one that is tried to move later on)
         Node srcNode = lockableNode.addNode(nodeName1, testNodeType);
@@ -277,7 +270,7 @@
         String pathRelToRoot = lockableNode.getPath().substring(1);
 
         // access node through another session to lock it
-        Session session2 = helper.getSuperuserSession();
+        Session session2 = getHelper().getSuperuserSession();
         try {
             Node node2 = session2.getRootNode().getNode(pathRelToRoot);
             node2.lock(true, true);
@@ -325,7 +318,7 @@
         superuser.save();
 
         // get moved tree root node with session 2
-        Session testSession = helper.getReadWriteSession();
+        Session testSession = getHelper().getReadWriteSession();
         try {
             testSession.getItem(destParentNode.getPath() + "/" + nodeName2);
             // node found
@@ -353,7 +346,7 @@
         superuser.save();
 
         // use a different session to verify if the node is there
-        Session s = helper.getReadOnlySession();
+        Session s = getHelper().getReadOnlySession();
         try {
             s.getItem(newNode.getPath());
             // throws PathNotFoundException if item was not saved
@@ -394,7 +387,7 @@
         // check if the child node was created properly
 
         // get a reference with a second session to the modified node
-        Session s = helper.getReadOnlySession();
+        Session s = getHelper().getReadOnlySession();
         try {
             Node newNodeSession2 = (Node) s.getItem(newNode.getPath());
             // check if child is there
@@ -456,7 +449,7 @@
         nodeSession1.addNode(nodeName2, testNodeType);
 
         // get the new node with a different session
-        Session testSession = helper.getReadWriteSession();
+        Session testSession = getHelper().getReadWriteSession();
         try {
             Node nodeSession2 = (Node) testSession.getItem(nodeSession1.getPath());
 
@@ -510,7 +503,7 @@
         testNode1Session1.addNode(nodeName2, testNodeType);
 
         // get session 2
-        Session session2 = helper.getReadWriteSession();
+        Session session2 = getHelper().getReadWriteSession();
 
         try {
             // get the second node
@@ -570,7 +563,7 @@
         testNode1Session1.addNode(nodeName2, testNodeType);
 
         // get session 2
-        Session session2 = helper.getReadWriteSession();
+        Session session2 = getHelper().getReadWriteSession();
 
         try {
             // get the second node



Mime
View raw message