incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1073729 - in /sling/trunk/testing/junit: core/src/main/java/org/apache/sling/junit/ core/src/main/java/org/apache/sling/junit/impl/ core/src/main/java/org/apache/sling/junit/impl/servlet/ remote/src/main/java/org/apache/sling/junit/remote/...
Date Wed, 23 Feb 2011 13:06:28 GMT
Author: bdelacretaz
Date: Wed Feb 23 13:06:27 2011
New Revision: 1073729

URL: http://svn.apache.org/viewvc?rev=1073729&view=rev
Log:
SLING-1963 - JUnitServlet requires POST to execute tests, GET only lists them

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/impl/TestsManagerImpl.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/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.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=1073729&r1=1073728&r2=1073729&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 Wed
Feb 23 13:06:27 2011
@@ -48,6 +48,9 @@ import org.junit.runner.notification.Run
     /** Render a title of a specified hierarchical level */
     void title(int level, String title);
     
+    /** Render a link to specified URL using specified HTTP method */
+    void link(String info, String url, String method);
+    
     /** Provide a RunListener for JUnit tests */
     RunListener getRunListener();
 }
\ No newline at end of file

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=1073729&r1=1073728&r2=1073729&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
Wed Feb 23 13:06:27 2011
@@ -148,13 +148,7 @@ public class TestsManagerImpl implements
     }
 
     /** @inheritDoc */
-    public void executeTests(Collection<String> testNames, Renderer renderer) throws
IOException {
-        renderer.title(2, "Test classes");
-        renderer.list("testNames", testNames);
-    }
-
-    /** @inheritDoc */
-    public void listTests(Collection<String> testNames, Renderer renderer) throws Exception
{
+    public void executeTests(Collection<String> testNames, Renderer renderer) throws
Exception {
         renderer.title(2, "Running tests");
         final JUnitCore junit = new JUnitCore();
         junit.addListener(renderer.getRunListener());
@@ -163,4 +157,10 @@ public class TestsManagerImpl implements
             junit.run(getTestClass(className));
         }
     }
+
+    /** @inheritDoc */
+    public void listTests(Collection<String> testNames, Renderer renderer) throws Exception
{
+        renderer.title(2, "Test classes");
+        renderer.list("testNames", testNames);
+    }
 }
\ No newline at end of file

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=1073729&r1=1073728&r2=1073729&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
Wed Feb 23 13:06:27 2011
@@ -70,6 +70,29 @@ public class HtmlRenderer extends RunLis
         HtmlFilter.escape(output, title);
         output.print("</h" + level + ">");
     }
+    
+    /** @inheritDoc */
+    public void link(String info, String url, String method) {
+        output.println("<div class='link'>");
+        
+        if("POST".equalsIgnoreCase(method)) {
+            output.print("<form method='POST' action='");
+            output.print(url);
+            output.print("'>");
+            output.print("<input type='submit' value='");
+            HtmlFilter.escape(output, info);
+            output.print("'/>");
+            output.println("</form>");
+        } else {
+            output.print("<a href='");
+            output.print(url);
+            HtmlFilter.escape(output, info);
+            output.print("'>");
+            output.println("</a>");
+        }
+        
+        output.println("</div>");
+    }
 
     /** @inheritDoc */
     public void setup(HttpServletResponse response, String pageTitle) throws IOException,
UnsupportedEncodingException {

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=1073729&r1=1073728&r2=1073729&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
Wed Feb 23 13:06:27 2011
@@ -125,6 +125,7 @@ public class JUnitServlet extends HttpSe
         }
     }
     
+    /** GET request lists available tests */
     @Override
     protected void doGet(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException {
@@ -168,11 +169,45 @@ public class JUnitServlet extends HttpSe
         } else {
             try {
                 testsManager.listTests(testNames, renderer);
-                testsManager.executeTests(testNames, renderer);
+                final String postPath = 
+                    request.getContextPath() 
+                    + servletPath
+                    + "/"
+                    + requestParser.getTestSelector()
+                    + "."
+                    + requestParser.getExtension();
+                renderer.link("Execute these tests", postPath, "POST");
             } catch(Exception e) {
                 throw new ServletException(e);
             }
         }
         renderer.cleanup();
     }
+    
+    /** POST request executes tests */
+    @Override
+    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
+    throws ServletException, IOException {
+        final RequestParser requestParser = new RequestParser(request);
+        
+        final Renderer renderer = rendererSelector.getRenderer(request);
+        if(renderer == null) {
+            throw new ServletException("No Renderer found for " + requestParser);
+        }
+        renderer.setup(response, getClass().getSimpleName());
+        
+        final List<String> testNames = getTestNames(requestParser.getTestSelector());
+        if(testNames.isEmpty()) {
+            response.sendError(
+                    HttpServletResponse.SC_NOT_FOUND, 
+                    "No tests found for " + requestParser);
+        }
+        try {
+            testsManager.executeTests(testNames, renderer);
+        } catch(Exception e) {
+            throw new ServletException(e);
+        }
+        
+        renderer.cleanup();
+    }
 }
\ 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=1073729&r1=1073728&r2=1073729&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
Wed Feb 23 13:06:27 2011
@@ -107,10 +107,23 @@ public class JsonRenderer extends RunLis
 
     /** @inheritDoc */
     public void title(int level, String title) {
-        // Titles are not needed
+        // Titles are not needed in JSON
     }
     
     /** @inheritDoc */
+    public void link(String info, String url, String method) {
+        try {
+            startItem("link");
+            writer.key("info").value(info);
+            writer.key("method").value(method);
+            writer.key("url").value(url);
+            endItem();
+        } catch(JSONException jex) {
+            log.warn("JSONException in link()", jex);
+        }
+    }
+
+    /** @inheritDoc */
     public RunListener getRunListener() {
         return this;
     }

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=1073729&r1=1073728&r2=1073729&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
Wed Feb 23 13:06:27 2011
@@ -74,6 +74,16 @@ public class PlainTextRenderer extends R
     }
     
     /** @inheritDoc */
+    public void link(String info, String url, String method) {
+        output.print("LINK: ");
+        output.print(info);
+        output.print(", url=");
+        output.print(url);
+        output.print(", method=");
+        output.println(method);
+    }
+
+    /** @inheritDoc */
     public RunListener getRunListener() {
         return this;
     }

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=1073729&r1=1073728&r2=1073729&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
Wed Feb 23 13:06:27 2011
@@ -137,6 +137,10 @@ public class XmlRenderer extends RunList
 		if (level == 3)
 			name = title;
 	}
+	
+    /** @inheritDoc */
+    public void link(String info, String url, String method) {
+    }
 
     /** @inheritDoc */
 	public void cleanup() {

Modified: 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=1073729&r1=1073728&r2=1073729&view=diff
==============================================================================
--- sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
(original)
+++ sling/trunk/testing/junit/remote/src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
Wed Feb 23 13:06:27 2011
@@ -83,11 +83,8 @@ public class SlingRemoteTestRunner exten
         }
         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
+        // POST request executes the tests
+        final Request r = builder.buildPostRequest(testParameters.getJunitServletPath() +
"/.json");
         executor.execute(r)
         .assertStatus(200)
         .assertContentType("application/json");



Mime
View raw message