You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2013/09/24 23:22:21 UTC
svn commit: r1526015 - in /sling/trunk:
contrib/extensions/healthcheck/samples/
contrib/extensions/healthcheck/samples/src/main/java/org/apache/sling/hc/samples/junit/
contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo...
Author: bdelacretaz
Date: Tue Sep 24 21:22:21 2013
New Revision: 1526015
URL: http://svn.apache.org/r1526015
Log:
SLING-3108 - JUnit-based health checks
Added:
sling/trunk/contrib/extensions/healthcheck/samples/src/main/java/org/apache/sling/hc/samples/junit/
sling/trunk/contrib/extensions/healthcheck/samples/src/main/java/org/apache/sling/hc/samples/junit/SampleJUnitTest.java (with props)
sling/trunk/contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.junit.healthcheck.impl.JUnitHealthCheck-1.json (with props)
sling/trunk/testing/junit/healthcheck/ (with props)
sling/trunk/testing/junit/healthcheck/pom.xml (with props)
sling/trunk/testing/junit/healthcheck/src/
sling/trunk/testing/junit/healthcheck/src/main/
sling/trunk/testing/junit/healthcheck/src/main/java/
sling/trunk/testing/junit/healthcheck/src/main/java/org/
sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/
sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/
sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/
sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/
sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/
sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitHealthCheck.java (with props)
sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelector.java (with props)
sling/trunk/testing/junit/healthcheck/src/main/resources/
sling/trunk/testing/junit/healthcheck/src/main/resources/OSGI-INF/
sling/trunk/testing/junit/healthcheck/src/main/resources/OSGI-INF/metatype/
sling/trunk/testing/junit/healthcheck/src/main/resources/OSGI-INF/metatype/metatype.properties (with props)
sling/trunk/testing/junit/healthcheck/src/test/
sling/trunk/testing/junit/healthcheck/src/test/java/
sling/trunk/testing/junit/healthcheck/src/test/java/org/
sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/
sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/sling/
sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/sling/junit/
sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/sling/junit/healthcheck/
sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/sling/junit/healthcheck/impl/
sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelectorTest.java (with props)
Modified:
sling/trunk/contrib/extensions/healthcheck/samples/pom.xml
Modified: sling/trunk/contrib/extensions/healthcheck/samples/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/samples/pom.xml?rev=1526015&r1=1526014&r2=1526015&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/samples/pom.xml (original)
+++ sling/trunk/contrib/extensions/healthcheck/samples/pom.xml Tue Sep 24 21:22:21 2013
@@ -41,7 +41,13 @@
<extensions>true</extensions>
<configuration>
<instructions>
+ <Import-Package>
+ org.junit.*;resolution:=optional,
+ org.apache.sling.junit.*;resolution:=optional,
+ *
+ </Import-Package>
<Sling-Initial-Content>SLING-CONTENT/apps/hc/demo;path:=/apps/hc/demo;overwrite:=true</Sling-Initial-Content>
+ <Sling-Test-Regexp>.*Test</Sling-Test-Regexp>
</instructions>
</configuration>
</plugin>
@@ -81,6 +87,12 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.junit.core</artifactId>
+ <version>1.0.8</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.api</artifactId>
<version>2.1.0</version>
<scope>provided</scope>
@@ -88,6 +100,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Added: sling/trunk/contrib/extensions/healthcheck/samples/src/main/java/org/apache/sling/hc/samples/junit/SampleJUnitTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/samples/src/main/java/org/apache/sling/hc/samples/junit/SampleJUnitTest.java?rev=1526015&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/samples/src/main/java/org/apache/sling/hc/samples/junit/SampleJUnitTest.java (added)
+++ sling/trunk/contrib/extensions/healthcheck/samples/src/main/java/org/apache/sling/hc/samples/junit/SampleJUnitTest.java Tue Sep 24 21:22:21 2013
@@ -0,0 +1,54 @@
+package org.apache.sling.hc.samples.junit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
+import org.apache.sling.junit.annotations.TestReference;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/*
+ * 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.
+ */
+
+/** Trivial test used to demonstrate the junit Health Check service.
+ * Verify that the BundleContext is injected and that a specific
+ * bundle is active.
+ */
+@RunWith(SlingAnnotationsTestRunner.class)
+public class SampleJUnitTest {
+
+ @TestReference
+ private BundleContext bundleContext;
+
+ @Test
+ public void checkBundleContext() {
+ assertNotNull(bundleContext);
+ }
+
+ @Test
+ public void checkGroovyBundleActive() {
+ final String symbolicName = "org.apache.sling.extensions.groovy";
+ for(Bundle b : bundleContext.getBundles()) {
+ if(symbolicName.equals(b.getSymbolicName())) {
+ assertEquals("Expecting " + symbolicName + " to be active", Bundle.ACTIVE, b.getState());
+ }
+ }
+ }
+}
Propchange: sling/trunk/contrib/extensions/healthcheck/samples/src/main/java/org/apache/sling/hc/samples/junit/SampleJUnitTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/healthcheck/samples/src/main/java/org/apache/sling/hc/samples/junit/SampleJUnitTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: sling/trunk/contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.junit.healthcheck.impl.JUnitHealthCheck-1.json
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.junit.healthcheck.impl.JUnitHealthCheck-1.json?rev=1526015&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.junit.healthcheck.impl.JUnitHealthCheck-1.json (added)
+++ sling/trunk/contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.junit.healthcheck.impl.JUnitHealthCheck-1.json Tue Sep 24 21:22:21 2013
@@ -0,0 +1,7 @@
+{
+ "jcr:primaryType" : "sling:OsgiConfig",
+ "hc.name" : "JUnit Health Check Sample",
+ "hc.tags" : [junit],
+ "test.package.or.class" : "org.apache.sling.hc",
+ "hc.mbean.name" : "JUnitHealthCheck"
+}
Propchange: sling/trunk/contrib/extensions/healthcheck/samples/src/main/resources/SLING-CONTENT/apps/hc/demo/install/org.apache.sling.junit.healthcheck.impl.JUnitHealthCheck-1.json
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/testing/junit/healthcheck/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Sep 24 21:22:21 2013
@@ -0,0 +1,14 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+
+
+
+
Added: sling/trunk/testing/junit/healthcheck/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/healthcheck/pom.xml?rev=1526015&view=auto
==============================================================================
--- sling/trunk/testing/junit/healthcheck/pom.xml (added)
+++ sling/trunk/testing/junit/healthcheck/pom.xml Tue Sep 24 21:22:21 2013
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<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>18</version>
+ <relativePath>../../../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.sling.junit.healthcheck</artifactId>
+ <version>0.0.9-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Sling JUnit Health Checks</name>
+ <description>Sling Health Check services that run JUnit tests</description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/testing/junit/remote</connection>
+ <developerConnection> scm:svn:https://svn.apache.org/repos/asf/sling/trunk/testing/junit/remote</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/testing/junit/remote</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>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.sling.junit.remote.exported.*,
+ org.apache.sling.junit.remote.ide.*
+ </Export-Package>
+ <Import-Package>
+ org.apache.http.*; resolution:=optional,
+ org.apache.sling.testing.tools.http; resolution:=optional,
+ org.junit.internal.*; resolution:=optional,
+ *
+ </Import-Package>
+ <Sling-Test-Regexp>.*Test</Sling-Test-Regexp>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.junit.core</artifactId>
+ <version>1.0.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.2</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.11</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.5.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.hc.core</artifactId>
+ <version>0.0.2-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Propchange: sling/trunk/testing/junit/healthcheck/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitHealthCheck.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitHealthCheck.java?rev=1526015&view=auto
==============================================================================
--- sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitHealthCheck.java (added)
+++ sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitHealthCheck.java Tue Sep 24 21:22:21 2013
@@ -0,0 +1,174 @@
+/*
+ * 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.junit.healthcheck.impl;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyUnbounded;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.hc.api.HealthCheck;
+import org.apache.sling.hc.api.Result;
+import org.apache.sling.hc.util.FormattingResultLog;
+import org.apache.sling.junit.Renderer;
+import org.apache.sling.junit.TestSelector;
+import org.apache.sling.junit.TestsManager;
+import org.junit.runner.Description;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** HealthCheck that executes JUnit tests */
+@Component(
+ configurationFactory=true,
+ policy=ConfigurationPolicy.REQUIRE,
+ metatype=true)
+@Properties({
+ @Property(name=HealthCheck.NAME),
+ @Property(name=HealthCheck.TAGS, unbounded=PropertyUnbounded.ARRAY),
+ @Property(name=HealthCheck.MBEAN_NAME)
+})
+@Service(value=HealthCheck.class)
+public class JUnitHealthCheck implements HealthCheck {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Reference
+ private TestsManager testsManager;
+
+ @Property
+ public static final String TEST_PACKAGE_OR_CLASS_PROP = "test.package.or.class";
+ private TestSelector testSelector;
+
+ @Property
+ public static final String TEST_METHOD = "test.method";
+
+ private static class CustomRunListener extends RunListener {
+
+ private final FormattingResultLog resultLog;
+ int nTests;
+
+ CustomRunListener(FormattingResultLog resultLog) {
+ this.resultLog = resultLog;
+ }
+
+ @Override
+ public void testFailure(Failure failure) throws Exception {
+ super.testFailure(failure);
+ resultLog.warn(failure.getMessage());
+ }
+
+ @Override
+ public void testFinished(Description description) throws Exception {
+ super.testFinished(description);
+ resultLog.debug("Test finished: {}", description);
+ nTests++;
+ }
+ }
+
+ private static class CustomRenderer implements Renderer {
+
+ private final String extension;
+ private final RunListener listener;
+ private final FormattingResultLog resultLog;
+
+ CustomRenderer(RunListener listener, String extension, FormattingResultLog resultLog) {
+ this.extension = extension;
+ this.listener = listener;
+ this.resultLog = resultLog;
+ }
+
+ public boolean appliesTo(TestSelector ts) {
+ return true;
+ }
+
+ public void cleanup() {
+ }
+
+ public String getExtension() {
+ return extension;
+ }
+
+ public RunListener getRunListener() {
+ return listener;
+ }
+
+ public void info(String role, String info) {
+ resultLog.info(info);
+ }
+
+ public void link(String arg0, String arg1, String arg2) {
+ }
+
+ public void list(String arg0, Collection<String> arg1) {
+ }
+
+ public void setup(HttpServletResponse arg0, String arg1) throws IOException, UnsupportedEncodingException {
+ }
+
+ public void title(int arg0, String arg1) {
+ }
+ }
+
+ @Activate
+ public void activate(final Map<String, Object> properties) {
+ final String extension = "json";
+ final Object o = properties.get(TEST_METHOD);
+ final String testMethod = o == null ? "" : o.toString();
+ testSelector = new JUnitTestSelector(
+ String.valueOf(properties.get(TEST_PACKAGE_OR_CLASS_PROP)),
+ testMethod,
+ extension);
+ log.info("Activated with TestSelector={}", testSelector);
+ }
+
+ public Result execute() {
+ final String extension ="json";
+ final FormattingResultLog resultLog = new FormattingResultLog();
+ final CustomRunListener listener = new CustomRunListener(resultLog);
+ final Renderer r = new CustomRenderer(listener, extension, resultLog);
+ final Collection<String> testNames = testsManager.getTestNames(testSelector);
+ if(testNames.isEmpty()) {
+ resultLog.warn("No tests found for selector {}", testSelector);
+ } else {
+ try {
+ testsManager.executeTests(testNames, r, testSelector);
+ if(listener.nTests == 0) {
+ resultLog.warn("No tests executed by {}", testSelector);
+ }
+ } catch(Exception e) {
+ resultLog.warn("Exception while executing tests (" + testSelector + ")" + e);
+ }
+ }
+
+ return new Result(resultLog);
+ }
+
+}
Propchange: sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitHealthCheck.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitHealthCheck.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelector.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelector.java?rev=1526015&view=auto
==============================================================================
--- sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelector.java (added)
+++ sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelector.java Tue Sep 24 21:22:21 2013
@@ -0,0 +1,52 @@
+/*
+ * 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.junit.healthcheck.impl;
+
+import org.apache.sling.junit.TestSelector;
+
+class JUnitTestSelector implements TestSelector {
+
+ private final String testPackageOrClass;
+ private final String testMethod;
+ private final String extension;
+
+ JUnitTestSelector(String testPackageOrClass, String testMethod, String extension) {
+ this.testPackageOrClass = testPackageOrClass;
+ this.testMethod = testMethod;
+ this.extension = extension;
+ }
+
+ public boolean acceptTestName(String name) {
+ return name.startsWith(testPackageOrClass);
+ }
+
+ public String getExtension() {
+ return extension;
+ }
+
+ public String getSelectedTestMethodName() {
+ return testMethod;
+ }
+
+ public String getTestSelectorString() {
+ return testPackageOrClass + (testMethod == null ? "" : "#" + testMethod);
+ }
+
+ public String toString() {
+ return getTestSelectorString();
+ }
+}
Propchange: sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/testing/junit/healthcheck/src/main/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelector.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: sling/trunk/testing/junit/healthcheck/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/healthcheck/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1526015&view=auto
==============================================================================
--- sling/trunk/testing/junit/healthcheck/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ sling/trunk/testing/junit/healthcheck/src/main/resources/OSGI-INF/metatype/metatype.properties Tue Sep 24 21:22:21 2013
@@ -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 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.
+#
+
+#
+# This file contains localization strings for configuration labels and
+# descriptions as used in the metatype.xml descriptor generated by the
+# the Sling SCR plugin
+
+org.apache.sling.junit.healthcheck.impl.name = JUnit Health Check
+org.apache.sling.junit.healthcheck.impl.description = Health Check that executes JUnit tests
+
+hc.mbean.name.name = MBean name
+hc.mbean.name.description = Name of the MBean to create for this Health Check.
+
+hc.tags.name = Health Check tags
+hc.tags.description = List of tags for this Health Check service, used to select \
+ subsets of Health Check services for execution.
+
+hc.name.name = Health Check Name
+hc.name.description = Name of this Health Check service. Used for the MBean that's created \
+ for this Health Check as well, unless a specific MBean name is configured.
+
+test.package.or.class.name = Test package or class
+test.package.or.class.description = Package or class name to use to select which tests \
+ to execute.
+
+test.method.name = Test method
+test.method.description = Name of a specific test method to execute (optional).
\ No newline at end of file
Propchange: sling/trunk/testing/junit/healthcheck/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelectorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelectorTest.java?rev=1526015&view=auto
==============================================================================
--- sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelectorTest.java (added)
+++ sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelectorTest.java Tue Sep 24 21:22:21 2013
@@ -0,0 +1,47 @@
+/*
+ * 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.junit.healthcheck.impl;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class JUnitTestSelectorTest {
+
+ @Test
+ public void testSelectorString() {
+ assertEquals("com.example.foo", new JUnitTestSelector("com.example.foo", null, null).getTestSelectorString());
+ assertEquals("com.example.testing#someMethod", new JUnitTestSelector("com.example.testing", "someMethod", null).getTestSelectorString());
+ }
+
+ @Test
+ public void testNoMethod() {
+ final JUnitTestSelector s = new JUnitTestSelector("com.example.foo", null, null);
+ assertTrue("Expecting package to be selected", s.acceptTestName("com.example.foo"));
+ assertTrue("Expecting subpackage to be selected", s.acceptTestName("com.example.foo.bar"));
+ assertTrue("Expecting class to be selected", s.acceptTestName("com.example.foo.some.ThisClass"));
+ assertFalse("Expecting other package.accept to return false", s.acceptTestName("com.other.foo"));
+ }
+
+ @Test
+ public void testWithMethod() {
+ final JUnitTestSelector s = new JUnitTestSelector("com.example.foo", "someMethod", null);
+ assertTrue("Expecting package to be selected", s.acceptTestName("com.example.foo"));
+ assertEquals("someMethod", s.getSelectedTestMethodName());
+ }
+}
Propchange: sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelectorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/testing/junit/healthcheck/src/test/java/org/apache/sling/junit/healthcheck/impl/JUnitTestSelectorTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL