incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1503306 - in /sling/trunk/launchpad: integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/ test-services/
Date Mon, 15 Jul 2013 15:45:16 GMT
Author: bdelacretaz
Date: Mon Jul 15 15:45:16 2013
New Revision: 1503306

URL: http://svn.apache.org/r1503306
Log:
SLING-2965 - refactor to allow for multiple server-side tests

Added:
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/ServerSideTestClient.java
Modified:
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ServerSideScriptsTest.java
    sling/trunk/launchpad/test-services/pom.xml

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ServerSideScriptsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ServerSideScriptsTest.java?rev=1503306&r1=1503305&r2=1503306&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ServerSideScriptsTest.java
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ServerSideScriptsTest.java
Mon Jul 15 15:45:16 2013
@@ -30,14 +30,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import org.apache.sling.commons.json.JSONArray;
-import org.apache.sling.commons.json.JSONObject;
-import org.apache.sling.commons.json.JSONTokener;
-import org.apache.sling.junit.remote.httpclient.RemoteTestHttpClient;
-import org.apache.sling.testing.tools.http.RequestExecutor;
-import org.apache.sling.testing.tools.jarexec.JarExecutor;
-import org.apache.sling.testing.tools.sling.SlingClient;
-import org.apache.sling.testing.tools.sling.SlingTestBase;
+import org.apache.sling.launchpad.webapp.integrationtest.util.ServerSideTestClient;
 import org.codehaus.plexus.util.Expand;
 import org.junit.After;
 import org.junit.Before;
@@ -188,10 +181,7 @@ public class ServerSideScriptsTest {
         }
     };
 
-    private final SlingClient slingClient;
-    private final String serverBaseUrl;
-    private final String serverUsername;
-    private final String serverPassword;
+    private final ServerSideTestClient slingClient;
     private final Definition test;
     
     @Parameters(name="{index} - {0}")
@@ -205,45 +195,7 @@ public class ServerSideScriptsTest {
 
     public ServerSideScriptsTest(Definition scriptableTest) {
         this.test = scriptableTest;
-
-        // get configuration - we can't inherit from SlingTestBase as
-        // this tries to start the JarExecutor which will fail in some
-        // situations (TODO: split that class into smaller utilities to avoid this problem)
-        final String configuredUrl = System.getProperty(SlingTestBase.TEST_SERVER_URL_PROP,
-                                                        System.getProperty("launchpad.http.server.url"));
-        if (configuredUrl != null) {
-            if ( configuredUrl.endsWith("/") ) {
-                serverBaseUrl = configuredUrl.substring(0, configuredUrl.length() - 1);
-            } else {
-                serverBaseUrl = configuredUrl;
-            }
-        } else {
-            String serverHost = System.getProperty(SlingTestBase.SERVER_HOSTNAME_PROP);
-            if (serverHost == null || serverHost.trim().length() == 0) {
-                serverHost = "localhost";
-            }
-            final String portStr = System.getProperty(JarExecutor.PROP_SERVER_PORT);
-            final int serverPort = portStr == null ? JarExecutor.DEFAULT_PORT : Integer.valueOf(portStr);
-            serverBaseUrl = "http://" + serverHost + ":" + String.valueOf(serverPort);
-        }
-
-        // Set configured username using "admin" as default credential
-        final String configuredUsername = System.getProperty(SlingTestBase.TEST_SERVER_USERNAME);
-        if (configuredUsername != null && configuredUsername.trim().length() >
0) {
-            serverUsername = configuredUsername;
-        } else {
-            serverUsername = SlingTestBase.ADMIN;
-        }
-
-        // Set configured password using "admin" as default credential
-        final String configuredPassword = System.getProperty(SlingTestBase.TEST_SERVER_PASSWORD);
-        if (configuredPassword != null && configuredPassword.trim().length() >
0) {
-            serverPassword = configuredPassword;
-        } else {
-            serverPassword = SlingTestBase.ADMIN;
-        }
-
-        this.slingClient = new SlingClient(this.serverBaseUrl, this.serverUsername, this.serverPassword);
+        this.slingClient = new ServerSideTestClient();
     }
 
     @Before
@@ -274,42 +226,16 @@ public class ServerSideScriptsTest {
             logger.info("Setting up node {} for {}", destPath, test.testScriptFile.getAbsoluteFile());
             this.slingClient.upload(destPath, new FileInputStream(test.testScriptFile), -1,
false);
 
-            final RemoteTestHttpClient testClient = new RemoteTestHttpClient(
-                this.serverBaseUrl + "/system/sling/junit",
-                this.serverUsername,
-                this.serverPassword,
-                true);
-
             final long startTime = System.currentTimeMillis();
-            final RequestExecutor executor = testClient.runTests(
-                    "org.apache.sling.junit.scriptable.ScriptableTestsProvider",
-                    null,
-                    "json"
-            );
-            executor.assertContentType("application/json");
-            String content = executor.getContent();
-            final JSONArray json = new JSONArray(new JSONTokener(content));
-
-            int testsCount = 0;
-            final List<String> failures = new ArrayList<String>();
-            for(int i = 0 ; i < json.length(); i++) {
-                final JSONObject obj = json.getJSONObject(i);
-                if("test".equals(obj.getString("INFO_TYPE"))) {
-                    testsCount++;
-                    if(obj.has("failure")) {
-                        failures.add(obj.get("failure").toString());
-                    }
-                }
-            }
-
-            assertEquals("Expecting 1 scriptable tests: ", 1, testsCount);
+            final ServerSideTestClient.TestResults results = slingClient.runTests("org.apache.sling.junit.scriptable.ScriptableTestsProvider");
+            assertEquals("Expecting 1 scriptable test", 1, results.getTestCount());
 
             final int failureCount = test.willFail ? 1 : 0;
-            if( failures.size() != failureCount) {
+            if( results.getFailures().size() != failureCount) {
                 fail("Expected "
-                        + failureCount + " failing tests but got " + failures.size()
+                        + failureCount + " failing tests but got " + results.getFailures().size()
                         + " for " + test.testScriptFile.getAbsolutePath()
-                        + ": " + failures);
+                        + ": " + results.getFailures());
             }
             
             logger.info("Execution of {} took {} msec", test, System.currentTimeMillis()
- startTime);

Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/ServerSideTestClient.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/ServerSideTestClient.java?rev=1503306&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/ServerSideTestClient.java
(added)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/util/ServerSideTestClient.java
Mon Jul 15 15:45:16 2013
@@ -0,0 +1,140 @@
+/*
+ * 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.launchpad.webapp.integrationtest.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.commons.json.JSONArray;
+import org.apache.sling.commons.json.JSONObject;
+import org.apache.sling.commons.json.JSONTokener;
+import org.apache.sling.junit.remote.httpclient.RemoteTestHttpClient;
+import org.apache.sling.testing.tools.http.RequestExecutor;
+import org.apache.sling.testing.tools.jarexec.JarExecutor;
+import org.apache.sling.testing.tools.sling.SlingClient;
+import org.apache.sling.testing.tools.sling.SlingTestBase;
+
+/** Configurable SlingClient for server-side tests.
+ *  We can't inherit from SlingTestBase as
+ *  that class tries to start the JarExecutor which will fail in some
+ *  situations (TODO: split that class into smaller utilities to avoid 
+ *  this problem)
+ */
+public class ServerSideTestClient extends SlingClient {
+
+    private final static String configuredUrl = System.getProperty(
+            SlingTestBase.TEST_SERVER_URL_PROP,
+            System.getProperty("launchpad.http.server.url"));
+    private final static String serverBaseUrl = getServerBaseUrl();
+    private final static String serverUsername = getUsername();
+    private final static String serverPassword = getPassword();
+
+    public static class TestResults {
+        int testCount;
+        List<String> failures = new ArrayList<String>();
+        
+        public int getTestCount() {
+            return testCount;
+        }
+        
+        public List<String> getFailures() {
+            return failures;
+        }
+    }
+    
+    public ServerSideTestClient() {
+        super(getServerBaseUrl(), getUsername(), getPassword());
+    }
+    
+    public TestResults runTests(String testPackageOrClassName) throws Exception {
+        final RemoteTestHttpClient testClient = new RemoteTestHttpClient(serverBaseUrl +
"/system/sling/junit",serverUsername,serverPassword,true);
+        final TestResults r = new TestResults();
+        final RequestExecutor executor = testClient.runTests(testPackageOrClassName, null,
"json");
+        executor.assertContentType("application/json");
+        String content = executor.getContent();
+        final JSONArray json = new JSONArray(new JSONTokener(content));
+
+        for(int i = 0 ; i < json.length(); i++) {
+            final JSONObject obj = json.getJSONObject(i);
+            if("test".equals(obj.getString("INFO_TYPE"))) {
+                r.testCount++;
+                if(obj.has("failure")) {
+                    r.failures.add(obj.get("failure").toString());
+                }
+            }
+        }
+
+        return r;
+    }
+    
+    public void assertTestsPass(String testPackageOrClassName, int expectedTestsCount) throws
Exception {
+        TestResults results = runTests(testPackageOrClassName);
+        assertEquals("Expecting " + expectedTestsCount + " test(s) for " + testPackageOrClassName,
expectedTestsCount, results.getTestCount());
+        if(!results.getFailures().isEmpty()) {
+            fail(results.getFailures().size() + " tests failed:" + results.getFailures());
+        }
+    }
+    
+    private static String getServerBaseUrl() {
+        String serverBaseUrl = null;
+        if (configuredUrl != null) {
+            if ( configuredUrl.endsWith("/") ) {
+                serverBaseUrl = configuredUrl.substring(0, configuredUrl.length() - 1);
+            } else {
+                serverBaseUrl = configuredUrl;
+            }
+        } else {
+            String serverHost = System.getProperty(SlingTestBase.SERVER_HOSTNAME_PROP);
+            if (serverHost == null || serverHost.trim().length() == 0) {
+                serverHost = "localhost";
+            }
+            final String portStr = System.getProperty(JarExecutor.PROP_SERVER_PORT);
+            final int serverPort = portStr == null ? JarExecutor.DEFAULT_PORT : Integer.valueOf(portStr);
+            serverBaseUrl = "http://" + serverHost + ":" + String.valueOf(serverPort);
+        }
+        return serverBaseUrl;
+    }
+
+    private static String getPassword() {
+        // Set configured password using "admin" as default credential
+        final String configuredPassword = System
+                .getProperty(SlingTestBase.TEST_SERVER_PASSWORD);
+        if (configuredPassword != null
+                && configuredPassword.trim().length() > 0) {
+            return configuredPassword;
+        } else {
+            return SlingTestBase.ADMIN;
+        }
+    }
+
+    private static String getUsername() {
+        // Set configured username using "admin" as default credential
+        final String configuredUsername = System
+                .getProperty(SlingTestBase.TEST_SERVER_USERNAME);
+        if (configuredUsername != null
+                && configuredUsername.trim().length() > 0) {
+            return configuredUsername;
+        } else {
+            return SlingTestBase.ADMIN;
+        }
+    }
+}
\ No newline at end of file

Modified: sling/trunk/launchpad/test-services/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/pom.xml?rev=1503306&r1=1503305&r2=1503306&view=diff
==============================================================================
--- sling/trunk/launchpad/test-services/pom.xml (original)
+++ sling/trunk/launchpad/test-services/pom.xml Mon Jul 15 15:45:16 2013
@@ -74,6 +74,9 @@
                         	/sling-test/sling/from-bundle;path:=/SLING-INF/res/sling-test/sling/from-bundle,
                         	/system;path:=/SLING-INF/res/sling-test/sling/SLING-1733
                         </Sling-Bundle-Resources>
+                        <Sling-Test-Regexp>
+                            org.apache.sling.launchpad.testservices.serversidetests.*Test
+                        </Sling-Test-Regexp>
                     </instructions>
                 </configuration>
             </plugin>
@@ -123,7 +126,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.1.0</version>
+            <version>2.4.2</version>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
@@ -142,6 +145,12 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.junit.core</artifactId>
+            <version>1.0.8</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
             <artifactId>adapter-annotations</artifactId>
             <version>1.0.0</version>
         </dependency>



Mime
View raw message