Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4C92A1152D for ; Mon, 14 Jul 2014 14:48:04 +0000 (UTC) Received: (qmail 56826 invoked by uid 500); 14 Jul 2014 14:48:04 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 56777 invoked by uid 500); 14 Jul 2014 14:48:04 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 56681 invoked by uid 99); 14 Jul 2014 14:48:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Jul 2014 14:48:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Jul 2014 14:48:03 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E1BC9238890D; Mon, 14 Jul 2014 14:47:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140714144737.E1BC9238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ + + + + 4.0.0 + + + org.apache.sling + sling + 19 + ../../../../parent/pom.xml + + + org.apache.sling + org.apache.sling.hc.junit.bridge + bundle + 0.9.9-SNAPSHOT + + Apache Sling Health Check JUnit Bridge + 2013 + + + Makes Sling Health Checks available as server-side JUnit tests, to + allow them to be used as part of integration tests. + + + + 6 + + + + scm:svn:http://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/healthcheck/junit-bridge + scm:svn:https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/healthcheck/junit-bridge + http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/healthcheck/junit-bridge + + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + + + + + org.osgi + org.osgi.core + + + org.osgi + org.osgi.compendium + + + org.apache.felix + org.apache.felix.scr.annotations + provided + + + org.slf4j + slf4j-api + 1.6.2 + + + junit + junit + provided + + + org.slf4j + slf4j-simple + 1.6.2 + test + + + org.apache.sling + org.apache.sling.commons.osgi + 2.2.0 + provided + + + org.apache.sling + org.apache.sling.hc.core + 1.1.0 + provided + + + org.apache.sling + org.apache.sling.junit.core + 1.0.6 + provided + + + 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 getTestNames() { + final List result = new ArrayList(); + // 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 testContext = new ThreadLocal(); + + 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