You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2017/12/29 14:18:11 UTC
[sling-site] branch master updated: extend documentation for Sling
Testing PaxExam
This is an automated email from the ASF dual-hosted git repository.
olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-site.git
The following commit(s) were added to refs/heads/master by this push:
new 6d8c532 extend documentation for Sling Testing PaxExam
6d8c532 is described below
commit 6d8c53216c0e411fbf36550e3ac8f598c659a61e
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Fri Dec 29 15:17:28 2017 +0100
extend documentation for Sling Testing PaxExam
---
.../documentation/development/testing-paxexam.md | 73 ++++++++++++++++++++--
.../jbake/content/documentation/pax-exam-utils.md | 2 +
.../testing-sling-based-applications.md | 6 +-
3 files changed, 74 insertions(+), 7 deletions(-)
diff --git a/src/main/jbake/content/documentation/development/testing-paxexam.md b/src/main/jbake/content/documentation/development/testing-paxexam.md
index 78d34e0..4f64acf 100644
--- a/src/main/jbake/content/documentation/development/testing-paxexam.md
+++ b/src/main/jbake/content/documentation/development/testing-paxexam.md
@@ -129,7 +129,7 @@ Create a test class (extend `TestSupport` to use helper methods and `Option`s) a
public Option[] configuration() {
return new Option[]{
baseConfiguration(), // from TestSupport
- quickstart(),
+ slingQuickstart(),
// build artifact
testBundle("bundle.filename"), // from TestSupport
// testing
@@ -137,17 +137,17 @@ Create a test class (extend `TestSupport` to use helper methods and `Option`s) a
};
}
- protected Option quickstart() {
+ protected Option slingQuickstart() {
final String workingDirectory = workingDirectory(); // from TestSupport
final int httpPort = findFreePort(); // from TestSupport
return composite(
slingQuickstartOakTar(workingDirectory, httpPort), // from SlingOptions
slingModels(), // from SlingOptions (for illustration)
- slingScriptingThymeleaf() // from SlingOptions (for illustration)
+ slingScripting() // from SlingOptions (for illustration)
);
}
-The above configuration provides all bundles and OSGi configurations to run a Sling Quickstart setup with Sling Models and Sling Scripting Thymeleaf.
+The above configuration provides all bundles and OSGi configurations to run a Sling Quickstart setup with Sling Models and Sling Scripting.
**NOTE:** When using `slingQuickstartOakTar()` or `slingQuickstartOakMongo()` without _working directory_, _HTTP port_ and _Mongo URI_ make sure to clean up file system and database after each test and do not run tests in parallel to prevent interferences between tests.
@@ -167,6 +167,71 @@ To use a version from project (`pom.xml`) use `setVersionFromProject(String, Str
## Examples
+### Set up a tailored Sling instance
+
+The `FreemarkerTestSupport` below from [Scripting FreeMarker](https://github.com/apache/sling-org-apache-sling-scripting-freemarker) shows how to set up a tailored Sling instance to test Scripting FreeMarker itself.
+
+`@Inject`ing `ServletResolver`, `SlingRequestProcessor`, `AuthenticationSupport`, `HttpService` and `ScriptEngineFactory` ensures testing is delayed until those services are available.
+
+The `@ProbeBuilder` annotated method modifies the [probe](https://ops4j1.jira.com/wiki/spaces/PAXEXAM4/pages/54263860/Concepts#Concepts-Probe) for Sling by adding `Export-Package`, `Sling-Model-Packages` and `Sling-Initial-Content` headers.
+
+ public abstract class FreemarkerTestSupport extends TestSupport {
+
+ @Inject
+ protected ServletResolver servletResolver;
+
+ @Inject
+ protected SlingRequestProcessor slingRequestProcessor;
+
+ @Inject
+ protected AuthenticationSupport authenticationSupport;
+
+ @Inject
+ protected HttpService httpService;
+
+ @Inject
+ @Filter(value = "(names=freemarker)")
+ protected ScriptEngineFactory scriptEngineFactory;
+
+ public Option baseConfiguration() {
+ return composite(
+ super.baseConfiguration(),
+ slingQuickstart(),
+ // Sling Scripting FreeMarker
+ testBundle("bundle.filename"),
+ mavenBundle().groupId("org.freemarker").artifactId("freemarker").versionAsInProject(),
+ mavenBundle().groupId("org.apache.servicemix.specs").artifactId("org.apache.servicemix.specs.jaxp-api-1.4").versionAsInProject(),
+ // testing
+ slingResourcePresence(),
+ mavenBundle().groupId("org.jsoup").artifactId("jsoup").versionAsInProject(),
+ mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").versionAsInProject(),
+ junitBundles()
+ );
+ }
+
+ @ProbeBuilder
+ public TestProbeBuilder probeConfiguration(final TestProbeBuilder testProbeBuilder) {
+ testProbeBuilder.setHeader(Constants.EXPORT_PACKAGE, "org.apache.sling.scripting.freemarker.it.app");
+ testProbeBuilder.setHeader("Sling-Model-Packages", "org.apache.sling.scripting.freemarker.it.app");
+ testProbeBuilder.setHeader("Sling-Initial-Content", String.join(",",
+ "apps/freemarker;path:=/apps/freemarker;overwrite:=true;uninstall:=true",
+ "content;path:=/content;overwrite:=true;uninstall:=true"
+ ));
+ return testProbeBuilder;
+ }
+
+ protected Option slingQuickstart() {
+ final int httpPort = findFreePort();
+ final String workingDirectory = workingDirectory();
+ return composite(
+ slingQuickstartOakTar(workingDirectory, httpPort),
+ slingModels(),
+ slingScripting()
+ );
+ }
+
+ }
+
### Testing HTML over HTTP with jsoup
The `SimpleIT` below from [Scripting FreeMarker](https://github.com/apache/sling-org-apache-sling-scripting-freemarker) shows how to test HTML rendering with [jsoup](https://jsoup.org). The use of [ResourcePresence](https://github.com/apache/sling-org-apache-sling-resource-presence) ensures that tests are delayed until Sling's repository is ready to serve the `Resource` at given path.
diff --git a/src/main/jbake/content/documentation/pax-exam-utils.md b/src/main/jbake/content/documentation/pax-exam-utils.md
index 929819a..9fee1ea 100644
--- a/src/main/jbake/content/documentation/pax-exam-utils.md
+++ b/src/main/jbake/content/documentation/pax-exam-utils.md
@@ -4,6 +4,8 @@ status=published
tags=development,testing
~~~~~~
+**NOTE: See [Testing PaxExam](/documentation/development/testing-paxexam.html) for advanced and up-to-date test support.**
+
Utilities to help testing Sling components with Pax Exam are available at
[https://github.com/apache/sling-org-apache-sling-paxexam-util](https://github.com/apache/sling-org-apache-sling-paxexam-util)
diff --git a/src/main/jbake/content/documentation/tutorials-how-tos/testing-sling-based-applications.md b/src/main/jbake/content/documentation/tutorials-how-tos/testing-sling-based-applications.md
index a2cf416..b184708 100644
--- a/src/main/jbake/content/documentation/tutorials-how-tos/testing-sling-based-applications.md
+++ b/src/main/jbake/content/documentation/tutorials-how-tos/testing-sling-based-applications.md
@@ -52,11 +52,11 @@ such as the [PrivateAccessor](http://junit-addons.sourceforge.net/junitx/util/Pr
## Pax Exam
-[Pax Exam](http://team.ops4j.org/wiki/display/paxexam/Pax+Exam) allows you to easily start an OSGi framework during execution of a JUnit test suite.
+[Pax Exam](https://ops4j1.jira.com/wiki/spaces/PAXEXAM4/overview) is an in-container testing framework for OSGi, Java EE and CDI.
-We currently use it for our [Sling installer integration tests](https://github.com/apache/sling-org-apache-sling-installer-it) for example. As parts of the installer interact directly with the OSGi framework, it felt safer to test it in a realistic situation rather than mock everything.
+Apache Sling [Testing PaxExam](/documentation/development/testing-paxexam.html) provides advanced and up-to-date test support for **in-container** and remote **testing over HTTP** with **real** Sling instances.
-Such tests are obviously slower than plain unit tests and tests that use mocks. Our installer integration tests, using Pax Exam, take about a minute to execute on a 2010 macbook pro.
+Plain Pax Exam is still used for our [Sling installer integration tests](https://github.com/apache/sling-org-apache-sling-installer-it) for example. As parts of the installer interact directly with the OSGi framework, it felt safer to test it in a realistic situation rather than mock everything.
## Server-side JUnit tests
--
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].