incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1065956 - in /sling/whiteboard/bdelacretaz/junit: extension/src/main/java/org/apache/sling/extensions/junit/ extension/src/main/java/org/apache/sling/extensions/junit/impl/ testbundle/ testbundle/src/main/java/org/apache/sling/extensions/j...
Date Tue, 01 Feb 2011 09:27:56 GMT
Author: bdelacretaz
Date: Tue Feb  1 09:27:55 2011
New Revision: 1065956

URL: http://svn.apache.org/viewvc?rev=1065956&view=rev
Log:
SLING-1963 - use more flexible Sling-Test-Regexp header to select test classes

Added:
    sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/JUnitConstants.java
  (with props)
    sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/MissingTest.java
  (with props)
    sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/SomeOtherClass.java
  (with props)
Modified:
    sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/impl/JUnitServlet.java
    sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/impl/JUnitTestsManagerImpl.java
    sling/whiteboard/bdelacretaz/junit/testbundle/pom.xml

Added: sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/JUnitConstants.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/JUnitConstants.java?rev=1065956&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/JUnitConstants.java
(added)
+++ sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/JUnitConstants.java
Tue Feb  1 09:27:55 2011
@@ -0,0 +1,21 @@
+/*
+ * 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.extensions.junit;
+
+public class JUnitConstants {
+    public static final String SLING_TEST_REGEXP = "Sling-Test-Regexp"; 
+}

Propchange: sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/JUnitConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/JUnitConstants.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/impl/JUnitServlet.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/impl/JUnitServlet.java?rev=1065956&r1=1065955&r2=1065956&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/impl/JUnitServlet.java
(original)
+++ sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/impl/JUnitServlet.java
Tue Feb  1 09:27:55 2011
@@ -29,6 +29,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.extensions.junit.JUnitConstants;
 import org.apache.sling.extensions.junit.JUnitTestsManager;
 import org.junit.runner.JUnitCore;
 
@@ -56,15 +57,15 @@ public class JUnitServlet extends SlingA
         final List<String> testClasses = testsManager.getTestClasses();
         if(testClasses.isEmpty()) {
             pw.println(
-                    "No test classes found, please activate at least one bundle"
-                    + " which exports JUnit test classes and points to them using a"
-                    + " Test-Package header."
+                    "No test classes found, please activate at least one bundle "
+                    + "which exports JUnit test classes and points to them using a "
+                    + JUnitConstants.SLING_TEST_REGEXP + " header."
                     );
             return;
         }
         
         // List test classes
-        pw.println("TEST CLASSES (found in bundles with Test-Package headers):");
+        pw.println("TEST CLASSES (found in bundles that have a " + JUnitConstants.SLING_TEST_REGEXP
+ " header):");
         for(String className : testClasses) {
             pw.println(className);
         }

Modified: sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/impl/JUnitTestsManagerImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/impl/JUnitTestsManagerImpl.java?rev=1065956&r1=1065955&r2=1065956&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/impl/JUnitTestsManagerImpl.java
(original)
+++ sling/whiteboard/bdelacretaz/junit/extension/src/main/java/org/apache/sling/extensions/junit/impl/JUnitTestsManagerImpl.java
Tue Feb  1 09:27:55 2011
@@ -16,12 +16,16 @@
  */
 package org.apache.sling.extensions.junit.impl;
 
+import static org.apache.sling.extensions.junit.JUnitConstants.SLING_TEST_REGEXP;
+
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
@@ -38,7 +42,6 @@ import org.slf4j.LoggerFactory;
 @Service
 public class JUnitTestsManagerImpl implements BundleListener,JUnitTestsManager {
     private final Logger log = LoggerFactory.getLogger(getClass());
-    public static final String TEST_PACKAGE_HEADER = "Test-Package";
     private BundleContext bundleContext;
     
     /** Symbolic names of bundles that changed state - if not empty, need
@@ -51,8 +54,8 @@ public class JUnitTestsManagerImpl imple
      */
     private final Map<String, List<String>> testClassesMap = new HashMap<String,
List<String>>();
 
-    private String getTestPackageName(Bundle b) {
-        return (String)b.getHeaders().get(TEST_PACKAGE_HEADER);
+    private String getSlingTestRegexp(Bundle b) {
+        return (String)b.getHeaders().get(SLING_TEST_REGEXP);
     }
     
     protected void activate(ComponentContext ctx) {
@@ -61,7 +64,7 @@ public class JUnitTestsManagerImpl imple
         
         // Initially consider all bundles as "changed"
         for(Bundle b : bundleContext.getBundles()) {
-            if(getTestPackageName(b) != null) {
+            if(getSlingTestRegexp(b) != null) {
                 changedBundles.add(b.getSymbolicName());
                 log.debug("Will look for test classes inside bundle {}", b.getSymbolicName());
             }
@@ -78,9 +81,9 @@ public class JUnitTestsManagerImpl imple
     public void bundleChanged(BundleEvent event) {
         // Only consider bundles which contain tests
         final Bundle b = event.getBundle();
-        if(getTestPackageName(b) == null) {
+        if(getSlingTestRegexp(b) == null) {
             log.debug("Bundle {} does not have {} header, ignored", 
-                    b.getSymbolicName(), TEST_PACKAGE_HEADER);
+                    b.getSymbolicName(), SLING_TEST_REGEXP);
             return;
         }
         synchronized (changedBundles) {
@@ -135,10 +138,19 @@ public class JUnitTestsManagerImpl imple
     /** Get test classes that bundle b provides (as done in Felix/Sigil) */
     private List<String> getTestClasses(Bundle b) {
         final List<String> result = new ArrayList<String>();
-        final String testPackage = getTestPackageName(b);
+        Pattern testClassRegexp = null;
+        final String headerValue = getSlingTestRegexp(b); 
+        try {
+            testClassRegexp = Pattern.compile(headerValue);
+        } catch(PatternSyntaxException pse) {
+            log.warn(
+                    "Invalid pattern '" + headerValue 
+                    + "' for bundle " + b.getSymbolicName() + ", ignored", 
+                    pse);
+        }
         
-        if(testPackage == null) {
-            log.info("Bundle {} does not have {} header, not looking for test classes", TEST_PACKAGE_HEADER);
+        if(testClassRegexp == null) {
+            log.info("Bundle {} does not have {} header, not looking for test classes", SLING_TEST_REGEXP);
         } else if(Bundle.ACTIVE != b.getState()) {
             log.info("Bundle {} is not active, no test classes considered", b.getSymbolicName());
         } else {
@@ -147,11 +159,11 @@ public class JUnitTestsManagerImpl imple
             while (classUrls.hasMoreElements()) {
                 URL url = classUrls.nextElement();
                 final String name = toClassName(url);
-                if(name.startsWith(testPackage)) {
+                if(testClassRegexp.matcher(name).matches()) {
                     result.add(name);
                 } else {
-                    log.debug("Class {} is not in test package {} of bundle {}, ignored",
-                            new Object[] { name, testPackage, b.getSymbolicName() });
+                    log.debug("Class {} does not match {} pattern {} of bundle {}, ignored",
+                            new Object[] { name, SLING_TEST_REGEXP, testClassRegexp, b.getSymbolicName()
});
                 }
             }
             log.info("{} test classes found in bundle {}", result.size(), b.getSymbolicName());

Modified: sling/whiteboard/bdelacretaz/junit/testbundle/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/testbundle/pom.xml?rev=1065956&r1=1065955&r2=1065956&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/testbundle/pom.xml (original)
+++ sling/whiteboard/bdelacretaz/junit/testbundle/pom.xml Tue Feb  1 09:27:55 2011
@@ -58,7 +58,7 @@
                 <configuration>
                     <instructions>
                         <Export-Package>org.apache.sling.extensions.junit.testbundle.*</Export-Package>
-                        <Test-Package>org.apache.sling.extensions.junit.testbundle.tests</Test-Package>
+                        <Sling-Test-Regexp>.*Test</Sling-Test-Regexp>
                     </instructions>
                 </configuration>
             </plugin>

Added: sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/MissingTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/MissingTest.java?rev=1065956&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/MissingTest.java
(added)
+++ sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/MissingTest.java
Tue Feb  1 09:27:55 2011
@@ -0,0 +1,23 @@
+/*
+ * 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.extensions.junit.testbundle.tests;
+
+/** JUnit should complain that this class doesn't contain
+ *  any tests.
+ */
+public class MissingTest {
+}

Propchange: sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/MissingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/MissingTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/SomeOtherClass.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/SomeOtherClass.java?rev=1065956&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/SomeOtherClass.java
(added)
+++ sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/SomeOtherClass.java
Tue Feb  1 09:27:55 2011
@@ -0,0 +1,24 @@
+/*
+ * 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.extensions.junit.testbundle.tests;
+
+/** Verify that this class is not included in the list
+ *  of tests (due to the Sling-Test-Regexp bundle header.
+ */
+public class SomeOtherClass {
+
+}

Propchange: sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/SomeOtherClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/bdelacretaz/junit/testbundle/src/main/java/org/apache/sling/extensions/junit/testbundle/tests/SomeOtherClass.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message