[dna-commits] DNA SVN: r1084 - in trunk: dna-graph/src/main/java/org/jboss/dna/graph/connector/map and 5 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Jul 9 12:29:04 EDT 2009


Author: rhauch
Date: 2009-07-09 12:29:03 -0400 (Thu, 09 Jul 2009)
New Revision: 1084

Added:
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java
Modified:
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/map/AbstractMapWorkspace.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/map/package-info.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/ItemDefinitionTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyDefinitionTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/MixinTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/RepositoryNodeTypeManagerTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TypeRegistrationTest.java
   trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
Log:
DNA-466 Changes following the merge of trunk onto this branch.

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Graph.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -2462,13 +2462,13 @@
                                                    Name desiredName,
                                                    Segment desiredSegment,
                                                    boolean removeExisting ) {
-                    requests.cloneBranch(from,
-                                         fromWorkspaceName,
-                                         into,
-                                         intoWorkspaceName,
-                                         desiredName,
-                                         desiredSegment,
-                                         removeExisting);
+                    requestQueue.cloneBranch(from,
+                                             fromWorkspaceName,
+                                             into,
+                                             intoWorkspaceName,
+                                             desiredName,
+                                             desiredSegment,
+                                             removeExisting);
                     return and();
                 }
             };
@@ -2611,9 +2611,9 @@
                                                    Locations from,
                                                    Location into,
                                                    Name copyName ) {
-	
+
                     String intoWorkspaceName = getCurrentWorkspaceName();
-                    if ( fromWorkspaceName == null ) fromWorkspaceName = intoWorkspaceName;
+                    if (fromWorkspaceName == null) fromWorkspaceName = intoWorkspaceName;
                     do {
                         requestQueue.copyBranch(from.getLocation(), fromWorkspaceName, into, intoWorkspaceName, copyName, null);
                     } while ((from = from.next()) != null);

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/map/AbstractMapWorkspace.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/map/AbstractMapWorkspace.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/map/AbstractMapWorkspace.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -458,6 +458,7 @@
         UUID uuidForCopy = reuseUuids ? original.getUuid() : UUID.randomUUID();
         MapNode copy = newWorkspace.createNode(context, newParent, childName, uuidForCopy);
         if (!reuseUuids) {
+            assert oldToNewUuids != null;
             oldToNewUuids.put(original.getUuid(), copy.getUuid());
         }
 

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/map/package-info.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/map/package-info.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/map/package-info.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -65,7 +65,6 @@
  * 
  * @see org.jboss.dna.graph.connector.inmemory.InMemoryRepository
  * @see org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource
- * @see org.jboss.dna.graph.connector.inmemory.InMemoryRepository#Workspace
  */
 
 package org.jboss.dna.graph.connector.map;

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/request/BatchRequestBuilder.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -29,6 +29,7 @@
 import java.util.Map;
 import org.jboss.dna.graph.Location;
 import org.jboss.dna.graph.NodeConflictBehavior;
+import org.jboss.dna.graph.connector.UuidAlreadyExistsException;
 import org.jboss.dna.graph.property.Name;
 import org.jboss.dna.graph.property.Path;
 import org.jboss.dna.graph.property.Property;
@@ -600,6 +601,33 @@
     }
 
     /**
+     * Add a request to clone a branch to another.
+     * 
+     * @param from the location of the top node in the existing branch that is to be cloned
+     * @param fromWorkspace the name of the workspace where the <code>from</code> node exists
+     * @param into the location of the existing node into which the clone should be placed
+     * @param intoWorkspace the name of the workspace where the <code>into</code> node is to be cloned
+     * @param nameForClone the desired name for the node that results from the clone, or null if the name of the original should
+     *        be used
+     * @param exactSegmentForClone the exact {@link Path.Segment segment} at which the cloned tree should be rooted.
+     * @param removeExisting whether any nodes in the intoWorkspace with the same UUIDs as a node in the source branch should be
+     *        removed (if true) or a {@link UuidAlreadyExistsException} should be thrown.
+     * @return this builder for method chaining; never null
+     * @throws IllegalArgumentException if any of the parameters are null except for {@code nameForClone} or {@code
+     *         exactSegmentForClone}. Exactly one of {@code nameForClone} and {@code exactSegmentForClone} must be null.
+     */
+    public BatchRequestBuilder cloneBranch( Location from,
+                                            String fromWorkspace,
+                                            Location into,
+                                            String intoWorkspace,
+                                            Name nameForClone,
+                                            Path.Segment exactSegmentForClone,
+                                            boolean removeExisting ) {
+        return add(new CloneBranchRequest(from, fromWorkspace, into, intoWorkspace, nameForClone, exactSegmentForClone,
+                                          removeExisting));
+    }
+
+    /**
      * Create a request to move a branch from one location into another.
      * 
      * @param from the location of the top node in the existing branch that is to be moved

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/session/GraphSession.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -59,6 +59,7 @@
 import org.jboss.dna.graph.property.Path.Segment;
 import org.jboss.dna.graph.request.BatchRequestBuilder;
 import org.jboss.dna.graph.request.ChangeRequest;
+import org.jboss.dna.graph.request.CloneBranchRequest;
 import org.jboss.dna.graph.request.CopyBranchRequest;
 import org.jboss.dna.graph.request.InvalidWorkspaceException;
 import org.jboss.dna.graph.request.Request;
@@ -564,6 +565,7 @@
      *        should be used
      * @param destination the path for the new cloned copy; may not be null index
      * @param removeExisting true if the original should be removed, or false if the original should be left
+     * @param destPathIncludesSegment true if the destination path includes the segment that should be used
      * @throws IllegalArgumentException either path is null or invalid
      * @throws InvalidWorkspaceException if the source workspace name is invalid or does not exist
      * @throws UuidAlreadyExistsException if copy could not be completed because the current workspace already includes at least
@@ -575,7 +577,8 @@
     public void immediateClone( Path source,
                                 String sourceWorkspace,
                                 Path destination,
-                                boolean removeExisting )
+                                boolean removeExisting,
+                                boolean destPathIncludesSegment )
         throws InvalidWorkspaceException, AccessControlException, UuidAlreadyExistsException, PathNotFoundException,
         RepositorySourceException {
         CheckArg.isNotNull(source, "source");
@@ -591,18 +594,42 @@
         Graph.Batch batch = store.batch();
         if (removeExisting) {
             // Perform the copy operation, but use the "to" form (not the "into", which takes the parent) ...
-            batch.copy(source).replacingExistingNodesWithSameUuids().fromWorkspace(sourceWorkspace).to(destination);
+            if (destPathIncludesSegment) {
+                batch.clone(source)
+                     .fromWorkspace(sourceWorkspace)
+                     .as(destination.getLastSegment())
+                     .into(destination.getParent())
+                     .replacingExistingNodesWithSameUuids();
+            } else {
+                Name newNodeName = destination.getLastSegment().getName();
+                batch.clone(source)
+                     .fromWorkspace(sourceWorkspace)
+                     .as(newNodeName)
+                     .into(destination.getParent())
+                     .replacingExistingNodesWithSameUuids();
+            }
         } else {
             // Perform the copy operation, but use the "to" form (not the "into", which takes the parent) ...
-            batch.copy(source).failingIfUuidsMatch().fromWorkspace(sourceWorkspace).to(destination);
+            if (destPathIncludesSegment) {
+                batch.clone(source)
+                     .fromWorkspace(sourceWorkspace)
+                     .as(destination.getLastSegment())
+                     .into(destination.getParent())
+                     .failingIfAnyUuidsMatch();
+            } else {
+                Name newNodeName = destination.getLastSegment().getName();
+                batch.clone(source)
+                     .fromWorkspace(sourceWorkspace)
+                     .as(newNodeName)
+                     .into(destination.getParent())
+                     .failingIfAnyUuidsMatch();
+            }
         }
-        // And read the children of the destination's parent ...
-        batch.readChildren().of(destination.getParent());
         // Now execute these two operations ...
         Results results = batch.execute();
 
         // Find the copy request to get the actual location of the copy ...
-        CopyBranchRequest request = (CopyBranchRequest)results.getRequests().get(0);
+        CloneBranchRequest request = (CloneBranchRequest)results.getRequests().get(0);
         Location locationOfCopy = request.getActualLocationAfter();
 
         // Find the parent node in the session ...

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/AbstractJcrNode.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -1444,7 +1444,14 @@
         throws NoSuchWorkspaceException, ItemNotFoundException, RepositoryException {
         CheckArg.isNotNull(workspaceName, "workspace name");
         NamespaceRegistry namespaces = this.context().getNamespaceRegistry();
+        return correspondingNodePath(workspaceName).getString(namespaces);
+    }
 
+    protected final Path correspondingNodePath( String workspaceName )
+        throws NoSuchWorkspaceException, ItemNotFoundException, RepositoryException {
+        assert workspaceName != null;
+        NamespaceRegistry namespaces = this.context().getNamespaceRegistry();
+
         // Find the closest ancestor (including this node) that is referenceable ...
         AbstractJcrNode referenceableRoot = this;
         while (!referenceableRoot.isNodeType(JcrMixLexicon.REFERENCEABLE.getString(namespaces))) {
@@ -1454,7 +1461,7 @@
         // Find the relative path from the nearest referenceable node to this node (or null if this node is referenceable) ...
         Path relativePath = path().equals(referenceableRoot.path()) ? null : path().relativeTo(referenceableRoot.path());
         UUID uuid = UUID.fromString(referenceableRoot.getUUID());
-        return this.cache.getPathForCorrespondingNode(workspaceName, uuid, relativePath).getString(namespaces);
+        return this.cache.getPathForCorrespondingNode(workspaceName, uuid, relativePath);
     }
 
     /**
@@ -1469,14 +1476,15 @@
             throw new InvalidItemStateException(JcrI18n.noPendingChangesAllowed.text());
         }
 
+        Path correspondingPath = null;
         try {
-            getCorrespondingNodePath(srcWorkspaceName);
+            correspondingPath = correspondingNodePath(srcWorkspaceName);
         } catch (ItemNotFoundException infe) {
             return;
         }
 
         // Need to force remove in case this node is not referenceable
-        this.session().workspace().clone(srcWorkspaceName, correspondingPath, path(), true, true);
+        cache.graphSession().immediateClone(correspondingPath, srcWorkspaceName, path(), true, true);
 
         session().refresh(false);
     }

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrLexicon.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -46,7 +46,6 @@
     public static final Name LOCK_IS_DEEP = new BasicName(Namespace.URI, "lockIsDeep");
     public static final Name LOCK_OWNER = new BasicName(Namespace.URI, "lockOwner");
     public static final Name MERGE_FAILED = new BasicName(Namespace.URI, "mergeFailed");
-    public static final Name NODE_TYPES = new BasicName(Namespace.URI, "nodeTypes");
     public static final Name PREDECESSORS = new BasicName(Namespace.URI, "predecessors");
     public static final Name ROOT = new BasicName(Namespace.URI, "root");
     public static final Name ROOT_VERSION = new BasicName(Namespace.URI, "rootVersion");

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrWorkspace.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -185,7 +185,7 @@
         this.queryManager = new JcrQueryManager(this.session);
 
         if (Boolean.valueOf(repository.getOptions().get(Option.PROJECT_NODE_TYPES))) {
-            Path parentOfTypeNodes = context.getValueFactories().getPathFactory().create(systemPath, JcrLexicon.NODE_TYPES);
+            Path parentOfTypeNodes = context.getValueFactories().getPathFactory().create(systemPath, DnaLexicon.NODE_TYPES);
             repoTypeManager.projectOnto(this.graph, parentOfTypeNodes);
         }
 
@@ -236,17 +236,16 @@
         try {
             Set<String> workspaceNamesFromGraph = graph.getWorkspaces();
             Set<String> workspaceNames = new HashSet<String>(workspaceNamesFromGraph.size());
-            
-            for(String workspaceName : workspaceNamesFromGraph) {
+
+            for (String workspaceName : workspaceNamesFromGraph) {
                 try {
                     session.checkPermission(workspaceName, null, JcrSession.JCR_READ_PERMISSION);
                     workspaceNames.add(workspaceName);
-                }
-                catch (AccessControlException ace) {
+                } catch (AccessControlException ace) {
                     // Can happen if user doesn't have the privileges to read from the workspace
                 }
             }
-            
+
             return workspaceNames.toArray(new String[workspaceNames.size()]);
         } catch (RepositorySourceException e) {
             throw new RepositoryException(JcrI18n.errorObtainingWorkspaceNames.text(getSourceName(), e.getMessage()), e);
@@ -354,7 +353,7 @@
             }
 
             // Now perform the clone, using the direct (non-session) method ...
-            cache.graphSession().immediateClone(srcPath, srcWorkspace, destPath, removeExisting);
+            cache.graphSession().immediateClone(srcPath, srcWorkspace, destPath, removeExisting, false);
         } catch (ItemNotFoundException e) {
             // The destination path was not found ...
             throw new PathNotFoundException(e.getLocalizedMessage(), e);

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrTest.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrTest.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -41,7 +41,10 @@
 import org.junit.BeforeClass;
 
 /**
+ * Abstract test that sets up a SessionCache environment with a real {@link RepositoryNodeTypeManager}, albeit with a mocked
+ * JcrSession, Workspace, and Repository.
  * 
+ * @see AbstractSessionTest for an alternative with a more complete environment
  */
 public abstract class AbstractJcrTest {
 
@@ -109,19 +112,23 @@
         store.importXmlFrom(AbstractJcrTest.class.getClassLoader().getResourceAsStream(xmlResourceName)).into("/");
         numberOfConnections = 0; // reset the number of connections
 
-        nodeTypes = new JcrNodeTypeManager(context, rntm);
-
-        // Stub the session ...
+        // Stub the session, workspace, and repository; then stub some critical methods ...
         jcrSession = mock(JcrSession.class);
-        stub(jcrSession.nodeTypeManager()).toReturn(nodeTypes);
-
-        cache = new SessionCache(jcrSession, store.getCurrentWorkspaceName(), context, nodeTypes, store);
-
         workspace = mock(Workspace.class);
         repository = mock(Repository.class);
+        stub(jcrSession.getExecutionContext()).toReturn(context);
         stub(jcrSession.getWorkspace()).toReturn(workspace);
         stub(jcrSession.getRepository()).toReturn(repository);
         stub(workspace.getName()).toReturn("workspace1");
+
+        // Create the node type manager for the session ...
+        // no need to stub the 'JcrSession.checkPermission' methods, since we're never calling 'register' on the
+        // JcrNodeTypeManager
+        nodeTypes = new JcrNodeTypeManager(jcrSession, rntm);
+        stub(jcrSession.nodeTypeManager()).toReturn(nodeTypes);
+
+        cache = new SessionCache(jcrSession, store.getCurrentWorkspaceName(), context, nodeTypes, store);
+
     }
 
     protected String getResourceNameOfXmlFileToImport() {

Added: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java	                        (rev 0)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -0,0 +1,152 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.jcr;
+
+import static org.mockito.Mockito.stub;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.jcr.RepositoryException;
+import org.jboss.dna.graph.ExecutionContext;
+import org.jboss.dna.graph.Graph;
+import org.jboss.dna.graph.MockSecurityContext;
+import org.jboss.dna.graph.SecurityContext;
+import org.jboss.dna.graph.connector.RepositoryConnection;
+import org.jboss.dna.graph.connector.RepositoryConnectionFactory;
+import org.jboss.dna.graph.connector.RepositorySourceException;
+import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
+import org.jboss.dna.graph.property.NamespaceRegistry;
+import org.jboss.dna.jcr.nodetype.NodeTypeTemplate;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+
+/**
+ * Abstract test class that sets up a working JcrSession environment, albeit with a mocked JcrRepository.
+ * 
+ * @see AbstractJcrTest for an alternative with a less complete environment
+ */
+public abstract class AbstractSessionTest {
+
+    protected String workspaceName;
+    protected ExecutionContext context;
+    protected InMemoryRepositorySource source;
+    protected JcrWorkspace workspace;
+    protected JcrSession session;
+    protected Graph graph;
+    protected RepositoryConnectionFactory connectionFactory;
+    protected RepositoryNodeTypeManager repoTypeManager;
+    protected Map<String, Object> sessionAttributes;
+    protected Map<JcrRepository.Option, String> options;
+    protected NamespaceRegistry registry;
+    @Mock
+    protected JcrRepository repository;
+
+    protected void beforeEach() throws Exception {
+        MockitoAnnotations.initMocks(this);
+
+        workspaceName = "workspace1";
+        final String repositorySourceName = "repository";
+
+        // Set up the source ...
+        source = new InMemoryRepositorySource();
+        source.setName(workspaceName);
+        source.setDefaultWorkspaceName(workspaceName);
+
+        // Set up the execution context ...
+        context = new ExecutionContext();
+        // Register the test namespace
+        context.getNamespaceRegistry().register(TestLexicon.Namespace.PREFIX, TestLexicon.Namespace.URI);
+
+        // Set up the initial content ...
+        graph = Graph.create(source, context);
+        initializeContent();
+
+        // Stub out the connection factory ...
+        connectionFactory = new RepositoryConnectionFactory() {
+            /**
+             * {@inheritDoc}
+             * 
+             * @see org.jboss.dna.graph.connector.RepositoryConnectionFactory#createConnection(java.lang.String)
+             */
+            public RepositoryConnection createConnection( String sourceName ) throws RepositorySourceException {
+                return repositorySourceName.equals(sourceName) ? source.getConnection() : null;
+            }
+        };
+
+        // Stub out the repository, since we only need a few methods ...
+        repoTypeManager = new RepositoryNodeTypeManager(context);
+
+        try {
+            this.repoTypeManager.registerNodeTypes(new CndNodeTypeSource(new String[] {"/org/jboss/dna/jcr/jsr_170_builtins.cnd",
+                "/org/jboss/dna/jcr/dna_builtins.cnd"}));
+            this.repoTypeManager.registerNodeTypes(new NodeTemplateNodeTypeSource(getTestTypes()));
+
+        } catch (RepositoryException re) {
+            re.printStackTrace();
+            throw new IllegalStateException("Could not load node type definition files", re);
+        } catch (IOException ioe) {
+            ioe.printStackTrace();
+            throw new IllegalStateException("Could not access node type definition files", ioe);
+        }
+
+        stub(repository.getRepositoryTypeManager()).toReturn(repoTypeManager);
+        stub(repository.getRepositorySourceName()).toReturn(repositorySourceName);
+        stub(repository.getConnectionFactory()).toReturn(connectionFactory);
+
+        initializeOptions();
+        stub(repository.getOptions()).toReturn(options);
+
+        // Set up the session attributes ...
+        // Set up the session attributes ...
+        sessionAttributes = new HashMap<String, Object>();
+        sessionAttributes.put("attribute1", "value1");
+
+        // Now create the workspace ...
+        SecurityContext mockSecurityContext = new MockSecurityContext(null,
+                                                                      Collections.singleton(JcrSession.DNA_WRITE_PERMISSION));
+        workspace = new JcrWorkspace(repository, workspaceName, context.with(mockSecurityContext), sessionAttributes);
+
+        // Create the session and log in ...
+        session = (JcrSession)workspace.getSession();
+        registry = session.getExecutionContext().getNamespaceRegistry();
+    }
+
+    protected List<NodeTypeTemplate> getTestTypes() {
+        return Collections.emptyList();
+    }
+
+    protected void initializeContent() {
+
+    }
+
+    protected void initializeOptions() {
+        // Stub out the repository options ...
+        options = new EnumMap<JcrRepository.Option, String>(JcrRepository.Option.class);
+        options.put(JcrRepository.Option.PROJECT_NODE_TYPES, Boolean.FALSE.toString());
+
+    }
+}


Property changes on: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/ItemDefinitionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/ItemDefinitionTest.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/ItemDefinitionTest.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -45,7 +45,7 @@
  * BDD test cases for property and child node definition inheritance. Could be part of RepositoryNodeTypeManagerTest, but split
  * off to isolate tests for this behavior vs. projection/inference and registration/unregistration behavior.
  */
-public class ItemDefinitionTest extends AbstractJcrTest {
+public class ItemDefinitionTest extends AbstractSessionTest {
 
     private static final Name NODE_TYPE_A = new BasicName(TestLexicon.Namespace.URI, "nodeA");
     private static final Name NODE_TYPE_B = new BasicName(TestLexicon.Namespace.URI, "nodeB");
@@ -67,9 +67,9 @@
     @Override
     protected void initializeContent() {
         graph.create("/jcr:system").and().create("/jcr:system/dna:namespaces");
-        
+
     }
-    
+
     @After
     public void after() throws Exception {
         if (session != null && session.isLive()) {

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyDefinitionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyDefinitionTest.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrPropertyDefinitionTest.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -46,7 +46,7 @@
  * Indirectly tests the JcrConstaintCheckerFactory through {@link JcrPropertyDefinition#satisfiesConstraints(Value)}, which
  * provides the wrapper around the factory that the rest of the API is expected to utilize.
  */
-public class JcrPropertyDefinitionTest extends AbstractJcrTest {
+public class JcrPropertyDefinitionTest extends AbstractSessionTest {
 
     protected final String[] EXPECTED_BINARY_CONSTRAINTS = new String[] {"[,5)", "[10, 20)", "(30,40]", "[50,]"};
     protected final String[] EXPECTED_DATE_CONSTRAINTS = new String[] {"[,+1945-08-01T01:30:00.000Z]",
@@ -60,7 +60,6 @@
 
     protected NodeTypeManager nodeTypeManager;
 
-
     @Override
     @Before
     public void beforeEach() throws Exception {
@@ -77,7 +76,7 @@
         graph.set("jcr:mixinTypes").on("/a").to(JcrMixLexicon.REFERENCEABLE);
 
     }
-    
+
     @After
     public void after() throws Exception {
         if (session != null && session.isLive()) {

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrSessionTest.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -66,7 +66,7 @@
 /**
  * @author jverhaeg
  */
-public class JcrSessionTest extends AbstractJcrTest {
+public class JcrSessionTest extends AbstractSessionTest {
 
     private static final String MULTI_LINE_VALUE = "Line\t1\nLine 2\rLine 3\r\nLine 4";
 
@@ -74,6 +74,7 @@
     @Before
     public void beforeEach() throws Exception {
         super.beforeEach();
+
     }
 
     @Override
@@ -88,20 +89,8 @@
         // Make sure the path to the namespaces exists ...
         graph.create("/jcr:system").and().create("/jcr:system/dna:namespaces").and();
 
-        // Set up the session attributes ...
-        sessionAttributes = new HashMap<String, Object>();
-        sessionAttributes.put("attribute1", "value1");
-
-        // Now create the workspace ...
-        SecurityContext mockSecurityContext = new MockSecurityContext(null,
-                                                                      Collections.singleton(JcrSession.DNA_WRITE_PERMISSION));
-        workspace = new JcrWorkspace(repository, workspaceName, context.with(mockSecurityContext), sessionAttributes);
-
-        // Create the session and log in ...
-        session = (JcrSession)workspace.getSession();
     }
 
-    
     @After
     public void after() throws Exception {
         if (session.isLive()) {
@@ -247,6 +236,8 @@
     public void shouldProvideRootNode() throws Exception {
         Node root = session.getRootNode();
         assertThat(root, notNullValue());
+        String uuid = root.getUUID();
+        assertThat(uuid, notNullValue());
     }
 
     @Test
@@ -420,15 +411,6 @@
      * this test.
      */
 
-    @Test
-    public void shouldProvideUuidIfReferenceable() throws Exception {
-        // The root node is referenceable in DNA
-        Node rootNode = session.getRootNode();
-
-        UUID uuid = ((AbstractJcrNode)rootNode).location.getUuid();
-        assertThat(rootNode.getUUID(), is(uuid.toString()));
-    }
-
     @Test( expected = UnsupportedRepositoryOperationException.class )
     public void shouldNotProvideUuidIfNotReferenceable() throws Exception {
         // The b node was not set up to be referenceable in this test, but does have a mixin type

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrTckTest.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -36,7 +36,6 @@
 import org.apache.jackrabbit.test.api.NodeItemIsNewTest;
 import org.apache.jackrabbit.test.api.NodeOrderableChildNodesTest;
 import org.apache.jackrabbit.test.api.NodeRemoveMixinTest;
-import org.apache.jackrabbit.test.api.NodeTest;
 import org.apache.jackrabbit.test.api.PropertyItemIsModifiedTest;
 import org.apache.jackrabbit.test.api.PropertyItemIsNewTest;
 import org.apache.jackrabbit.test.api.PropertyTest;
@@ -174,7 +173,7 @@
             // addTestSuite(ReferencesTest.class);
             // dna-466 addTestSuite(SessionTest.class);
             // addTestSuite(SessionUUIDTest.class);
-            addTestSuite(NodeTest.class);
+            // dna-466 addTestSuite(NodeTest.class);
             // addTestSuite(NodeUUIDTest.class);
             addTestSuite(NodeOrderableChildNodesTest.class);
             addTestSuite(PropertyTest.class);

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrWorkspaceTest.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -41,7 +41,7 @@
 /**
  * @author jverhaeg
  */
-public class JcrWorkspaceTest extends AbstractJcrTest {
+public class JcrWorkspaceTest extends AbstractSessionTest {
 
     @BeforeClass
     public static void beforeClass() {
@@ -73,7 +73,7 @@
         graph.create("/jcr:system").and().create("/jcr:system/dna:namespaces").ifAbsent().and();
 
     }
-    
+
     @Test( expected = IllegalArgumentException.class )
     public void shouldNotAllowCloneWithNullWorkspaceName() throws Exception {
         workspace.clone(null, "/src", "/dest", false);

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/MixinTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/MixinTest.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/MixinTest.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -44,7 +44,7 @@
 import org.junit.Before;
 import org.junit.Test;
 
-public class MixinTest extends AbstractJcrTest {
+public class MixinTest extends AbstractSessionTest {
 
     /*
      * Declares the following node types:
@@ -235,7 +235,9 @@
     public void shouldAllowAdditionIfResidualChildNodeDoesNotConflict() throws Exception {
         graph.create("/a").and().create("/a/" + CHILD_NODE_B).and();
         graph.set(JcrLexicon.PRIMARY_TYPE.getString(registry)).on("/a").to(JcrNtLexicon.UNSTRUCTURED.getString(registry));
-        graph.set(JcrLexicon.PRIMARY_TYPE.getString(registry)).on("/a/" + CHILD_NODE_B).to(JcrNtLexicon.UNSTRUCTURED.getString(registry));
+        graph.set(JcrLexicon.PRIMARY_TYPE.getString(registry))
+             .on("/a/" + CHILD_NODE_B)
+             .to(JcrNtLexicon.UNSTRUCTURED.getString(registry));
 
         Node rootNode = session.getRootNode();
         Node nodeA = rootNode.getNode("a");

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/RepositoryNodeTypeManagerTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/RepositoryNodeTypeManagerTest.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/RepositoryNodeTypeManagerTest.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -49,10 +49,9 @@
 import org.jboss.dna.graph.property.NamespaceRegistry;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
-public class RepositoryNodeTypeManagerTest extends AbstractJcrTest {
+public class RepositoryNodeTypeManagerTest extends AbstractSessionTest {
 
     @Override
     @Before
@@ -80,24 +79,8 @@
         options = new EnumMap<JcrRepository.Option, String>(JcrRepository.Option.class);
         options.put(JcrRepository.Option.PROJECT_NODE_TYPES, Boolean.TRUE.toString());
 
-        stub(repository.getOptions()).toReturn(options);
-
-        // Set up the session attributes ...
-        sessionAttributes = new HashMap<String, Object>();
-        sessionAttributes.put("attribute1", "value1");
-
-        // Now create the workspace ...
-        SecurityContext mockSecurityContext = new MockSecurityContext("testuser",
-                                                                      Collections.singleton(JcrSession.DNA_READ_PERMISSION));
-        workspace = new JcrWorkspace(repository, workspaceName, context.with(mockSecurityContext), sessionAttributes);
-
-        // Create the session and log in ...
-        session = (JcrSession)workspace.getSession();
-
-        graph.set("jcr:primaryType").on("/jcr:system/dna:namespaces").to(DnaLexicon.NAMESPACES);
-
     }
-    
+
     @After
     public void after() throws Exception {
         if (session != null && session.isLive()) {
@@ -119,7 +102,6 @@
         assertEquals(namespacesNodes.getSize(), 1);
     }
 
-    @Ignore( "dna-466" )
     @Test
     public void shouldOnlyHaveOneNodeTypesNode() throws Exception {
         NamespaceRegistry registry = context.getNamespaceRegistry();
@@ -130,7 +112,7 @@
         Node systemNode = rootNode.getNode(JcrLexicon.SYSTEM.getString(registry));
         assertThat(systemNode, is(notNullValue()));
 
-        NodeIterator nodeTypesNodes = systemNode.getNodes(JcrLexicon.NODE_TYPES.getString(registry));
+        NodeIterator nodeTypesNodes = systemNode.getNodes(DnaLexicon.NODE_TYPES.getString(registry));
         assertEquals(nodeTypesNodes.getSize(), 1);
     }
 
@@ -160,7 +142,7 @@
         Node systemNode = rootNode.getNode(JcrLexicon.SYSTEM.getString(registry));
         assertThat(systemNode, is(notNullValue()));
 
-        Node typesNode = systemNode.getNode(JcrLexicon.NODE_TYPES.getString(registry));
+        Node typesNode = systemNode.getNode(DnaLexicon.NODE_TYPES.getString(registry));
         assertThat(typesNode, is(notNullValue()));
 
         Collection<JcrNodeType> allNodeTypes = repoTypeManager.getAllNodeTypes();

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TypeRegistrationTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TypeRegistrationTest.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/TypeRegistrationTest.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -46,7 +46,7 @@
 import org.junit.Before;
 import org.junit.Test;
 
-public class TypeRegistrationTest extends AbstractJcrTest {
+public class TypeRegistrationTest extends AbstractSessionTest {
 
     private static final String TEST_TYPE_NAME = "dna:testNode";
     private static final String TEST_TYPE_NAME2 = "dna:testNode2";
@@ -691,97 +691,94 @@
      * Unregistration tests
      */
 
-    @Test (expected=IllegalArgumentException.class)
+    @Test( expected = IllegalArgumentException.class )
     public void shouldNotAllowUnregisteringNullCollection() throws Exception {
         repoTypeManager.unregisterNodeType(null);
     }
-    
-    @Test (expected=NoSuchNodeTypeException.class)
+
+    @Test( expected = NoSuchNodeTypeException.class )
     public void shouldNotAllowUnregisteringInvalidTypeNames() throws Exception {
-        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] { JcrNtLexicon.FILE, JcrLexicon.DATA}));
+        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] {JcrNtLexicon.FILE, JcrLexicon.DATA}));
     }
 
-    @Test (expected=InvalidNodeTypeDefinitionException.class)
+    @Test( expected = InvalidNodeTypeDefinitionException.class )
     public void shouldNotAllowUnregisteringSupertype() throws Exception {
-        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] { JcrNtLexicon.HIERARCHY_NODE, }));
-        
+        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] {JcrNtLexicon.HIERARCHY_NODE,}));
+
     }
 
-    @Test (expected=InvalidNodeTypeDefinitionException.class)
+    @Test( expected = InvalidNodeTypeDefinitionException.class )
     public void shouldNotAllowUnregisteringRequiredPrimaryType() throws Exception {
-        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] { JcrNtLexicon.FROZEN_NODE, }));
+        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] {JcrNtLexicon.FROZEN_NODE,}));
     }
-    
-    @Test (expected=InvalidNodeTypeDefinitionException.class)
+
+    @Test( expected = InvalidNodeTypeDefinitionException.class )
     public void shouldNotAllowUnregisteringDefaultPrimaryType() throws Exception {
         ntTemplate.setName(TEST_TYPE_NAME);
-        
+
         JcrNodeDefinitionTemplate childNode = new JcrNodeDefinitionTemplate(this.context);
         childNode.setDefaultPrimaryType(JcrNtLexicon.FILE.getString(this.registry));
         ntTemplate.getNodeDefinitionTemplates().add(childNode);
-        
+
         try {
             repoTypeManager.registerNodeType(ntTemplate, false);
-        }
-        catch (Exception ex) {
+        } catch (Exception ex) {
             fail(ex.getMessage());
         }
-        
-        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] { JcrNtLexicon.FILE, }));
+
+        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] {JcrNtLexicon.FILE,}));
     }
 
-    @Test 
+    @Test
     public void shouldAllowUnregisteringUnusedType() throws Exception {
         ntTemplate.setName(TEST_TYPE_NAME);
-        
+
         JcrNodeDefinitionTemplate childNode = new JcrNodeDefinitionTemplate(this.context);
         childNode.setDefaultPrimaryType(JcrNtLexicon.FILE.getString(this.registry));
         ntTemplate.getNodeDefinitionTemplates().add(childNode);
-        
+
         try {
             repoTypeManager.registerNodeType(ntTemplate, false);
-        }
-        catch (Exception ex) {
+        } catch (Exception ex) {
             fail(ex.getMessage());
         }
-        
+
         Name typeNameAsName = nameFactory.create(TEST_TYPE_NAME);
         int nodeTypeCount = repoTypeManager.getAllNodeTypes().size();
-        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] { typeNameAsName }));
+        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] {typeNameAsName}));
         assertThat(repoTypeManager.getAllNodeTypes().size(), is(nodeTypeCount - 1));
         assertThat(repoTypeManager.getNodeType(typeNameAsName), is(nullValue()));
     }
 
-    @Test 
+    @Test
     public void shouldAllowUnregisteringUnusedTypesWithMutualDependencies() throws Exception {
         ntTemplate.setName(TEST_TYPE_NAME);
-        
+
         JcrNodeDefinitionTemplate childNode = new JcrNodeDefinitionTemplate(this.context);
         childNode.setDefaultPrimaryType(TEST_TYPE_NAME2);
         ntTemplate.getNodeDefinitionTemplates().add(childNode);
 
         NodeTypeTemplate ntTemplate2 = new JcrNodeTypeTemplate(this.context);
         ntTemplate2.setName(TEST_TYPE_NAME2);
-        
+
         JcrNodeDefinitionTemplate childNode2 = new JcrNodeDefinitionTemplate(this.context);
         childNode2.setDefaultPrimaryType(TEST_TYPE_NAME);
         ntTemplate2.getNodeDefinitionTemplates().add(childNode2);
 
         try {
-            repoTypeManager.registerNodeTypes(Arrays.asList(new NodeTypeDefinition[] { ntTemplate, ntTemplate2 }), false);
-        }
-        catch (Exception ex) {
+            repoTypeManager.registerNodeTypes(Arrays.asList(new NodeTypeDefinition[] {ntTemplate, ntTemplate2}), false);
+        } catch (Exception ex) {
             fail(ex.getMessage());
         }
-        
+
         Name typeNameAsName = nameFactory.create(TEST_TYPE_NAME);
         Name type2NameAsName = nameFactory.create(TEST_TYPE_NAME2);
         int nodeTypeCount = repoTypeManager.getAllNodeTypes().size();
-        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] { typeNameAsName, type2NameAsName }));
+        repoTypeManager.unregisterNodeType(Arrays.asList(new Name[] {typeNameAsName, type2NameAsName}));
         assertThat(repoTypeManager.getAllNodeTypes().size(), is(nodeTypeCount - 2));
         assertThat(repoTypeManager.getNodeType(typeNameAsName), is(nullValue()));
         assertThat(repoTypeManager.getNodeType(type2NameAsName), is(nullValue()));
-        
+
     }
 
     private void compareTemplatesToNodeTypes( List<NodeTypeDefinition> templates,

Modified: trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java
===================================================================
--- trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java	2009-07-09 16:27:15 UTC (rev 1083)
+++ trunk/extensions/dna-connector-jbosscache/src/main/java/org/jboss/dna/connector/jbosscache/JBossCacheSource.java	2009-07-09 16:29:03 UTC (rev 1084)
@@ -477,7 +477,7 @@
             // Create the set of initial names ...
             for (String initialName : getPredefinedWorkspaceNames())
                 repository.createWorkspace(null, initialName, CreateConflictBehavior.DO_NOT_CREATE);
-        
+
         }
 
         return new MapRepositoryConnection(this, this.repository);
@@ -488,11 +488,13 @@
      * probably called at most once for each workspace name (except if this method fails to create a cache for a given workspace
      * name).
      * 
-     * @param workspaceName the name of the workspace
+     * @param cacheFactory the cache factory
+     * @param repositoryName the name of the repository
      * @return the new cache that corresponds to the workspace name
      */
     @GuardedBy( "writeLock" )
-    protected Cache<UUID, MapNode> createNewCache( CacheFactory<UUID, MapNode> cacheFactory, String repositoryName ) {
+    protected Cache<UUID, MapNode> createNewCache( CacheFactory<UUID, MapNode> cacheFactory,
+                                                   String repositoryName ) {
         assert repositoryName != null;
         if (cacheFactory == null) return null;
 
@@ -523,7 +525,6 @@
         return cacheFactory.createCache();
     }
 
-    
     /**
      * @return repositoryContext
      */




More information about the dna-commits mailing list