sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject svn commit: r1593274 - in /sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl: ContentDeploymentTest.java helpers/ProjectAdapter.java helpers/SlingWstServer.java
Date Thu, 08 May 2014 13:30:25 GMT
Author: rombert
Date: Thu May  8 13:30:24 2014
New Revision: 1593274

URL: http://svn.apache.org/r1593274
Log:
SLING-3544 - Integration tests running against a live Sling Launchpad
instance

Added a ContentDeploymentTest which creates/updated/delete a file which
is expected to be synced.

Also adapted the SlingWstServer to cleanup after itself between
executions so that multiple tests can be executed on a single workspace.

Added:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ContentDeploymentTest.java
  (with props)
Modified:
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/ProjectAdapter.java
    sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/SlingWstServer.java

Added: 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=1593274&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ContentDeploymentTest.java
(added)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ContentDeploymentTest.java
Thu May  8 13:30:24 2014
@@ -0,0 +1,152 @@
+/*
+ * 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.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
+import org.apache.commons.httpclient.methods.multipart.Part;
+import org.apache.commons.httpclient.methods.multipart.StringPart;
+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.LaunchpadUtils;
+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.SlingWstServer;
+import org.apache.sling.ide.test.impl.helpers.TemporaryProject;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.JavaCore;
+import org.junit.After;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
+
+/**
+ * The <tt>ContentDeploymentTest</tt> validates simple content deployment based
on the resources changes in the
+ * workspace
+ *
+ */
+public class ContentDeploymentTest {
+
+    private final SlingWstServer wstServer = new SlingWstServer();
+
+    @Rule
+    public TestRule chain = RuleChain.outerRule(new ExternalSlingLaunchpad()).around(wstServer);
+
+    @Rule
+    public TemporaryProject projectRule = new TemporaryProject();
+
+    @Rule
+    public DisableDebugStatusHandlers disableDebugHandlers = new DisableDebugStatusHandlers();
+
+    @Test
+    public void deployFile() throws CoreException, InterruptedException, URIException, HttpException,
IOException {
+
+        wstServer.waitForServerToStart();
+
+        // create faceted project
+        IProject contentProject = projectRule.getProject();
+
+        ProjectAdapter project = new ProjectAdapter(contentProject);
+        project.addNatures(JavaCore.NATURE_ID, "org.eclipse.wst.common.project.facet.core.nature");
+
+        project.createOrUpdateFile(Path.fromPortableString("jcr_root/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);
+
+        Thread.sleep(1000); // for good measure, make sure the output is there - TODO replace
with polling
+
+        // verify that file is created
+        assertSimpleCallsSucceeds("hello, world");
+
+        project.createOrUpdateFile(Path.fromPortableString("jcr_root/hello.txt"), new ByteArrayInputStream(
+                "goodbye, world".getBytes()));
+
+        Thread.sleep(2000); // for good measure, make sure the output is there - TODO replace
with polling
+
+        // verify that file is updated
+        assertSimpleCallsSucceeds("goodbye, world");
+
+        project.deleteMember(Path.fromPortableString("/jcr_root/hello.txt"));
+
+        Thread.sleep(2000); // for good measure, make sure the output is there - TODO replace
with polling
+        // verify that the file is deleted
+        assertResourceNotFound();
+    }
+
+    private void assertSimpleCallsSucceeds(String expectedOutput) throws IOException, HttpException,
URIException {
+        HttpClient c = new HttpClient();
+        GetMethod gm = new GetMethod("http://localhost:" + LaunchpadUtils.getLaunchpadPort()
+ "/hello.txt");
+        try {
+            int status = c.executeMethod(gm);
+
+            assertThat("Unexpected status code for " + gm.getURI(), status, equalTo(200));
+            assertThat("Unexpected response for " + gm.getURI(), gm.getResponseBodyAsString(),
equalTo(expectedOutput));
+
+        } finally {
+            gm.releaseConnection();
+        }
+    }
+
+    private void assertResourceNotFound() throws IOException, HttpException, URIException
{
+        HttpClient c = new HttpClient();
+        GetMethod gm = new GetMethod("http://localhost:" + LaunchpadUtils.getLaunchpadPort()
+ "/hello.txt");
+        try {
+            int status = c.executeMethod(gm);
+
+            assertThat("Unexpected status code for " + gm.getURI(), status, equalTo(404));
+        } finally {
+            gm.releaseConnection();
+        }
+    }
+
+    @After
+    public void cleanUp() throws HttpException, IOException {
+        HttpClient c = new HttpClient();
+        c.getParams().setAuthenticationPreemptive(true);
+        c.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin",
"admin"));
+        PostMethod pm = new PostMethod("http://localhost:" + LaunchpadUtils.getLaunchpadPort()
+ "/hello.txt");
+        Part[] parts = { new StringPart(":operation", "delete") };
+        pm.setRequestEntity(new MultipartRequestEntity(parts, pm.getParams()));
+        try {
+            int status = c.executeMethod(pm);
+
+            System.out.println("Delete operation got status " + status);
+        } finally {
+            pm.releaseConnection();
+        }
+    }
+}

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

Propchange: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/ContentDeploymentTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/ProjectAdapter.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/ProjectAdapter.java?rev=1593274&r1=1593273&r2=1593274&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/ProjectAdapter.java
(original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/ProjectAdapter.java
Thu May  8 13:30:24 2014
@@ -168,4 +168,13 @@ public class ProjectAdapter {
 
     }
 
+
+    public void deleteMember(IPath path) throws CoreException {
+
+        IResource member = project.findMember(path);
+        if (member != null) {
+            member.delete(true, new NullProgressMonitor());
+        }
+    }
+
 }

Modified: sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/SlingWstServer.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/SlingWstServer.java?rev=1593274&r1=1593273&r2=1593274&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/SlingWstServer.java
(original)
+++ sling/trunk/tooling/ide/eclipse-test/src/org/apache/sling/ide/test/impl/helpers/SlingWstServer.java
Thu May  8 13:30:24 2014
@@ -23,6 +23,7 @@ import java.util.concurrent.CountDownLat
 import java.util.concurrent.TimeUnit;
 
 import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.debug.core.ILaunchManager;
@@ -45,9 +46,6 @@ public class SlingWstServer extends Exte
 
     @Override
     protected void before() throws Throwable {
-        int expectedServerCount = ServerCore.getServers().length + 1;
-        int expectedRuntimeCount = ServerCore.getRuntimes().length + 1;
-
         IRuntimeType launchpadRuntime = null;
         for (IRuntimeType type : ServerCore.getRuntimeTypes()) {
             if ("org.apache.sling.ide.launchpadRuntimeType".equals(type.getId())) {
@@ -60,7 +58,8 @@ public class SlingWstServer extends Exte
             throw new IllegalArgumentException("No runtime of type 'org.apache.sling.ide.launchpadRuntimeType'
found");
         }
 
-        IRuntimeWorkingCopy rtwc = launchpadRuntime.createRuntime("temp.rt.id", new NullProgressMonitor());
+        IRuntimeWorkingCopy rtwc = launchpadRuntime.createRuntime("temp.sling.launchpad.rt.id",
+                new NullProgressMonitor());
         rtwc.save(true, new NullProgressMonitor());
 
         IServerType serverType = null;
@@ -76,7 +75,8 @@ public class SlingWstServer extends Exte
             throw new IllegalArgumentException("No server type of type 'org.apache.sling.ide.launchpadServer'
found");
         }
 
-        IServerWorkingCopy wc = serverType.createServer("tmp.server.id", null, new NullProgressMonitor());
+        IServerWorkingCopy wc = serverType.createServer("temp.sling.launchpad.server.id",
null,
+                new NullProgressMonitor());
         // TODO - remove hardcoding
         wc.setHost("localhost");
         wc.setAttribute(ISlingLaunchpadServer.PROP_PORT, LaunchpadUtils.getLaunchpadPort());
@@ -87,17 +87,15 @@ public class SlingWstServer extends Exte
         wc.setAttribute("auto-publish-time", 0);
 
         server = wc.save(true, new NullProgressMonitor());
-
-        assertThat("server creation not registered - ServerCore.servers.length", ServerCore.getServers().length,
-                equalTo(expectedServerCount));
-        assertThat("runtime creation not registered - ServerCore.runtimes.length", ServerCore.getRuntimes().length,
-                equalTo(expectedRuntimeCount));
     }
 
     @Override
     protected void after() {
-
-        // TODO - destroy the server
+        try {
+            server.delete();
+        } catch (CoreException e) {
+            // TODO log
+        }
     }
 
     public void waitForServerToStart() throws InterruptedException {



Mime
View raw message