You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2014/05/09 22:58:58 UTC

svn commit: r1593618 - in /sling/trunk/tooling/ide: eclipse-test/src/org/apache/sling/ide/test/impl/ impl-vlt/src/org/apache/sling/ide/impl/vlt/

Author: rombert
Date: Fri May  9 20:58:58 2014
New Revision: 1593618

URL: http://svn.apache.org/r1593618
Log:
SLING-3236 - Unable to change node primary type once created

Update the node's primary type if necessary.

Added:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-folder-nodetype.xml   (with props)
Modified:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ContentDeploymentTest.java
    sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java

Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ContentDeploymentTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ContentDeploymentTest.java?rev=1593618&r1=1593617&r2=1593618&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ContentDeploymentTest.java (original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ContentDeploymentTest.java Fri May  9 20:58:58 2014
@@ -16,19 +16,29 @@
  */
 package org.apache.sling.ide.test.impl;
 
+import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasChildrenCount;
+import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasPath;
+import static org.apache.sling.ide.test.impl.helpers.jcr.JcrMatchers.hasPrimaryType;
+import static org.hamcrest.CoreMatchers.allOf;
+
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.concurrent.Callable;
 
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
 import org.apache.commons.httpclient.HttpException;
 import org.apache.commons.httpclient.URIException;
+import org.apache.commons.io.IOUtils;
 import org.apache.sling.ide.test.impl.helpers.DisableDebugStatusHandlers;
 import org.apache.sling.ide.test.impl.helpers.ExternalSlingLaunchpad;
 import org.apache.sling.ide.test.impl.helpers.LaunchpadConfig;
 import org.apache.sling.ide.test.impl.helpers.Poller;
 import org.apache.sling.ide.test.impl.helpers.ProjectAdapter;
-import org.apache.sling.ide.test.impl.helpers.ServerAdapter;
 import org.apache.sling.ide.test.impl.helpers.RepositoryAccessor;
+import org.apache.sling.ide.test.impl.helpers.ServerAdapter;
 import org.apache.sling.ide.test.impl.helpers.SlingWstServer;
 import org.apache.sling.ide.test.impl.helpers.TemporaryProject;
 import org.eclipse.core.resources.IProject;
@@ -36,6 +46,7 @@ import org.eclipse.core.runtime.CoreExce
 import org.eclipse.core.runtime.Path;
 import org.eclipse.jdt.core.JavaCore;
 import org.hamcrest.CoreMatchers;
+import org.hamcrest.Matcher;
 import org.junit.After;
 import org.junit.Rule;
 import org.junit.Test;
@@ -119,9 +130,63 @@ public class ContentDeploymentTest {
 
     }
 
+    @Test
+    public void changeNodePrimaryType() throws Exception {
+
+        wstServer.waitForServerToStart();
+
+        // create faceted project
+        IProject contentProject = projectRule.getProject();
+
+        ProjectAdapter project = new ProjectAdapter(contentProject);
+        project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
+
+        project.createOrUpdateFile(Path.fromPortableString("jcr_root/test/hello.txt"),
+                new ByteArrayInputStream("hello, world".getBytes()));
+
+        // install bundle facet
+        project.installFacet("sling.content", "1.0");
+
+        ServerAdapter server = new ServerAdapter(wstServer.getServer());
+        server.installModule(contentProject);
+
+        // verifications
+        Matcher postConditions = allOf(hasPath("/test"), hasPrimaryType("nt:folder"), hasChildrenCount(1));
+
+        final RepositoryAccessor repo = new RepositoryAccessor(config);
+        Poller poller = new Poller();
+        poller.pollUntil(new Callable<Node>() {
+            @Override
+            public Node call() throws RepositoryException {
+                return repo.getNode("/test");
+
+            }
+        }, postConditions);
+
+        // change node type to sling:Folder
+        InputStream contentXml = getClass().getResourceAsStream("sling-folder-nodetype.xml");
+        try {
+            project.createOrUpdateFile(Path.fromPortableString("jcr_root/test/.content.xml"), contentXml);
+        } finally {
+            IOUtils.closeQuietly(contentXml);
+        }
+
+        // verifications (2)
+        postConditions = allOf(hasPath("/test"), hasPrimaryType("sling:Folder"), hasChildrenCount(1));
+
+        poller.pollUntil(new Callable<Node>() {
+            @Override
+            public Node call() throws RepositoryException {
+                return repo.getNode("/test");
+
+            }
+        }, postConditions);
+    }
+
     @After
     public void cleanUp() throws Exception {
 
         new RepositoryAccessor(config).tryDeleteResource("/hello.txt");
+        new RepositoryAccessor(config).tryDeleteResource("/test");
     }
 }

Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-folder-nodetype.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-folder-nodetype.xml?rev=1593618&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-folder-nodetype.xml (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-folder-nodetype.xml Fri May  9 20:58:58 2014
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
+    jcr:primaryType="sling:Folder">
+</jcr:root>
\ No newline at end of file

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-folder-nodetype.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sling-folder-nodetype.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java?rev=1593618&r1=1593617&r2=1593618&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java (original)
+++ sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/AddOrUpdateNodeCommand.java Fri May  9 20:58:58 2014
@@ -154,6 +154,11 @@ public class AddOrUpdateNodeCommand exte
             updateMixins(node, mixinTypes);
         }
 
+        String primaryType = (String) resource.getProperties().get(JcrConstants.JCR_PRIMARYTYPE);
+        if (!node.getPrimaryNodeType().getName().equals(primaryType)) {
+            node.setPrimaryType(primaryType);
+        }
+
         // TODO - review for completeness and filevault compatibility
         for (Map.Entry<String, Object> entry : resource.getProperties().entrySet()) {