Author: rombert Date: Wed Oct 1 19:44:32 2014 New Revision: 1628819 URL: http://svn.apache.org/r1628819 Log: SLING-3989 - Content Navigator can't create full coverage nodes under partial coverage nodes
Fix and tests Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrNodeCreationTest.java Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrNodeCreationTest.java URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrNodeCreationTest.java?rev=1628819&view=auto ============================================================================== --- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrNodeCreationTest.java (added) +++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/JcrNodeCreationTest.java Wed Oct 1 19:44:32 2014 @@ -0,0 +1,137 @@ +/* + * 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.ide.test.impl; + +import static org.apache.sling.ide.test.impl.helpers.EclipseResourceMatchers.hasFile; +import static org.apache.sling.ide.test.impl.helpers.EclipseResourceMatchers.hasFolder; +import static org.junit.Assert.assertThat; + +import java.io.InputStream; + +import org.apache.sling.ide.eclipse.ui.nav.model.JcrNode; +import org.apache.sling.ide.eclipse.ui.nav.model.SyncDir; +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.ProjectAdapter; +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.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.Path; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.RuleChain; +import org.junit.rules.TestRule; + +/** + * The <tt>JcrNodeCreationTest</tt> tests node creation scenarios + * + */ +public class JcrNodeCreationTest { + + private final LaunchpadConfig config = LaunchpadConfig.getInstance(); + + private final SlingWstServer wstServer = new SlingWstServer(config); + + @Rule + public TestRule chain = RuleChain.outerRule(new ExternalSlingLaunchpad(config)).around(wstServer); + + @Rule + public TemporaryProject projectRule = new TemporaryProject(); + + @Rule + public DisableDebugStatusHandlers disableDebugHandlers = new DisableDebugStatusHandlers(); + + private SyncDir syncDirNode; + + @Before + public void prepareProjectAndContent() 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"); + + // install content facet + project.installFacet("sling.content", "1.0"); + + ServerAdapter server = new ServerAdapter(wstServer.getServer()); + server.installModule(contentProject); + + // create .content.xml structure + InputStream contentXml = getClass().getResourceAsStream("content-nested-structure.xml"); + project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/en.xml"), contentXml); + + // directly create the root node + syncDirNode = new SyncDir((IFolder) contentProject.findMember("jcr_root")); + + } + + @Test + public void createNtFolderNode() throws Exception { + + JcrNode contentNode = syncDirNode.getNode("/content/test-root"); + contentNode.createChild("folder", "nt:folder"); + + assertThat(projectRule.getProject(), hasFolder("/jcr_root/content/test-root/folder")); + } + + @Test + public void createNtFileNode() throws Exception { + + JcrNode contentNode = syncDirNode.getNode("/content/test-root"); + contentNode.createChild("hello.txt", "nt:file"); + + assertThat(projectRule.getProject(), hasFile("/jcr_root/content/test-root/hello.txt")); + } + + @Test + public void createFullCoverageNodeUnderFolder() throws Exception { + + JcrNode contentNode = syncDirNode.getNode("/content/test-root"); + contentNode.createChild("messages", "sling:OsgiConfig"); + + assertThat(projectRule.getProject(), hasFile("/jcr_root/content/test-root/messages.xml")); + } + + @Test + public void createFullCoverageNodeUnderPartialCoverageNode() throws Exception { + + IProject project = projectRule.getProject(); + new ProjectAdapter(project).createOrUpdateFile(Path + .fromPortableString("jcr_root/content/test-root/holder/.content.xml"), + getClass().getResourceAsStream("nt-unstructured-nodetype.xml")); + + JcrNode contentNode = syncDirNode.getNode("/content/test-root/holder"); + contentNode.createChild("org.apache.sling.SomeComponent", "sling:OsgiConfig"); + + assertThat(project, hasFile("/jcr_root/content/test-root/holder/org.apache.sling.SomeComponent.xml")); + } + + @After + public void cleanup() throws Exception { + new RepositoryAccessor(config).tryDeleteResource("/content/test-root"); + } +} Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java?rev=1628819&r1=1628818&r2=1628819&view=diff ============================================================================== --- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java (original) +++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/nav/model/JcrNode.java Wed Oct 1 19:44:32 2014 @@ -889,7 +889,8 @@ public class JcrNode implements IAdaptab MessageDialog.openError(Display.getDefault().getActiveShell(), "Error creating node", "Error creating child of "+thisNodeType+" with type "+childNodeType+": "+e); return; } - } else if (parentSk==SerializationKind.FOLDER && childSk==SerializationKind.METADATA_FULL) { + } else if ((parentSk == SerializationKind.FOLDER || parentSk == SerializationKind.METADATA_PARTIAL) + && childSk == SerializationKind.METADATA_FULL) { createVaultFile((IFolder)resource, childNodeName+".xml", childNodeType); } else if (parentSk==SerializationKind.FOLDER && childSk==SerializationKind.METADATA_PARTIAL) { // createVaultFile((IFolder)resource, childNodeName+".xml", childNodeType); @@ -924,6 +925,11 @@ public class JcrNode implements IAdaptab return; } //TODO: FILE not yet supported + + Activator.getDefault().getPluginLogger() + .error("Cannot create child node of type " + childNodeType + ", serializationKind " + childSk + + " under child node of type " + thisNodeType + ", serializationKind " + parentSk); + MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Error creating node", "Cannot create child of "+thisNodeType+" with type "+childNodeType+" (yet?)"); return; }