incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1073678 - in /sling/trunk/testing/junit/core/src/main: java/org/apache/sling/junit/impl/servlet/JUnitServlet.java resources/OSGI-INF/ resources/OSGI-INF/metatype/ resources/OSGI-INF/metatype/metatype.properties
Date Wed, 23 Feb 2011 10:30:50 GMT
Author: bdelacretaz
Date: Wed Feb 23 10:30:50 2011
New Revision: 1073678

URL: http://svn.apache.org/viewvc?rev=1073678&view=rev
Log:
SLING-1992 - JUnitServlet can be disabled and mounted on a different path by configuration

Added:
    sling/trunk/testing/junit/core/src/main/resources/OSGI-INF/
    sling/trunk/testing/junit/core/src/main/resources/OSGI-INF/metatype/
    sling/trunk/testing/junit/core/src/main/resources/OSGI-INF/metatype/metatype.properties
  (with props)
Modified:
    sling/trunk/testing/junit/core/src/main/java/org/apache/sling/junit/impl/servlet/JUnitServlet.java

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=1073678&r1=1073677&r2=1073678&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 10:30:50 2011
@@ -21,6 +21,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Dictionary;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -30,11 +31,11 @@ import javax.servlet.http.HttpServletReq
 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.ReferencePolicy;
 import org.apache.sling.junit.JUnitTestsManager;
 import org.junit.runner.JUnitCore;
+import org.osgi.service.component.ComponentContext;
 import org.osgi.service.http.HttpService;
 import org.osgi.service.http.NamespaceException;
 import org.slf4j.Logger;
@@ -42,32 +43,46 @@ import org.slf4j.LoggerFactory;
 
 /** Simple test runner servlet */
 @SuppressWarnings("serial")
-@Component(immediate=true)
+@Component(immediate=true, metatype=true)
 public class JUnitServlet extends HttpServlet {
     
     private final Logger log = LoggerFactory.getLogger(getClass());
     
     public static final String CSS = "junit.css";
     
-    /** TODO make this configurable */
-    public static final String SERVLET_PATH = "/system/sling/junit";
+    @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 */ 
+    private String servletPath;
     
     @Reference
     private JUnitTestsManager testsManager;
     
-    @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY, policy=ReferencePolicy.DYNAMIC)
+    @Reference
     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 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);
+        } else {
+            servletPath = (String)config.get(SERVLET_PATH_NAME);
+            httpService.registerServlet(servletPath, this, null, null);
+            log.info("Servlet registered at {}", servletPath);
+        }
     }
     
-    protected void unbindHttpService(HttpService h) throws ServletException, NamespaceException
{
-        h.unregister(SERVLET_PATH);
-        httpService = null;
-        log.info("Servlet unregistered from path {}", SERVLET_PATH);
+    protected void deactivate(ComponentContext ctx) throws ServletException, NamespaceException
{
+        if(servletPath != null) {
+            httpService.unregister(servletPath);
+            log.info("Servlet unregistered from path {}", servletPath);
+        }
     }
     
     /** Return the list of available tests
@@ -125,7 +140,7 @@ public class JUnitServlet extends HttpSe
         {
             final String pi = request.getPathInfo();
             if(pi == null) {
-                response.sendRedirect(request.getContextPath() + SERVLET_PATH + "/");
+                response.sendRedirect(request.getContextPath() + servletPath + "/");
             } else if(pi.endsWith(CSS)) {
                 sendCss(response);
                 return;

Added: sling/trunk/testing/junit/core/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/core/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1073678&view=auto
==============================================================================
--- sling/trunk/testing/junit/core/src/main/resources/OSGI-INF/metatype/metatype.properties
(added)
+++ sling/trunk/testing/junit/core/src/main/resources/OSGI-INF/metatype/metatype.properties
Wed Feb 23 10:30:50 2011
@@ -0,0 +1,31 @@
+#
+#  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.
+#
+
+org.apache.sling.junit.impl.servlet.JUnitServlet.name = \
+	Apache Sling JUnit Servlet 
+org.apache.sling.junit.impl.servlet.JUnitServlet.description =  \
+	Servlet that executes JUnit tests registered by \
+	TestsProvider services
+
+servlet.disabled.name = Disable servlet
+servlet.disabled.description = If true, the servlet will \
+	be disabled
+
+servlet.path.name = Servlet path
+servlet.path.description = The path at which the servlet is mounted
\ No newline at end of file

Propchange: sling/trunk/testing/junit/core/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message