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 2016/07/19 15:54:39 UTC

svn commit: r1753399 - in /sling/trunk/bundles: extensions/repoinit/it/src/main/provisioning/ extensions/repoinit/it/src/test/java/org/apache/sling/repoinit/it/ extensions/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/ jcr/r...

Author: bdelacretaz
Date: Tue Jul 19 15:54:38 2016
New Revision: 1753399

URL: http://svn.apache.org/viewvc?rev=1753399&view=rev
Log:
SLING-5842, SLING-5843 - implement the register namespace and nodetype operations in the jcr.repoinit module

Added:
    sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/DoNothingVisitor.java
    sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java
    sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/NodetypesVisitor.java
    sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java
      - copied, changed from r1753237, sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java
    sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/ExecutionOrderTest.java
    sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java
    sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/RegisterNodetypesTest.java
Removed:
    sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java
Modified:
    sling/trunk/bundles/extensions/repoinit/it/src/main/provisioning/repoinit.txt
    sling/trunk/bundles/extensions/repoinit/it/src/main/provisioning/sling.txt
    sling/trunk/bundles/extensions/repoinit/it/src/test/java/org/apache/sling/repoinit/it/ProvisioningModelIT.java
    sling/trunk/bundles/extensions/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNamespace.java
    sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java
    sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java

Modified: sling/trunk/bundles/extensions/repoinit/it/src/main/provisioning/repoinit.txt
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/repoinit/it/src/main/provisioning/repoinit.txt?rev=1753399&r1=1753398&r2=1753399&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/repoinit/it/src/main/provisioning/repoinit.txt (original)
+++ sling/trunk/bundles/extensions/repoinit/it/src/main/provisioning/repoinit.txt Tue Jul 19 15:54:38 2016
@@ -40,3 +40,11 @@ set ACL for userFromProvisioningModel
   allow jcr:read on /repoinit/fromProvisioningModel
   deny jcr:write on /repoinit/fromProvisioningModel
 end
+
+register namespace (slingtest) http://sling.apache.org/ns/test/repoinit-it/v1.0
+
+register nodetypes
+<<===
+<< <slingtest='http://sling.apache.org/ns/test/repoinit-it/v1.0'>
+<< [slingtest:unstructured] > nt:unstructured
+===>>
\ No newline at end of file

Modified: sling/trunk/bundles/extensions/repoinit/it/src/main/provisioning/sling.txt
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/repoinit/it/src/main/provisioning/sling.txt?rev=1753399&r1=1753398&r2=1753399&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/repoinit/it/src/main/provisioning/sling.txt (original)
+++ sling/trunk/bundles/extensions/repoinit/it/src/main/provisioning/sling.txt Tue Jul 19 15:54:38 2016
@@ -45,7 +45,6 @@
     org.apache.sling/org.apache.sling.commons.threads/3.2.4
     org.apache.sling/org.apache.sling.engine/2.4.6
     org.apache.sling/org.apache.sling.event/4.0.0
-    org.apache.sling/org.apache.sling.event.dea/1.0.4
     org.apache.sling/org.apache.sling.jcr.resource/2.7.4
     org.apache.sling/org.apache.sling.resourceresolver/1.4.12
     org.apache.sling/org.apache.sling.scripting.api/2.1.8
@@ -55,7 +54,6 @@
     org.apache.sling/org.apache.sling.servlets.post/2.3.12
     org.apache.sling/org.apache.sling.servlets.resolver/2.4.2
     javax.mail/mail/1.4.7
-    org.apache.geronimo.bundles/jstl/1.2_1
     org.apache.felix/org.apache.felix.http.whiteboard/3.0.0
 
 [artifacts startLevel=5]
@@ -63,9 +61,6 @@
     org.apache.felix/org.apache.felix.webconsole/4.2.14
     org.apache.geronimo.bundles/json/20090211_1
     org.apache.sling/org.apache.sling.commons.json/2.0.16
-    org.apache.aries.jmx/org.apache.aries.jmx.api/1.1.0
-    org.apache.aries.jmx/org.apache.aries.jmx.core/1.1.1
-    org.apache.aries.jmx/org.apache.aries.jmx.whiteboard/1.0.0
     commons-io/commons-io/2.4
     commons-fileupload/commons-fileupload/1.3.1
 

Modified: sling/trunk/bundles/extensions/repoinit/it/src/test/java/org/apache/sling/repoinit/it/ProvisioningModelIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/repoinit/it/src/test/java/org/apache/sling/repoinit/it/ProvisioningModelIT.java?rev=1753399&r1=1753398&r2=1753399&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/repoinit/it/src/test/java/org/apache/sling/repoinit/it/ProvisioningModelIT.java (original)
+++ sling/trunk/bundles/extensions/repoinit/it/src/test/java/org/apache/sling/repoinit/it/ProvisioningModelIT.java Tue Jul 19 15:54:38 2016
@@ -19,6 +19,9 @@ package org.apache.sling.repoinit.it;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.util.UUID;
+
+import javax.jcr.Node;
 import javax.jcr.Session;
 
 import org.apache.sling.jcr.api.SlingRepository;
@@ -26,7 +29,6 @@ import org.apache.sling.junit.rules.Tele
 import org.apache.sling.repoinit.parser.RepoInitParser;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -36,6 +38,7 @@ public class ProvisioningModelIT {
     private Session session;
     private static final String TEST_PATH = "/repoinit/fromProvisioningModel";
     private static final String TEST_USER = "userFromProvisioningModel";
+    private final String uniqueID = UUID.randomUUID().toString();
     
     @Rule
     public TeleporterRule teleporter = TeleporterRule.forClass(getClass(), "IT");
@@ -54,13 +57,20 @@ public class ProvisioningModelIT {
     }
     
     @Test
-    public void provisioningModelUserExists() throws Exception {
+    public void userCreated() throws Exception {
         assertTrue("Expecting user " + TEST_USER, U.userExists(session, TEST_USER));
     }
     
     @Test
-    public void provisioningModelUserAcl() throws Exception {
+    public void userAclSet() throws Exception {
         assertTrue("Expecting read access", U.canRead(session, TEST_USER, TEST_PATH));
         assertFalse("Expecting no write access",  U.canWrite(session, TEST_USER, TEST_PATH));
     }
+    
+    @Test
+    public void namespaceAndCndRegistered() throws Exception {
+        final String nodeName = "ns-" + uniqueID;
+        session.getRootNode().addNode(nodeName, "slingtest:unstructured");
+        session.save();
+    }
 }

Modified: sling/trunk/bundles/extensions/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNamespace.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNamespace.java?rev=1753399&r1=1753398&r2=1753399&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNamespace.java (original)
+++ sling/trunk/bundles/extensions/repoinit/parser/src/main/java/org/apache/sling/repoinit/parser/operations/RegisterNamespace.java Tue Jul 19 15:54:38 2016
@@ -43,4 +43,12 @@ public class RegisterNamespace extends O
     public void accept(OperationVisitor v) {
         v.visitRegisterNamespace(this);
     }
+    
+    public String getPrefix() {
+        return prefix;
+    }
+    
+    public String getURI() {
+        return uri;
+    }
 }

Added: sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/DoNothingVisitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/DoNothingVisitor.java?rev=1753399&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/DoNothingVisitor.java (added)
+++ sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/DoNothingVisitor.java Tue Jul 19 15:54:38 2016
@@ -0,0 +1,87 @@
+/*
+ * 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.jcr.repoinit.impl;
+
+import javax.jcr.Session;
+
+import org.apache.sling.repoinit.parser.operations.CreatePath;
+import org.apache.sling.repoinit.parser.operations.CreateServiceUser;
+import org.apache.sling.repoinit.parser.operations.DeleteServiceUser;
+import org.apache.sling.repoinit.parser.operations.OperationVisitor;
+import org.apache.sling.repoinit.parser.operations.RegisterNamespace;
+import org.apache.sling.repoinit.parser.operations.RegisterNodetypes;
+import org.apache.sling.repoinit.parser.operations.SetAclPaths;
+import org.apache.sling.repoinit.parser.operations.SetAclPrincipals;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Base class for specialized OperationVisitors.
+ */
+class DoNothingVisitor implements OperationVisitor {
+
+    protected final Logger log = LoggerFactory.getLogger(getClass());
+    
+    protected final Session session;
+    
+    /** Create a visitor using the supplied JCR Session.
+     * @param s must have sufficient rights to create users
+     *      and set ACLs.
+     */
+    protected DoNothingVisitor(Session s) {
+        session = s;
+    }
+    
+    protected void report(Exception e, String message) {
+        throw new RuntimeException(message, e);
+    }
+    
+    protected static String excerpt(String s, int maxLength) {
+        if(s.length() < maxLength) {
+            return s;
+        } else {
+            return s.substring(0, maxLength -1) + "...";
+        }
+    }
+    
+    @Override
+    public void visitCreateServiceUser(CreateServiceUser s) {
+    }
+
+    @Override
+    public void visitDeleteServiceUser(DeleteServiceUser s) {
+    }
+
+    @Override
+    public void visitSetAclPrincipal(SetAclPrincipals s) {
+     }
+
+    @Override
+    public void visitSetAclPaths(SetAclPaths s) {
+    }
+
+    @Override
+    public void visitCreatePath(CreatePath cp) {
+    }
+
+    @Override
+    public void visitRegisterNamespace(RegisterNamespace rn) {
+    }
+
+    @Override
+    public void visitRegisterNodetypes(RegisterNodetypes rn) {
+    }
+}

Modified: sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java?rev=1753399&r1=1753398&r2=1753399&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java (original)
+++ sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOpsProcessorImpl.java Tue Jul 19 15:54:38 2016
@@ -24,15 +24,28 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.jcr.repoinit.JcrRepoInitOpsProcessor;
 import org.apache.sling.repoinit.parser.operations.Operation;
+import org.apache.sling.repoinit.parser.operations.OperationVisitor;
 
 /** Apply Operations produced by the repoinit parser to a JCR Repository */
 @Component
 @Service(JcrRepoInitOpsProcessor.class)
 public class JcrRepoInitOpsProcessorImpl implements JcrRepoInitOpsProcessor {
+    
+    /** Apply the supplied operations: first the namespaces and nodetypes
+     *  registrations, then the service users, paths and ACLs.
+     */
     public void apply(Session session, List<Operation> ops) {
-        final JcrRepoInitOperationVisitor v = new JcrRepoInitOperationVisitor(session);
-        for(Operation op : ops) {
-            op.accept(v);
+        
+        final OperationVisitor [] visitors = {
+                new NamespacesVisitor(session),
+                new NodetypesVisitor(session),
+                new ServiceAndAclVisitor(session)
+        };
+        
+        for(OperationVisitor v : visitors) {
+            for(Operation op : ops) {
+                op.accept(v);
+            }
         }
     }
 }

Added: sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java?rev=1753399&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java (added)
+++ sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/NamespacesVisitor.java Tue Jul 19 15:54:38 2016
@@ -0,0 +1,48 @@
+/*
+ * 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.jcr.repoinit.impl;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.Session;
+
+import org.apache.sling.repoinit.parser.operations.RegisterNamespace;
+
+/** OperationVisitor which processes only operations related to
+ *  namespaces and nodetypes. Having several such specialized visitors 
+ *  makes it easy to control the execution order.
+ */
+class NamespacesVisitor extends DoNothingVisitor {
+
+    /** Create a visitor using the supplied JCR Session.
+     * @param s must have sufficient rights to create users
+     *      and set ACLs.
+     */
+    public NamespacesVisitor(Session s) {
+        super(s);
+    }
+    
+    @Override
+    public void visitRegisterNamespace(RegisterNamespace rn) {
+        try {
+            final NamespaceRegistry reg = session.getWorkspace().getNamespaceRegistry();
+            log.info("Registering namespace from {}", rn);
+            reg.registerNamespace(rn.getPrefix(), rn.getURI());
+        } catch(Exception e) {
+            report(e, "Unable to register namespace from " + rn);
+        }
+    }
+}

Added: sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/NodetypesVisitor.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/NodetypesVisitor.java?rev=1753399&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/NodetypesVisitor.java (added)
+++ sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/NodetypesVisitor.java Tue Jul 19 15:54:38 2016
@@ -0,0 +1,49 @@
+/*
+ * 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.jcr.repoinit.impl;
+
+import java.io.StringReader;
+
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.commons.cnd.CndImporter;
+import org.apache.sling.repoinit.parser.operations.RegisterNodetypes;
+
+/** OperationVisitor which processes only operations related to
+ *  namespaces and nodetypes. Having several such specialized visitors 
+ *  makes it easy to control the execution order.
+ */
+class NodetypesVisitor extends DoNothingVisitor {
+
+    /** Create a visitor using the supplied JCR Session.
+     * @param s must have sufficient rights to create users
+     *      and set ACLs.
+     */
+    public NodetypesVisitor(Session s) {
+        super(s);
+    }
+    
+    @Override
+    public void visitRegisterNodetypes(RegisterNodetypes rn) {
+        try {
+            log.info("Registering nodetypes from {}", excerpt(rn.getCndStatements(), 100));
+            CndImporter.registerNodeTypes(new StringReader(rn.getCndStatements()), session);
+        } catch(Exception e) {
+            report(e, "Unable to register nodetypes from " + rn);
+        }
+    }
+}

Copied: sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java (from r1753237, sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java)
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java?p2=sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java&p1=sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java&r1=1753237&r2=1753399&rev=1753399&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/JcrRepoInitOperationVisitor.java (original)
+++ sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/ServiceAndAclVisitor.java Tue Jul 19 15:54:38 2016
@@ -38,23 +38,18 @@ import org.apache.sling.repoinit.parser.
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** JCR visitor for the Operations produced by the repoinit parser */
-class JcrRepoInitOperationVisitor implements OperationVisitor {
+/** OperationVisitor which processes only operations related to
+ *  service users and ACLs. Having several such specialized visitors 
+ *  makes it easy to control the execution order. 
+ */
+class ServiceAndAclVisitor extends DoNothingVisitor {
 
-    private final Logger log = LoggerFactory.getLogger(getClass());
-    
-    private Session session;
-    
     /** Create a visitor using the supplied JCR Session.
      * @param s must have sufficient rights to create users
      *      and set ACLs.
      */
-    public JcrRepoInitOperationVisitor(Session s) {
-        session = s;
-    }
-    
-    private void report(Exception e, String message) {
-        throw new RuntimeException(message, e);
+    public ServiceAndAclVisitor(Session s) {
+        super(s);
     }
     
     @Override
@@ -141,14 +136,4 @@ class JcrRepoInitOperationVisitor implem
             throw new RuntimeException("Session.save failed: "+ e, e);
         }
     }
-
-    @Override
-    public void visitRegisterNamespace(RegisterNamespace rn) {
-        throw new UnsupportedOperationException(rn.toString());
-    }
-
-    @Override
-    public void visitRegisterNodetypes(RegisterNodetypes b) {
-        throw new UnsupportedOperationException(b.getClass().getName());
-    }
 }

Added: sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/ExecutionOrderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/ExecutionOrderTest.java?rev=1753399&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/ExecutionOrderTest.java (added)
+++ sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/ExecutionOrderTest.java Tue Jul 19 15:54:38 2016
@@ -0,0 +1,71 @@
+/*
+ * 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.jcr.repoinit;
+
+import static org.junit.Assert.assertEquals;
+import java.util.UUID;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.jcr.repoinit.impl.TestUtil;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/** Verify that namespaces and nodetypes are executed before path creation */
+public class ExecutionOrderTest {
+
+    @Rule
+    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+    
+    private TestUtil U;
+    
+    private static final String TEST_ID = UUID.randomUUID().toString();
+    private static final String NS_PREFIX = ExecutionOrderTest.class.getSimpleName();
+    private static final String NS_URI = "uri:" + NS_PREFIX + ":" + TEST_ID;
+    private static final String REL_PATH = ExecutionOrderTest.class.getSimpleName() + "-" + TEST_ID;
+    
+    @Before
+    public void setup() throws RepositoryException, RepoInitParsingException {
+        U = new TestUtil(context);
+        
+        final String stmt = 
+            "create path (" + NS_PREFIX + ":foo) /" + REL_PATH + "\n"
+            + U.getTestCndStatement(NS_PREFIX, NS_URI) + "\n"
+            + "register namespace (" + NS_PREFIX + ") " + NS_URI + "\n";
+        ;
+        
+        U.parseAndExecute(stmt);
+    }
+
+    @After
+    public void cleanup() throws RepositoryException, RepoInitParsingException {
+        U.cleanup();
+    }
+    
+    @Test
+    public void pathCreated() throws PathNotFoundException, RepositoryException {
+        final Node n = U.getAdminSession().getNode("/" + REL_PATH);
+        assertEquals(NS_PREFIX + ":foo", n.getProperty("jcr:primaryType").getString());
+    }
+}
\ No newline at end of file

Added: sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java?rev=1753399&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java (added)
+++ sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/RegisterNamespacesTest.java Tue Jul 19 15:54:38 2016
@@ -0,0 +1,70 @@
+/*
+ * 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.jcr.repoinit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.UUID;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.jcr.repoinit.impl.TestUtil;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/** Test register namespace statements */
+public class RegisterNamespacesTest {
+
+    @Rule
+    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+    
+    private TestUtil U;
+    private NamespaceRegistry ns;
+    
+    private static final String TEST_ID = UUID.randomUUID().toString();
+    private static final String NS1 = "uri:ns:test1:" + TEST_ID;
+    private static final String NS2 = "http://example.com/ns/" + TEST_ID;
+   
+    @Before
+    public void setup() throws RepositoryException, RepoInitParsingException {
+        U = new TestUtil(context);
+        U.parseAndExecute("register namespace (one) " + NS1);
+        U.parseAndExecute("register namespace (two) " + NS2);
+        ns = U.getAdminSession().getWorkspace().getNamespaceRegistry();
+    }
+
+    @After
+    public void cleanup() throws RepositoryException, RepoInitParsingException {
+        U.cleanup();
+    }
+    
+    @Test
+    public void NS1registered() throws Exception {
+        assertEquals(NS1, ns.getURI("one"));
+    }
+    
+    @Test
+    public void NS2registered() throws Exception {
+        assertEquals(NS2, ns.getURI("two"));
+    }
+}

Added: sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/RegisterNodetypesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/RegisterNodetypesTest.java?rev=1753399&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/RegisterNodetypesTest.java (added)
+++ sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/RegisterNodetypesTest.java Tue Jul 19 15:54:38 2016
@@ -0,0 +1,69 @@
+/*
+ * 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.jcr.repoinit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.UUID;
+
+import javax.jcr.NamespaceRegistry;
+import javax.jcr.RepositoryException;
+
+import org.apache.sling.jcr.repoinit.impl.TestUtil;
+import org.apache.sling.repoinit.parser.RepoInitParsingException;
+import org.apache.sling.testing.mock.sling.ResourceResolverType;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/** Test register nodetypes statements. Also registers a namespace */
+public class RegisterNodetypesTest {
+
+    @Rule
+    public final SlingContext context = new SlingContext(ResourceResolverType.JCR_OAK);
+    
+    private TestUtil U;
+    
+    private static final String TEST_ID = UUID.randomUUID().toString();
+    private static final String NS_PREFIX = RegisterNodetypesTest.class.getSimpleName();
+    private static final String NS_URI = "uri:" + NS_PREFIX + ":" + TEST_ID;
+    
+    @Before
+    public void setup() throws RepositoryException, RepoInitParsingException {
+        U = new TestUtil(context);
+        U.parseAndExecute("register namespace (" + NS_PREFIX + ") " + NS_URI);
+        U.parseAndExecute(U.getTestCndStatement(NS_PREFIX, NS_URI));
+    }
+
+    @After
+    public void cleanup() throws RepositoryException, RepoInitParsingException {
+        U.cleanup();
+    }
+    
+    @Test
+    public void NSregistered() throws Exception {
+        final NamespaceRegistry ns = U.getAdminSession().getWorkspace().getNamespaceRegistry();
+        assertEquals(NS_URI, ns.getURI(NS_PREFIX));
+    }
+    
+    @Test
+    public void fooNodetypeRegistered() throws Exception {
+        U.getAdminSession().getRootNode().addNode("test_" + TEST_ID, NS_PREFIX + ":foo");
+    }
+ }
\ No newline at end of file

Modified: sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java?rev=1753399&r1=1753398&r2=1753399&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java (original)
+++ sling/trunk/bundles/jcr/repoinit/src/test/java/org/apache/sling/jcr/repoinit/impl/TestUtil.java Tue Jul 19 15:54:38 2016
@@ -93,10 +93,8 @@ public class TestUtil {
     }
     
     public void parseAndExecute(String input) throws RepositoryException, RepoInitParsingException {
-        final JcrRepoInitOperationVisitor v = new JcrRepoInitOperationVisitor(adminSession);
-        for(Operation o : parse(input)) {
-            o.accept(v);
-        }
+        final JcrRepoInitOpsProcessorImpl p = new JcrRepoInitOpsProcessorImpl();
+        p.apply(adminSession, parse(input));
         adminSession.save();
     }
     
@@ -109,4 +107,25 @@ public class TestUtil {
         final SimpleCredentials cred = new SimpleCredentials(serviceUsername, new char[0]);
         return adminSession.impersonate(cred);
     }
+    
+    public Session getAdminSession() {
+        return adminSession;
+    }
+    
+    public void cleanup() {
+        adminSession.logout();
+    }
+    
+    public String getTestCndStatement(String nsPrefix, String nsURI) throws RepositoryException, RepoInitParsingException {
+        return "register nodetypes\n"
+                + "<<===\n"
+                + getTestCND(nsPrefix, nsURI)
+                + "===>>\n"
+        ;
+    }
+    
+    public String getTestCND(String nsPrefix, String nsURI) {
+        return "<" + nsPrefix + "='" + nsURI + "'>\n"
+                + "[" + nsPrefix + ":foo] > nt:unstructured\n";
+    }
 }