You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2008/01/23 12:22:05 UTC

svn commit: r614496 - in /incubator/sling/trunk: commons/testing/ commons/testing/src/ commons/testing/src/main/ commons/testing/src/main/java/ commons/testing/src/main/java/org/ commons/testing/src/main/java/org/apache/ commons/testing/src/main/java/o...

Author: bdelacretaz
Date: Wed Jan 23 03:22:03 2008
New Revision: 614496

URL: http://svn.apache.org/viewvc?rev=614496&view=rev
Log:
SLING-187 - new org.apache.sling.commons.testing module, contains reusable test code extracted from the jcr/resource module

Added:
    incubator/sling/trunk/commons/testing/
    incubator/sling/trunk/commons/testing/pom.xml   (with props)
    incubator/sling/trunk/commons/testing/src/
    incubator/sling/trunk/commons/testing/src/main/
    incubator/sling/trunk/commons/testing/src/main/java/
    incubator/sling/trunk/commons/testing/src/main/java/org/
    incubator/sling/trunk/commons/testing/src/main/java/org/apache/
    incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/
    incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/
    incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/
    incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/
    incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java   (with props)
    incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeIterator.java   (with props)
    incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java   (with props)
    incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java   (with props)
    incubator/sling/trunk/jcr/resource/src/test/test-config/jackrabbit-test-config.xml
      - copied unchanged from r614468, incubator/sling/trunk/jcr/resource/src/test/test-config/repository-derby.xml
Removed:
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/testhelper/
    incubator/sling/trunk/jcr/resource/src/test/test-config/repository-derby.xml
Modified:
    incubator/sling/trunk/jcr/resource/pom.xml
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java

Added: incubator/sling/trunk/commons/testing/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/commons/testing/pom.xml?rev=614496&view=auto
==============================================================================
--- incubator/sling/trunk/commons/testing/pom.xml (added)
+++ incubator/sling/trunk/commons/testing/pom.xml Wed Jan 23 03:22:03 2008
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>1-incubator-SNAPSHOT</version>
+        <relativePath>../../parent/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.sling.commons.testing</artifactId>
+    <packaging>jar</packaging>
+    <version>2.0.0-incubator-SNAPSHOT</version>
+
+    <name>Sling - testing utilities</name>
+    <description>
+	Tools and utilities for automated testing of Sling modules
+    </description>
+
+    <scm>
+        <connection>
+            scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/commons/testing
+        </connection>
+        <developerConnection>
+            scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/commons/testing
+        </developerConnection>
+        <url>
+            http://svn.apache.org/viewvc/incubator/sling/trunk/commons/testing
+        </url>
+    </scm>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.jcr.api</artifactId>
+            <version>2.0.0-incubator-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+</project>

Propchange: incubator/sling/trunk/commons/testing/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java?rev=614496&view=auto
==============================================================================
--- incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java (added)
+++ incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java Wed Jan 23 03:22:03 2008
@@ -0,0 +1,344 @@
+/*
+ * 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.sling.commons.testing.jcr;
+
+import java.io.InputStream;
+import java.util.Calendar;
+
+import javax.jcr.Item;
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.lock.Lock;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
+
+// simple mock implementation of a node
+public class MockNode implements Node {
+
+    private String path;
+
+    private NodeType nodeType;
+
+    public MockNode(String path) {
+        this(path, null);
+    }
+
+    public MockNode(String path, String type) {
+        this.path = path;
+        this.nodeType = new MockNodeType(type);
+    }
+
+    public String getName() {
+        return path.substring(path.lastIndexOf('/') + 1);
+    }
+
+    public Node getParent() {
+        return new MockNode(path.substring(0, path.lastIndexOf('/')));
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public NodeType getPrimaryNodeType() {
+        return nodeType;
+    }
+
+    public boolean isSame(Item otherItem) {
+        return equals(otherItem);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj == this) {
+            return true;
+        } else if (!(obj instanceof MockNode)) {
+            return false;
+        }
+
+        return ((MockNode) obj).getPath().equals(getPath());
+    }
+
+    @Override
+    public int hashCode() {
+        return super.hashCode();
+    }
+
+    @Override
+    public String toString() {
+        return "MockNode: path=" + getPath();
+    }
+
+    public void addMixin(String mixinName) {
+    }
+
+    public Node addNode(String relPath) {
+        return null;
+    }
+
+    public Node addNode(String relPath, String primaryNodeTypeName) {
+        return null;
+    }
+
+    public boolean canAddMixin(String mixinName) {
+        return false;
+    }
+
+    public void cancelMerge(Version version) {
+
+    }
+
+    public Version checkin() {
+        return null;
+    }
+
+    public void checkout() {
+    }
+
+    public void doneMerge(Version version) {
+    }
+
+    public Version getBaseVersion() {
+        return null;
+    }
+
+    public String getCorrespondingNodePath(String workspaceName) {
+        return null;
+    }
+
+    public NodeDefinition getDefinition() {
+        return null;
+    }
+
+    public int getIndex() {
+        return 0;
+    }
+
+    public Lock getLock() {
+        return null;
+    }
+
+    public NodeType[] getMixinNodeTypes() {
+        return null;
+    }
+
+    public Node getNode(String relPath) {
+        return new MockNode(path + "/" + relPath);
+    }
+
+    public NodeIterator getNodes() {
+        return null;
+    }
+
+    public NodeIterator getNodes(String namePattern) {
+        return null;
+    }
+
+    public Item getPrimaryItem() {
+        return null;
+    }
+
+    public PropertyIterator getProperties() {
+        return null;
+    }
+
+    public PropertyIterator getProperties(String namePattern) {
+        return null;
+    }
+
+    public Property getProperty(String relPath) {
+        return null;
+    }
+
+    public PropertyIterator getReferences() {
+        return null;
+    }
+
+    public String getUUID() {
+        return null;
+    }
+
+    public VersionHistory getVersionHistory() {
+        return null;
+    }
+
+    public boolean hasNode(String relPath) {
+        return false;
+    }
+
+    public boolean hasNodes() {
+        return false;
+    }
+
+    public boolean hasProperties() {
+        return false;
+    }
+
+    public boolean hasProperty(String relPath) {
+        return false;
+    }
+
+    public boolean holdsLock() {
+        return false;
+    }
+
+    public boolean isCheckedOut() {
+        return false;
+    }
+
+    public boolean isLocked() {
+        return false;
+    }
+
+    public boolean isNodeType(String nodeTypeName) {
+        return false;
+    }
+
+    public Lock lock(boolean isDeep, boolean isSessionScoped) {
+        return null;
+    }
+
+    public NodeIterator merge(String srcWorkspace, boolean bestEffort) {
+        return null;
+    }
+
+    public void orderBefore(String srcChildRelPath, String destChildRelPath) {
+    }
+
+    public void removeMixin(String mixinName) {
+    }
+
+    public void restore(String versionName, boolean removeExisting) {
+    }
+
+    public void restore(Version version, boolean removeExisting) {
+    }
+
+    public void restore(Version version, String relPath, boolean removeExisting) {
+    }
+
+    public void restoreByLabel(String versionLabel, boolean removeExisting) {
+    }
+
+    public Property setProperty(String name, Value value) {
+        return null;
+    }
+
+    public Property setProperty(String name, Value[] values) {
+        return null;
+    }
+
+    public Property setProperty(String name, String[] values) {
+        return null;
+    }
+
+    public Property setProperty(String name, String value) {
+        return null;
+    }
+
+    public Property setProperty(String name, InputStream value) {
+        return null;
+    }
+
+    public Property setProperty(String name, boolean value) {
+        return null;
+    }
+
+    public Property setProperty(String name, double value) {
+        return null;
+    }
+
+    public Property setProperty(String name, long value) {
+        return null;
+    }
+
+    public Property setProperty(String name, Calendar value) {
+        return null;
+    }
+
+    public Property setProperty(String name, Node value) {
+        return null;
+    }
+
+    public Property setProperty(String name, Value value, int type) {
+        return null;
+    }
+
+    public Property setProperty(String name, Value[] values, int type) {
+        return null;
+    }
+
+    public Property setProperty(String name, String[] values, int type) {
+        return null;
+    }
+
+    public Property setProperty(String name, String value, int type) {
+        return null;
+    }
+
+    public void unlock() {
+    }
+
+    public void update(String srcWorkspaceName) {
+    }
+
+    public void accept(ItemVisitor visitor) {
+    }
+
+    public Item getAncestor(int depth) {
+        return null;
+    }
+
+    public int getDepth() {
+        return 0;
+    }
+
+    public Session getSession() {
+        return null;
+    }
+
+    public boolean isModified() {
+        return false;
+    }
+
+    public boolean isNew() {
+        return false;
+    }
+
+    public boolean isNode() {
+        return true;
+    }
+
+    public void refresh(boolean keepChanges) {
+    }
+
+    public void remove() {
+    }
+
+    public void save() {
+    }
+
+}

Propchange: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeIterator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeIterator.java?rev=614496&view=auto
==============================================================================
--- incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeIterator.java (added)
+++ incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeIterator.java Wed Jan 23 03:22:03 2008
@@ -0,0 +1,68 @@
+/*
+ * 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.sling.commons.testing.jcr;
+
+import java.util.NoSuchElementException;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+
+public class MockNodeIterator implements NodeIterator {
+
+    private Node[] nodes;
+    private int idx;
+
+    public MockNodeIterator(Node[] nodes) {
+        this.nodes = (nodes != null) ? nodes : new Node[0];
+        this.idx = 0;
+    }
+
+    public Node nextNode() {
+        if (!hasNext()) {
+            throw new NoSuchElementException();
+        }
+
+        return nodes[idx++];
+    }
+
+    public long getPosition() {
+        return idx-1;
+    }
+
+    public long getSize() {
+        return nodes.length;
+    }
+
+    public void skip(long skipNum) {
+        idx += skipNum;
+    }
+
+    public boolean hasNext() {
+        return idx < nodes.length;
+    }
+
+    public Object next() {
+        return nextNode();
+    }
+
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+
+}

Propchange: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeIterator.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java?rev=614496&view=auto
==============================================================================
--- incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java (added)
+++ incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java Wed Jan 23 03:22:03 2008
@@ -0,0 +1,98 @@
+/*
+ * 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.sling.commons.testing.jcr;
+
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+
+public class MockNodeType implements NodeType {
+
+    private String name;
+
+    public MockNodeType(String name) {
+        this.name = (name == null) ? "nt:unstructured" : name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public boolean canAddChildNode(String childNodeName) {
+        return false;
+    }
+
+    public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
+        return false;
+    }
+
+    public boolean canRemoveItem(String itemName) {
+        return false;
+    }
+
+    public boolean canSetProperty(String propertyName, Value value) {
+        return false;
+    }
+
+    public boolean canSetProperty(String propertyName, Value[] values) {
+        return false;
+    }
+
+    public NodeDefinition[] getChildNodeDefinitions() {
+        return null;
+    }
+
+    public NodeDefinition[] getDeclaredChildNodeDefinitions() {
+        return null;
+    }
+
+    public PropertyDefinition[] getDeclaredPropertyDefinitions() {
+        return null;
+    }
+
+    public NodeType[] getDeclaredSupertypes() {
+        return null;
+    }
+
+    public String getPrimaryItemName() {
+        return null;
+    }
+
+    public PropertyDefinition[] getPropertyDefinitions() {
+        return null;
+    }
+
+    public NodeType[] getSupertypes() {
+        return null;
+    }
+
+    public boolean hasOrderableChildNodes() {
+        return false;
+    }
+
+    public boolean isMixin() {
+        return false;
+    }
+
+    public boolean isNodeType(String nodeTypeName) {
+        return false;
+    }
+
+}

Propchange: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java?rev=614496&view=auto
==============================================================================
--- incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java (added)
+++ incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java Wed Jan 23 03:22:03 2008
@@ -0,0 +1,207 @@
+/*
+ * 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.sling.commons.testing.jcr;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Hashtable;
+
+import javax.jcr.Credentials;
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.Workspace;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
+import org.apache.jackrabbit.core.jndi.RegistryHelper;
+import org.apache.sling.jcr.api.SlingRepository;
+
+/**
+ * Utility class for managing JCR repositories, used to
+ * initialize temporary Jackrabbit repositories for testing.
+ */
+public class RepositoryUtil {
+
+    public static final String REPOSITORY_NAME = "repositoryTest";
+
+    public static final String ADMIN_NAME = "admin";
+
+    public static final String ADMIN_PASSWORD = "admin";
+
+    public static final String CONTEXT_FACTORY = "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory";
+
+    public static final String PROVIDER_URL = "localhost";
+
+    public static final String CONFIG_FILE = "src/test/test-config/jackrabbit-test-config.xml";
+
+    public static final String HOME_DIR = "target/repository";
+
+    protected static InitialContext getInitialContext() throws NamingException {
+        final Hashtable<String, String> env = new Hashtable<String, String>();
+        env.put(Context.INITIAL_CONTEXT_FACTORY, CONTEXT_FACTORY);
+        env.put(Context.PROVIDER_URL, PROVIDER_URL);
+        return new InitialContext(env);
+    }
+
+    /**
+     * Start a new repository
+     *
+     * @throws RepositoryException when it is not possible to start the
+     *             repository.
+     * @throws NamingException
+     */
+    public static void startRepository() throws RepositoryException,
+            NamingException {
+        RegistryHelper.registerRepository(getInitialContext(), REPOSITORY_NAME,
+            CONFIG_FILE, HOME_DIR, true);
+    }
+
+    /**
+     * Stop a repository.
+     *
+     * @throws NamingException when it is not possible to stop the
+     *             repository
+     * @throws NamingException
+     */
+    public static void stopRepository() throws NamingException {
+        RegistryHelper.unregisterRepository(getInitialContext(),
+            REPOSITORY_NAME);
+    }
+
+    /**
+     * Get a repository
+     *
+     * @return a JCR repository reference
+     * @throws NamingException when it is not possible to get the
+     *             repository. Before calling this method, the repository has to
+     *             be registered (@see RepositoryUtil#registerRepository(String,
+     *             String, String)
+     * @throws NamingException
+     */
+    public static SlingRepository getRepository() throws NamingException {
+        return new RepositoryWrapper((Repository) getInitialContext().lookup(
+            REPOSITORY_NAME));
+    }
+
+    /**
+     * Registers node types from the CND file read from the <code>source</code>
+     * with the node type manager available from the given <code>session</code>.
+     * <p>
+     * The <code>NodeTypeManager</code> returned by the <code>session</code>'s
+     * workspace is expected to be of type
+     * <code>org.apache.jackrabbit.api.JackrabbitNodeTypeManager</code> for
+     * the node type registration to succeed.
+     * <p>
+     * This method is not synchronized. It is up to the calling method to
+     * prevent paralell execution.
+     *
+     * @param session The <code>Session</code> providing the node type manager
+     *            through which the node type is to be registered.
+     * @param source The <code>InputStream</code> from which the CND file is
+     *            read.
+     * @return <code>true</code> if registration of all node types succeeded.
+     */
+    public static boolean registerNodeType(Session session, InputStream source)
+            throws IOException, RepositoryException {
+
+        Workspace workspace = session.getWorkspace();
+        NodeTypeManager ntm = workspace.getNodeTypeManager();
+        if (ntm instanceof JackrabbitNodeTypeManager) {
+            JackrabbitNodeTypeManager jntm = (JackrabbitNodeTypeManager) ntm;
+            try {
+                jntm.registerNodeTypes(source,
+                    JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+                return true;
+            } catch (RepositoryException re) {
+                Throwable t = re.getCause();
+                if (t != null
+                    && t.getClass().getName().endsWith(
+                        ".InvalidNodeTypeDefException")) {
+                    // hacky wacky: interpret message to check whether it is for
+                    // duplicate node type -> very bad, that this is the only
+                    // way to check !!!
+                    if (re.getCause().getMessage().indexOf("already exists") >= 0) {
+                        // alright, node types are already registered, ignore
+                        // this
+                        return true;
+                    }
+                }
+
+                // get here to rethrow the RepositoryException
+                throw re;
+            }
+        }
+
+        return false;
+    }
+
+    public static final class RepositoryWrapper implements SlingRepository {
+
+        protected final Repository wrapped;
+
+        public RepositoryWrapper(Repository r) {
+            wrapped = r;
+        }
+
+        public String getDescriptor(String key) {
+            return wrapped.getDescriptor(key);
+        }
+
+        public String[] getDescriptorKeys() {
+            return wrapped.getDescriptorKeys();
+        }
+
+        public Session login() throws LoginException, RepositoryException {
+            return wrapped.login();
+        }
+
+        public Session login(Credentials credentials, String workspaceName)
+                throws LoginException, NoSuchWorkspaceException,
+                RepositoryException {
+            return wrapped.login(credentials, workspaceName);
+        }
+
+        public Session login(Credentials credentials) throws LoginException,
+                RepositoryException {
+            return wrapped.login(credentials);
+        }
+
+        public Session login(String workspaceName) throws LoginException,
+                NoSuchWorkspaceException, RepositoryException {
+            return wrapped.login(workspaceName);
+        }
+
+        public String getDefaultWorkspace() {
+            return "default";
+        }
+
+        public Session loginAdministrative(String workspace)
+                throws RepositoryException {
+            final Credentials credentials = new SimpleCredentials(ADMIN_NAME,
+                ADMIN_PASSWORD.toCharArray());
+            return this.login(credentials, workspace);
+        }
+
+    }
+}
\ No newline at end of file

Propchange: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/commons/testing/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/trunk/jcr/resource/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/pom.xml?rev=614496&r1=614495&r2=614496&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/pom.xml (original)
+++ incubator/sling/trunk/jcr/resource/pom.xml Wed Jan 23 03:22:03 2008
@@ -145,6 +145,12 @@
             <version>2.0.0-incubator-SNAPSHOT</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.testing</artifactId>
+            <version>2.0.0-incubator-SNAPSHOT</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-simple</artifactId>
         </dependency>

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java?rev=614496&r1=614495&r2=614496&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java (original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java Wed Jan 23 03:22:03 2008
@@ -40,10 +40,10 @@
 import org.apache.sling.api.resource.NonExistingResource;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.testing.jcr.RepositoryUtil;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.resource.JcrResourceConstants;
 import org.apache.sling.jcr.resource.internal.helper.Mapping;
-import org.apache.sling.jcr.resource.testhelper.RepositoryUtil;
 
 public class JcrResourceResolverTest extends TestCase {
 

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java?rev=614496&r1=614495&r2=614496&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java (original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/JcrNodeResourceIteratorTest.java Wed Jan 23 03:22:03 2008
@@ -27,9 +27,9 @@
 import junit.framework.TestCase;
 
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.commons.testing.jcr.MockNode;
+import org.apache.sling.commons.testing.jcr.MockNodeIterator;
 import org.apache.sling.jcr.resource.internal.helper.jcr.JcrNodeResourceIterator;
-import org.apache.sling.jcr.resource.testhelper.MockNode;
-import org.apache.sling.jcr.resource.testhelper.MockNodeIterator;
 
 public class JcrNodeResourceIteratorTest extends TestCase {