incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1076648 - 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/ junit/core/src/test/java/org/apache/sli...
Date Thu, 03 Mar 2011 15:11:08 GMT
Author: bdelacretaz
Date: Thu Mar  3 15:11:07 2011
New Revision: 1076648

URL: http://svn.apache.org/viewvc?rev=1076648&view=rev
Log:
SLING-2015 - additional JUnit tests runner servlet that runs as a Sling servlet

Added:
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/SlingJUnitServlet.java   (with props)
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/
      - copied from r1076572, sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideSingleMethodTest.java   (with props)
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTest.java   (with props)
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java   (with props)
    sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java   (with props)
Removed:
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/testtools/
Modified:
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/Renderer.java
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RendererSelector.java
    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/TestSelector.java
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/RendererSelectorImpl.java
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/HtmlRenderer.java
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JUnitServlet.java
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JsonRenderer.java
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/PlainTextRenderer.java
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/XmlRenderer.java
    sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/RequestParserTest.java
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java
    sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/ide/SerializedRenderer.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/http/OsgiConsoleTest.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/DontCareForTestsCountTest.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/FailingTestsTest.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/JSONResponseTest.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideSampleTest.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/SingleServerSideMethodTest.java
    sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java
    sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/Renderer.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/Renderer.java?rev=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/Renderer.java (original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/Renderer.java Thu Mar  3 15:11:07 2011
@@ -27,7 +27,7 @@ import org.junit.runner.notification.Run
 /** Renderer for our servlet output */
  public interface Renderer {
     /** True if this renderer applies to supplied request */
-     boolean appliesTo(RequestParser p);
+     boolean appliesTo(TestSelector selector);
      
     /** Called first to setup rendering */
     void setup(HttpServletResponse response, String pageTitle) throws IOException, UnsupportedEncodingException;
@@ -53,4 +53,7 @@ import org.junit.runner.notification.Run
     
     /** Provide a RunListener for JUnit tests */
     RunListener getRunListener();
+    
+    /** Return the extension that triggers this renderer */
+    String getExtension();
 }
\ No newline at end of file

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RendererSelector.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RendererSelector.java?rev=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RendererSelector.java (original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/RendererSelector.java Thu Mar  3 15:11:07 2011
@@ -18,16 +18,11 @@ package org.apache.sling.junit;
 
 import java.util.Collection;
 
-import javax.servlet.http.HttpServletRequest;
-
 /** Provides a Renderer to execute tests */
 public interface RendererSelector {
     /** Return all available Renderers */
     Collection<Renderer> getRenderers();
     
-    /** Select a Renderer for supplied request */
-    Renderer getRenderer(HttpServletRequest r);
-    
-    /** Select a Renderer for supplied RequestParser */
-    Renderer getRenderer(RequestParser rp);
+    /** Select a Renderer for supplied TestSelector */
+    Renderer getRenderer(TestSelector selector);
 }

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=1076648&r1=1076647&r2=1076648&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 Thu Mar  3 15:11:07 2011
@@ -16,7 +16,6 @@
  */
 package org.apache.sling.junit;
 
-import javax.servlet.http.HttpServletRequest;
 
 /** Parse information from a request, to define which
  *  tests to run and which renderer to select.
@@ -29,66 +28,49 @@ public class RequestParser implements Te
     private final String testNameSelector;
     private final String selectedMethodName;
     private final String extension;
-    private final HttpServletRequest request;
     private static final String EMPTY_STRING = "";
 
-    /** Build from a request using standard parsing */
-    public RequestParser(HttpServletRequest request) {
-        this(parsePathInfo(request.getPathInfo()), request);
-    }
-    
-    /** Build from pre-parsed values */
-    public RequestParser(HttpServletRequest request, String testSelector, String outputExtension, String testMethodName) {
-        this.request = request;
-        this.testNameSelector = testSelector == null ? "" : testSelector;
-        this.extension = outputExtension == null ? "" : outputExtension;
-        this.selectedMethodName = testMethodName == null ? "" : testMethodName;
-    }
-    
-    RequestParser(String [] s, HttpServletRequest request) {
-        this.request = request;
-        testNameSelector = s[0];
-        extension = s[1];
-        selectedMethodName = s[2];
-    }
-    
-    static String [] parsePathInfo(String pathInfo) {
-        final String [] result = new String[3];
+    /** Parse subpath, which is in the form 
+     *  TEST_SELECTOR/TEST_METHOD.EXTENSION
+     *  or
+     *  TEST_SELECTOR.EXTENSION
+     */
+    public RequestParser(String subpath) {
         
-        if (pathInfo != null) {
-            if (pathInfo.startsWith("/")) {
-                pathInfo = pathInfo.substring(1);
+        if (subpath == null) {
+            testNameSelector = EMPTY_STRING;
+            selectedMethodName = EMPTY_STRING;
+            extension = EMPTY_STRING;
+        } else {
+            if (subpath.startsWith("/")) {
+                subpath = subpath.substring(1);
             }
             
             // Split at last dot to find extension
+            String beforeExtension = null;
             {
-                final int pos = pathInfo.lastIndexOf('.');
+                final int pos = subpath.lastIndexOf('.');
                 if (pos >= 0) {
-                    result[0] = pathInfo.substring(0, pos);
-                    result[1] = pathInfo.substring(pos+1);
+                    beforeExtension = subpath.substring(0, pos);
+                    extension = subpath.substring(pos+1);
                 } else {
-                    result[0] = pathInfo;
+                    beforeExtension = subpath;
+                    extension = EMPTY_STRING;
                 }
             }
             
-            // And if extension contains a /, what follows is test method selector
-            final String ext = result[1];
-            if(ext != null) {
-                final int pos = ext.indexOf('/');
+            // And split at last / between test selector and test method name
+            {
+                final int pos = beforeExtension.lastIndexOf('/');
                 if(pos >= 0) {
-                    result[1] = ext.substring(0, pos);
-                    result[2] = ext.substring(pos+1);
+                    testNameSelector = beforeExtension.substring(0, pos);
+                    selectedMethodName = beforeExtension.substring(pos+1);
+                } else {
+                    testNameSelector = beforeExtension;
+                    selectedMethodName = EMPTY_STRING;
                 }
             }
         }
-        
-        for(int i=0; i < result.length; i++) {
-            if(result[i] == null) {
-                result[i] = EMPTY_STRING;
-            }
-        }
-        
-        return result;
     }
 
     public String toString() {
@@ -99,7 +81,7 @@ public class RequestParser implements Te
                 ;
     }
 
-    public String getTestSelector() {
+    public String getTestSelectorString() {
         return testNameSelector;
     }
 
@@ -111,10 +93,6 @@ public class RequestParser implements Te
         return selectedMethodName;
     }
     
-    public HttpServletRequest getRequest() {
-        return request;
-    }
-
     /** @inheritDoc */
     public boolean acceptTestName(String testName) {
         if(testNameSelector.length() == 0) {

Modified: 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=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestSelector.java (original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/TestSelector.java Thu Mar  3 15:11:07 2011
@@ -23,4 +23,10 @@ public interface TestSelector {
     
     /** If not null, only test methods having this name are executed */
     String getSelectedTestMethodName();
+    
+    /** Return the String used to select tests */
+    String getTestSelectorString();
+    
+    /** Return the extension used to render results */
+    String getExtension();
 }

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/RendererSelectorImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/RendererSelectorImpl.java?rev=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/RendererSelectorImpl.java (original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/RendererSelectorImpl.java Thu Mar  3 15:11:07 2011
@@ -22,13 +22,12 @@ import java.util.Collections;
 import java.util.List;
 
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
 
 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.RendererSelector;
-import org.apache.sling.junit.RequestParser;
+import org.apache.sling.junit.TestSelector;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.component.ComponentContext;
@@ -51,11 +50,7 @@ public class RendererSelectorImpl implem
         return Collections.unmodifiableCollection(renderers);
     }
     
-    public Renderer getRenderer(HttpServletRequest request) {
-        return getRenderer(new RequestParser(request));
-    }
-    
-    public Renderer getRenderer(RequestParser rp) {
+    public Renderer getRenderer(TestSelector selector) {
         if(renderersTracker.getTrackingCount() != renderersTrackerTrackingCount) {
             log.debug("Rebuilding list of {}", Renderer.class.getSimpleName());
             renderersTrackerTrackingCount = renderersTracker.getTrackingCount();
@@ -72,7 +67,7 @@ public class RendererSelectorImpl implem
         }
         
         for(Renderer r : renderers) {
-            if(r.appliesTo(rp)) {
+            if(r.appliesTo(selector)) {
                 return r;
             }
         }

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/HtmlRenderer.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/HtmlRenderer.java?rev=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/HtmlRenderer.java (original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/HtmlRenderer.java Thu Mar  3 15:11:07 2011
@@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletRes
 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.RequestParser;
+import org.apache.sling.junit.TestSelector;
 import org.junit.runner.Description;
 import org.junit.runner.Result;
 import org.junit.runner.notification.Failure;
@@ -37,13 +37,19 @@ import org.junit.runner.notification.Run
 @Service
 public class HtmlRenderer extends RunListener implements Renderer {
 
+    public static final String EXTENSION = "html";
     private PrintWriter output;
     
     /** @inheritDoc */
-    public boolean appliesTo(RequestParser p) {
+    public boolean appliesTo(TestSelector s) {
         // This is our default renderer, applies to the empty
         // extension as well
-        return "html".equals(p.getExtension()) || "".equals(p.getExtension()); 
+        return EXTENSION.equals(s.getExtension()) || "".equals(s.getExtension()); 
+    }
+    
+    /** @inheritDoc */
+    public String getExtension() {
+        return EXTENSION;
     }
 
     /** @inheritDoc */

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=1076648&r1=1076647&r2=1076648&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 Thu Mar  3 15:11:07 2011
@@ -55,10 +55,7 @@ public class JUnitServlet extends HttpSe
     @Property(value="/system/sling/junit")
     static final String SERVLET_PATH_NAME = "servlet.path";
     
-    @Property(boolValue=false)
-    static final String SERVLET_DISABLED_NAME = "servlet.disabled";
-    
-    /** This will be null if we're disabled by configuration */ 
+    /** Non-null if we are registered with HttpService */ 
     private String servletPath;
     
     @Reference
@@ -71,23 +68,33 @@ public class JUnitServlet extends HttpSe
     private RendererSelector rendererSelector;
     
     protected void activate(ComponentContext ctx) throws ServletException, NamespaceException {
-        final Dictionary<?, ?> config = ctx.getProperties();
-        boolean disabled = ((Boolean)config.get(SERVLET_DISABLED_NAME)).booleanValue();
-        if(disabled) {
-            servletPath = null;
-            log.info("Servlet disabled by {} configuration parameter", SERVLET_DISABLED_NAME);
+        servletPath = getServletPath(ctx);
+        if(servletPath == null) {
+            log.info("Servlet path is null, not registering with HttpService");
         } else {
-            servletPath = (String)config.get(SERVLET_PATH_NAME);
             httpService.registerServlet(servletPath, this, null, null);
             log.info("Servlet registered at {}", servletPath);
         }
     }
+
+    /** Return the path at which to mount this servlet, or null
+     *  if it must not be mounted.
+     */
+    protected String getServletPath(ComponentContext ctx) {
+        final Dictionary<?, ?> config = ctx.getProperties();
+        String result = (String)config.get(SERVLET_PATH_NAME);
+        if(result != null && result.trim().length() == 0) {
+            result = null;
+        }
+        return result;
+    }
     
     protected void deactivate(ComponentContext ctx) throws ServletException, NamespaceException {
         if(servletPath != null) {
             httpService.unregister(servletPath);
             log.info("Servlet unregistered from path {}", servletPath);
         }
+        servletPath = null;
     }
     
     /** Return sorted list of available tests
@@ -131,42 +138,30 @@ public class JUnitServlet extends HttpSe
                 return;
             }
         }
-        
-        final RequestParser requestParser = new RequestParser(request);
-        final Renderer renderer = rendererSelector.getRenderer(request);
+
+        final TestSelector selector = getTestSelector(request);
+        final Renderer renderer = rendererSelector.getRenderer(selector);
         if(renderer == null) {
-            throw new ServletException("No Renderer found for " + requestParser);
+            throw new ServletException("No Renderer found for " + selector);
         }
-        log.debug("GET request: {}", requestParser);
+        log.debug("GET request: {}", selector);
 
         renderer.setup(response, getClass().getSimpleName());
-        
-        if(requestParser.getTestSelector().length() > 0) {
-            renderer.info("info", "Test selector: " + requestParser.getTestSelector()); 
-        } else {
-            renderer.info("info", "Test selector is empty: " 
-                    + "add class name prefix + extension at the end of the URL to select a subset of tests"); 
-        }
+        renderer.info("info", "Test selector: " + selector); 
         
         // Any test classes?
-        final List<String> testNames = getTestNames(requestParser); 
+        final List<String> testNames = getTestNames(selector); 
         if(testNames.isEmpty()) {
             renderer.info(
                     "warning",
-                    "No test classes found with prefix=" + requestParser.getTestSelector()
+                    "No test classes found for selector " + selector
                     + ", check the requirements of the active " +
                     "TestsProvider services for how to supply tests." 
                     );
         } else {
             try {
                 testsManager.listTests(testNames, renderer);
-                final String postPath = 
-                    request.getContextPath() 
-                    + servletPath
-                    + "/"
-                    + requestParser.getTestSelector()
-                    + "."
-                    + requestParser.getExtension();
+                final String postPath = getTestExecutionPath(request, selector, renderer.getExtension()); 
                 renderer.link("Execute these tests", postPath, "POST");
             } catch(Exception e) {
                 throw new ServletException(e);
@@ -179,27 +174,48 @@ public class JUnitServlet extends HttpSe
     @Override
     protected void doPost(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException {
-        final RequestParser requestParser = new RequestParser(request);
-        log.info("POST request, executing tests: {}", requestParser);
+        final TestSelector selector = getTestSelector(request);
+        log.info("POST request, executing tests: {}", selector);
         
-        final Renderer renderer = rendererSelector.getRenderer(request);
+        final Renderer renderer = rendererSelector.getRenderer(selector);
         if(renderer == null) {
-            throw new ServletException("No Renderer found for " + requestParser);
+            throw new ServletException("No Renderer found for " + selector);
         }
         renderer.setup(response, getClass().getSimpleName());
         
-        final List<String> testNames = getTestNames(requestParser);
+        final List<String> testNames = getTestNames(selector);
         if(testNames.isEmpty()) {
             response.sendError(
                     HttpServletResponse.SC_NOT_FOUND, 
-                    "No tests found for " + requestParser);
+                    "No tests found for " + selector);
         }
         try {
-            testsManager.executeTests(testNames, renderer, requestParser);
+            testsManager.executeTests(testNames, renderer, selector);
         } catch(Exception e) {
             throw new ServletException(e);
         }
         
         renderer.cleanup();
     }
+    
+    /** Return a TestSelector for supplied request */
+    protected TestSelector getTestSelector(HttpServletRequest request) {
+        return new RequestParser(getTestSelectionPath(request));
+    }
+    
+    /** Return subpath to use for selecting tests */
+    protected String getTestSelectionPath(HttpServletRequest request) {
+        return request.getPathInfo();
+    }
+    
+    /** Return path to which to POST to execute specified test */
+    protected String getTestExecutionPath(HttpServletRequest request, TestSelector selector, String extension) {
+        return request.getContextPath() 
+        + servletPath
+        + "/"
+        + selector.getTestSelectorString()
+        + "."
+        + extension
+        ;
+    }
 }
\ No newline at end of file

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JsonRenderer.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JsonRenderer.java?rev=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JsonRenderer.java (original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JsonRenderer.java Thu Mar  3 15:11:07 2011
@@ -27,7 +27,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.io.JSONWriter;
 import org.apache.sling.junit.Renderer;
-import org.apache.sling.junit.RequestParser;
+import org.apache.sling.junit.TestSelector;
 import org.junit.runner.Description;
 import org.junit.runner.Result;
 import org.junit.runner.notification.Failure;
@@ -40,6 +40,7 @@ import org.slf4j.LoggerFactory;
 @Service
 public class JsonRenderer extends RunListener implements Renderer {
 
+    public static final String EXTENSION = "json";
     public static final String INFO_TYPE_KEY = "INFO_TYPE";
     public static final String INFO_SUBTYPE_KEY = "INFO_SUBTYPE";
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -47,8 +48,13 @@ public class JsonRenderer extends RunLis
     private int counter;
     
     /** @inheritDoc */
-    public boolean appliesTo(RequestParser p) {
-        return "json".equals(p.getExtension());
+    public boolean appliesTo(TestSelector selector) {
+        return EXTENSION.equals(selector.getExtension());
+    }
+
+    /** @inheritDoc */
+    public String getExtension() {
+        return EXTENSION;
     }
 
     /** @inheritDoc */

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/PlainTextRenderer.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/PlainTextRenderer.java?rev=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/PlainTextRenderer.java (original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/PlainTextRenderer.java Thu Mar  3 15:11:07 2011
@@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletRes
 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.RequestParser;
+import org.apache.sling.junit.TestSelector;
 import org.junit.runner.Description;
 import org.junit.runner.Result;
 import org.junit.runner.notification.Failure;
@@ -36,11 +36,18 @@ import org.junit.runner.notification.Run
 @Service
 /** Plain text renderer */
 public class PlainTextRenderer extends RunListener implements Renderer {
+    public static final String EXTENSION = "txt";
     private PrintWriter output;
     
     /** @inheritDoc */
-    public boolean appliesTo(RequestParser p) {
-        return "txt".equals(p.getExtension());
+    public boolean appliesTo(TestSelector selector) {
+        return EXTENSION.equals(selector.getExtension());
+    }
+
+    
+    /** @inheritDoc */
+    public String getExtension() {
+        return EXTENSION;
     }
 
     /** @inheritDoc */

Added: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/SlingJUnitServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/SlingJUnitServlet.java?rev=1076648&view=auto
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/SlingJUnitServlet.java (added)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/SlingJUnitServlet.java Thu Mar  3 15:11:07 2011
@@ -0,0 +1,81 @@
+/*
+ * 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.impl.servlet;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.junit.TestSelector;
+import org.osgi.service.component.ComponentContext;
+
+/** Alternate entry point for testing, that uses
+ *  the Sling request/response cycle.
+ *
+ *  Can be used to run tests in an environment that
+ *  more closely matches how Sling components run,
+ *  but requires Sling - so we keep both servlets
+ *  in order for this module to be reusable without 
+ *  Sling.
+ *  
+ *  This servlet is registered with a specific resource
+ *  type, to call it a Sling resource must be created
+ *  with this resource type.
+ */
+@SuppressWarnings("serial")
+@Component
+@Service(value=javax.servlet.Servlet.class)
+@Properties({
+        @Property(name="sling.servlet.resourceTypes", value="sling/junit/testing"),
+        @Property(name="sling.servlet.extensions", value="junit"),
+        @Property(name="sling.servlet.methods", value={"GET","POST"})
+})
+public class SlingJUnitServlet extends JUnitServlet {
+    
+    public static final String EXTENSION = ".junit";
+    
+    /** Do not register this servlet with HttpService ourselves,
+     *  Sling will take care of that.
+     */
+    @Override
+    protected String getServletPath(ComponentContext ctx) {
+        return null;
+    }
+    
+    @Override
+    protected String getTestSelectionPath(HttpServletRequest request) {
+        // PathInfo contains the path to our resource, followed
+        // by the .junit extension - cut up to that
+        String result = request.getPathInfo();
+        final int pos = result.indexOf(EXTENSION);
+        if(pos >= 0) {
+            result = result.substring(pos + EXTENSION.length());
+        }
+        return result;
+    }
+    
+    /** Return path to which to POST to execute specified test */
+    protected String getTestExecutionPath(HttpServletRequest request, TestSelector selector, String extension) {
+        return  "./"
+        + selector.getTestSelectorString()
+        + "."
+        + extension
+        ;
+    }
+}

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

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

Modified: sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/XmlRenderer.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/XmlRenderer.java?rev=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/XmlRenderer.java (original)
+++ sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/XmlRenderer.java Thu Mar  3 15:11:07 2011
@@ -41,7 +41,7 @@ import junit.runner.BaseTestRunner;
 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.RequestParser;
+import org.apache.sling.junit.TestSelector;
 import org.junit.runner.Description;
 import org.junit.runner.Result;
 import org.junit.runner.notification.Failure;
@@ -54,6 +54,11 @@ import org.w3c.dom.Text;
 @Component(immediate=false)
 @Service
 public class XmlRenderer extends RunListener implements Renderer {
+    
+    /**
+     * This renderer's extension
+     */
+    public static final String EXTENSION = "xml";
 
 	/**
 	 * Writer used for output.
@@ -106,8 +111,13 @@ public class XmlRenderer extends RunList
 	private int testSuiteCount = 0;
 
     /** @inheritDoc */
-    public boolean appliesTo(RequestParser p) {
-        return "xml".equals(p.getExtension());
+    public boolean appliesTo(TestSelector selector) {
+        return EXTENSION.equals(selector.getExtension());
+    }
+
+    /** @inheritDoc */
+    public String getExtension() {
+        return EXTENSION;
     }
 
     /** @inheritDoc */

Modified: sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/RequestParserTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/RequestParserTest.java?rev=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/RequestParserTest.java (original)
+++ sling/trunk/testing/junit/core/src/test/java/org/apache/sling/junit/RequestParserTest.java Thu Mar  3 15:11:07 2011
@@ -38,7 +38,7 @@ public class RequestParserTest {
         this.expectedTestSelector = expectedTestSelector;
         this.expectedExtension = expectedExtension;
         this.expectedMethodSelector = expectedMethodSelector;
-        parser = new RequestParser(RequestParser.parsePathInfo(pathInfo), null);
+        parser = new RequestParser(pathInfo);
     }
 
     @Override
@@ -48,7 +48,7 @@ public class RequestParserTest {
     
     @Test
     public void testSelector() {
-        assertEquals(toString(), expectedTestSelector, parser.getTestSelector());
+        assertEquals(toString(), expectedTestSelector, parser.getTestSelectorString());
     }
     
     @Test
@@ -71,10 +71,12 @@ public class RequestParserTest {
                 { "/someTests.here.html", "someTests.here", "html", EMPTY },
                 { "someTests.here.html", "someTests.here", "html", EMPTY },
                 { "someTests.here.html.json", "someTests.here.html", "json", EMPTY },
-                { "someTests.here.html.json/TEST_METHOD_NAME", "someTests.here.html", "json", "TEST_METHOD_NAME" },
-                { ".json/TEST_METHOD_NAME", "", "json", "TEST_METHOD_NAME" },
-                { "/.json/TEST_METHOD_NAME", "", "json", "TEST_METHOD_NAME" },
-                { "/.html.json/TEST_METHOD_NAME", ".html", "json", "TEST_METHOD_NAME" },
+                { "someTests.here.html.json/TEST_METHOD_NAME.txt", "someTests.here.html.json", "txt", "TEST_METHOD_NAME" },
+                { ".json/TEST_METHOD_NAME", "", "json/TEST_METHOD_NAME", "" },
+                { ".json/TEST_METHOD_NAME.txt", ".json", "txt", "TEST_METHOD_NAME" },
+                { "/.json/TEST_METHOD_NAME.txt", ".json", "txt", "TEST_METHOD_NAME" },
+                { "/.json/TEST_METHOD_NAME.txt", ".json", "txt", "TEST_METHOD_NAME" },
+                { "/.html.json/TEST_METHOD_NAME.txt", ".html.json", "txt", "TEST_METHOD_NAME" },
         };
         
         return Arrays.asList(data);

Modified: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java?rev=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java (original)
+++ sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/httpclient/RemoteTestHttpClient.java Thu Mar  3 15:11:07 2011
@@ -59,21 +59,27 @@ public class RemoteTestHttpClient {
             }
         };
         
-        // POST request executes the tests
+        // Build path for POST request to execute the tests
+        
+        // Test classes selector
         subpath = new StringBuilder();
         if(!junitServletUrl.endsWith(SLASH)) {
             subpath.append(SLASH);
         }
         subpath.append(testClassesSelector);
-        if(!extension.startsWith(DOT)) {
-            subpath.append(DOT);
-        }
-        subpath.append(extension);
+        
+        // Test method selector
         if(testMethodSelector != null && testMethodSelector.length() > 0) {
             subpath.append("/");
             subpath.append(testMethodSelector);
         }
         
+        // Extension
+        if(!extension.startsWith(DOT)) {
+            subpath.append(DOT);
+        }
+        subpath.append(extension);
+        
         log.info("Executing test remotely, path={} JUnit servlet URL={}", 
                 subpath, junitServletUrl);
         final Request r = builder.buildPostRequest(subpath.toString());

Modified: sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/ide/SerializedRenderer.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/ide/SerializedRenderer.java?rev=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/ide/SerializedRenderer.java (original)
+++ sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/ide/SerializedRenderer.java Thu Mar  3 15:11:07 2011
@@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletRes
 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.RequestParser;
+import org.apache.sling.junit.TestSelector;
 import org.junit.runner.Result;
 import org.junit.runner.notification.RunListener;
 import org.slf4j.Logger;
@@ -46,8 +46,13 @@ public class SerializedRenderer extends 
     private final Logger log = LoggerFactory.getLogger(getClass());
 
     /** @inheritDoc */
-    public boolean appliesTo(RequestParser p) {
-        return EXTENSION.equals(p.getExtension());
+    public boolean appliesTo(TestSelector s) {
+        return EXTENSION.equals(s.getExtension());
+    }
+    
+    /** @inheritDoc */
+    public String getExtension() {
+        return EXTENSION;
     }
 
     /** @inheritDoc */

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/http/OsgiConsoleTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/http/OsgiConsoleTest.java?rev=1076648&r1=1076572&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/http/OsgiConsoleTest.java (original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/http/OsgiConsoleTest.java Thu Mar  3 15:11:07 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.testing.samples.testtools.http;
+package org.apache.sling.testing.samples.integrationtests.http;
 
 import org.apache.sling.testing.tools.sling.SlingTestBase;
 import org.junit.Test;

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/DontCareForTestsCountTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/DontCareForTestsCountTest.java?rev=1076648&r1=1076572&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/DontCareForTestsCountTest.java (original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/DontCareForTestsCountTest.java Thu Mar  3 15:11:07 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.testing.samples.testtools.serverside;
+package org.apache.sling.testing.samples.integrationtests.serverside;
 
 import org.apache.sling.junit.remote.testrunner.SlingRemoteTestRunner;
 import org.junit.runner.RunWith;

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/FailingTestsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/FailingTestsTest.java?rev=1076648&r1=1076572&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/FailingTestsTest.java (original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/FailingTestsTest.java Thu Mar  3 15:11:07 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.testing.samples.testtools.serverside;
+package org.apache.sling.testing.samples.integrationtests.serverside;
 
 import static org.junit.Assert.assertEquals;
 

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/JSONResponseTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/JSONResponseTest.java?rev=1076648&r1=1076572&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/JSONResponseTest.java (original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/JSONResponseTest.java Thu Mar  3 15:11:07 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.testing.samples.testtools.serverside;
+package org.apache.sling.testing.samples.integrationtests.serverside;
 
 import static org.junit.Assert.assertTrue;
 

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideSampleTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideSampleTest.java?rev=1076648&r1=1076572&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideSampleTest.java (original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideSampleTest.java Thu Mar  3 15:11:07 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.testing.samples.testtools.serverside;
+package org.apache.sling.testing.samples.integrationtests.serverside;
 
 import org.apache.sling.junit.remote.testrunner.SlingRemoteTestParameters;
 import org.apache.sling.junit.remote.testrunner.SlingRemoteTestRunner;

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java?rev=1076648&r1=1076572&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java (original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/ServerSideTestsBase.java Thu Mar  3 15:11:07 2011
@@ -14,11 +14,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.testing.samples.testtools.serverside;
+package org.apache.sling.testing.samples.integrationtests.serverside;
 
 import static org.junit.Assert.fail;
 
-import org.apache.sling.testing.tools.retry.RetryLoop;
+import org.apache.sling.testing.tools.http.RetryingContentChecker;
 import org.apache.sling.testing.tools.sling.SlingTestBase;
 import org.apache.sling.testing.tools.sling.TimeoutsProvider;
 import org.slf4j.Logger;
@@ -30,6 +30,7 @@ import org.slf4j.LoggerFactory;
 public class ServerSideTestsBase extends SlingTestBase {
     public static final String JUNIT_SERVLET_PATH = "/system/sling/junit";
     
+    private RetryingContentChecker junitServletChecker;
     private static boolean junitServletOk;
     private static boolean junitServletCheckFailed;
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -38,47 +39,35 @@ public class ServerSideTestsBase extends
     @Override
     protected void onServerReady(boolean serverStartedByThisClass) throws Exception {
         super.onServerReady(serverStartedByThisClass);
-        try {
-            checkJunitServletPresent();
-        } catch(Exception e) {
-            throw new IllegalStateException("JUnit Servlet not ready: ", e);
-        }
-    }
-
-    private void checkJunitServletPresent() throws Exception {
-        if(junitServletOk) {
-            return;
-        }
         if(junitServletCheckFailed) {
             fail("Previous check of JUnit servlet failed, cannot run tests");
         }
-
-        // Retry accessing the junit servlet until it responds or timeout
-        // (as we might just have installed the required bundles)
-        final int expectedStatus = 200;
-        final RetryLoop.Condition c = new RetryLoop.Condition() {
-            public String getDescription() {
-                return "Checking that " + JUNIT_SERVLET_PATH + " returns " + expectedStatus;
-            }
-
-            public boolean isTrue() throws Exception {
-                getRequestExecutor().execute(
-                        getRequestBuilder().buildGetRequest(JUNIT_SERVLET_PATH))
-                .assertStatus(expectedStatus);
-                return true;
-            }
-                
-        };
         
-        log.info(c.getDescription());
-        new RetryLoop(c, JUNIT_SERVLET_TIMEOUT_SECONDS, TimeoutsProvider.getInstance().getTimeout(500)) {
-            @Override
-            protected void onTimeout() {
-                super.onTimeout();
-                junitServletCheckFailed = true;
+        try {
+            if(!junitServletOk) {
+                if(junitServletChecker == null) {
+                    junitServletChecker = 
+                        new RetryingContentChecker(getRequestExecutor(), getRequestBuilder()) {
+                        @Override
+                        public void onTimeout() {
+                            junitServletCheckFailed = true;
+                        }
+                    };
+                }
+                
+                final String path = JUNIT_SERVLET_PATH;
+                final int status = 200;
+                final int timeout = TimeoutsProvider.getInstance().getTimeout(JUNIT_SERVLET_TIMEOUT_SECONDS);
+                final int intervalMsec = TimeoutsProvider.getInstance().getTimeout(500);
+                
+                log.info("Checking that {} returns status {}, timeout={} seconds",
+                        new Object[] { path, status, timeout });
+                junitServletChecker.check(path,status,timeout,intervalMsec);
+                junitServletOk = true;
             }
             
-        };
-        junitServletOk = true;
+        } catch(Exception e) {
+            throw new IllegalStateException("JUnit Servlet not ready: ", e);
+        }
     }
 }

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/SingleServerSideMethodTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/SingleServerSideMethodTest.java?rev=1076648&r1=1076572&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/SingleServerSideMethodTest.java (original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/SingleServerSideMethodTest.java Thu Mar  3 15:11:07 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.testing.samples.testtools.serverside;
+package org.apache.sling.testing.samples.integrationtests.serverside;
 
 import org.apache.sling.junit.remote.testrunner.SlingRemoteTestParameters;
 import org.apache.sling.junit.remote.testrunner.SlingRemoteTestRunner;

Modified: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java?rev=1076648&r1=1076572&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java (original)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/scriptable/ScriptableTestsTest.java Thu Mar  3 15:11:07 2011
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.testing.samples.testtools.serverside.scriptable;
+package org.apache.sling.testing.samples.integrationtests.serverside.scriptable;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
@@ -28,7 +28,7 @@ import org.apache.sling.commons.json.JSO
 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.samples.testtools.serverside.ServerSideTestsBase;
+import org.apache.sling.testing.samples.integrationtests.serverside.ServerSideTestsBase;
 import org.apache.sling.testing.tools.http.RequestExecutor;
 import org.apache.sling.testing.tools.sling.SlingClient;
 import org.junit.After;

Added: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideSingleMethodTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideSingleMethodTest.java?rev=1076648&view=auto
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideSingleMethodTest.java (added)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideSingleMethodTest.java Thu Mar  3 15:11:07 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.samples.integrationtests.serverside.sling;
+
+import org.apache.sling.junit.remote.testrunner.SlingRemoteTestParameters;
+import org.apache.sling.junit.remote.testrunner.SlingRemoteTestRunner;
+import org.junit.runner.RunWith;
+
+/** Run a single server-side test method using the Sling JUnit servlet */
+@RunWith(SlingRemoteTestRunner.class)
+public class SlingServerSideSingleMethodTest extends SlingServerSideTestsBase implements SlingRemoteTestParameters{
+    public static final String TEST_CLASS = "org.apache.sling.testing.samples.sampletests.JUnit4Test";
+    public static final String TEST_METHOD = "testRequiresBefore";
+    public static final int TESTS_AT_THIS_PATH = 1;
+
+    public int getExpectedNumberOfTests() {
+        return TESTS_AT_THIS_PATH;
+    }
+
+    public String getJunitServletUrl() {
+        return getServerBaseUrl() + SLING_JUNIT_SERVLET_PATH;
+    }
+
+    public String getTestClassesSelector() {
+        return TEST_CLASS;
+    }
+
+    public String getTestMethodSelector() {
+        return TEST_METHOD;
+    }
+}

Propchange: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideSingleMethodTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideSingleMethodTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTest.java?rev=1076648&view=auto
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTest.java (added)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTest.java Thu Mar  3 15:11:07 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.samples.integrationtests.serverside.sling;
+
+import org.apache.sling.junit.remote.testrunner.SlingRemoteTestParameters;
+import org.apache.sling.junit.remote.testrunner.SlingRemoteTestRunner;
+import org.junit.runner.RunWith;
+
+/** Run some server-side tests using the Sling JUnit servlet */
+@RunWith(SlingRemoteTestRunner.class)
+public class SlingServerSideTest extends SlingServerSideTestsBase implements SlingRemoteTestParameters {
+    
+    public static final String TEST_SELECTOR = "org.apache.sling.testing.samples.sampletests";
+    public static final int TESTS_AT_THIS_PATH = 5;
+    
+    public int getExpectedNumberOfTests() {
+        return TESTS_AT_THIS_PATH;
+    }
+    
+    public String getJunitServletUrl() {
+        return getServerBaseUrl() + SLING_JUNIT_SERVLET_PATH;
+    }
+
+    public String getTestClassesSelector() {
+        return TEST_SELECTOR;
+    }
+
+    public String getTestMethodSelector() {
+        return null;
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java?rev=1076648&view=auto
==============================================================================
--- sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java (added)
+++ sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java Thu Mar  3 15:11:07 2011
@@ -0,0 +1,85 @@
+/*
+ * 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.samples.integrationtests.serverside.sling;
+
+import org.apache.sling.testing.tools.http.RetryingContentChecker;
+import org.apache.sling.testing.tools.sling.SlingClient;
+import org.apache.sling.testing.tools.sling.SlingTestBase;
+import org.apache.sling.testing.tools.sling.TimeoutsProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.fail;
+
+/** Test server-side tests using the Sling JUnit servlet, as opposed
+ *  to the plain JUnit servlet.
+ */
+public class SlingServerSideTestsBase extends SlingTestBase {
+    /** Path to node that maps to Sling JUnit servlet */
+    public static final String SERVLET_NODE_PATH =  "/test/sling/" + System.currentTimeMillis();
+    
+    /** Path used to request the Sling JUnit servlet */
+    public static final String SLING_JUNIT_SERVLET_PATH = SERVLET_NODE_PATH + ".junit";
+    
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    private RetryingContentChecker servletChecker;
+    private boolean servletCheckFailed;
+    private boolean servletOk;
+    private SlingClient slingClient;
+    private static boolean servletNodeCreated;
+    
+    /** At startup, setup a node that gives access to the Sling JUnit servlet,
+     *  and check (with timeout) that the servlet is ready */
+    @Override
+    protected void onServerReady(boolean serverStartedByThisClass) throws Exception {
+        super.onServerReady(serverStartedByThisClass);
+        
+        if(!servletNodeCreated) {
+            slingClient = new SlingClient(getServerBaseUrl(), ADMIN, ADMIN);
+            try {
+                slingClient.createNode(SERVLET_NODE_PATH, "sling:resourceType", "sling/junit/testing");
+                servletNodeCreated = true;
+            } catch(Exception e) {
+                fail("Exception while setting up Sling JUnit servlet: " + e);
+            }
+        }
+        
+        if(servletCheckFailed) {
+            fail(SLING_JUNIT_SERVLET_PATH + " check failed previously, cannot run tests");
+        }
+        
+        if(!servletOk) {
+            if(servletChecker == null) {
+                servletChecker = new RetryingContentChecker(getRequestExecutor(), getRequestBuilder()) {
+                    @Override
+                    public void onTimeout() {
+                        servletCheckFailed = true;
+                    }
+                };
+            }
+
+            final String path = SLING_JUNIT_SERVLET_PATH;
+            final int status = 200;
+            final int timeout = TimeoutsProvider.getInstance().getTimeout(30);
+            final int intervalMsec = TimeoutsProvider.getInstance().getTimeout(500);
+            log.info("Checking that {} returns status {}, timeout={} seconds",
+                    new Object[] { path, status, timeout });
+            servletChecker.check(path, status, timeout, intervalMsec);
+            servletOk = true;
+        }
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/samples/integration-tests/src/test/java/org/apache/sling/testing/samples/integrationtests/serverside/sling/SlingServerSideTestsBase.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java?rev=1076648&view=auto
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java (added)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java Thu Mar  3 15:11:07 2011
@@ -0,0 +1,56 @@
+/*
+ * 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.tools.http;
+
+import org.apache.sling.testing.tools.retry.RetryLoop;
+
+/** Retry a GET on an URL until it returns 200 or 
+ *  until this times out.
+ */
+public class RetryingContentChecker {
+    private final RequestExecutor executor;
+    private final RequestBuilder builder;
+    
+    public RetryingContentChecker(RequestExecutor executor, RequestBuilder builder) {
+        this.executor = executor;
+        this.builder = builder;
+    }
+
+    /** Check specified path for expected status, or timeout */
+    public void check(final String path, final int expectedStatus, int timeoutSeconds, int intervalBetweenrequestsMsec) {
+        final RetryLoop.Condition c = new RetryLoop.Condition() {
+            public String getDescription() {
+                return "Expecting " + path + " to return HTTP status " + expectedStatus;
+            }
+
+            public boolean isTrue() throws Exception {
+                executor.execute(builder.buildGetRequest(path)).assertStatus(expectedStatus);
+                return true;
+            }
+                
+        };
+        new RetryLoop(c, timeoutSeconds, intervalBetweenrequestsMsec) {
+            @Override
+            protected void onTimeout() {
+                RetryingContentChecker.this.onTimeout();
+            }
+        };
+    }
+    
+    protected void onTimeout() {
+    }
+}

Propchange: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/http/RetryingContentChecker.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java?rev=1076648&r1=1076647&r2=1076648&view=diff
==============================================================================
--- sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java (original)
+++ sling/trunk/testing/tools/src/main/java/org/apache/sling/testing/tools/sling/SlingTestBase.java Thu Mar  3 15:11:07 2011
@@ -157,6 +157,7 @@ public class SlingTestBase {
         // our configured request paths with a 200 result and content
         // that contains the pattern that's optionally supplied with the 
         // path, separated by a colon
+        log.info("Checking that GET requests return expected content (timeout={} seconds): {}", timeoutSec, testPaths);
         while(System.currentTimeMillis() < endTime) {
             boolean errors = false;
             for(String p : testPaths) {
@@ -169,11 +170,11 @@ public class SlingTestBase {
                     .assertContentContains(pattern);
                 } catch(AssertionError ae) {
                     errors = true;
-                    log.info("Request to {}{} failed, will retry ({})", 
+                    log.debug("Request to {}{} failed, will retry ({})", 
                             new Object[] { serverBaseUrl, path, ae});
                 } catch(Exception e) {
                     errors = true;
-                    log.info("Request to {}{} failed, will retry ({})",
+                    log.debug("Request to {}{} failed, will retry ({})",
                             new Object[] { serverBaseUrl, path, pattern, e });
                 }
             }



Mime
View raw message