jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r477177 - in /jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/name: ./ NamespaceRegistryTest.java
Date Mon, 20 Nov 2006 13:54:30 GMT
Author: angela
Date: Mon Nov 20 05:54:29 2006
New Revision: 477177

URL: http://svn.apache.org/viewvc?view=rev&rev=477177
Log:
work in progress

- tests

Added:
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/name/
    jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/name/NamespaceRegistryTest.java
  (with props)

Added: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/name/NamespaceRegistryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/name/NamespaceRegistryTest.java?view=auto&rev=477177
==============================================================================
--- jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/name/NamespaceRegistryTest.java
(added)
+++ jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/name/NamespaceRegistryTest.java
Mon Nov 20 05:54:29 2006
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.jcr2spi.name;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.test.NotExecutableException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.NamespaceException;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+
+/**
+ * <code>NamespaceRegistryTest</code>...
+ */
+public class NamespaceRegistryTest extends AbstractJCRTest {
+
+    private static Logger log = LoggerFactory.getLogger(NamespaceRegistryTest.class);
+
+    /** Default value of test prefix */
+    private static final String TEST_PREFIX = "test";
+
+    /** Default value of test namespace uri */
+    private static final String TEST_URI = "http://www.apache.org/jackrabbit/test/namespaceRegistryTest";
+
+    private NamespaceRegistry nsRegistry;
+    private String testPrefix;
+    private String testURI;
+
+    protected void setUp() throws Exception {
+        Session superuser = helper.getSuperuserSession();
+        nsRegistry = superuser.getWorkspace().getNamespaceRegistry();
+
+        testPrefix = getUnusedPrefix();
+        testURI = getUnusedURI();
+
+        boolean level2 = Boolean.valueOf((String) superuser.getRepository().getDescriptor(Repository.LEVEL_2_SUPPORTED)).booleanValue();
+        if (!level2) {
+            throw new NotExecutableException("Cannot test namespace registration/unregistration.
Repository is a Level 1 only.");
+        }
+
+    }
+
+    /**
+     * Test if a new registred namespace is immediately visible through another
+     * session object.
+     *
+     * @throws RepositoryException
+     */
+    public void testRegisteredNamespaceVisibility() throws RepositoryException {
+        NamespaceRegistry other = helper.getReadOnlySession().getWorkspace().getNamespaceRegistry();
+
+        nsRegistry.registerNamespace(testPrefix, testURI);
+        String otherUri = other.getURI(testPrefix);
+        String otherPrefix = other.getPrefix(testURI);
+        assertTrue("Namespace registered must be immediately visible to any other session.",
testURI.equals(otherUri) && testPrefix.equals(otherPrefix));
+    }
+
+    /**
+     * Test if a replace namespace prefix cannot be used as key any more to
+     * retrieve the uri.
+     *
+     * @throws RepositoryException
+     */
+    public void testReRegisteredNamespace() throws RepositoryException {
+        nsRegistry.registerNamespace(testPrefix, testURI);
+        String replacePrefix = getUnusedPrefix();
+        nsRegistry.registerNamespace(replacePrefix, testURI);
+        try {
+            nsRegistry.getURI(testPrefix);
+            fail("Namespace with prefix " + testPrefix + " has been reregistered with new
prefix " + replacePrefix);
+        } catch (NamespaceException e) {
+            // OK
+        }
+    }
+
+    /**
+     * Test if a replace namespace prefix cannot be used as key any more to
+     * retrieve the uri in the <code>NamespaceRegistry</code> retrieved by
+     * another Session object.
+     *
+     * @throws RepositoryException
+     */
+    public void testReRegisteredNamespace2() throws RepositoryException {
+        NamespaceRegistry other = helper.getReadOnlySession().getWorkspace().getNamespaceRegistry();
+
+        nsRegistry.registerNamespace(testPrefix, testURI);
+        other.getPrefix(testURI);
+
+        String replacePrefix = getUnusedPrefix();
+        nsRegistry.registerNamespace(replacePrefix, testURI);
+
+        String otherPrefix = other.getPrefix(testURI);
+        assertEquals("Namespace with prefix " + testPrefix + " has been reregistered with
new prefix " + replacePrefix, replacePrefix, otherPrefix);
+    }
+
+    /**
+     * Test if a replaced namespace prefix is immediately visible in the
+     * NamespaceRegistry obtained from another session object.
+     *
+     * @throws RepositoryException
+     */
+    public void testReRegisteredNamespaceVisibility() throws RepositoryException {
+        NamespaceRegistry other = helper.getReadOnlySession().getWorkspace().getNamespaceRegistry();
+
+        nsRegistry.registerNamespace(testPrefix, testURI);
+        other.getPrefix(testURI);
+
+        String replacePrefix = getUnusedPrefix();
+        nsRegistry.registerNamespace(replacePrefix, testURI);
+
+        String otherUri = other.getURI(replacePrefix);
+        String otherPrefix = other.getPrefix(testURI);
+        assertTrue("Namespace registered must be immediately visible to any other session.",
testURI.equals(otherUri) && replacePrefix.equals(otherPrefix));
+
+        try {
+            other.getURI(testPrefix);
+            fail("Namespace with prefix " + testPrefix + " has been reregistered with new
prefix " + replacePrefix);
+        } catch (NamespaceException e) {
+            // OK
+        }
+    }
+
+    /**
+     * Test if unregistering a namespace is propagated to all other sessions.
+     *
+     * @throws RepositoryException
+     */
+    public void testUnregisteredNamespaceVisibility() throws RepositoryException, NotExecutableException
{
+        String prefix = getUnusedPrefix();
+        String uri = getUnusedURI();
+
+        NamespaceRegistry other = helper.getReadOnlySession().getWorkspace().getNamespaceRegistry();
+
+        nsRegistry.registerNamespace(prefix, uri);
+        try {
+            nsRegistry.unregisterNamespace(prefix);
+        } catch (NamespaceException e) {
+            throw new NotExecutableException("Repository does not support unregistration
of namespaces.");
+        }
+
+        String otherUri = other.getURI(prefix);
+        String otherPrefix = other.getPrefix(uri);
+        assertTrue("Namespace registered must be immediately visible to any other session.",
uri.equals(otherUri) && prefix.equals(otherPrefix));
+    }
+
+    /**
+     * Returns a namespace prefix that currently not used in the namespace
+     * registry.
+     * @return an unused namespace prefix.
+     */
+    private String getUnusedPrefix() throws RepositoryException {
+        Set prefixes = new HashSet(Arrays.asList(nsRegistry.getPrefixes()));
+        String prefix = TEST_PREFIX;
+        int i = 0;
+        while (prefixes.contains(prefix)) {
+            prefix = TEST_PREFIX + i++;
+        }
+        return prefix;
+    }
+
+    /**
+     * Returns a namespace URI that currently not used in the namespace
+     * registry.
+     * @return an unused namespace URI.
+     */
+    private String getUnusedURI() throws RepositoryException {
+        Set uris = new HashSet(Arrays.asList(nsRegistry.getURIs()));
+        String uri = TEST_URI;
+        int i = 0;
+        while (uris.contains(uri)) {
+            uri = TEST_URI + i++;
+        }
+        return uri;
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/name/NamespaceRegistryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/contrib/spi/client/src/test/java/org/apache/jackrabbit/jcr2spi/name/NamespaceRegistryTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url



Mime
View raw message