[dna-commits] DNA SVN: r1552 - in trunk: dna-jcr/src/main/java/org/jboss/dna/jcr and 1 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Jan 7 13:24:40 EST 2010


Author: bcarothers
Date: 2010-01-07 13:24:39 -0500 (Thu, 07 Jan 2010)
New Revision: 1552

Modified:
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/plan/CanonicalPlanner.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrQueryManager.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
   trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryQueryManager.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/CndNodeTypeRegistrationTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrQueryManagerTest.java
   trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/WorkspaceLockManagerTest.java
Log:
DNA-460 NodeTypeManager.unregisterType

Applied patch that changes the query language from XPath to SQL to allow the use of the LIMIT keyword. The patch also corrects a minor problem with limit/offset parsing.


Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/plan/CanonicalPlanner.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/plan/CanonicalPlanner.java	2010-01-07 14:47:53 UTC (rev 1551)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/query/plan/CanonicalPlanner.java	2010-01-07 18:24:39 UTC (rev 1552)
@@ -361,11 +361,11 @@
 
         boolean attach = false;
         if (limit.getOffset() != 0) {
-            limitNode.setProperty(Property.LIMIT_COUNT, limit.getOffset());
+            limitNode.setProperty(Property.LIMIT_OFFSET, limit.getOffset());
             attach = true;
         }
         if (!limit.isUnlimited()) {
-            limitNode.setProperty(Property.LIMIT_OFFSET, limit.getRowLimit());
+            limitNode.setProperty(Property.LIMIT_COUNT, limit.getRowLimit());
             attach = true;
         }
         if (attach) {

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrQueryManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrQueryManager.java	2010-01-07 14:47:53 UTC (rev 1551)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrQueryManager.java	2010-01-07 18:24:39 UTC (rev 1552)
@@ -331,7 +331,7 @@
         public QueryResult execute() throws RepositoryException {
             // Submit immediately to the workspace graph ...
             Schemata schemata = session.workspace().nodeTypeManager().schemata();
-            QueryResults result = session.repository().queryManager().query(session.workspace(),
+            QueryResults result = session.repository().queryManager().query(session.workspace().getName(),
                                                                             query,
                                                                             schemata,
                                                                             hints,
@@ -383,7 +383,7 @@
          */
         public QueryResult execute() throws RepositoryException {
             // Submit immediately to the workspace graph ...
-            QueryResults result = session.repository().queryManager().search(session.workspace(),
+            QueryResults result = session.repository().queryManager().search(session.workspace().getName(),
                                                                              statement,
                                                                              MAXIMUM_RESULTS_FOR_FULL_TEXT_SEARCH_QUERIES,
                                                                              0);

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java	2010-01-07 14:47:53 UTC (rev 1551)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/JcrRepository.java	2010-01-07 18:24:39 UTC (rev 1552)
@@ -95,6 +95,7 @@
 import org.jboss.dna.graph.query.parse.QueryParsers;
 import org.jboss.dna.graph.query.parse.SqlQueryParser;
 import org.jboss.dna.graph.request.InvalidWorkspaceException;
+import org.jboss.dna.jcr.RepositoryQueryManager.PushDown;
 import org.jboss.dna.jcr.xpath.XPathQueryParser;
 
 /**
@@ -536,7 +537,8 @@
         // Set up the repository type manager ...
         try {
             boolean includeInheritedProperties = Boolean.valueOf(this.options.get(Option.TABLES_INCLUDE_COLUMNS_FOR_INHERITED_PROPERTIES));
-            this.repositoryTypeManager = new RepositoryNodeTypeManager(this.executionContext, includeInheritedProperties);
+            // this.repositoryTypeManager = new RepositoryNodeTypeManager(this, includeInheritedProperties);
+            this.repositoryTypeManager = new RepositoryNodeTypeManager(this, includeInheritedProperties);
             this.repositoryTypeManager.registerNodeTypes(new CndNodeTypeSource(new String[] {
                 "/org/jboss/dna/jcr/jsr_170_builtins.cnd", "/org/jboss/dna/jcr/dna_builtins.cnd"}));
         } catch (RepositoryException re) {
@@ -585,7 +587,7 @@
             // We can query the federated source if it supports queries and searches
             // AND the original source supports queries and searches ...
             if (canQuerySource && canQueryFederated) {
-                this.queryManager = new RepositoryQueryManager();
+                this.queryManager = new PushDown(this.sourceName, executionContext, connectionFactory);
             } else {
                 // Otherwise create a repository query manager that maintains its own search engine ...
                 String indexDirectory = this.options.get(Option.QUERY_INDEX_DIRECTORY);
@@ -595,7 +597,7 @@
                                                                              indexDirectory, updateIndexesSynchronously);
             }
         } else {
-            this.queryManager = new RepositoryQueryManager.Disabled();
+            this.queryManager = new RepositoryQueryManager.Disabled(this.sourceName);
         }
 
         /*
@@ -953,6 +955,13 @@
     }
 
     /**
+     * @return a list of all workspace names, without regard to the access permissions of any particular user
+     */
+    Set<String> workspaceNames() {
+        return Graph.create(sourceName, connectionFactory, executionContext).getWorkspaces();
+    }
+
+    /**
      * Returns the lock manager for the named workspace (if one already exists) or creates a new lock manager and returns it. This
      * method is thread-safe.
      * 

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java	2010-01-07 14:47:53 UTC (rev 1551)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryNodeTypeManager.java	2010-01-07 18:24:39 UTC (rev 1552)
@@ -31,6 +31,7 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import javax.jcr.PropertyType;
@@ -42,6 +43,7 @@
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.NodeType;
 import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.query.InvalidQueryException;
 import javax.jcr.version.OnParentVersionAction;
 import net.jcip.annotations.GuardedBy;
 import net.jcip.annotations.ThreadSafe;
@@ -64,6 +66,12 @@
 import org.jboss.dna.graph.property.PropertyFactory;
 import org.jboss.dna.graph.property.ValueFactories;
 import org.jboss.dna.graph.property.ValueFactory;
+import org.jboss.dna.graph.query.QueryResults;
+import org.jboss.dna.graph.query.model.QueryCommand;
+import org.jboss.dna.graph.query.model.TypeSystem;
+import org.jboss.dna.graph.query.parse.QueryParser;
+import org.jboss.dna.graph.query.parse.SqlQueryParser;
+import org.jboss.dna.graph.query.validate.Schemata;
 import org.jboss.dna.jcr.nodetype.InvalidNodeTypeDefinitionException;
 import org.jboss.dna.jcr.nodetype.NodeTypeDefinition;
 import org.jboss.dna.jcr.nodetype.NodeTypeExistsException;
@@ -105,6 +113,8 @@
 
     private static final TextEncoder NAME_ENCODER = new XmlNameEncoder();
 
+    private final JcrRepository repository;
+    private final QueryParser queryParser;
     private final ExecutionContext context;
 
     @GuardedBy( "nodeTypeManagerLock" )
@@ -142,9 +152,10 @@
         ANY
     }
 
-    RepositoryNodeTypeManager( ExecutionContext context,
+    RepositoryNodeTypeManager( JcrRepository repository,
                                boolean includeColumnsForInheritedProperties ) {
-        this.context = context;
+        this.repository = repository;
+        this.context = repository.getExecutionContext();
         this.includeColumnsForInheritedProperties = includeColumnsForInheritedProperties;
         this.propertyFactory = context.getPropertyFactory();
         this.pathFactory = context.getValueFactories().getPathFactory();
@@ -152,6 +163,8 @@
         propertyDefinitions = new HashMap<PropertyDefinitionId, JcrPropertyDefinition>();
         childNodeDefinitions = new HashMap<NodeDefinitionId, JcrNodeDefinition>();
         nodeTypes = new HashMap<Name, JcrNodeType>(50);
+        queryParser = new SqlQueryParser();
+
     }
 
     /**
@@ -1199,13 +1212,18 @@
                                                                                                                           childNode.getName()));
                         }
                     }
+
+                    /*
+                     * Search the content graph to make sure that this type isn't being used
+                     */
+                    if (isNodeTypeInUse(nodeTypeName)) {
+                        throw new InvalidNodeTypeDefinitionException(JcrI18n.cannotUnregisterInUseType.text(name));
+
+                    }
+
                 }
             }
 
-            /*
-             * Do a full recursive search over the content graph to make sure that this type isn't being used
-             */
-            // TODO: replace this with a query after queries work
             this.nodeTypes.keySet().removeAll(nodeTypeNames);
             this.schemata = null;
 
@@ -1215,6 +1233,36 @@
     }
 
     /**
+     * Check if the named node type is in use in any workspace in the repository
+     * 
+     * @param nodeTypeName the name of the node type to check
+     * @return true if at least one node is using that type; false otherwise
+     * @throws InvalidQueryException if there is an error searching for uses of the named node type
+     */
+    boolean isNodeTypeInUse( Name nodeTypeName ) throws InvalidQueryException {
+        String nodeTypeString = nodeTypeName.getString(context.getNamespaceRegistry());
+        String expression = "SELECT * from [" + nodeTypeString + "] LIMIT 1";
+
+        TypeSystem typeSystem = context.getValueFactories().getTypeSystem();
+        // Parsing must be done now ...
+        QueryCommand command = queryParser.parseQuery(expression, typeSystem);
+        assert command != null : "Could not parse " + expression;
+
+        Schemata schemata = getRepositorySchemata();
+
+        Set<String> workspaceNames = repository.workspaceNames();
+        for (String workspaceName : workspaceNames) {
+            QueryResults result = repository.queryManager().query(workspaceName, command, schemata, null, null);
+
+            if (result.getRowCount() > 0) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
      * Registers a new node type or updates an existing node type using the specified definition and returns the resulting {@code
      * NodeType} object.
      * <p>

Modified: trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryQueryManager.java
===================================================================
--- trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryQueryManager.java	2010-01-07 14:47:53 UTC (rev 1551)
+++ trunk/dna-jcr/src/main/java/org/jboss/dna/jcr/RepositoryQueryManager.java	2010-01-07 18:24:39 UTC (rev 1552)
@@ -77,31 +77,25 @@
 /**
  * 
  */
-class RepositoryQueryManager {
+abstract class RepositoryQueryManager {
 
-    RepositoryQueryManager() {
-    }
+    protected final String sourceName;
 
-    @SuppressWarnings( "unused" )
-    public QueryResults query( JcrWorkspace workspace,
-                               QueryCommand query,
-                               Schemata schemata,
-                               PlanHints hints,
-                               Map<String, Object> variables ) throws InvalidQueryException {
-        Graph.BuildQuery builder = workspace.graph().query(query, schemata);
-        if (variables != null) builder.using(variables);
-        if (hints != null) builder.using(hints);
-        return builder.execute();
+    RepositoryQueryManager( String sourceName ) {
+        this.sourceName = sourceName;
     }
 
-    @SuppressWarnings( "unused" )
-    public QueryResults search( JcrWorkspace workspace,
-                                String searchExpression,
-                                int maxRowCount,
-                                int offset ) throws InvalidQueryException {
-        return workspace.graph().search(searchExpression, maxRowCount, offset);
-    }
+    public abstract QueryResults query( String workspaceName,
+                                        QueryCommand query,
+                                        Schemata schemata,
+                                        PlanHints hints,
+                                        Map<String, Object> variables ) throws InvalidQueryException;
 
+    public abstract QueryResults search( String workspaceName,
+                                         String searchExpression,
+                                         int maxRowCount,
+                                         int offset ) throws InvalidQueryException;
+
     /**
      * Crawl and index the content in the named workspace.
      * 
@@ -138,35 +132,82 @@
         // do nothing by default
     }
 
+    static class PushDown extends RepositoryQueryManager {
+        private final ExecutionContext context;
+        private final RepositoryConnectionFactory connectionFactory;
+
+        PushDown( String sourceName,
+                  ExecutionContext context,
+                  RepositoryConnectionFactory connectionFactory ) {
+            super(sourceName);
+            this.context = context;
+            this.connectionFactory = connectionFactory;
+        }
+
+        private Graph workspaceGraph( String workspaceName ) {
+            Graph graph = Graph.create(this.sourceName, connectionFactory, context);
+
+            if (workspaceName != null) {
+                graph.useWorkspace(workspaceName);
+            }
+
+            return graph;
+        }
+
+        @Override
+        public QueryResults query( String workspaceName,
+                                   QueryCommand query,
+                                   Schemata schemata,
+                                   PlanHints hints,
+                                   Map<String, Object> variables ) throws InvalidQueryException {
+            Graph.BuildQuery builder = workspaceGraph(workspaceName).query(query, schemata);
+            if (variables != null) builder.using(variables);
+            if (hints != null) builder.using(hints);
+            return builder.execute();
+        }
+
+        @Override
+        public QueryResults search( String workspaceName,
+                                    String searchExpression,
+                                    int maxRowCount,
+                                    int offset ) throws InvalidQueryException {
+            return workspaceGraph(workspaceName).search(searchExpression, maxRowCount, offset);
+        }
+
+    }
+
     static class Disabled extends RepositoryQueryManager {
 
+        Disabled( String sourceName ) {
+            super(sourceName);
+        }
+
         /**
          * {@inheritDoc}
          * 
-         * @see org.jboss.dna.jcr.RepositoryQueryManager#query(org.jboss.dna.jcr.JcrWorkspace,
-         *      org.jboss.dna.graph.query.model.QueryCommand, org.jboss.dna.graph.query.validate.Schemata,
-         *      org.jboss.dna.graph.query.plan.PlanHints, java.util.Map)
+         * @see org.jboss.dna.jcr.RepositoryQueryManager#query(java.lang.String, org.jboss.dna.graph.query.model.QueryCommand,
+         *      org.jboss.dna.graph.query.validate.Schemata, org.jboss.dna.graph.query.plan.PlanHints, java.util.Map)
          */
         @Override
-        public QueryResults query( JcrWorkspace workspace,
+        public QueryResults query( String workspaceName,
                                    QueryCommand query,
                                    Schemata schemata,
                                    PlanHints hints,
                                    Map<String, Object> variables ) throws InvalidQueryException {
-            throw new InvalidQueryException(JcrI18n.queryIsDisabledInRepository.text(workspace.getSourceName()));
+            throw new InvalidQueryException(JcrI18n.queryIsDisabledInRepository.text(this.sourceName));
         }
 
         /**
          * {@inheritDoc}
          * 
-         * @see org.jboss.dna.jcr.RepositoryQueryManager#search(org.jboss.dna.jcr.JcrWorkspace, java.lang.String, int, int)
+         * @see org.jboss.dna.jcr.RepositoryQueryManager#search(java.lang.String, java.lang.String, int, int)
          */
         @Override
-        public QueryResults search( JcrWorkspace workspace,
+        public QueryResults search( String workspaceName,
                                     String searchExpression,
                                     int maxRowCount,
                                     int offset ) throws InvalidQueryException {
-            throw new InvalidQueryException(JcrI18n.queryIsDisabledInRepository.text(workspace.getSourceName()));
+            throw new InvalidQueryException(JcrI18n.queryIsDisabledInRepository.text(this.sourceName));
         }
     }
 
@@ -186,6 +227,8 @@
                        Observable observable,
                        String indexDirectory,
                        boolean updateIndexesSynchronously ) throws RepositoryException {
+            super(nameOfSourceToBeSearchable);
+
             this.context = context;
             this.sourceName = nameOfSourceToBeSearchable;
             this.connectionFactory = connectionFactory;
@@ -301,22 +344,36 @@
         }
 
         @Override
-        public QueryResults query( JcrWorkspace workspace,
+        public QueryResults query( String workspaceName,
                                    QueryCommand query,
                                    Schemata schemata,
                                    PlanHints hints,
                                    Map<String, Object> variables ) {
-            TypeSystem typeSystem = workspace.context().getValueFactories().getTypeSystem();
+            TypeSystem typeSystem = context.getValueFactories().getTypeSystem();
             SearchEngineProcessor processor = searchEngine.createProcessor(context, null, true);
             try {
                 QueryContext context = new GraphQueryContext(schemata, typeSystem, hints, new SimpleProblems(), variables,
-                                                             processor, workspace.getName());
+                                                             processor, workspaceName);
                 return queryEngine.execute(context, query);
             } finally {
                 processor.close();
             }
         }
 
+        @Override
+        public QueryResults search( String workspaceName,
+                                    String searchExpression,
+                                    int maxRowCount,
+                                    int offset ) throws InvalidQueryException {
+            Graph graph = Graph.create(sourceName, connectionFactory, context);
+
+            if (workspaceName != null) {
+                graph.useWorkspace(workspaceName);
+            }
+
+            return graph.search(searchExpression, maxRowCount, offset);
+        }
+
         /**
          * {@inheritDoc}
          * 

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	2010-01-07 14:47:53 UTC (rev 1551)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractJcrTest.java	2010-01-07 18:24:39 UTC (rev 1552)
@@ -26,7 +26,6 @@
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.stub;
 import java.io.IOException;
-import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Workspace;
 import org.jboss.dna.graph.ExecutionContext;
@@ -49,6 +48,7 @@
 public abstract class AbstractJcrTest {
 
     protected static ExecutionContext context;
+    protected static JcrRepository repository;
     protected static RepositoryNodeTypeManager rntm;
     protected InMemoryRepositorySource source;
     protected Graph store;
@@ -57,7 +57,6 @@
     protected JcrSession jcrSession;
     protected JcrNodeTypeManager nodeTypes;
     protected Workspace workspace;
-    protected Repository repository;
 
     /**
      * Initialize the expensive activities, and in particular the RepositoryNodeTypeManager instance.
@@ -70,7 +69,10 @@
 
         // Create the node type manager ...
         context.getNamespaceRegistry().register(Vehicles.Lexicon.Namespace.PREFIX, Vehicles.Lexicon.Namespace.URI);
-        rntm = new RepositoryNodeTypeManager(context, true);
+        repository = mock(JcrRepository.class);
+        stub(repository.getExecutionContext()).toReturn(context);
+
+        rntm = new RepositoryNodeTypeManager(repository, true);
         try {
             rntm.registerNodeTypes(new CndNodeTypeSource(new String[] {"/org/jboss/dna/jcr/jsr_170_builtins.cnd",
                 "/org/jboss/dna/jcr/dna_builtins.cnd"}));
@@ -115,7 +117,6 @@
         // Stub the session, workspace, and repository; then stub some critical methods ...
         jcrSession = mock(JcrSession.class);
         workspace = mock(Workspace.class);
-        repository = mock(Repository.class);
         stub(jcrSession.getExecutionContext()).toReturn(context);
         stub(jcrSession.getWorkspace()).toReturn(workspace);
         stub(jcrSession.getRepository()).toReturn(repository);

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java	2010-01-07 14:47:53 UTC (rev 1551)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/AbstractSessionTest.java	2010-01-07 18:24:39 UTC (rev 1552)
@@ -122,8 +122,24 @@
             }
         };
 
+        stub(repository.getExecutionContext()).toReturn(context);
+        stub(repository.getRepositorySourceName()).toReturn(repositorySourceName);
+        stub(repository.getPersistentRegistry()).toReturn(context.getNamespaceRegistry());
+        stub(repository.createWorkspaceGraph(anyString(), (ExecutionContext)anyObject())).toAnswer(new Answer<Graph>() {
+            public Graph answer( InvocationOnMock invocation ) throws Throwable {
+                return graph;
+            }
+        });
+        stub(repository.createSystemGraph(context)).toAnswer(new Answer<Graph>() {
+            public Graph answer( InvocationOnMock invocation ) throws Throwable {
+                return graph;
+            }
+        });
+        stub(this.repository.getRepositoryObservable()).toReturn(new MockObservable());
+
         // Stub out the repository, since we only need a few methods ...
-        repoTypeManager = new RepositoryNodeTypeManager(context, true);
+        repoTypeManager = new RepositoryNodeTypeManager(repository, true);
+        stub(repository.getRepositoryTypeManager()).toReturn(repoTypeManager);
 
         try {
             this.repoTypeManager.registerNodeTypes(new CndNodeTypeSource(new String[] {"/org/jboss/dna/jcr/jsr_170_builtins.cnd",
@@ -139,21 +155,6 @@
         }
         this.repoTypeManager.projectOnto(graph, pathFactory.create("/jcr:system/jcr:nodeTypes"));
 
-        stub(repository.getRepositoryTypeManager()).toReturn(repoTypeManager);
-        stub(repository.getRepositorySourceName()).toReturn(repositorySourceName);
-        stub(repository.getPersistentRegistry()).toReturn(context.getNamespaceRegistry());
-        stub(repository.createWorkspaceGraph(anyString(), (ExecutionContext)anyObject())).toAnswer(new Answer<Graph>() {
-            public Graph answer( InvocationOnMock invocation ) throws Throwable {
-                return graph;
-            }
-        });
-        stub(repository.createSystemGraph(context)).toAnswer(new Answer<Graph>() {
-            public Graph answer( InvocationOnMock invocation ) throws Throwable {
-                return graph;
-            }
-        });
-        stub(this.repository.getRepositoryObservable()).toReturn(new MockObservable());
-
         Path locksPath = pathFactory.createAbsolutePath(JcrLexicon.SYSTEM, DnaLexicon.LOCKS);
         workspaceLockManager = new WorkspaceLockManager(context, repository, workspaceName, locksPath);
 

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/CndNodeTypeRegistrationTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/CndNodeTypeRegistrationTest.java	2010-01-07 14:47:53 UTC (rev 1551)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/CndNodeTypeRegistrationTest.java	2010-01-07 18:24:39 UTC (rev 1552)
@@ -26,6 +26,7 @@
 import static org.hamcrest.core.Is.is;
 import static org.hamcrest.core.IsNull.notNullValue;
 import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.stub;
 import java.io.IOException;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -35,6 +36,7 @@
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
 
 /**
  * Test of CND-based type definitions. These test cases focus on ensuring that an import of a type from a CND file registers the
@@ -49,6 +51,8 @@
     private ExecutionContext context;
     private RepositoryNodeTypeManager repoTypeManager;
     private JcrNodeTypeSource nodeTypes;
+    @Mock
+    protected JcrRepository repository;
 
     @Before
     public void beforeEach() throws Exception {
@@ -56,7 +60,9 @@
         context = new ExecutionContext();
         context.getNamespaceRegistry().register(TestLexicon.Namespace.PREFIX, TestLexicon.Namespace.URI);
 
-        repoTypeManager = new RepositoryNodeTypeManager(context, true);
+        stub(repository.getExecutionContext()).toReturn(context);
+
+        repoTypeManager = new RepositoryNodeTypeManager(repository, true);
         try {
             this.repoTypeManager.registerNodeTypes(new CndNodeTypeSource(new String[] {"/org/jboss/dna/jcr/jsr_170_builtins.cnd",
                 "/org/jboss/dna/jcr/dna_builtins.cnd"}));

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrQueryManagerTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrQueryManagerTest.java	2010-01-07 14:47:53 UTC (rev 1551)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/JcrQueryManagerTest.java	2010-01-07 18:24:39 UTC (rev 1552)
@@ -31,6 +31,7 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -39,6 +40,7 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryResult;
 import org.jboss.dna.graph.connector.inmemory.InMemoryRepositorySource;
@@ -47,6 +49,8 @@
 import org.jboss.dna.jcr.JcrQueryManager.JcrQueryResult;
 import org.jboss.dna.jcr.JcrRepository.Option;
 import org.jboss.dna.jcr.JcrRepository.QueryLanguage;
+import org.jboss.dna.jcr.nodetype.InvalidNodeTypeDefinitionException;
+import org.jboss.security.config.IDTrustConfiguration;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -93,10 +97,22 @@
                      .registerNamespace("car", "http://www.jboss.org/dna/examples/cars/1.0")
                      .addNodeTypes(resourceUrl("cars.cnd"))
                      .setOption(Option.ANONYMOUS_USER_ROLES,
-                                JcrSession.DNA_READ_PERMISSION + "," + JcrSession.DNA_WRITE_PERMISSION);
+                                JcrSession.DNA_READ_PERMISSION + "," + JcrSession.DNA_WRITE_PERMISSION)
+                     .setOption(Option.JAAS_LOGIN_CONFIG_NAME, "dna-jcr");
         engine = configuration.build();
         engine.start();
 
+        // Initialize the JAAS configuration to allow for an admin login later
+        // Initialize IDTrust
+        String configFile = "security/jaas.conf.xml";
+        IDTrustConfiguration idtrustConfig = new IDTrustConfiguration();
+
+        try {
+            idtrustConfig.config(configFile);
+        } catch (Exception ex) {
+            throw new IllegalStateException(ex);
+        }
+
         // Start the repository ...
         repository = engine.getRepository("cars");
 
@@ -363,4 +379,23 @@
         assertResults(query, result, 1);
         assertResultsHaveColumns(result, "jcr:primaryType", "jcr:path", "jcr:score");
     }
+
+    /*
+     * Adding this test case since its primarily a test of integration between the RNTM and the query engine
+     */
+    @Test( expected = InvalidNodeTypeDefinitionException.class )
+    public void shouldNotAllowUnregisteringUsedPrimaryType() throws Exception {
+        Session adminSession = null;
+
+        try {
+            adminSession = repository.login(new SimpleCredentials("superuser", "superuser".toCharArray()));
+            adminSession.setNamespacePrefix("cars", "http://www.jboss.org/dna/examples/cars/1.0");
+
+            JcrNodeTypeManager nodeTypeManager = (JcrNodeTypeManager)adminSession.getWorkspace().getNodeTypeManager();
+            nodeTypeManager.unregisterNodeType(Collections.singletonList("cars:Car"));
+        } finally {
+            if (adminSession != null) adminSession.logout();
+        }
+    }
+
 }

Modified: trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/WorkspaceLockManagerTest.java
===================================================================
--- trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/WorkspaceLockManagerTest.java	2010-01-07 14:47:53 UTC (rev 1551)
+++ trunk/dna-jcr/src/test/java/org/jboss/dna/jcr/WorkspaceLockManagerTest.java	2010-01-07 18:24:39 UTC (rev 1552)
@@ -65,11 +65,9 @@
         validUuid = UUID.randomUUID();
         validLocation = Location.create(validUuid);
 
-        // Stub out the repository, since we only need a few methods ...
-        repoTypeManager = new RepositoryNodeTypeManager(context, true);
 
         PathFactory pathFactory = context.getValueFactories().getPathFactory();
-        stub(repository.getRepositoryTypeManager()).toReturn(repoTypeManager);
+        stub(repository.getExecutionContext()).toReturn(context);
         stub(repository.getRepositorySourceName()).toReturn(sourceName);
         stub(repository.getPersistentRegistry()).toReturn(context.getNamespaceRegistry());
         stub(repository.createWorkspaceGraph(anyString(), (ExecutionContext)anyObject())).toAnswer(new Answer<Graph>() {
@@ -92,6 +90,11 @@
             }
         });
 
+        // Stub out the repository, since we only need a few methods ...
+        repoTypeManager = new RepositoryNodeTypeManager(repository, true);
+
+        stub(repository.getRepositoryTypeManager()).toReturn(repoTypeManager);
+
         executedRequests.clear();
     }
 



More information about the dna-commits mailing list