You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bu...@apache.org on 2015/09/22 11:55:51 UTC

svn commit: r966323 - in /websites/staging/sling/trunk/content: ./ documentation/bundles/org-apache-sling-junit-bundles.html documentation/development/sling-testing-tools.html

Author: buildbot
Date: Tue Sep 22 09:55:48 2015
New Revision: 966323

Log:
Staging update by buildbot for sling

Modified:
    websites/staging/sling/trunk/content/   (props changed)
    websites/staging/sling/trunk/content/documentation/bundles/org-apache-sling-junit-bundles.html
    websites/staging/sling/trunk/content/documentation/development/sling-testing-tools.html

Propchange: websites/staging/sling/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Tue Sep 22 09:55:48 2015
@@ -1 +1 @@
-1704495
+1704502

Modified: websites/staging/sling/trunk/content/documentation/bundles/org-apache-sling-junit-bundles.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/bundles/org-apache-sling-junit-bundles.html (original)
+++ websites/staging/sling/trunk/content/documentation/bundles/org-apache-sling-junit-bundles.html Tue Sep 22 09:55:48 2015
@@ -114,8 +114,14 @@ h2:hover > .headerlink, h3:hover > .head
 h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
 <p>This is an overview of the Sling bundles that provide support for server-side JUnit tests. </p>
 <h2 id="orgapacheslingjunitcore-server-side-junit-tests-support">org.apache.sling.junit.core: server-side JUnit tests support<a class="headerlink" href="#orgapacheslingjunitcore-server-side-junit-tests-support" title="Permanent link">&para;</a></h2>
-<p>The <code>org.apache.sling.junit.remote</code> bundle provides a <code>JUnitServlet</code> that runs JUnit tests found
-in bundles. </p>
+<p>This bundle provides a <code>JUnitServlet</code> that runs JUnit tests found in bundles. </p>
+<p>To make tests available to that servlet, the bundle that contains them must point to them
+with a <code>Sling-Test-Regexp</code> bundle header that defines a regular expression that matches
+the test class names, like for example:</p>
+<div class="codehilite"><pre><span class="n">Sling</span><span class="o">-</span><span class="n">Test</span><span class="o">-</span><span class="n">Regexp</span><span class="p">=</span>`<span class="n">com</span><span class="p">.</span><span class="n">example</span><span class="o">.*</span><span class="n">ServerSideTest</span>
+</pre></div>
+
+
 <div class="warning">
 Note that the JUnitServlet does not require authentication, so it would allow any client to run tests. The servlet can be disabled by configuration if needed, but in general the `/system` path should not be accessible to website visitors anyway.
 </div>
@@ -124,13 +130,31 @@ Note that the JUnitServlet does not requ
 For tighter integration with Sling, the alternate `SlingJUnitServlet` is registered with the `sling/junit/testing` resource type and `.junit` selector, if the bundle is running in a Sling system. Using this servlet instead of the plain JUnitServlet also allows Sling authentication to be used for running the tests, and the standard Sling request processing is used, including servlet filters for example.
 </div>
 
-<p>To make tests available to that servlet, the bundle that contains them must point to them
-with a <code>Sling-Test-Regexp</code> bundle header that defines a regular expression that matches
-the test class names, like <code>Sling-Test-Regexp=</code>com.example.*ServerSideTest` for example.</p>
 <p>The <code>TeleporterRule</code> supplied by this bundle makes it easy to write such tests, using this
-rule they can be mixed with other tests in the source code if that's convenient. </p>
+rule they can be mixed with other tests in the source code if that's convenient. Here's a basic example of such a
+"teleported" test that accesses OSGi services:</p>
+<div class="codehilite"><pre><span class="n">public</span> <span class="n">class</span> <span class="n">BasicTeleporterTest</span> <span class="p">{</span>
+
+    <span class="p">@</span><span class="n">Rule</span>
+    <span class="n">public</span> <span class="n">final</span> <span class="n">TeleporterRule</span> <span class="n">teleporter</span> <span class="p">=</span> <span class="n">TeleporterRule</span><span class="p">.</span><span class="n">forClass</span><span class="p">(</span><span class="n">getClass</span><span class="p">(),</span> &quot;<span class="n">Launchpad</span>&quot;<span class="p">);</span>
+
+    <span class="p">@</span><span class="n">Test</span>
+    <span class="n">public</span> <span class="n">void</span> <span class="n">testConfigAdmin</span><span class="p">()</span> <span class="n">throws</span> <span class="n">IOException</span> <span class="p">{</span>
+        <span class="n">final</span> <span class="n">String</span> <span class="n">pid</span> <span class="p">=</span> &quot;<span class="n">TEST_</span>&quot; <span class="o">+</span> <span class="n">getClass</span><span class="p">().</span><span class="n">getName</span><span class="p">()</span> <span class="o">+</span> <span class="n">UUID</span><span class="p">.</span><span class="n">randomUUID</span><span class="p">();</span>
+
+        <span class="n">final</span> <span class="n">ConfigurationAdmin</span> <span class="n">ca</span> <span class="p">=</span> <span class="n">teleporter</span><span class="p">.</span><span class="n">getService</span><span class="p">(</span><span class="n">ConfigurationAdmin</span><span class="p">.</span><span class="n">class</span><span class="p">);</span>
+        <span class="n">assertNotNull</span><span class="p">(</span>&quot;<span class="n">Teleporter</span> <span class="n">should</span> <span class="n">provide</span> <span class="n">a</span> <span class="n">ConfigurationAdmin</span>&quot;<span class="p">,</span> <span class="n">ca</span><span class="p">);</span>
+
+        <span class="n">final</span> <span class="n">Configuration</span> <span class="n">cfg</span> <span class="p">=</span> <span class="n">ca</span><span class="p">.</span><span class="n">getConfiguration</span><span class="p">(</span><span class="n">pid</span><span class="p">);</span>
+        <span class="n">assertNotNull</span><span class="p">(</span>&quot;<span class="n">Expecting</span> <span class="n">to</span> <span class="n">get</span> <span class="n">a</span> <span class="n">Configuration</span>&quot;<span class="p">,</span> <span class="n">cfg</span><span class="p">);</span>
+        <span class="n">assertEquals</span><span class="p">(</span>&quot;<span class="n">Expecting</span> <span class="n">the</span> <span class="n">correct</span> <span class="n">pid</span>&quot;<span class="p">,</span> <span class="n">pid</span><span class="p">,</span> <span class="n">cfg</span><span class="p">.</span><span class="n">getPid</span><span class="p">());</span>
+    <span class="p">}</span>
+<span class="p">}</span>
+</pre></div>
+
+
 <p>Using the teleporter module described below, the <code>TeleporterRule</code> creates a temporary bundle 
-that contains the  test code along with any required classes, adds the appropriate 
+that contains the test class along with any classes required to run it, adds the appropriate 
 <code>Sling-Test-Regexp</code> header to it, installs the bundle, runs the test via the <code>JUnitServlet</code>,
 collects the results and uninstalls the bundle. This happens quickly as the temporary bundle is
 very small, and both the client-side and server-side parts of the test can be debugged easily
@@ -143,17 +167,17 @@ package. </p>
 <p>To try the JUnitServlet interactively, you can install the 
 <a href="http://svn.apache.org/repos/asf/sling/trunk/testing/samples/sample-tests">org.apache.sling.testing.samples.sampletests</a> 
 bundle, or any other bundle that contains tests and a <code>Sling-Test-Regexp</code> bundle header that points to them, as
-described above. Or use the TeleporterRule`and set a breakpoint in the tests execution, when the test bundle ins
-installed and will be listed by the test servlet.</p>
-<p>To list the available tests, open http://localhost:8080/system/sling/junit/ . The servlet shows available tests, 
-and allows you to execute them via a POST request.</p>
+described above. Or use the <code>TeleporterRule</code>and set a breakpoint in the tests execution, when the test bundle in
+installed and listed by the test servlet.</p>
+<p>To list the available tests, open <code>/system/sling/junit/</code> in your browser. The servlet shows available tests and allows 
+you to execute them via a POST request.</p>
 <p>Adding a path allows you to select a specific subset of tests, as in 
-http://localhost:8080/system/sling/junit/org.apache.sling.junit.remote.html</p>
+<code>/system/sling/junit/org.apache.sling.junit.remote.html</code></p>
 <p>The JUnitServlet provides various output formats, including in particular JSON, see 
- http://localhost:8080/system/sling/junit/.json for example.</p>
+ <code>/system/sling/junit/.json</code> for example.</p>
 <h2 id="orgapacheslingjunitteleporter-client-side-teleporterrule-support">org.apache.sling.junit.teleporter: client-side TeleporterRule support<a class="headerlink" href="#orgapacheslingjunitteleporter-client-side-teleporterrule-support" title="Permanent link">&para;</a></h2>
-<p>This module mostly provides the <code>ClientSideTeleporter</code> which the <code>TeleporterRule</code> uses to teleport the tests
-to the server side. It is only used on the client as a dependency when running the tests.</p>
+<p>This module provides the <code>ClientSideTeleporter</code> which the <code>TeleporterRule</code> uses to teleport the tests
+to the server side. It is not a bundle, as it's used on the client only, as a dependency when running the tests.</p>
 <p>A <code>TeleporterRule.Customizer</code> is used to setup the <code>ClientSideTeleporter</code>. That customizer is instantiated dynamically
 based on a String passed to the <code>TeleporterRule</code> creation code.</p>
 <p>As an example from our <code>launchpad/integration-tests</code> module, this call</p>
@@ -162,18 +186,18 @@ based on a String passed to the <code>Te
 
 
 <p>Causes the <code>TeleporterRule</code> to use the <code>org.apache.sling.junit.teleporter.customizers.LaunchpadCustomizer</code> class
-to setup the <code>ClientSideTeleporter</code>, and passes the "author" string to it as an option. This can be used to select 
-which server to run the tests on, in this case the customizer could look for a server that runs with the "author" 
-run mode.</p>
+to setup the <code>ClientSideTeleporter</code>, and passes the "author" string to it as an option. Although our current <code>LaunchpadCustomizer</code>
+does not use this options string, it is meant to select a specific server (of family of servers) to run the tests on.</p>
 <p>The options string can also use a full class name instead of the <code>Launchpad</code> short form used here, if needed. The part
 of that string that follows the first colon is passed to the customizer as is.</p>
 <p>Using Strings for customization reduces the coupling with the <code>junit.core</code> bundle, as it does not need to know those
 classes which are used only on the client side when running tests. </p>
 <h2 id="orgapacheslingjunithealthcheck-run-junit-tests-as-sling-health-checks">org.apache.sling.junit.healthcheck: run JUnit tests as Sling Health Checks<a class="headerlink" href="#orgapacheslingjunithealthcheck-run-junit-tests-as-sling-health-checks" title="Permanent link">&para;</a></h2>
 <p>This bundle allows JUnit tests to run as <a href="/documentation/bundles/sling-health-check-tool.html">Sling Health Checks</a>,
-which can be useful when defining smoke tests for example, allowing them to be used both at build time and run time. </p>
+which can be useful when defining smoke tests for example, allowing them to be used both at build time and run time.</p>
+<p>See the <code>JUnitHealthCheck</code> class for details. </p>
 <h2 id="orgapacheslingjunitscriptable-scriptable-server-side-tests">org.apache.sling.junit.scriptable: scriptable server-side tests<a class="headerlink" href="#orgapacheslingjunitscriptable-scriptable-server-side-tests" title="Permanent link">&para;</a></h2>
-<p>This bundle allows Sling scripts to be executed from the <code>JUnitServlet</code>, as follows:</p>
+<p>This bundle allows Sling scripts to be executed from the <code>JUnitServlet</code> as JUnit tests, as follows:</p>
 <ul>
 <li>A node that has the <code>sling:Test</code> mixin is a scriptable test node.</li>
 <li>For security reasons, scriptable test nodes are only executed as tests if they are found under <code>/libs</code> or <code>/apps</code>, or more precisely under a path that's part of Sling's <code>ResourceResolver</code> search path.</li>
@@ -212,7 +236,7 @@ same request again.      </p>
 but using the newer <code>TeleporterRule</code> described above is much simpler. As a result, this bundle
 should only be needed for existing tests that were written using its mechanisms.   </p>
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1704493 by bdelacretaz on Tue, 22 Sep 2015 09:40:41 +0000
+        Rev. 1704502 by bdelacretaz on Tue, 22 Sep 2015 09:55:32 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project

Modified: websites/staging/sling/trunk/content/documentation/development/sling-testing-tools.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/development/sling-testing-tools.html (original)
+++ websites/staging/sling/trunk/content/documentation/development/sling-testing-tools.html Tue Sep 22 09:55:48 2015
@@ -112,6 +112,11 @@ h2:hover > .headerlink, h3:hover > .head
   visibility: hidden;
 }
 h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
+<div class="warning">
+While this information is still valid, we recommend using the tools and techniques described
+in the newer [Junit Server-Side Tests Support](/documentation/bundles/org-apache-sling-junit-bundles.html) page instead. 
+</div>
+
 <p>Sling provides a number of testing tools to support the following use cases:</p>
 <ul>
 <li>Run JUnit tests contributed by OSGi bundles in an OSGi system. This does not require Sling and should work in other OSGi  environments.</li>
@@ -242,7 +247,7 @@ for an example of how to do that.</p>
 
 <p>the server start is interrupted until a debugger is connected on port 8000.</p>
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1703508 by kwin on Thu, 17 Sep 2015 07:36:02 +0000
+        Rev. 1704502 by bdelacretaz on Tue, 22 Sep 2015 09:55:32 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project