incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1071581 - in /sling/trunk/testing/samples/test-tools: ./ src/test/java/org/apache/sling/junit/sample/ src/test/java/org/apache/sling/testing/ src/test/java/org/apache/sling/testing/sample/ src/test/java/org/apache/sling/testing/sample/serv...
Date Thu, 17 Feb 2011 11:25:22 GMT
Author: bdelacretaz
Date: Thu Feb 17 11:25:22 2011
New Revision: 1071581

URL: http://svn.apache.org/viewvc?rev=1071581&view=rev
Log:
SLING-1981 - install additional bundles and prepare for running server-side tests (requires
up-to-date stanbol snapshots)

Added:
    sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/
    sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/sample/
    sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/sample/serverside/
    sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/sample/serverside/ServerSideTest.java
  (with props)
Modified:
    sling/trunk/testing/samples/test-tools/pom.xml
    sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/junit/sample/SlingTestBase.java

Modified: sling/trunk/testing/samples/test-tools/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/test-tools/pom.xml?rev=1071581&r1=1071580&r2=1071581&view=diff
==============================================================================
--- sling/trunk/testing/samples/test-tools/pom.xml (original)
+++ sling/trunk/testing/samples/test-tools/pom.xml Thu Feb 17 11:25:22 2011
@@ -92,6 +92,27 @@
                             <overWriteSnapshots>false</overWriteSnapshots>
                         </configuration>
                     </execution>
+                    <execution>
+                        <!-- 
+                            Consider all "provided" dependencies 
+                            as additional bundles that need to be
+                            installed before running tests  
+                        -->
+                        <id>copy-additional-bundles</id>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                            <phase>process-resources</phase>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}/sling/additional-bundles</outputDirectory>
+                            <includeArtifactIds>
+                                org.apache.sling.junit.core,org.apache.sling.testing.samples.testbundle
+                            </includeArtifactIds>
+                            <excludeTransitive>true</excludeTransitive>
+                            <overWriteReleases>false</overWriteReleases>
+                            <overWriteSnapshots>false</overWriteSnapshots>
+                        </configuration>
+                    </execution>
                 </executions>
             </plugin>
             <plugin>
@@ -124,6 +145,7 @@
                         <jar.executor.vm.options>${jar.executor.vm.options}</jar.executor.vm.options>
                         <jar.executor.jar.folder>${project.basedir}/target/dependency</jar.executor.jar.folder>
                         <jar.executor.jar.name.regexp>org.apache.sling.launchpad.*jar$</jar.executor.jar.name.regexp>
+                        <additional.bundles.path>${project.basedir}/target/sling/additional-bundles</additional.bundles.path>
                         <keepJarRunning>${keepJarRunning}</keepJarRunning>
                         <server.ready.timeout.seconds>60</server.ready.timeout.seconds>
                         <server.ready.path.1>/:script src="system/sling.js"</server.ready.path.1>
@@ -136,6 +158,21 @@
     </build>
 
     <dependencies>
+        <!-- Additional bundles needed by the Sling instance under test -->
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.junit.core</artifactId>
+            <version>0.1.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.samples.testbundle</artifactId>
+            <version>0.1.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        
+        <!-- actual dependencies -->
         <dependency>
             <groupId>org.apache.stanbol</groupId>
             <artifactId>org.apache.stanbol.commons.testing.jarexec</artifactId>
@@ -153,6 +190,11 @@
             <version>6-SNAPSHOT</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpmime</artifactId>
+            <version>4.0.1</version>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <version>1.5.11</version>

Modified: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/junit/sample/SlingTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/junit/sample/SlingTestBase.java?rev=1071581&r1=1071580&r2=1071581&view=diff
==============================================================================
--- sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/junit/sample/SlingTestBase.java
(original)
+++ sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/junit/sample/SlingTestBase.java
Thu Feb 17 11:25:22 2011
@@ -17,10 +17,15 @@
 package org.apache.sling.junit.sample;
 
 import static org.junit.Assert.fail;
+
+import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.TreeSet;
 
+import org.apache.http.entity.mime.MultipartEntity;
+import org.apache.http.entity.mime.content.FileBody;
+import org.apache.http.entity.mime.content.StringBody;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.stanbol.commons.testing.http.RequestBuilder;
 import org.apache.stanbol.commons.testing.http.RequestExecutor;
@@ -38,6 +43,8 @@ public class SlingTestBase {
     public static final String SERVER_READY_TIMEOUT_PROP = "server.ready.timeout.seconds";
     public static final String SERVER_READY_PROP_PREFIX = "server.ready.path";
     public static final String KEEP_JAR_RUNNING_PROP = "keepJarRunning";
+    public static final String ADDITONAL_BUNDLES_PATH = "additional.bundles.path";
+    public static final String ADMIN = "admin";
     
     protected static String serverBaseUrl;
     protected static RequestBuilder builder;
@@ -132,11 +139,70 @@ public class SlingTestBase {
             Thread.sleep(1000L);
         }
         
-        if(!serverReady) {
+        if(serverReady) {
+            onServerReady();
+        } else {
             serverReadyTestFailed = true;
             final String msg = "Server not ready after " + timeoutSec + " seconds, giving
up";
             log.info(msg);
             fail(msg);
         }
     }
+    
+    /** Called once when the server is found to be ready, can be used for additional
+     *  server setup (extra bundles etc.). If overridden, must be called by overriding
+     *  method. 
+     */
+    protected void onServerReady() throws Exception {
+        installExtraBundles();
+    }
+    
+    /** Install all bundles found under our additional bundles path */
+    protected void installExtraBundles() throws Exception {
+        final String path = System.getProperty(ADDITONAL_BUNDLES_PATH);
+        if(path == null) {
+            log.info("System property {} not set, additional bundles won't be installed",

+                    ADDITONAL_BUNDLES_PATH);
+            return;
+        }
+        
+        final File dir = new File(path);
+        if(!dir.isDirectory() || !dir.canRead()) {
+            log.info("Cannot read additional bundles directory {}, ignored", dir.getAbsolutePath());
+            return;
+        }
+        
+        int count = 0;
+        final String [] files = dir.list();
+        if(files != null) {
+            for(String file : files) {
+                if(file.endsWith(".jar")) {
+                    File f = new File(dir, file);
+                    installBundle(f);
+                    count++;
+                }
+            }
+        }
+        
+        log.info("{} additional bundles installed from {}", count, dir.getAbsolutePath());
+    }
+ 
+    /** Install a bundle using the Felix webconsole HTTP interface */
+    protected void installBundle(File f) throws Exception {
+        log.info("Installing additional bundle {}", f.getName());
+        
+        // Setup request for Felix Webconsole bundle install
+        final MultipartEntity entity = new MultipartEntity();
+        entity.addPart("action",new StringBody("install"));
+        entity.addPart("bundlestart", new StringBody("true"));
+        entity.addPart("bundlefile", new FileBody(f));
+        
+        // Console returns a 302 on success (and in a POST this
+        // is not handled automatically as per HTTP spec)
+        executor.execute(
+                builder.buildPostRequest("/system/console/bundles")
+                .withCredentials(ADMIN, ADMIN)
+                .withEntity(entity)
+        ).assertStatus(302);
+    }
 }
\ No newline at end of file

Added: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/sample/serverside/ServerSideTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/sample/serverside/ServerSideTest.java?rev=1071581&view=auto
==============================================================================
--- sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/sample/serverside/ServerSideTest.java
(added)
+++ sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/sample/serverside/ServerSideTest.java
Thu Feb 17 11:25:22 2011
@@ -0,0 +1,67 @@
+/*
+ * 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.testing.sample.serverside;
+
+import org.apache.sling.junit.sample.SlingTestBase;
+import org.apache.stanbol.commons.testing.http.RetryLoop;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Run all server-side tests */ 
+public class ServerSideTest extends SlingTestBase {
+    public static final String JUNIT_SERVLET_PATH = "/system/sling/junit";
+    private static boolean junitServletOk;
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    // TODO compute those timeouts based on a configured factor
+    // to cope with slower testing systems??
+    public static final int JUNIT_SERVLET_TIMEOUT_SECONDS = 60;
+    
+    @Before
+    public void checkJunitServletPresent() throws Exception {
+        if(junitServletOk) {
+            return;
+        }
+    
+        // Retry accessing the junit servlet until it responds or timeout
+        // (as we might just have installed the required bundles)
+        final RetryLoop.Condition c = new RetryLoop.Condition() {
+            public String getDescription() {
+                return "Checking that " + JUNIT_SERVLET_PATH + " returns 200";
+            }
+
+            public boolean isTrue() throws Exception {
+                executor.execute(
+                        builder.buildGetRequest(JUNIT_SERVLET_PATH))
+                .assertStatus(200);
+                return true;
+            }
+                
+        };
+        
+        new RetryLoop(c, JUNIT_SERVLET_TIMEOUT_SECONDS, 500); 
+        junitServletOk = true;
+    }
+    
+    @Test
+    public void testNothing() {
+        // TODO run the actual tests via junit servlet
+        log.info("If we get there that means " + JUNIT_SERVLET_PATH + " works");
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/sample/serverside/ServerSideTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/samples/test-tools/src/test/java/org/apache/sling/testing/sample/serverside/ServerSideTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message