Author: buildbot Date: Mon Oct 13 14:41:23 2014 New Revision: 925624 Log: Staging update by buildbot for sling
Modified: websites/staging/sling/trunk/content/ (props changed) websites/staging/sling/trunk/content/documentation/development/osgi-mock.html Propchange: websites/staging/sling/trunk/content/ ------------------------------------------------------------------------------ --- cms:source-revision (original) +++ cms:source-revision Mon Oct 13 14:41:23 2014 @@ -1 +1 @@ -1631410 +1631424 Modified: websites/staging/sling/trunk/content/documentation/development/osgi-mock.html ============================================================================== --- websites/staging/sling/trunk/content/documentation/development/osgi-mock.html (original) +++ websites/staging/sling/trunk/content/documentation/development/osgi-mock.html Mon Oct 13 14:41:23 2014 @@ -98,6 +98,7 @@ <li><a href="#usage">Usage</a><ul> <li><a href="#getting-osgi-mock-objects">Getting OSGi mock objects</a></li> <li><a href="#activation-and-dependency-injection">Activation and Dependency Injection</a></li> +<li><a href="#usage-with-slingcontext-junit-rule">Usage with SlingContext JUnit rule</a></li> </ul> </li> </ul> @@ -202,12 +203,29 @@ tries to to its best to execute all as e </pre></div> </td></tr></table> -<p>Please note: The injectServices, activate and deactivate Methods can only work properly when the SCR XML metadata files +<p>Please note:</p> +<ul> +<li>Injection does not take place automatically if a new service is added that is an (optional or mandatory) references of a service already registered. So you should ensure that you register you services in the correct order of their dependency chain.</li> +<li>The injectServices, activate and deactivate Methods can only work properly when the SCR XML metadata files are preset in the classpath at <code>/OSGI-INF</code>. They are generated automatically by the Maven SCR plugin, but might be missing if your clean and build the project within your IDE (e.g. Eclipse). In this case you have to compile the -project again with maven and can run the tests - or use a Maven IDE Integration like m2eclipse.</p> +project again with maven and can run the tests - or use a Maven IDE Integration like m2eclipse.</li> +</ul> +<h3 id="usage-with-slingcontext-junit-rule">Usage with <code>SlingContext</code> JUnit rule</h3> +<p>If you are using the <code>SlingContext</code> JUnit rule from <a href="/documentation/development/sling-mock.html">sling-mock</a> it is even easier asseccing and registering OSGi services:</p> +<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre>1 +2 +3 +4 +5</pre></div></td><td class="code"><div class="codehilite"><pre><span class="c1">// register service, inject dependencies and call activate method</span> +<span class="n">context</span><span class="o">.</span><span class="na">registerInjectActivateService</span><span class="o">(</span><span class="n">myService</span><span class="o">);</span> + +<span class="c1">// get service instance</span> +<span class="n">MyClass</span> <span class="n">service</span> <span class="o">=</span> <span class="n">context</span><span class="o">.</span><span class="na">getService</span><span class="o">(</span><span class="n">MyClass</span><span class="o">.</span><span class="na">class</span><span class="o">);</span> +</pre></div> +</td></tr></table> <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;"> - Rev. 1631410 by sseifert on Mon, 13 Oct 2014 14:24:15 +0000 + Rev. 1631424 by sseifert on Mon, 13 Oct 2014 14:41:16 +0000 </div> <div class="trademarkFooter"> Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project