Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 12981 invoked from network); 17 Feb 2011 11:25:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Feb 2011 11:25:49 -0000 Received: (qmail 41820 invoked by uid 500); 17 Feb 2011 11:25:49 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 41733 invoked by uid 500); 17 Feb 2011 11:25:46 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 41720 invoked by uid 99); 17 Feb 2011 11:25:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Feb 2011 11:25:44 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Feb 2011 11:25:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DB23D2388A39; Thu, 17 Feb 2011 11:25:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110217112522.DB23D2388A39@eris.apache.org> 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 @@ false + + + copy-additional-bundles + + copy-dependencies + + process-resources + + ${project.build.directory}/sling/additional-bundles + + org.apache.sling.junit.core,org.apache.sling.testing.samples.testbundle + + true + false + false + + @@ -124,6 +145,7 @@ ${jar.executor.vm.options} ${project.basedir}/target/dependency org.apache.sling.launchpad.*jar$ + ${project.basedir}/target/sling/additional-bundles ${keepJarRunning} 60 /:script src="system/sling.js" @@ -136,6 +158,21 @@ + + + org.apache.sling + org.apache.sling.junit.core + 0.1.1-SNAPSHOT + provided + + + org.apache.sling + org.apache.sling.testing.samples.testbundle + 0.1.1-SNAPSHOT + provided + + + org.apache.stanbol org.apache.stanbol.commons.testing.jarexec @@ -153,6 +190,11 @@ 6-SNAPSHOT + org.apache.httpcomponents + httpmime + 4.0.1 + + org.slf4j slf4j-api 1.5.11 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