incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1075321 - in /sling/trunk/testing: junit/core/src/main/java/org/apache/sling/junit/ junit/core/src/main/java/org/apache/sling/junit/impl/ junit/core/src/main/java/org/apache/sling/junit/impl/servlet/ samples/integration-tests/
Date Mon, 28 Feb 2011 13:39:24 GMT
Author: bdelacretaz
Date: Mon Feb 28 13:39:24 2011
New Revision: 1075321

URL: http://svn.apache.org/viewvc?rev=1075321&view=rev
Log:
SLING-1963 - test selection refactored using TestSelector interface

Added:
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestSelector.java
  (with props)
Modified:
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RequestParser.java
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestsManager.java
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/TestsManagerImpl.java
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JUnitServlet.java
    sling/trunk/testing/samples/integration-tests/pom.xml

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RequestParser.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RequestParser.java?rev=1075321&r1=1075320&r2=1075321&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RequestParser.java
(original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RequestParser.java
Mon Feb 28 13:39:24 2011
@@ -25,9 +25,9 @@ import javax.servlet.http.HttpServletReq
  *  keep the junit core module reusable in other OSGi 
  *  environments.
  */
-public class RequestParser {
-    private final String testSelector;
-    private final String methodName;
+public class RequestParser implements TestSelector {
+    private final String testNameSelector;
+    private final String selectedMethodName;
     private final String extension;
     private final HttpServletRequest request;
     private static final String EMPTY_STRING = "";
@@ -40,16 +40,16 @@ public class RequestParser {
     /** Build from pre-parsed values */
     public RequestParser(HttpServletRequest request, String testSelector, String outputExtension,
String testMethodName) {
         this.request = request;
-        this.testSelector = testSelector;
+        this.testNameSelector = testSelector;
         this.extension = outputExtension;
-        this.methodName = testMethodName;
+        this.selectedMethodName = testMethodName;
     }
     
     RequestParser(String [] s, HttpServletRequest request) {
         this.request = request;
-        testSelector = s[0];
+        testNameSelector = s[0];
         extension = s[1];
-        methodName = s[2];
+        selectedMethodName = s[2];
     }
     
     static String [] parsePathInfo(String pathInfo) {
@@ -93,14 +93,14 @@ public class RequestParser {
 
     public String toString() {
         return getClass().getSimpleName() 
-                + ", testSelector [" + testSelector + "]"
-                + ", methodName [" + methodName + "]"
+                + ", testSelector [" + testNameSelector + "]"
+                + ", methodName [" + selectedMethodName + "]"
                 + ", extension [" + extension + "]"
                 ;
     }
 
     public String getTestSelector() {
-        return testSelector;
+        return testNameSelector;
     }
 
     public String getExtension() {
@@ -108,10 +108,24 @@ public class RequestParser {
     }
     
     public String getMethodName() {
-        return methodName;
+        return selectedMethodName;
     }
     
     public HttpServletRequest getRequest() {
         return request;
-    }   
+    }
+
+    /** @inheritDoc */
+    public boolean acceptTestName(String testName) {
+        if(testNameSelector.isEmpty()) {
+            return true;
+        } else {
+            return testName.startsWith(testNameSelector);
+        }
+    }
+
+    /** @inheritDoc */
+    public String getSelectedTestMethodName() {
+        return selectedMethodName;
+    }
 }
\ No newline at end of file

Added: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestSelector.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestSelector.java?rev=1075321&view=auto
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestSelector.java
(added)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestSelector.java
Mon Feb 28 13:39:24 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;
+
+/** Used by the {@link TestsManager} to select which tests to run */
+public interface TestSelector {
+    /** If true, testName will be selected */
+    boolean acceptTestName(String testName);
+    
+    /** If not null, only test methods having this name are executed */
+    String getSelectedTestMethodName();
+}

Propchange: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestSelector.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestsManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestsManager.java?rev=1075321&r1=1075320&r2=1075321&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestsManager.java
(original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestsManager.java
Mon Feb 28 13:39:24 2011
@@ -20,8 +20,10 @@ import java.util.Collection;
 
 /** Service that gives access to JUnit test classes */
 public interface TestsManager {
-    /** Return the names of all currently available tests */
-    public Collection<String> getTestNames();
+    /** Return the names of available tests 
+     *  @param selector if null, returns all available tests.
+     */
+    public Collection<String> getTestNames(TestSelector selector);
     
     /** Instantiate test class for specified test */
     public Class<?> getTestClass(String testName) throws ClassNotFoundException;
@@ -33,7 +35,7 @@ public interface TestsManager {
     
     /** Execute tests and report results using supplied Renderer - does NOT call setup or
cleanup
      *  on renderer.
-     *  @param testMethodName if not empty, only test methods that have this name are executed
+     *  @param selector if not null, used to select tests and test methods.
      */ 
-    public void executeTests(Collection<String> testNames, Renderer renderer, String
testMethodName) throws Exception;
+    public void executeTests(Collection<String> testNames, Renderer renderer, TestSelector
selector) throws Exception;
 }

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/TestsManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/TestsManagerImpl.java?rev=1075321&r1=1075320&r2=1075321&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/TestsManagerImpl.java
(original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/TestsManagerImpl.java
Mon Feb 28 13:39:24 2011
@@ -19,12 +19,14 @@ package org.apache.sling.junit.impl;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.sling.junit.Renderer;
+import org.apache.sling.junit.TestSelector;
 import org.apache.sling.junit.TestsManager;
 import org.apache.sling.junit.TestsProvider;
 import org.junit.runner.JUnitCore;
@@ -93,7 +95,7 @@ public class TestsManagerImpl implements
     }
 
     /** inheritDoc */
-    public Collection<String> getTestNames() {
+    public Collection<String> getTestNames(TestSelector selector) {
         maybeUpdateProviders();
         
         // If any provider has changes, reload the whole list
@@ -126,7 +128,20 @@ public class TestsManagerImpl implements
             log.info("Test names reloaded, total {} names from {} providers", tests.size(),
providers.size());
         }
         
-        return tests.keySet();
+        final Collection<String> allTests = tests.keySet();
+        if(selector == null) {
+            log.debug("No TestSelector supplied, returning all {} tests", allTests.size());
+            return allTests;
+        } else {
+            final List<String> result = new LinkedList<String>();
+            for(String test : allTests) {
+                if(selector.acceptTestName(test)) {
+                    result.add(test);
+                }
+            }
+            log.debug("{} selected {} tests out of {}", new Object[] { selector, result.size(),
allTests.size() });
+            return result;
+        }
     }
     
     /** Update our list of providers if tracker changed */
@@ -148,12 +163,13 @@ public class TestsManagerImpl implements
     }
 
     /** @inheritDoc */
-    public void executeTests(Collection<String> testNames, Renderer renderer, String
testMethodName) throws Exception {
+    public void executeTests(Collection<String> testNames, Renderer renderer, TestSelector
selector) throws Exception {
         renderer.title(2, "Running tests");
         final JUnitCore junit = new JUnitCore();
         junit.addListener(renderer.getRunListener());
         for(String className : testNames) {
             renderer.title(3, className);
+            final String testMethodName = selector == null ? null : selector.getSelectedTestMethodName();
             if(testMethodName != null && testMethodName.length() > 0) {
                 log.debug("Running test method {} from test class {}", testMethodName, className);
                 junit.run(Request.method(getTestClass(className), testMethodName));

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JUnitServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JUnitServlet.java?rev=1075321&r1=1075320&r2=1075321&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JUnitServlet.java
(original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JUnitServlet.java
Mon Feb 28 13:39:24 2011
@@ -19,7 +19,6 @@ package org.apache.sling.junit.impl.serv
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.LinkedList;
@@ -36,6 +35,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.sling.junit.Renderer;
 import org.apache.sling.junit.RendererSelector;
 import org.apache.sling.junit.RequestParser;
+import org.apache.sling.junit.TestSelector;
 import org.apache.sling.junit.TestsManager;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.http.HttpService;
@@ -90,23 +90,14 @@ public class JUnitServlet extends HttpSe
         }
     }
     
-    /** Return the list of available tests
+    /** Return sorted list of available tests
      * @param prefix optionally select only names that match this prefix
      */
-    private List<String> getTestNames(String prefix) {
-        final Collection<String> testClassesCollection = testsManager.getTestNames();
-        final List<String> testClasses = new LinkedList<String>();
-        if(prefix == null || prefix.length() == 0) {
-            testClasses.addAll(testClassesCollection);
-        } else {
-            for(String name : testClassesCollection) {
-                if(name.startsWith(prefix)) {
-                    testClasses.add(name);
-                }
-            }
-        }
-        Collections.sort(testClasses);
-        return testClasses;
+    private List<String> getTestNames(TestSelector selector) {
+        final List<String> result = new LinkedList<String>();
+        result.addAll(testsManager.getTestNames(selector));
+        Collections.sort(result);
+        return result;
     }
     
     private void sendCss(HttpServletResponse response) throws IOException {
@@ -158,7 +149,7 @@ public class JUnitServlet extends HttpSe
         }
         
         // Any test classes?
-        final List<String> testNames = getTestNames(requestParser.getTestSelector());

+        final List<String> testNames = getTestNames(requestParser); 
         if(testNames.isEmpty()) {
             renderer.info(
                     "warning",
@@ -197,14 +188,14 @@ public class JUnitServlet extends HttpSe
         }
         renderer.setup(response, getClass().getSimpleName());
         
-        final List<String> testNames = getTestNames(requestParser.getTestSelector());
+        final List<String> testNames = getTestNames(requestParser);
         if(testNames.isEmpty()) {
             response.sendError(
                     HttpServletResponse.SC_NOT_FOUND, 
                     "No tests found for " + requestParser);
         }
         try {
-            testsManager.executeTests(testNames, renderer, requestParser.getMethodName());
+            testsManager.executeTests(testNames, renderer, requestParser);
         } catch(Exception e) {
             throw new ServletException(e);
         }

Modified: sling/trunk/testing/samples/integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/pom.xml?rev=1075321&r1=1075320&r2=1075321&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/pom.xml (original)
+++ sling/trunk/testing/samples/integration-tests/pom.xml Mon Feb 28 13:39:24 2011
@@ -106,7 +106,7 @@
                         <configuration>
                             <outputDirectory>${project.build.directory}/sling/additional-bundles</outputDirectory>
                             <includeArtifactIds>
-                                org.apache.sling.junit.core,org.apache.sling.testing.samples.sampletests,org.apache.sling.junit.core,org.apache.sling.testing.samples.failingtests,org.apache.sling.junit.scriptable
+                                org.apache.sling.junit.core,org.apache.sling.testing.samples.sampletests,org.apache.sling.junit.core,org.apache.sling.testing.samples.failingtests,org.apache.sling.junit.scriptable,org.apache.sling.junit.remote
                             </includeArtifactIds>
                             <excludeTransitive>true</excludeTransitive>
                             <overWriteReleases>false</overWriteReleases>
@@ -183,6 +183,12 @@
             <version>0.1.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.junit.remote</artifactId>
+            <version>0.1.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
         
         <!-- actual dependencies -->
         <dependency>



Mime
View raw message