sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1610720 - in /sling/whiteboard/bdelacretaz/junit-bridge: ./ src/main/java/org/apache/sling/hc/junitbridge/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/sling/ src/test/java/org/apache/sling...
Date Tue, 15 Jul 2014 15:01:45 GMT
Author: bdelacretaz
Date: Tue Jul 15 15:01:44 2014
New Revision: 1610720

URL: http://svn.apache.org/r1610720
Log:
Configurable tag groups, and start testing

Added:
    sling/whiteboard/bdelacretaz/junit-bridge/src/test/
    sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/
    sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/org/
    sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/org/apache/
    sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/org/apache/sling/
    sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/org/apache/sling/hc/
    sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/org/apache/sling/hc/junitbridge/
    sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/org/apache/sling/hc/junitbridge/tests/
    sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/org/apache/sling/hc/junitbridge/tests/HealthCheckTestsProviderTest.java
Modified:
    sling/whiteboard/bdelacretaz/junit-bridge/pom.xml
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTestsProvider.java

Modified: sling/whiteboard/bdelacretaz/junit-bridge/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit-bridge/pom.xml?rev=1610720&r1=1610719&r2=1610720&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/junit-bridge/pom.xml (original)
+++ sling/whiteboard/bdelacretaz/junit-bridge/pom.xml Tue Jul 15 15:01:44 2014
@@ -71,7 +71,18 @@
             <artifactId>junit</artifactId>
             <scope>provided</scope>
         </dependency>
-         <dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>1.9.5</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-simple</artifactId>
             <version>1.6.2</version>

Modified: sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTestsProvider.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTestsProvider.java?rev=1610720&r1=1610719&r2=1610720&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTestsProvider.java
(original)
+++ sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTestsProvider.java
Tue Jul 15 15:01:44 2014
@@ -23,16 +23,20 @@ import java.util.List;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.commons.osgi.PropertiesUtil;
 import org.apache.sling.junit.TestsProvider;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /** Bridge Health Checks into the Sling JUnit server-side test
  *  framework, based on their tags.
  */
-@Component
+@Component(metatype=true)
 @Service
 public class HealthCheckTestsProvider implements TestsProvider {
 
@@ -40,20 +44,26 @@ public class HealthCheckTestsProvider im
     private long lastModified;
     private BundleContext bundleContext;
     
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
     public static final String TEST_NAME_PREFIX = "HealthChecks(";
     public static final String TEST_NAME_SUFFIX = ")";
 
-    // TODO configurable
-    private String [] tags = { 
-        "script",
-        "sling",
-        "bundles,script",
-        "bundles,-script"
-    };
+    @Property(cardinality=2147483647, 
+            label="Health Check Tags",
+            description="Groups of health check tags to execute as JUnit tests. Use the standard
Health Checks 'includeThis,-omitThat' syntax")
+    public static final String PROP_TAG_GROUPS = "health.check.tag.groups";
+    
+    private String [] tagGroups;
     
     @Activate
     protected void activate(ComponentContext ctx) {
         bundleContext = ctx.getBundleContext();
+        tagGroups = PropertiesUtil.toStringArray(ctx.getProperties().get(PROP_TAG_GROUPS));
+        if(tagGroups == null) {
+            tagGroups = new String[]{};
+            log.warn("No tag groups configured via {}, Health Checks won't be available as
JUnit tests", PROP_TAG_GROUPS);
+        }
         servicePid = (String)ctx.getProperties().get(Constants.SERVICE_PID);
         lastModified = System.currentTimeMillis();
     }
@@ -89,7 +99,7 @@ public class HealthCheckTestsProvider im
     @Override
     public List<String> getTestNames() {
         final List<String> result = new ArrayList<String>();
-        for(String t : tags) {
+        for(String t : tagGroups) {
             result.add(TEST_NAME_PREFIX + t + TEST_NAME_SUFFIX);
         }
         return result;

Added: sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/org/apache/sling/hc/junitbridge/tests/HealthCheckTestsProviderTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/org/apache/sling/hc/junitbridge/tests/HealthCheckTestsProviderTest.java?rev=1610720&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/org/apache/sling/hc/junitbridge/tests/HealthCheckTestsProviderTest.java
(added)
+++ sling/whiteboard/bdelacretaz/junit-bridge/src/test/java/org/apache/sling/hc/junitbridge/tests/HealthCheckTestsProviderTest.java
Tue Jul 15 15:01:44 2014
@@ -0,0 +1,57 @@
+package org.apache.sling.hc.junitbridge.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.sling.hc.junitbridge.HealthCheckTestsProvider;
+import org.apache.sling.junit.TestsProvider;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.osgi.service.component.ComponentContext;
+
+/** Test the HealthCheckTestsProvider, which 
+ *  uses everything else.
+ */
+public class HealthCheckTestsProviderTest {
+    private TestsProvider provider;
+    
+    final String [] TAG_GROUPS = {
+            "foo,bar",
+            "wii",
+            "blue"
+    };
+    
+    private static String testName(String tagGroup) {
+        return HealthCheckTestsProvider.TEST_NAME_PREFIX + tagGroup + HealthCheckTestsProvider.TEST_NAME_SUFFIX;
+    }
+            
+    @Before
+    public void setup() {
+        final ComponentContext ctx = Mockito.mock(ComponentContext.class);
+        final Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put(HealthCheckTestsProvider.PROP_TAG_GROUPS, TAG_GROUPS);
+        Mockito.when(ctx.getProperties()).thenReturn(props);
+        
+        provider = new HealthCheckTestsProvider() {
+            {
+                activate(ctx);
+            }
+        };
+    }
+    
+    @Test
+    public void testGetTestNames() {
+        final List<String> names = provider.getTestNames();
+        assertEquals(TAG_GROUPS.length, names.size());
+        for(String tag : TAG_GROUPS) {
+            final String expected = testName(tag);
+            assertTrue("Expecting test names to contain " + expected + ", " + names, names.contains(expected));
+        }
+    }
+    
+}



Mime
View raw message