sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1610419 - in /sling/whiteboard/bdelacretaz/junit-bridge: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/hc/ src/main/java/org/apache/sling/hc/jun...
Date Mon, 14 Jul 2014 14:47:37 GMT
Author: bdelacretaz
Date: Mon Jul 14 14:47:37 2014
New Revision: 1610419

URL: http://svn.apache.org/r1610419
Log:
JUnit bridge for health checks, work in progress

Added:
    sling/whiteboard/bdelacretaz/junit-bridge/   (with props)
    sling/whiteboard/bdelacretaz/junit-bridge/pom.xml
    sling/whiteboard/bdelacretaz/junit-bridge/src/
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTest.java
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTestsProvider.java
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/JUnitTestBridge.java
    sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/TestBridgeContext.java

Propchange: sling/whiteboard/bdelacretaz/junit-bridge/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jul 14 14:47:37 2014
@@ -0,0 +1,16 @@
+target
+sling
+bin
+logs
+jackrabbit
+derby.log
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+oak-server-default-NodeStore
+

Added: sling/whiteboard/bdelacretaz/junit-bridge/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit-bridge/pom.xml?rev=1610419&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit-bridge/pom.xml (added)
+++ sling/whiteboard/bdelacretaz/junit-bridge/pom.xml Mon Jul 14 14:47:37 2014
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>19</version>
+        <relativePath>../../../../parent/pom.xml</relativePath>
+    </parent>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.hc.junit.bridge</artifactId>
+    <packaging>bundle</packaging>
+    <version>0.9.9-SNAPSHOT</version>
+
+    <name>Apache Sling Health Check JUnit Bridge</name>
+    <inceptionYear>2013</inceptionYear>
+    
+    <description>
+        Makes Sling Health Checks available as server-side JUnit tests, to
+        allow them to be used as part of integration tests.
+    </description>
+
+    <properties>
+        <sling.java.version>6</sling.java.version>
+    </properties>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/healthcheck/junit-bridge</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/healthcheck/junit-bridge</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/junit-bridge</url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.6.2</version>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>provided</scope>
+        </dependency>
+         <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <version>1.6.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
+            <version>2.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.hc.core</artifactId>
+            <version>1.1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.junit.core</artifactId>
+            <version>1.0.6</version>
+            <scope>provided</scope>
+        </dependency>
+     </dependencies>
+</project>

Added: sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTest.java?rev=1610419&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTest.java
(added)
+++ sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTest.java
Mon Jul 14 14:47:37 2014
@@ -0,0 +1,66 @@
+/*
+ * 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 SF 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.hc.junitbridge;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.hc.api.HealthCheck;
+import org.apache.sling.hc.api.Result;
+import org.apache.sling.hc.api.ResultLog;
+
+public class HealthCheckTest extends TestCase {
+    private final HealthCheck hc;
+    private final String name;
+        
+    HealthCheckTest(HealthCheck hc) {
+        super("testHealthCheck");
+        this.hc = hc;
+        
+        // TODO HC name? see webconsole
+        name = hc.getClass().getName();
+    }
+    
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    /** Execute our health check and dump its log
+     *  messages > INFO if it fails */
+    public void testHealthCheck() {
+        final Result r = hc.execute(); 
+        final StringBuilder failMsg = new StringBuilder();
+        if(!r.isOk()) {
+            failMsg.append(name);
+            failMsg.append("\n");
+            for(ResultLog.Entry log : r) {
+                if(failMsg.length() > 0) {
+                    failMsg.append("\n");
+                }
+                if(log.getStatus().compareTo(Result.Status.INFO) > 0) {
+                    failMsg.append(log.getStatus().toString());
+                    failMsg.append(" - ");
+                    failMsg.append(log.getMessage());
+                }
+            }
+        }
+        if(failMsg.length() > 0) {
+            fail("Health Check failed: " + failMsg.toString());
+        }
+    }
+}
\ No newline at end of file

Added: 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=1610419&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTestsProvider.java
(added)
+++ sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/HealthCheckTestsProvider.java
Mon Jul 14 14:47:37 2014
@@ -0,0 +1,73 @@
+/*
+ * 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 SF 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.hc.junitbridge;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.hc.util.HealthCheckFilter;
+import org.apache.sling.junit.TestsProvider;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.ComponentContext;
+
+/** Bridge Health Checks into the Sling JUnit server-side test
+ *  framework, based on their tags.
+ */
+@Component
+@Service
+public class HealthCheckTestsProvider implements TestsProvider {
+
+    private String servicePid;
+
+    // TODO configurable
+    private String [] tags = { "script" };
+    private HealthCheckFilter filter;
+    
+    @Activate
+    protected void activate(ComponentContext ctx) {
+        servicePid = (String)ctx.getProperties().get(Constants.SERVICE_PID);
+        filter = new HealthCheckFilter(ctx.getBundleContext());
+    }
+    
+    @Override
+    public Class<?> createTestClass(String testName) throws ClassNotFoundException
{
+        JUnitTestBridge.setContext(new TestBridgeContext(filter, tags));
+        return JUnitTestBridge.class;
+    }
+
+    @Override
+    public String getServicePid() {
+        return servicePid;
+    }
+
+    @Override
+    public List<String> getTestNames() {
+        final List<String> result = new ArrayList<String>();
+        // TODO use a configurable name?
+        result.add("HealthChecks(sling,slow)");
+        return result;
+    }
+
+    @Override
+    public long lastModified() {
+        return 0;
+    }
+}
\ No newline at end of file

Added: sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/JUnitTestBridge.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/JUnitTestBridge.java?rev=1610419&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/JUnitTestBridge.java
(added)
+++ sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/JUnitTestBridge.java
Mon Jul 14 14:47:37 2014
@@ -0,0 +1,44 @@
+/*
+ * 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 SF 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.hc.junitbridge;
+
+import static org.junit.Assert.assertNotNull;
+import junit.framework.TestSuite;
+
+import org.apache.sling.hc.api.HealthCheck;
+import org.junit.runner.RunWith;
+import org.junit.runners.AllTests;
+
+@RunWith(AllTests.class)
+public class JUnitTestBridge {
+    private static ThreadLocal<TestBridgeContext> testContext = new ThreadLocal<TestBridgeContext>();
+    
+    static void setContext(TestBridgeContext c) {
+        testContext.set(c);
+    }
+    
+    public static junit.framework.Test suite() {
+        final TestBridgeContext context = testContext.get();
+        assertNotNull("Expecting non-null TestBridgeContext, via ThreadLocal", context);
+        TestSuite suite = new TestSuite();
+        for(HealthCheck hc : context.getFilter().getTaggedHealthChecks(context.getTags()))
{
+            suite.addTest(new HealthCheckTest(hc));
+        }
+        return suite;
+    }
+}
\ No newline at end of file

Added: sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/TestBridgeContext.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/TestBridgeContext.java?rev=1610419&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/TestBridgeContext.java
(added)
+++ sling/whiteboard/bdelacretaz/junit-bridge/src/main/java/org/apache/sling/hc/junitbridge/TestBridgeContext.java
Mon Jul 14 14:47:37 2014
@@ -0,0 +1,38 @@
+/*
+ * 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 SF 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.hc.junitbridge;
+
+import org.apache.sling.hc.util.HealthCheckFilter;
+
+class TestBridgeContext {
+    private final String [] tags;
+    private final HealthCheckFilter filter;
+        
+    TestBridgeContext(HealthCheckFilter filter, String [] tags) {
+        this.tags = tags;
+        this.filter = filter;
+    }
+    
+    String [] getTags() {
+        return tags;
+    }
+    
+    HealthCheckFilter getFilter() {
+        return filter;
+    }
+}
\ No newline at end of file



Mime
View raw message