incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1073404 - in /sling/trunk/testing/junit/remote: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/junit/ src/main/java/org/apache/sling/junit/remote...
Date Tue, 22 Feb 2011 16:56:20 GMT
Author: bdelacretaz
Date: Tue Feb 22 16:56:19 2011
New Revision: 1073404

URL: http://svn.apache.org/viewvc?rev=1073404&view=rev
Log:
SLING-1963 - remote tests runner, work in progress

Added:
    sling/trunk/testing/junit/remote/   (with props)
    sling/trunk/testing/junit/remote/pom.xml   (with props)
    sling/trunk/testing/junit/remote/src/
    sling/trunk/testing/junit/remote/src/main/
    sling/trunk/testing/junit/remote/src/main/java/
    sling/trunk/testing/junit/remote/src/main/java/org/
    sling/trunk/testing/junit/remote/src/main/java/org/apache/
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTest.java
  (with props)
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestParameters.java
  (with props)
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
  (with props)

Propchange: sling/trunk/testing/junit/remote/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Feb 22 16:56:19 2011
@@ -0,0 +1,14 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+
+
+
+

Added: sling/trunk/testing/junit/remote/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/remote/pom.xml?rev=1073404&view=auto
==============================================================================
--- sling/trunk/testing/junit/remote/pom.xml (added)
+++ sling/trunk/testing/junit/remote/pom.xml Tue Feb 22 16:56:19 2011
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>10</version>
+    </parent>
+
+    <artifactId>org.apache.sling.junit.remote</artifactId>
+    <version>0.1.1-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>Apache Sling JUnit Remote Extension</name>
+    <description>Runs JUnit tests remotely</description>
+    
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/testing/junit/remote</connection>
+        <developerConnection> scm:svn:https://svn.apache.org/repos/asf/sling/trunk/testing/junit/remote</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/testing/junit/remote</url>
+    </scm>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.junit.core</artifactId>
+            <version>0.1.1-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.2</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.5.11</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.stanbol</groupId>
+            <artifactId>org.apache.stanbol.commons.testing.http</artifactId>
+            <version>0.9-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.json</artifactId>
+            <version>2.0.6</version>
+        </dependency>
+    </dependencies>
+</project>

Propchange: sling/trunk/testing/junit/remote/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTest.java?rev=1073404&view=auto
==============================================================================
--- sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTest.java
(added)
+++ sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTest.java
Tue Feb 22 16:56:19 2011
@@ -0,0 +1,47 @@
+/*
+ * 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.junit.remote.testrunner;
+
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.JSONObject;
+import org.junit.runner.Description;
+
+/** Info about a remote tests, as provided by the Sling JUnit servlet */
+class SlingRemoteTest {
+    private final Class<?> testClass;
+    private final String description;
+    private final String failure;
+    
+    public static final String DESCRIPTION = "description";
+    public static final String FAILURE = "failure";
+    
+    SlingRemoteTest(Class<?> testClass, JSONObject json) throws JSONException {
+        this.testClass = testClass;
+        description = json.getString(DESCRIPTION);
+        failure = json.has(FAILURE) ? json.getString(FAILURE) : null;
+    }
+    
+    Description describe() {
+        return Description.createTestDescription(testClass, description);
+    }
+    
+    void run() {
+        if(failure != null && failure.trim().length() > 0) {
+            throw new AssertionError(failure);
+        }
+    }
+}

Propchange: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestParameters.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestParameters.java?rev=1073404&view=auto
==============================================================================
--- sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestParameters.java
(added)
+++ sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestParameters.java
Tue Feb 22 16:56:19 2011
@@ -0,0 +1,26 @@
+/*
+ * 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.junit.remote.testrunner;
+
+/** Test class "proxies" implement this to indicate where to
+ *  run the tests.
+ */
+public interface SlingRemoteTestParameters {
+    int getExpectedNumberOfTests();
+    String getServerBaseUrl();
+    String getJunitServletPath();
+}

Propchange: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestParameters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestParameters.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java?rev=1073404&view=auto
==============================================================================
--- sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
(added)
+++ sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
Tue Feb 22 16:56:19 2011
@@ -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.junit.remote.testrunner;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.sling.commons.json.JSONArray;
+import org.apache.sling.commons.json.JSONObject;
+import org.apache.sling.commons.json.JSONTokener;
+import org.apache.stanbol.commons.testing.http.Request;
+import org.apache.stanbol.commons.testing.http.RequestBuilder;
+import org.apache.stanbol.commons.testing.http.RequestExecutor;
+import org.junit.internal.AssumptionViolatedException;
+import org.junit.internal.runners.model.EachTestNotifier;
+import org.junit.runner.Description;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.ParentRunner;
+import org.junit.runners.model.InitializationError;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** JUnit TestRunner that talks to a remote
+ *  Sling JUnit test servlet. Using this test
+ *  runner lets a test class discover tests
+ *  that the JUnit servlet can execute, execute
+ *  them and report results exactly as if the tests
+ *  ran locally.
+ */
+public class SlingRemoteTestRunner extends ParentRunner<SlingRemoteTest> {
+    private static final Logger log = LoggerFactory.getLogger(SlingRemoteTestRunner.class);
+    private final SlingRemoteTestParameters testParameters;
+    private RequestExecutor executor;
+    private RequestBuilder builder;
+    private final Class<?> testClass;
+    
+    private final List<SlingRemoteTest> children = new LinkedList<SlingRemoteTest>();
+    
+    public SlingRemoteTestRunner(Class<?> testClass) throws InitializationError {
+        super(testClass);
+        this.testClass = testClass;
+        
+        Object o = null;
+        try {
+            o = testClass.newInstance();
+            if( !(o instanceof SlingRemoteTestParameters)) {
+                throw new IllegalArgumentException(o.getClass().getName() 
+                        + " is not a " + SlingRemoteTestParameters.class.getSimpleName());
+            }
+        } catch(Exception e) {
+            throw new InitializationError(e);
+        }
+        
+        testParameters = (SlingRemoteTestParameters)o;
+    }
+    
+    private void maybeExecuteTests() throws Exception {
+        if(executor != null) {
+            return;
+        }
+        
+        // Setup request execution
+        executor = new RequestExecutor(new DefaultHttpClient());
+        if(testParameters.getServerBaseUrl() == null) {
+            throw new IllegalStateException("Server base URL is null, cannot run tests");
+        }
+        builder = new RequestBuilder(testParameters.getServerBaseUrl());
+        
+        // TODO for now we run tests at the same time as we count them,
+        // as the junit servlet uses only GET - need to change that to GET and POST
+        final Request r = builder.buildGetRequest(testParameters.getJunitServletPath() +
"/.json");
+        
+        // Get list of tests in JSON format
+        executor.execute(r)
+        .assertStatus(200)
+        .assertContentType("application/json");
+        
+        final JSONArray json = new JSONArray(new JSONTokener((executor.getContent())));
+
+        // Response contains an array of objects identified by 
+        // their INFO_TYPE, extract the tests
+        // based on this vlaue
+        for(int i = 0 ; i < json.length(); i++) {
+            final JSONObject obj = json.getJSONObject(i);
+            if("test".equals(obj.getString("INFO_TYPE"))) {
+                children.add(new SlingRemoteTest(testClass, obj));
+            }
+        }
+        
+        log.info("{} server-side tests executed at {}", 
+                children.size(), testParameters.getJunitServletPath());
+        
+        // Check that number of tests is as expected
+        assertEquals("Expecting " + testParameters.getExpectedNumberOfTests() + " tests",
+                testParameters.getExpectedNumberOfTests(),
+                children.size());
+    }
+    
+    @Override
+    protected Description describeChild(SlingRemoteTest t) {
+        return t.describe();
+    }
+
+    @Override
+    protected List<SlingRemoteTest> getChildren() {
+        try {
+            maybeExecuteTests();
+        } catch(Exception e) {
+            throw new Error(e);
+        }
+        return children;
+    }
+
+    @Override
+    protected void runChild(SlingRemoteTest t, RunNotifier notifier) {
+        try {
+            maybeExecuteTests();
+        } catch(Exception e) {
+            throw new Error(e);
+        }
+        
+        EachTestNotifier eachNotifier= new EachTestNotifier(notifier, t.describe());
+        eachNotifier.fireTestStarted();
+        try {
+            log.debug("Running test {}", t.describe());
+            t.run();
+        } catch (AssumptionViolatedException e) {
+            eachNotifier.addFailedAssumption(e);
+        } catch (Throwable e) {
+            eachNotifier.addFailure(e);
+        } finally {
+            eachNotifier.fireTestFinished();
+        }
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message