This is an automated email from the ASF dual-hosted git repository.
radu pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-junit-core.git
The following commit(s) were added to refs/heads/master by this push:
new ef40bf6 SLING-9586 - Update jUnit Core to parent pom 39 or higher
ef40bf6 is described below
commit ef40bf6678e193f4be90bf3c9f6e5d823350366a
Author: Radu Cotescu <[email protected]>
AuthorDate: Tue Jul 14 12:02:06 2020 +0200
SLING-9586 - Update jUnit Core to parent pom 39 or higher
* updated OSGi annotations
* updated JavaDoc to make it comply with Java 11
---
bnd.bnd | 12 ++
pom.xml | 101 ++++++++-------
release.properties | 22 ++++
src/main/java/org/apache/sling/junit/Renderer.java | 87 +++++++++----
.../org/apache/sling/junit/RendererSelector.java | 19 ++-
.../java/org/apache/sling/junit/RequestParser.java | 4 +-
.../java/org/apache/sling/junit/TestSelector.java | 35 +++--
.../java/org/apache/sling/junit/TestsManager.java | 55 +++++---
.../java/org/apache/sling/junit/TestsProvider.java | 40 ++++--
.../sling/junit/annotations/TestReference.java | 27 ++--
.../sling/junit/annotations/package-info.java | 22 ++++
.../sling/junit/impl/AnnotationsProcessor.java | 8 +-
.../sling/junit/impl/BundleTestsProvider.java | 4 +-
.../sling/junit/impl/RendererSelectorImpl.java | 19 ++-
.../apache/sling/junit/impl/TestsManagerImpl.java | 7 +-
.../sling/junit/impl/servlet/HtmlRenderer.java | 10 +-
.../junit/impl/servlet/JUnitResultRenderer.java | 6 +-
.../sling/junit/impl/servlet/JUnitServlet.java | 23 ++--
.../sling/junit/impl/servlet/JacocoServlet.java | 18 +--
.../sling/junit/impl/servlet/JsonRenderer.java | 8 +-
.../junit/impl/servlet/PlainTextRenderer.java | 8 +-
.../junit/impl/servlet/SlingJUnitServlet.java | 30 +++--
.../sling/junit/impl/servlet/TestLogServlet.java | 39 +++---
.../sling/junit/impl/servlet/XmlRenderer.java | 6 +-
.../java/org/apache/sling/junit/package-info.java | 22 ++++
.../apache/sling/junit/rules/TeleporterRule.java | 141 +++++++++++++--------
.../org/apache/sling/junit/rules/package-info.java | 22 ++++
.../resources/OSGI-INF/l10n/metatype.properties | 31 -----
28 files changed, 510 insertions(+), 316 deletions(-)
diff --git a/bnd.bnd b/bnd.bnd
new file mode 100644
index 0000000..ccedd05
--- /dev/null
+++ b/bnd.bnd
@@ -0,0 +1,12 @@
+Bundle-Activator: org.apache.sling.junit.Activator
+Export-Package: junit.framework;version=${junit.version}, \
+ org.junit;version=${junit.version}, \
+ org.junit.matchers.*;version=${junit.version}, \
+ org.junit.rules.*;version=${junit.version}, \
+ org.junit.runner.*;version=${junit.version}, \
+ org.junit.runners.*;version=${junit.version}, \
+ org.junit.experimental.categories.*;version=${junit.version}, \
+ org.junit.validator.*;version=${junit.version}, \
+
org.hamcrest.*;version=${hamcrest.version};-split-package:=merge-first
+-conditionalpackage: org.hamcrest.*, org.junit.*, junit.*
+-includeresource: @org.jacoco.agent-*.jar!/org/jacoco/agent/rt/IAgent*
diff --git a/pom.xml b/pom.xml
index 6341b1b..98bde0d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,14 +22,13 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>26</version>
+ <artifactId>sling-bundle-parent</artifactId>
+ <version>39</version>
<relativePath />
</parent>
<artifactId>org.apache.sling.junit.core</artifactId>
<version>1.0.29-SNAPSHOT</version>
- <packaging>bundle</packaging>
<name>Apache Sling JUnit Core</name>
<description>Runs JUnit tests in an OSGi framework and provides the JUnit
libraries</description>
@@ -50,42 +49,15 @@
<build>
<plugins>
<plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
- <version>1.26.4</version>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
</plugin>
<plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <extensions>true</extensions>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
<configuration>
- <instructions>
-
<Bundle-Activator>org.apache.sling.junit.Activator</Bundle-Activator>
- <Export-Package>
- org.apache.sling.junit;version=1.1.0,
- org.apache.sling.junit.rules;version=1.3.0,
- org.apache.sling.junit.annotations;version=1.0.8,
- </Export-Package>
- <_exportcontents>
- junit.framework;version=${junit.version},
- org.junit;version=${junit.version},
- org.junit.matchers.*;version=${junit.version},
- org.junit.rules.*;version=${junit.version},
- org.junit.runner.*;version=${junit.version},
- org.junit.runners.*;version=${junit.version},
-
org.junit.experimental.categories.*;version=${junit.version},
- org.junit.validator.*;version=${junit.version},
- org.hamcrest;version=${hamcrest.version},
- org.hamcrest.*;version=${hamcrest.version}
- </_exportcontents>
-
<Private-Package>org.apache.sling.junit.impl.*</Private-Package>
- <Embed-Dependency>
-
org.jacoco.agent;classifier=runtime;inline=org/jacoco/agent/rt/IAgent.class,
- *;artifactId=junit,
- *;artifactId=hamcrest-core,
- *;artifactId=hamcrest-library
- </Embed-Dependency>
- </instructions>
+ <stylesheet>maven</stylesheet>
+
<excludePackageNames>org.apache.sling.junit.impl;org.apache.sling.junit.impl.*</excludePackageNames>
</configuration>
</plugin>
</plugins>
@@ -123,21 +95,60 @@
</profile>
</profiles>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>javadoc</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ <configuration>
+ <stylesheet>maven</stylesheet>
+
<excludePackageNames>org.apache.sling.junit.impl;org.apache.sling.junit.impl.*;${site.javadoc.exclude}</excludePackageNames>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>4.3.0</version>
+ <artifactId>org.osgi.annotation.versioning</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <version>4.3.0</version>
+ <artifactId>org.osgi.service.http</artifactId>
+ <version>1.2.1</version>
+ <scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.scr.annotations</artifactId>
- <scope>provided</scope>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.framework</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.servlets.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
@@ -152,10 +163,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- </dependency>
- <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.http.whiteboard</artifactId>
<version>1.0.0</version>
diff --git a/release.properties b/release.properties
new file mode 100644
index 0000000..3ad67bb
--- /dev/null
+++ b/release.properties
@@ -0,0 +1,22 @@
+#release configuration
+#Tue Jul 14 11:56:57 CEST 2020
+projectVersionPolicyId=OddEvenVersionPolicy
+scm.rollbackCommitComment=@{prefix} rollback the release of @{releaseLabel}
+remoteTagging=true
+scm.commentPrefix=[maven-release-plugin]
+releaseStrategyId=default
+scm.branchCommitComment=@{prefix} prepare branch @{releaseLabel}
+project.scm.org.apache.sling\:org.apache.sling.junit.core.url=https\://gitbox.apache.org/repos/asf?p\=sling-org-apache-sling-junit-core.git
+project.scm.org.apache.sling\:org.apache.sling.junit.core.developerConnection=scm\:git\:https\://gitbox.apache.org/repos/asf/sling-org-apache-sling-junit-core.git
+completedPhase=check-poms
+scm.url=scm\:git\:https\://gitbox.apache.org/repos/asf/sling-org-apache-sling-junit-core.git
+scm.developmentCommitComment=@{prefix} prepare for next development iteration
+scm.tagNameFormat=@{project.artifactId}-@{project.version}
+exec.additionalArguments=-Papache-release
+pushChanges=true
+project.scm.org.apache.sling\:org.apache.sling.junit.core.tag=HEAD
+exec.snapshotReleasePluginAllowed=false
+project.scm.org.apache.sling\:org.apache.sling.junit.core.connection=scm\:git\:https\://gitbox.apache.org/repos/asf/sling-org-apache-sling-junit-core.git
+preparationGoals=clean verify
+scm.releaseCommitComment=@{prefix} prepare release @{releaseLabel}
+exec.pomFileName=pom.xml
diff --git a/src/main/java/org/apache/sling/junit/Renderer.java
b/src/main/java/org/apache/sling/junit/Renderer.java
index 1b37a5e..ee6f277 100644
--- a/src/main/java/org/apache/sling/junit/Renderer.java
+++ b/src/main/java/org/apache/sling/junit/Renderer.java
@@ -17,46 +17,83 @@
package org.apache.sling.junit;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.util.Collection;
import javax.servlet.http.HttpServletResponse;
import org.junit.runner.notification.RunListener;
-/** Renderer for our servlet output. Should not be used directly for
- * rendering as it leads to non-reentrant renderers. Use only via
- * {@link RendererFactory} as {@link
org.apache.sling.junit.impl.RendererSelectorImpl} does
+/**
+ * Renderer for our servlet output. Should not be used directly for rendering
as it leads to non-reentrant renderers. Use only via {@link
+ * RendererFactory} as {@link
org.apache.sling.junit.impl.RendererSelectorImpl} does
*/
- public interface Renderer {
- /** True if this renderer applies to supplied request */
- boolean appliesTo(TestSelector selector);
-
- /** Called first to setup rendering */
- void setup(HttpServletResponse response, String pageTitle) throws
IOException, UnsupportedEncodingException;
-
- /** Called once rendering is done */
+public interface Renderer {
+ /**
+ * True if this renderer applies to supplied request
+ *
+ * @param selector a test selector
+ * @return {@code true} if this renderer applied to the provided selector,
{@code false} otherwise
+ **/
+ boolean appliesTo(TestSelector selector);
+
+ /**
+ * Called first to setup rendering
+ *
+ * @param response the http response
+ * @param pageTitle the page title
+ * @throws IOException if an error occurs
+ **/
+ void setup(HttpServletResponse response, String pageTitle) throws
IOException;
+
+ /**
+ * Called once rendering is done
+ */
void cleanup();
-
- /** Render a list of things
+
+ /**
+ * Render a list of things
+ *
* @param role describes the role of the list, must be a valid CSS class
value
+ * @param data the list to render
*/
void list(String role, Collection<String> data);
-
- /** Render general information
+
+ /**
+ * Render general information
+ *
* @param role describes the role of the list, must be a valid CSS class
value
+ * @param info the general information
*/
void info(String role, String info);
-
- /** Render a title of a specified hierarchical level */
+
+ /**
+ * Render a title of a specified hierarchical level
+ *
+ * @param level the level
+ * @param title the title
+ */
void title(int level, String title);
-
- /** Render a link to specified URL using specified HTTP method */
+
+ /**
+ * Render a link to specified URL using specified HTTP method
+ *
+ * @param info the info
+ * @param url the link to render
+ * @param method the HTTP method to use
+ */
void link(String info, String url, String method);
-
- /** Provide a RunListener for JUnit tests */
+
+ /**
+ * Provide a RunListener for JUnit tests
+ *
+ * @return the run listener
+ */
RunListener getRunListener();
-
- /** Return the extension that triggers this renderer */
+
+ /**
+ * Return the extension that triggers this renderer
+ *
+ * @return the extension that triggers this renderer
+ */
String getExtension();
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/junit/RendererSelector.java
b/src/main/java/org/apache/sling/junit/RendererSelector.java
index edb9e41..5466f97 100644
--- a/src/main/java/org/apache/sling/junit/RendererSelector.java
+++ b/src/main/java/org/apache/sling/junit/RendererSelector.java
@@ -18,11 +18,22 @@ package org.apache.sling.junit;
import java.util.Collection;
-/** Provides a Renderer to execute tests */
+/**
+ * Provides a Renderer to execute tests
+ */
public interface RendererSelector {
- /** Return all available Renderers */
+ /**
+ * Return all available Renderers
+ *
+ * @return the renderers collection
+ */
Collection<Renderer> getRenderers();
-
- /** Select a Renderer for supplied TestSelector */
+
+ /**
+ * Select a Renderer for supplied TestSelector.
+ *
+ * @param selector a test selector
+ * @return a renderer for the supplied test selector
+ */
Renderer getRenderer(TestSelector selector);
}
diff --git a/src/main/java/org/apache/sling/junit/RequestParser.java
b/src/main/java/org/apache/sling/junit/RequestParser.java
index 3404516..d680a2c 100644
--- a/src/main/java/org/apache/sling/junit/RequestParser.java
+++ b/src/main/java/org/apache/sling/junit/RequestParser.java
@@ -34,6 +34,8 @@ public class RequestParser implements TestSelector {
* TEST_SELECTOR/TEST_METHOD.EXTENSION
* or
* TEST_SELECTOR.EXTENSION
+ *
+ * @param subpath the sub-path
*/
public RequestParser(String subpath) {
@@ -104,4 +106,4 @@ public class RequestParser implements TestSelector {
public String getSelectedTestMethodName() {
return selectedMethodName;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/junit/TestSelector.java
b/src/main/java/org/apache/sling/junit/TestSelector.java
index e25d77a..9e54a45 100644
--- a/src/main/java/org/apache/sling/junit/TestSelector.java
+++ b/src/main/java/org/apache/sling/junit/TestSelector.java
@@ -16,17 +16,36 @@
*/
package org.apache.sling.junit;
-/** Used by the {@link TestsManager} to select which tests to run */
+/**
+ * Used by the {@link TestsManager} to select which tests to run
+ */
public interface TestSelector {
- /** If true, testName will be selected */
+ /**
+ * If true, testName will be selected
+ *
+ * @param testName the name of the test
+ * @return {@code true} if the test will be selected, {@code false}
otherwise
+ */
boolean acceptTestName(String testName);
-
- /** If not null, only test methods having this name are executed */
+
+ /**
+ * Returns the name of the selected test.
+ *
+ * @return the name of the selected test
+ */
String getSelectedTestMethodName();
-
- /** Return the String used to select tests */
+
+ /**
+ * Return the String used to select tests
+ *
+ * @return the string used to select the tests
+ */
String getTestSelectorString();
-
- /** Return the extension used to render results */
+
+ /**
+ * Return the extension used to render results
+ *
+ * @return the extension used to render the results
+ */
String getExtension();
}
diff --git a/src/main/java/org/apache/sling/junit/TestsManager.java
b/src/main/java/org/apache/sling/junit/TestsManager.java
index baaa1b5..497ad0b 100644
--- a/src/main/java/org/apache/sling/junit/TestsManager.java
+++ b/src/main/java/org/apache/sling/junit/TestsManager.java
@@ -18,33 +18,52 @@ package org.apache.sling.junit;
import java.util.Collection;
-import aQute.bnd.annotation.ProviderType;
+import org.osgi.annotation.versioning.ProviderType;
-/** Service that gives access to JUnit test classes */
+/**
+ * Service that gives access to JUnit test classes
+ */
@ProviderType
public interface TestsManager {
- /** Return the names of available tests
- * @param selector if null, returns all available tests.
+ /**
+ * Return the names of available tests
+ *
+ * @param selector if null, returns all available tests.
+ * @return the name of the tests
*/
- public Collection<String> getTestNames(TestSelector selector);
+ Collection<String> getTestNames(TestSelector selector);
- /** Clear our internal caches. Useful in automated testing, to make
- * sure changes introduced by recent uploads or configuration or bundles
- * changes are taken into account immediately.
+ /**
+ * Clear our internal caches. Useful in automated testing, to make sure
changes introduced by recent uploads or configuration or bundles
+ * changes are taken into account immediately.
*/
- public void clearCaches();
+ void clearCaches();
- /** Instantiate test class for specified test */
- public Class<?> getTestClass(String testName) throws
ClassNotFoundException;
+ /**
+ * Instantiate test class for specified test
+ *
+ * @param testName the test class
+ * @return an instance of the class
+ * @throws ClassNotFoundException if a class for {@code testName} cannot
be found
+ */
+ Class<?> getTestClass(String testName) throws ClassNotFoundException;
- /** List tests using supplied Renderer - does NOT call setup or cleanup
- * on renderer.
+ /**
+ * List tests using supplied Renderer - does NOT call setup or cleanup on
renderer.
+ *
+ * @param testNames the tests to list
+ * @param renderer the renderer to use
+ * @throws Exception if any error occurs
*/
- public void listTests(Collection<String> testNames, Renderer renderer)
throws Exception;
+ void listTests(Collection<String> testNames, Renderer renderer) throws
Exception;
- /** Execute tests and report results using supplied Renderer - does NOT
call setup or cleanup
- * on renderer.
- * @param selector if not null, used to select tests and test methods.
+ /**
+ * Execute tests and report results using supplied Renderer - does NOT
call setup or cleanup on renderer.
+ *
+ * @param testNames the tests
+ * @param renderer the renderer to use for the reporting
+ * @param selector the selector used to select tests and test methods (it
can be {@code null})
+ * @throws Exception if any error occurs
*/
- public void executeTests(Collection<String> testNames, Renderer renderer,
TestSelector selector) throws Exception;
+ void executeTests(Collection<String> testNames, Renderer renderer,
TestSelector selector) throws Exception;
}
diff --git a/src/main/java/org/apache/sling/junit/TestsProvider.java
b/src/main/java/org/apache/sling/junit/TestsProvider.java
index 45bab80..31e0a69 100644
--- a/src/main/java/org/apache/sling/junit/TestsProvider.java
+++ b/src/main/java/org/apache/sling/junit/TestsProvider.java
@@ -18,24 +18,38 @@ package org.apache.sling.junit;
import java.util.List;
-/** Provides tests, for example by scanning bundles,
- * finding test resources in a content repository, etc.
+/**
+ * Provides tests, for example by scanning bundles, finding test resources in
a content repository, etc.
*/
public interface TestsProvider {
- /** Return this service's PID, client might use it later
- * to instantiate a specific test.
+ /**
+ * Return this service's PID, client might use it later to instantiate a
specific test.
+ *
+ * @return the service pid
*/
String getServicePid();
-
- /** Return the list of available tests */
+
+ /**
+ * Return the list of available tests
+ *
+ * @return the list of available tests
+ */
List<String> getTestNames();
-
- /** Create a test class to execute the specified test.
- * The test executes in the same thread that calls
- * this method, to allow using ThreadLocals to pass
- * context to the test if needed. */
+
+ /**
+ * Create a test class to execute the specified test. The test executes in
the same thread that calls this method, to allow using
+ * ThreadLocals to pass context to the test if needed.
+ *
+ * @param testName the name of the test for which a test class needs to be
created
+ * @return the test class
+ * @throws ClassNotFoundException when the class cannot be created
+ */
Class<?> createTestClass(String testName) throws ClassNotFoundException;
-
- /** Return the timestamp at which our list of tests was last modified */
+
+ /**
+ * Return the timestamp at which our list of tests was last modified
+ *
+ * @return the last modified date of the tests list as a timestamp
+ */
long lastModified();
}
diff --git
a/src/main/java/org/apache/sling/junit/annotations/TestReference.java
b/src/main/java/org/apache/sling/junit/annotations/TestReference.java
index a96849d..21bb398 100644
--- a/src/main/java/org/apache/sling/junit/annotations/TestReference.java
+++ b/src/main/java/org/apache/sling/junit/annotations/TestReference.java
@@ -22,29 +22,28 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-/** Annotation used to inject services in test classes. Similar
- * to the Felix @Reference annotation, but we need RetentionPolicy.RUNTIME
- * so we cannot use that one.
- *
- * @deprecated - the {#link TeleporterRule} is a much simpler way of executing
- * server-side tests, including OSGi service injection.
+/**
+ * Annotation used to inject services in test classes. Similar to the Felix
@Reference annotation, but we need RetentionPolicy.RUNTIME so we
+ * cannot use that one.
+ *
+ * @deprecated - the {#link TeleporterRule} is a much simpler way of executing
server-side tests, including OSGi service injection.
*/
-@Target( { ElementType.FIELD })
+@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Deprecated
public @interface TestReference {
/**
- * The local name of the reference.
- * Default value is the name of the field to
- * which the annotation applies.
+ * The local name of the reference. Default value is the name of the field
to which the annotation applies.
+ *
+ * @return the local name of the reference ("" by default)
*/
String name() default "";
/**
- * The name of the service interface. This name is used by the Service
- * Component Runtime to access the service on behalf of the component.
- * The default value for is the type of the field to which
- * the annotation applies.
+ * The name of the service interface. This name is used by the Service
Component Runtime to access the service on behalf of the
+ * component. The default value for is the type of the field to which the
annotation applies.
+ *
+ * @return the service interface
*/
Class<?> referenceInterface() default AutoDetect.class;
}
diff --git a/src/main/java/org/apache/sling/junit/annotations/package-info.java
b/src/main/java/org/apache/sling/junit/annotations/package-info.java
new file mode 100644
index 0000000..46f3101
--- /dev/null
+++ b/src/main/java/org/apache/sling/junit/annotations/package-info.java
@@ -0,0 +1,22 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+@Version("1.0.8")
+package org.apache.sling.junit.annotations;
+
+import org.osgi.annotation.versioning.Version;
diff --git
a/src/main/java/org/apache/sling/junit/impl/AnnotationsProcessor.java
b/src/main/java/org/apache/sling/junit/impl/AnnotationsProcessor.java
index 93ddf95..c4a4e92 100644
--- a/src/main/java/org/apache/sling/junit/impl/AnnotationsProcessor.java
+++ b/src/main/java/org/apache/sling/junit/impl/AnnotationsProcessor.java
@@ -18,19 +18,17 @@ package org.apache.sling.junit.impl;
import java.lang.reflect.Field;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.junit.TestObjectProcessor;
import org.apache.sling.junit.annotations.TestReference;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** Processor for annotations in test classes */
-@Component(immediate=true)
-@Service
+@Component
public class AnnotationsProcessor implements TestObjectProcessor {
private Logger log = LoggerFactory.getLogger(getClass());
private BundleContext bundleContext;
@@ -93,4 +91,4 @@ public class AnnotationsProcessor implements
TestObjectProcessor {
}
return result;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/junit/impl/BundleTestsProvider.java
b/src/main/java/org/apache/sling/junit/impl/BundleTestsProvider.java
index d4367da..55a47f5 100644
--- a/src/main/java/org/apache/sling/junit/impl/BundleTestsProvider.java
+++ b/src/main/java/org/apache/sling/junit/impl/BundleTestsProvider.java
@@ -25,14 +25,13 @@ 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;
import org.apache.sling.junit.TestsProvider;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +40,6 @@ import org.slf4j.LoggerFactory;
* exported classes.
*/
@Component
-@Service
public class BundleTestsProvider implements TestsProvider, BundleListener {
private final Logger log = LoggerFactory.getLogger(getClass());
private static final String COMPONENT_NAME = "component.name";
diff --git
a/src/main/java/org/apache/sling/junit/impl/RendererSelectorImpl.java
b/src/main/java/org/apache/sling/junit/impl/RendererSelectorImpl.java
index 9ebb553..d767b29 100644
--- a/src/main/java/org/apache/sling/junit/impl/RendererSelectorImpl.java
+++ b/src/main/java/org/apache/sling/junit/impl/RendererSelectorImpl.java
@@ -21,10 +21,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import javax.servlet.ServletException;
-
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.junit.Renderer;
import org.apache.sling.junit.RendererFactory;
import org.apache.sling.junit.RendererSelector;
@@ -32,14 +28,15 @@ import org.apache.sling.junit.TestSelector;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
-import org.osgi.service.http.NamespaceException;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** Default RendererSelector */
-@Component(immediate=false)
-@Service
+@Component
public class RendererSelectorImpl implements RendererSelector {
private final Logger log = LoggerFactory.getLogger(getClass());
private final List<Renderer> renderers = new ArrayList<Renderer>();
@@ -78,14 +75,16 @@ public class RendererSelectorImpl implements
RendererSelector {
return null;
}
-
- protected void activate(ComponentContext ctx) throws ServletException,
NamespaceException {
+
+ @Activate
+ protected void activate(ComponentContext ctx) {
bundleContext = ctx.getBundleContext();
renderersTracker = new ServiceTracker(ctx.getBundleContext(),
Renderer.class.getName(), null);
renderersTracker.open();
}
- protected void deactivate(ComponentContext ctx) throws ServletException,
NamespaceException {
+ @Deactivate
+ protected void deactivate(ComponentContext ctx) {
if(renderersTracker != null) {
renderersTracker.close();
renderersTracker = null;
diff --git a/src/main/java/org/apache/sling/junit/impl/TestsManagerImpl.java
b/src/main/java/org/apache/sling/junit/impl/TestsManagerImpl.java
index f939c5f..82b5ab8 100644
--- a/src/main/java/org/apache/sling/junit/impl/TestsManagerImpl.java
+++ b/src/main/java/org/apache/sling/junit/impl/TestsManagerImpl.java
@@ -27,10 +27,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
-import java.util.function.LongUnaryOperator;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.junit.Activator;
import org.apache.sling.junit.Renderer;
import org.apache.sling.junit.SlingTestContextProvider;
@@ -44,12 +41,12 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Component;
import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
-@Service
public class TestsManagerImpl implements TestsManager {
private static final Logger log =
LoggerFactory.getLogger(TestsManagerImpl.class);
@@ -290,4 +287,4 @@ public class TestsManagerImpl implements TestsManager {
private static boolean isFragment(final Bundle bundle) {
return bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;
}
-}
\ No newline at end of file
+}
diff --git
a/src/main/java/org/apache/sling/junit/impl/servlet/HtmlRenderer.java
b/src/main/java/org/apache/sling/junit/impl/servlet/HtmlRenderer.java
index f9f570c..c0b2ce0 100644
--- a/src/main/java/org/apache/sling/junit/impl/servlet/HtmlRenderer.java
+++ b/src/main/java/org/apache/sling/junit/impl/servlet/HtmlRenderer.java
@@ -18,13 +18,10 @@ package org.apache.sling.junit.impl.servlet;
import java.io.IOException;
import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
import java.util.Collection;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.junit.Renderer;
import org.apache.sling.junit.RendererFactory;
import org.apache.sling.junit.TestSelector;
@@ -32,10 +29,11 @@ import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.ServiceScope;
/** HTML renderer for JUnit servlet */
-@Component(immediate=false)
-@Service(serviceFactory=true)
+@Component(scope = ServiceScope.BUNDLE, service = {Renderer.class,
RendererFactory.class})
public class HtmlRenderer extends RunListener implements
Renderer,RendererFactory {
public static final String EXTENSION = "html";
@@ -99,7 +97,7 @@ public class HtmlRenderer extends RunListener implements
Renderer,RendererFactor
output.println("</div>");
}
- public void setup(HttpServletResponse response, String pageTitle) throws
IOException, UnsupportedEncodingException {
+ public void setup(HttpServletResponse response, String pageTitle) throws
IOException {
if(output != null) {
throw new IllegalStateException("Output Writer already set");
}
diff --git
a/src/main/java/org/apache/sling/junit/impl/servlet/JUnitResultRenderer.java
b/src/main/java/org/apache/sling/junit/impl/servlet/JUnitResultRenderer.java
index 0ae1c31..4793eea 100644
--- a/src/main/java/org/apache/sling/junit/impl/servlet/JUnitResultRenderer.java
+++ b/src/main/java/org/apache/sling/junit/impl/servlet/JUnitResultRenderer.java
@@ -23,13 +23,12 @@ import java.util.Collection;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.junit.Renderer;
import org.apache.sling.junit.RendererFactory;
import org.apache.sling.junit.TestSelector;
import org.junit.runner.Result;
import org.junit.runner.notification.RunListener;
+import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -37,7 +36,6 @@ import org.slf4j.LoggerFactory;
* renders the serialized JUnit Result object.
*/
@Component
-@Service
public class JUnitResultRenderer extends RunListener implements
Renderer,RendererFactory {
public static final String EXTENSION = "junit_result";
@@ -92,4 +90,4 @@ public class JUnitResultRenderer extends RunListener
implements Renderer,Rendere
public void testRunFinished(Result result) throws IOException {
outputStream.writeObject(result);
}
-}
\ No newline at end of file
+}
diff --git
a/src/main/java/org/apache/sling/junit/impl/servlet/JUnitServlet.java
b/src/main/java/org/apache/sling/junit/impl/servlet/JUnitServlet.java
index 22fe833..abdb079 100644
--- a/src/main/java/org/apache/sling/junit/impl/servlet/JUnitServlet.java
+++ b/src/main/java/org/apache/sling/junit/impl/servlet/JUnitServlet.java
@@ -24,12 +24,13 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.junit.RendererSelector;
import org.apache.sling.junit.TestsManager;
import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.slf4j.Logger;
@@ -37,13 +38,17 @@ import org.slf4j.LoggerFactory;
/** Simple test runner servlet */
@SuppressWarnings("serial")
-@Component(immediate=true, metatype=true)
+@Component(
+ immediate=true,
+ property = {
+ JacocoServlet.SERVLET_PATH_NAME + "=/system/sling/junit"
+ }
+)
public class JUnitServlet extends HttpServlet {
private final Logger log = LoggerFactory.getLogger(getClass());
- @Property(value="/system/sling/junit")
- static final String SERVLET_PATH_NAME = "servlet.path";
+ public static final String SERVLET_PATH_NAME = "servlet.path";
/** Non-null if we are registered with HttpService */
private String servletPath;
@@ -59,6 +64,7 @@ public class JUnitServlet extends HttpServlet {
private volatile ServletProcessor processor;
+ @Activate
protected void activate(final ComponentContext ctx) throws
ServletException, NamespaceException {
servletPath = getServletPath(ctx);
if(servletPath == null) {
@@ -82,7 +88,8 @@ public class JUnitServlet extends HttpServlet {
return result;
}
- protected void deactivate(ComponentContext ctx) throws ServletException,
NamespaceException {
+ @Deactivate
+ protected void deactivate(ComponentContext ctx) {
if(servletPath != null) {
httpService.unregister(servletPath);
log.info("Servlet unregistered from path {}", servletPath);
@@ -104,4 +111,4 @@ public class JUnitServlet extends HttpServlet {
}
-}
\ No newline at end of file
+}
diff --git
a/src/main/java/org/apache/sling/junit/impl/servlet/JacocoServlet.java
b/src/main/java/org/apache/sling/junit/impl/servlet/JacocoServlet.java
index 5d7d574..ef3c899 100644
--- a/src/main/java/org/apache/sling/junit/impl/servlet/JacocoServlet.java
+++ b/src/main/java/org/apache/sling/junit/impl/servlet/JacocoServlet.java
@@ -16,11 +16,10 @@
*/
package org.apache.sling.junit.impl.servlet;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
import org.jacoco.agent.rt.IAgent;
import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.slf4j.Logger;
@@ -43,7 +42,10 @@ import java.util.Dictionary;
* which is also available at /system/sling/jacoco after installing this
servlet with the default settings.
*/
@SuppressWarnings("serial")
-@Component(immediate = true, metatype = true)
+@Component(immediate = true,
+ property = {
+ JacocoServlet.SERVLET_PATH_NAME + "=/system/sling/jacoco"
+ })
public class JacocoServlet extends HttpServlet {
private static final String PARAM_SESSION_ID = ":sessionId";
private static final String JMX_NAME = "org.jacoco:type=Runtime";
@@ -71,8 +73,7 @@ public class JacocoServlet extends HttpServlet {
private final Logger log = LoggerFactory.getLogger(getClass());
- @Property(value="/system/sling/jacoco")
- static final String SERVLET_PATH_NAME = "servlet.path";
+ public static final String SERVLET_PATH_NAME = "servlet.path";
/** Requests ending with this subpath send the jacoco data */
public static final String EXEC_PATH = "/exec";
@@ -117,11 +118,10 @@ public class JacocoServlet extends HttpServlet {
* Get the jacoco execution data without resetting the agent
* @param req the request
* @param resp the response
- * @throws ServletException
* @throws IOException
*/
@Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
if(EXEC_PATH.equals(req.getPathInfo())) {
final IAgent agent = getAgent();
if (agent == null) {
@@ -147,7 +147,7 @@ public class JacocoServlet extends HttpServlet {
* @throws IOException
*/
@Override
- protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
sendJacocoData(req, resp, true);
}
diff --git
a/src/main/java/org/apache/sling/junit/impl/servlet/JsonRenderer.java
b/src/main/java/org/apache/sling/junit/impl/servlet/JsonRenderer.java
index 240ebbe..1324bf3 100644
--- a/src/main/java/org/apache/sling/junit/impl/servlet/JsonRenderer.java
+++ b/src/main/java/org/apache/sling/junit/impl/servlet/JsonRenderer.java
@@ -26,8 +26,6 @@ import javax.json.JsonException;
import javax.json.stream.JsonGenerator;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.junit.Renderer;
import org.apache.sling.junit.RendererFactory;
import org.apache.sling.junit.SlingTestContextProvider;
@@ -36,12 +34,12 @@ import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
+import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** Json renderer for JUnit servlet */
-@Component(immediate=false)
-@Service
+@Component
public class JsonRenderer extends RunListener implements
Renderer,RendererFactory {
public static final String EXTENSION = "json";
@@ -200,4 +198,4 @@ public class JsonRenderer extends RunListener implements
Renderer,RendererFactor
writer.writeEnd();
}
}
-}
\ No newline at end of file
+}
diff --git
a/src/main/java/org/apache/sling/junit/impl/servlet/PlainTextRenderer.java
b/src/main/java/org/apache/sling/junit/impl/servlet/PlainTextRenderer.java
index be026a2..937bc72 100644
--- a/src/main/java/org/apache/sling/junit/impl/servlet/PlainTextRenderer.java
+++ b/src/main/java/org/apache/sling/junit/impl/servlet/PlainTextRenderer.java
@@ -23,8 +23,6 @@ import java.util.Collection;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.junit.Renderer;
import org.apache.sling.junit.RendererFactory;
import org.apache.sling.junit.TestSelector;
@@ -32,9 +30,9 @@ import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
+import org.osgi.service.component.annotations.Component;
-@Component(immediate=false)
-@Service
+@Component
/** Plain text renderer */
public class PlainTextRenderer extends RunListener implements Renderer,
RendererFactory {
public static final String EXTENSION = "txt";
@@ -133,4 +131,4 @@ public class PlainTextRenderer extends RunListener
implements Renderer, Renderer
public void testStarted(Description description) throws Exception {
super.testStarted(description);
}
-}
\ No newline at end of file
+}
diff --git
a/src/main/java/org/apache/sling/junit/impl/servlet/SlingJUnitServlet.java
b/src/main/java/org/apache/sling/junit/impl/servlet/SlingJUnitServlet.java
index 4d1efd0..2c55550 100644
--- a/src/main/java/org/apache/sling/junit/impl/servlet/SlingJUnitServlet.java
+++ b/src/main/java/org/apache/sling/junit/impl/servlet/SlingJUnitServlet.java
@@ -18,20 +18,21 @@ package org.apache.sling.junit.impl.servlet;
import java.io.IOException;
+import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.junit.RendererSelector;
import org.apache.sling.junit.TestSelector;
import org.apache.sling.junit.TestsManager;
+import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.NamespaceException;
/** Alternate entry point for testing, that uses
@@ -48,13 +49,12 @@ import org.osgi.service.http.NamespaceException;
* with this resource type.
*/
@SuppressWarnings("serial")
-@Component(metatype=true)
-@Service(value=javax.servlet.Servlet.class)
-@Properties({
- @Property(name="sling.servlet.resourceTypes",
value="sling/junit/testing"),
- @Property(name="sling.servlet.extensions", value="junit"),
- @Property(name="sling.servlet.methods", value={"GET","POST"})
-})
+@Component(service = Servlet.class)
+@SlingServletResourceTypes(
+ resourceTypes = "sling/junit/testing",
+ extensions = "junit",
+ methods = {"GET", "POST"}
+)
public class SlingJUnitServlet extends HttpServlet {
public static final String EXTENSION = ".junit";
@@ -67,7 +67,8 @@ public class SlingJUnitServlet extends HttpServlet {
private volatile ServletProcessor processor;
- protected void activate(final ComponentContext ctx) throws
ServletException, NamespaceException {
+ @Activate
+ protected void activate(final ComponentContext ctx) {
this.processor = new ServletProcessor(testsManager, rendererSelector) {
@Override
protected String getTestSelectionPath(HttpServletRequest request) {
@@ -98,7 +99,8 @@ public class SlingJUnitServlet extends HttpServlet {
};
}
- protected void deactivate(ComponentContext ctx) throws ServletException,
NamespaceException {
+ @Deactivate
+ protected void deactivate(ComponentContext ctx) {
this.processor = null;
}
diff --git
a/src/main/java/org/apache/sling/junit/impl/servlet/TestLogServlet.java
b/src/main/java/org/apache/sling/junit/impl/servlet/TestLogServlet.java
index d260760..38e3ca8 100644
--- a/src/main/java/org/apache/sling/junit/impl/servlet/TestLogServlet.java
+++ b/src/main/java/org/apache/sling/junit/impl/servlet/TestLogServlet.java
@@ -34,16 +34,15 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
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.Deactivate;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.junit.runner.Description;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
@@ -57,9 +56,13 @@ import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Layout;
import ch.qos.logback.core.read.CyclicBufferAppender;
-@Component(immediate=true, metatype=true,
- label = "Apache Sling Test Log Collector",
- description = "Servlet that exposes logs collected for a particular
test execution"
+@Component(
+ immediate=true,
+ property = {
+ TestLogServlet.SERVLET_PATH_NAME + "=/system/sling/testlog",
+ TestLogServlet.LOG_BUFFER_SIZE + ":Integer=" +
TestLogServlet.DEFAULT_SIZE,
+ TestLogServlet.PROP_MSG_PATTERN + "=" +
TestLogServlet.DEFAULT_PATTERN
+ }
)
public class TestLogServlet extends HttpServlet {
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -70,23 +73,13 @@ public class TestLogServlet extends HttpServlet {
public static final String TEST_NAME = "X-Sling-TestName";
public static final String TEST_CLASS = "X-Sling-TestClass";
- @Property(value="/system/sling/testlog")
- static final String SERVLET_PATH_NAME = "servlet.path";
-
- static final int DEFAULT_SIZE = 1000;
- @Property(intValue = DEFAULT_SIZE,
- label = "Log Buffer Size",
- description = "Size of in memory log buffer. Only recent logs upto
buffer size would be retained"
- )
- static final String LOG_BUFFER_SIZE = "log.buffer.size";
+ public static final String SERVLET_PATH_NAME = "servlet.path";
- private static final String DEFAULT_PATTERN = "%d{dd.MM.yyyy HH:mm:ss.SSS}
*%level* [%thread] %logger %msg%n";
+ public static final int DEFAULT_SIZE = 1000;
+ public static final String LOG_BUFFER_SIZE = "log.buffer.size";
- @Property(label = "Log Pattern",
- description = "Message Pattern for formatting the log messages",
- value = DEFAULT_PATTERN
- )
- private static final String PROP_MSG_PATTERN = "logPattern";
+ public static final String DEFAULT_PATTERN = "%d{dd.MM.yyyy HH:mm:ss.SSS}
*%level* [%thread] %logger %msg%n";
+ public static final String PROP_MSG_PATTERN = "logPattern";
/** Non-null if we are registered with HttpService */
private String servletPath;
diff --git a/src/main/java/org/apache/sling/junit/impl/servlet/XmlRenderer.java
b/src/main/java/org/apache/sling/junit/impl/servlet/XmlRenderer.java
index ad64e30..50a297b 100644
--- a/src/main/java/org/apache/sling/junit/impl/servlet/XmlRenderer.java
+++ b/src/main/java/org/apache/sling/junit/impl/servlet/XmlRenderer.java
@@ -38,8 +38,6 @@ import javax.xml.transform.stream.StreamResult;
import junit.runner.BaseTestRunner;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.junit.Renderer;
import org.apache.sling.junit.RendererFactory;
import org.apache.sling.junit.TestSelector;
@@ -47,13 +45,13 @@ import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
+import org.osgi.service.component.annotations.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
/** XML renderer for JUnit servlet */
-@Component(immediate=false)
-@Service
+@Component
public class XmlRenderer extends RunListener implements Renderer,
RendererFactory {
/**
diff --git a/src/main/java/org/apache/sling/junit/package-info.java
b/src/main/java/org/apache/sling/junit/package-info.java
new file mode 100644
index 0000000..374ef48
--- /dev/null
+++ b/src/main/java/org/apache/sling/junit/package-info.java
@@ -0,0 +1,22 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+@Version("1.1.1")
+package org.apache.sling.junit;
+
+import org.osgi.annotation.versioning.Version;
diff --git a/src/main/java/org/apache/sling/junit/rules/TeleporterRule.java
b/src/main/java/org/apache/sling/junit/rules/TeleporterRule.java
index 5a36654..b051aa4 100644
--- a/src/main/java/org/apache/sling/junit/rules/TeleporterRule.java
+++ b/src/main/java/org/apache/sling/junit/rules/TeleporterRule.java
@@ -22,62 +22,79 @@ import java.util.List;
import org.apache.sling.junit.Activator;
import org.junit.rules.ExternalResource;
-/** JUnit Rule used to teleport a server-side test to a Sling instance
- * to execute it there. See the launchpad/integration-tests module for
- * usage examples (coming soon).
- * A concrete TeleporterRule class is selected to match the different
required
- * behaviors of the server-side and client-side variants of this rule.
- * The junit.core module only contains the server-side code, to minimize
- * its dependencies, and the client-side part is in the sling
testing.teleporter
- * module.
+/**
+ * JUnit Rule used to teleport a server-side test to a Sling instance to
execute it there. See the launchpad/integration-tests module for
+ * usage examples (coming soon). A concrete TeleporterRule class is selected
to match the different required behaviors of the server-side
+ * and client-side variants of this rule. The junit.core module only contains
the server-side code, to minimize its dependencies, and the
+ * client-side part is in the sling testing.teleporter module.
*/
public abstract class TeleporterRule extends ExternalResource {
protected Class<?> classUnderTest;
- /** Name of the implementation class to use when running on the client
side */
+ /**
+ * Name of the implementation class to use when running on the client side
+ */
public static final String CLIENT_CLASS =
"org.apache.sling.testing.teleporter.client.ClientSideTeleporter";
-
- /** Class name pattern for Customizers */
+
+ /**
+ * Class name pattern for Customizers
+ */
public static final String CUSTOMIZER_PATTERN =
"org.apache.sling.junit.teleporter.customizers.<NAME>Customizer";
-
+
private static final String DEFAULT_CUSTOMIZER_CLASS =
"org.apache.sling.testing.teleporter.client.DefaultPropertyBasedCustomizer";
-
- /** Customizer is used client-side to setup the server URL and other
parameters */
+
+ /**
+ * Customizer is used client-side to setup the server URL and other
parameters
+ */
public static interface Customizer {
void customize(TeleporterRule t, String options);
}
+
private String clientSetupOptions;
protected List<String> embeddedResourcePaths = new ArrayList<String>();
- /** Meant to be instantiated via {@link #forClass} */
+ /**
+ * Meant to be instantiated via {@link #forClass}
+ */
protected TeleporterRule() {
}
-
+
protected void setClassUnderTest(Class<?> c) {
this.classUnderTest = c;
}
- /** True if running on the server-side. */
+ /**
+ * True if running on the server-side.
+ *
+ * @return {@code true} if running server-side, {@code false} otherwise
+ */
public static boolean isServerSide() {
return Activator.getBundleContext() != null;
}
-
- /** Build a TeleporterRule for the given class, with no client setup
options */
- public static TeleporterRule forClass(Class <?> classUnderTest) {
+
+ /**
+ * Build a TeleporterRule for the given class, with no client setup
options.
+ *
+ * @param classUnderTest the class under test
+ * @return the teleporter rule
+ */
+ public static TeleporterRule forClass(Class<?> classUnderTest) {
return forClass(classUnderTest, null);
}
-
- /** Build a TeleporterRule for the given class, with optional
clientSetupOptions.
- *
- * @param clientSetupOptions If supplied, the part of that string before
the first colon
- * is used as the class name of a Customizer (or shorthand for that if it
contains no dots).
- * The rest of the string is then passed to the Customizer so that it can
be used to define
- * options (which server to run the test on, etc)
+
+ /**
+ * Build a TeleporterRule for the given class, with optional
clientSetupOptions.
+ *
+ * @param classUnderTest the class under test
+ * @param clientSetupOptions If supplied, the part of that string before
the first colon is used as the class name of a Customizer (or
+ * shorthand for that if it contains no dots).
The rest of the string is then passed to the Customizer so that
+ * it can be used to define options (which
server to run the test on, etc)
+ * @return the teleporter rule
*/
- public static TeleporterRule forClass(Class <?> classUnderTest, String
clientSetupOptions) {
+ public static TeleporterRule forClass(Class<?> classUnderTest, String
clientSetupOptions) {
TeleporterRule result = null;
-
- if(isServerSide()) {
+
+ if (isServerSide()) {
result = new ServerSideTeleporter(classUnderTest);
} else {
// Client-side. Instantiate the class dynamically to
@@ -85,33 +102,35 @@ public abstract class TeleporterRule extends
ExternalResource {
// it's running on the server side
try {
result = createInstance(TeleporterRule.class, CLIENT_CLASS);
- } catch(Exception e) {
+ } catch (Exception e) {
throw new RuntimeException("Unable to instantiate Teleporter
client " + CLIENT_CLASS, e);
}
}
-
+
result.clientSetupOptions = clientSetupOptions;
result.setClassUnderTest(classUnderTest);
return result;
}
- /** Use a Customizer, if one was defined, to customize this Rule */
+ /**
+ * Use a Customizer, if one was defined, to customize this Rule
+ */
protected void customize() {
// As with the client-side rule implementation, instantiate our
Customizer
// dynamically to avoid requiring its class on the server side.
- if(!isServerSide()) {
- if((clientSetupOptions != null) && !clientSetupOptions.isEmpty()) {
+ if (!isServerSide()) {
+ if ((clientSetupOptions != null) && !clientSetupOptions.isEmpty())
{
String customizerClassName = clientSetupOptions;
String customizerOptions = "";
final int firstColon = clientSetupOptions.indexOf(":");
- if(firstColon > 0) {
+ if (firstColon > 0) {
customizerClassName = clientSetupOptions.substring(0,
firstColon);
customizerOptions =
clientSetupOptions.substring(firstColon + 1);
}
// If a short name is used, transform it using our pattern.
// Simplifies referring to these customizers in test code,
// without having to make the customizer classes accessible to
this bundle
- if(!customizerClassName.contains(".")) {
+ if (!customizerClassName.contains(".")) {
customizerClassName = CUSTOMIZER_PATTERN.replace("<NAME>",
customizerClassName);
}
createInstance(Customizer.class,
customizerClassName).customize(this, customizerOptions);
@@ -121,34 +140,48 @@ public abstract class TeleporterRule extends
ExternalResource {
}
}
}
-
+
@SuppressWarnings("unchecked")
protected static <T> T createInstance(Class<T> objectClass, String
className) {
try {
- return
(T)(TeleporterRule.class.getClassLoader().loadClass(className).newInstance());
- } catch(Exception e) {
+ return (T)
(TeleporterRule.class.getClassLoader().loadClass(className).newInstance());
+ } catch (Exception e) {
throw new RuntimeException("Unable to instantiate " + className,
e);
}
}
-
- /** If running on the server side, get an OSGi service */
- public final <T> T getService (Class<T> serviceClass) {
+
+ /**
+ * If running on the server side, get an OSGi service
+ *
+ * @param <T> the service type
+ * @param serviceClass the class
+ * @return the service instance, if one was found, or {@code null}
+ */
+ public final <T> T getService(Class<T> serviceClass) {
return getService(serviceClass, null);
}
-
- /** If running on the server side, get an OSGi service specified by an
LDAP service filter */
- public <T> T getService (Class<T> serviceClass, String ldapFilter) {
+
+ /**
+ * If running on the server side, get an OSGi service specified by an LDAP
service filter
+ *
+ * @param <T> the service type
+ * @param serviceClass the class
+ * @param ldapFilter a filter to select the service
+ * @return the service instance, if one was found, or {@code null}
+ */
+ public <T> T getService(Class<T> serviceClass, String ldapFilter) {
throw new UnsupportedOperationException("This TeleporterRule does not
implement getService()");
}
-
- /** Tell the concrete teleporter to embed resources, based on their path,
in
- * the test bundle.
- * @param paths 0..N resource paths to add to the current rule. A path
that
- * ends with a / causes all resources found under it
- * to be recursively embedded as well.
+
+ /**
+ * Tell the concrete teleporter to embed resources, based on their path,
in the test bundle.
+ *
+ * @param paths 0..N resource paths to add to the current rule. A path
that ends with a / causes all resources found under it to be
+ * recursively embedded as well.
+ * @return this enhanced rule
*/
- public TeleporterRule withResources(String ...paths) {
- for(String path : paths) {
+ public TeleporterRule withResources(String... paths) {
+ for (String path : paths) {
embeddedResourcePaths.add(path);
}
return this;
diff --git a/src/main/java/org/apache/sling/junit/rules/package-info.java
b/src/main/java/org/apache/sling/junit/rules/package-info.java
new file mode 100644
index 0000000..862759b
--- /dev/null
+++ b/src/main/java/org/apache/sling/junit/rules/package-info.java
@@ -0,0 +1,22 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+@Version("1.3.0")
+package org.apache.sling.junit.rules;
+
+import org.osgi.annotation.versioning.Version;
diff --git a/src/main/resources/OSGI-INF/l10n/metatype.properties
b/src/main/resources/OSGI-INF/l10n/metatype.properties
deleted file mode 100644
index 273bdb7..0000000
--- a/src/main/resources/OSGI-INF/l10n/metatype.properties
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# 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.
-#
-
-org.apache.sling.junit.impl.servlet.JUnitServlet.name = \
- Apache Sling JUnit Servlet
-org.apache.sling.junit.impl.servlet.JUnitServlet.description = \
- Servlet that executes JUnit tests registered by \
- TestsProvider services
-
-servlet.disabled.name = Disable servlet
-servlet.disabled.description = If true, the servlet will \
- be disabled
-
-servlet.path.name = Servlet path
-servlet.path.description = The path at which the servlet is mounted
\ No newline at end of file