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 2016/02/24 16:20:48 UTC

svn commit: r1732166 - in /sling/trunk/tooling/ide: eclipse-sightly-core/META-INF/MANIFEST.MF eclipse-test/src/org/apache/sling/ide/test/impl/sightly/SightlyNatureTesterTest.java

Author: rombert
Date: Wed Feb 24 15:20:48 2016
New Revision: 1732166

URL: http://svn.apache.org/viewvc?rev=1732166&view=rev
Log:
SLING-5538 - Create new Sightly file wizards

Add a SightlyNatureTesterTest

Added:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sightly/SightlyNatureTesterTest.java
Modified:
    sling/trunk/tooling/ide/eclipse-sightly-core/META-INF/MANIFEST.MF

Modified: sling/trunk/tooling/ide/eclipse-sightly-core/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-sightly-core/META-INF/MANIFEST.MF?rev=1732166&r1=1732165&r2=1732166&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-sightly-core/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/eclipse-sightly-core/META-INF/MANIFEST.MF Wed Feb 24 15:20:48 2016
@@ -33,4 +33,5 @@ Import-Package: org.apache.sling.ide.ecl
  org.eclipse.wst.xml.core.internal.regions
 Export-Package: org.apache.sling.ide.eclipse.sightly,
  org.apache.sling.ide.eclipse.sightly.model,
- org.apache.sling.ide.eclipse.sightly.validation
+ org.apache.sling.ide.eclipse.sightly.validation,
+ org.apache.sling.ide.eclipse.sightly.internal;x-friends:="org.apache.sling.ide.eclipse-test"

Added: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sightly/SightlyNatureTesterTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sightly/SightlyNatureTesterTest.java?rev=1732166&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sightly/SightlyNatureTesterTest.java (added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/sightly/SightlyNatureTesterTest.java Wed Feb 24 15:20:48 2016
@@ -0,0 +1,99 @@
+/*
+ * 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.sightly;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+
+import org.apache.sling.ide.eclipse.sightly.internal.SightlyNatureTester;
+import org.apache.sling.ide.eclipse.ui.nav.JcrContentContentProvider;
+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.ProjectAdapter;
+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.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class SightlyNatureTesterTest {
+
+    @Rule
+    public TemporaryProject projectRule = new TemporaryProject();
+
+    private SightlyNatureTester tester;
+    private ProjectAdapter projectAdapter;
+
+    @Before
+    public void prepare() throws Exception {
+
+        final IProject project = projectRule.getProject();
+
+        projectAdapter = new ProjectAdapter(project);
+        projectAdapter.addNatures("org.eclipse.wst.common.project.facet.core.nature");
+        projectAdapter.installFacet("sling.content", "1.0");
+
+        tester = new SightlyNatureTester();
+    }
+
+    @Test
+    public void testOnSightlyProject() throws Exception {
+
+        testOnProject(true);
+    }
+
+    private void testOnProject(boolean hasSightlyNature) throws CoreException {
+
+        if (hasSightlyNature) {
+            projectAdapter.installFacet("sightly", "1.1");
+        }
+
+        final IPath sightlyTemplatePath = Path.fromPortableString("/jcr_root/libs/my/component/html.html");
+        projectAdapter.createOrUpdateFile(sightlyTemplatePath, new ByteArrayInputStream(("<html />").getBytes()));
+
+        // test on resources directly
+        assertEquals("Test on project", hasSightlyNature,
+                tester.test(projectRule.getProject(), "sightlyNature", new Object[0], null));
+        assertEquals("Test on folder", hasSightlyNature,
+                tester.test(projectRule.getProject().getFolder("jcr_root"), "sightlyNature", new Object[0], null));
+        assertEquals("Test on file", hasSightlyNature, tester
+                .test(projectRule.getProject().getFile(sightlyTemplatePath), "sightlyNature", new Object[0], null));
+        
+        // directly create the root node
+        SyncDir syncDirNode = new SyncDir((IFolder) projectRule.getProject().findMember("jcr_root"));
+        assertEquals("Test on sync dir node", hasSightlyNature,
+                tester.test(syncDirNode, "sightlyNature", new Object[0], null));
+        
+        // test on jcr nodes
+        JcrContentContentProvider contentProvider = new JcrContentContentProvider();
+        JcrNode firstChild = (JcrNode) contentProvider.getChildren(syncDirNode)[0];
+        assertEquals("Test on jcr node", hasSightlyNature,
+                tester.test(firstChild, "sightlyNature", new Object[0], null));
+
+    }
+
+    @Test
+    public void testOnNonSightlyProject() throws Exception {
+
+        testOnProject(false);
+    }
+}