incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1067132 - in /sling/whiteboard/bdelacretaz/junit/core: pom.xml src/main/java/org/apache/sling/junit/impl/JUnitServlet.java
Date Fri, 04 Feb 2011 10:24:20 GMT
Author: bdelacretaz
Date: Fri Feb  4 10:24:20 2011
New Revision: 1067132

URL: http://svn.apache.org/viewvc?rev=1067132&view=rev
Log:
SLING-1963 - remove dependencies on Sling, not needed here

Modified:
    sling/whiteboard/bdelacretaz/junit/core/pom.xml
    sling/whiteboard/bdelacretaz/junit/core/src/main/java/org/apache/sling/junit/impl/JUnitServlet.java

Modified: sling/whiteboard/bdelacretaz/junit/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/core/pom.xml?rev=1067132&r1=1067131&r2=1067132&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/core/pom.xml (original)
+++ sling/whiteboard/bdelacretaz/junit/core/pom.xml Fri Feb  4 10:24:20 2011
@@ -31,7 +31,7 @@
     <packaging>bundle</packaging>
 
     <name>Apache Sling JUnit Extension</name>
-    <description>Runs JUnit tests in a Sling instance</description>
+    <description>Runs JUnit tests in OSGi</description>
     
     <properties>
         <junit.version>4.8.2</junit.version>
@@ -92,12 +92,6 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.api</artifactId>
-            <version>2.0.2-incubator</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
         </dependency>

Modified: sling/whiteboard/bdelacretaz/junit/core/src/main/java/org/apache/sling/junit/impl/JUnitServlet.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/core/src/main/java/org/apache/sling/junit/impl/JUnitServlet.java?rev=1067132&r1=1067131&r2=1067132&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/core/src/main/java/org/apache/sling/junit/impl/JUnitServlet.java
(original)
+++ sling/whiteboard/bdelacretaz/junit/core/src/main/java/org/apache/sling/junit/impl/JUnitServlet.java
Fri Feb  4 10:24:20 2011
@@ -21,29 +21,52 @@ import java.io.PrintWriter;
 import java.util.Collection;
 
 import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.Service;
-import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.api.servlets.SlingAllMethodsServlet;
 import org.apache.sling.junit.JUnitTestsManager;
 import org.junit.runner.JUnitCore;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /** Simple test runner servlet */
 @SuppressWarnings("serial")
 @Component
 @Service
-@Property(name="sling.servlet.paths",value="/system/sling/junit")
-public class JUnitServlet extends SlingAllMethodsServlet {
+public class JUnitServlet extends HttpServlet {
+    
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    /** TODO make this configurable */
+    public static final String SERVLET_PATH = "/system/sling/junit";
     
     @Reference
     private JUnitTestsManager testsManager;
     
+    @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY)
+    private HttpService httpService;
+
+    protected void bindHttpService(HttpService h) throws ServletException, NamespaceException
{
+        httpService = h;
+        httpService.registerServlet(SERVLET_PATH, this, null, null);
+        log.info("Servlet registered at path {}", SERVLET_PATH);
+    }
+    
+    protected void unbindHttpService(HttpService h) throws ServletException, NamespaceException
{
+        h.unregister(SERVLET_PATH);
+        httpService = null;
+        log.info("Servlet unregistered from path {}", SERVLET_PATH);
+    }
+    
     @Override
-    protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)

+    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
     throws ServletException, IOException {
         
         response.setContentType("text/plain");
@@ -82,4 +105,4 @@ public class JUnitServlet extends SlingA
             throw new ServletException("Test class not found", cnfe);
         }
     }
-}
+}
\ No newline at end of file



Mime
View raw message