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 2016/12/10 08:31:59 UTC

svn commit: r1002558 - in /websites/staging/sling/trunk/content: ./ documentation/bundles/context-aware-configuration/context-aware-configuration.html

Author: buildbot
Date: Sat Dec 10 08:31:59 2016
New Revision: 1002558

Log:
Staging update by buildbot for sling

Modified:
    websites/staging/sling/trunk/content/   (props changed)
    websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.html

Propchange: websites/staging/sling/trunk/content/
------------------------------------------------------------------------------
--- cms:source-revision (original)
+++ cms:source-revision Sat Dec 10 08:31:59 2016
@@ -1 +1 @@
-1773500
+1773504

Modified: websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.html
==============================================================================
--- websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.html (original)
+++ websites/staging/sling/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.html Sat Dec 10 08:31:59 2016
@@ -124,7 +124,9 @@ h2:hover > .headerlink, h3:hover > .head
 </li>
 <li><a href="#contexts-and-configuration-references">Contexts and configuration references</a></li>
 <li><a href="#describe-configurations-via-annotation-classes">Describe configurations via annotation classes</a></li>
+<li><a href="#accessing-configuration-from-htlsightly-templates">Accessing configuration from HTL/Sightly templates</a></li>
 <li><a href="#context-aware-configuration-bnd-plugin">Context-Aware Configuration bnd plugin</a></li>
+<li><a href="#unit-tests-with-context-aware-configuration">Unit Tests with Context-Aware Configuration</a></li>
 <li><a href="#customizing-the-configuration-lookup">Customizing the configuration lookup</a></li>
 <li><a href="#web-console-plugins">Web Console plugins</a></li>
 <li><a href="#references">References</a></li>
@@ -238,6 +240,28 @@ the applications/libraries you use, or y
 
 
 <p>To automate this you can use the Context-Aware Configuration bnd plugin (see next chapter).     </p>
+<h1 id="accessing-configuration-from-htlsightly-templates">Accessing configuration from HTL/Sightly templates<a class="headerlink" href="#accessing-configuration-from-htlsightly-templates" title="Permanent link">&para;</a></h1>
+<p>Context-Aware configuration contains a Scripting Binding Values provider with automatically registeres a <code>caconfig</code> variable in your HTL/Sightly scripts to directly access context-aware configurations. It supports both singleton configurations and configuration lists. Please note that configuration lists are only supported when configuration metadata is present (e.g. via an annotation class).</p>
+<p>Example for accessing a property of a singleton configuration (with a config name <code>x.y.z.ConfigSample</code>):</p>
+<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre>1
+2
+3
+4</pre></div></td><td class="code"><div class="codehilite"><pre><span class="nt">&lt;dl&gt;</span>
+    <span class="nt">&lt;dt&gt;</span>stringParam:<span class="nt">&lt;/dt&gt;</span>
+    <span class="nt">&lt;dd&gt;</span>${caconfig[&#39;x.y.z.ConfigSample&#39;].stringParam}<span class="nt">&lt;/dd&gt;</span>
+<span class="nt">&lt;/dl&gt;</span>
+</pre></div>
+</td></tr></table>
+
+<p>Example for accessing a property of a configuration list (with a config name <code>x.y.z.ConfigSampleList</code>):</p>
+<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre>1
+2
+3</pre></div></td><td class="code"><div class="codehilite"><pre><span class="nt">&lt;ul</span> <span class="na">data-sly-list</span><span class="err">.</span><span class="na">item=</span><span class="s">&quot;${caconfig[&#39;x.y.z.ConfigSampleList&#39;]}&quot;</span><span class="nt">&gt;</span>
+    <span class="nt">&lt;li&gt;</span>stringParam: ${item.stringParam}<span class="nt">&lt;/li&gt;</span>
+<span class="nt">&lt;/ul&gt;</span>
+</pre></div>
+</td></tr></table>
+
 <h1 id="context-aware-configuration-bnd-plugin">Context-Aware Configuration bnd plugin<a class="headerlink" href="#context-aware-configuration-bnd-plugin" title="Permanent link">&para;</a></h1>
 <p>A <a href="http://bnd.bndtools.org/">bnd</a> plugin is provided that scans the classpath of a bundle Maven project at build time and automatically generates a <code>Sling-ContextAware-Configuration-Classes</code> bundle header for all annotation classes annotated with <code>@Configuration</code>. It can be used by both <a href="http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html">maven-bundle-plugin</a> and <a href="https://github.com/bndtools/bnd/tree/master/maven">bnd-maven-plugin</a>, as both use the bnd library internally.</p>
 <p>Example configuration:</p>
@@ -279,6 +303,38 @@ the applications/libraries you use, or y
 </pre></div>
 </td></tr></table>
 
+<h1 id="unit-tests-with-context-aware-configuration">Unit Tests with Context-Aware Configuration<a class="headerlink" href="#unit-tests-with-context-aware-configuration" title="Permanent link">&para;</a></h1>
+<p>When your code depends on Sling Context-Aware Configuration and you want to write Sling Mocks-based unit tests running against the Context-Aware configuration implementation you have to register the proper OSGi services to use them. To make this easier, a "Apache Sling Context-Aware Configuration Mock Plugin" is provided which does this job for you.</p>
+<p>Example for setting up the unit test context rule:</p>
+<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13</pre></div></td><td class="code"><div class="codehilite"><pre><span class="kn">import</span> <span class="nn">static</span> <span class="n">org</span><span class="o">.</span><span class="na">apache</span><span class="o">.</span><span class="na">sling</span><span class="o">.</span><span class="na">testing</span><span class="o">.</span><span class="na">mock</span><span class="o">.</span><span class="na">caconfig</span><span class="o">.</span><span class="na">ContextPlugins</span><span class="o">.</span><span class="na">CACONFIG</span><span class="o">;</span>
+
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MyTest</span> <span class="o">{</span>
+
+    <span class="nd">@Rule</span>
+    <span class="kd">public</span> <span class="n">SlingContext</span> <span class="n">context</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SlingContextBuilder</span><span class="o">().</span><span class="na">plugin</span><span class="o">(</span><span class="n">CACONFIG</span><span class="o">).</span><span class="na">build</span><span class="o">();</span>
+
+    <span class="nd">@Before</span>
+    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">setUp</span><span class="o">()</span> <span class="o">{</span>
+        <span class="c1">// register configuration annotation class</span>
+        <span class="n">MockContextAwareConfig</span><span class="o">.</span><span class="na">registerAnnotationClasses</span><span class="o">(</span><span class="n">context</span><span class="o">,</span> <span class="n">SimpleConfig</span><span class="o">.</span><span class="na">class</span><span class="o">);</span>
+    <span class="o">}</span>
+<span class="o">...</span>
+</pre></div>
+</td></tr></table>
+
+<p>Full example: <a href="https://github.com/apache/sling/blob/trunk/contrib/extensions/contextaware-config/testing/mocks/caconfig-mock-plugin/src/test/java/org/apache/sling/testing/mock/caconfig/ContextPluginsTest.java">Apache Sling Context-Aware Configuration Mock Plugin Test</a></p>
 <h1 id="customizing-the-configuration-lookup">Customizing the configuration lookup<a class="headerlink" href="#customizing-the-configuration-lookup" title="Permanent link">&para;</a></h1>
 <p>The Context-Aware Configuration implementation provides a set of Service Provider Interfaces (SPI) that allows you to overlay, enhance or replace the default implementation and adapt it to your needs.</p>
 <p>See <a href="http://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration-spi.html">SPI</a> for details.</p>
@@ -298,7 +354,7 @@ the applications/libraries you use, or y
 <li><a href="https://adapt.to/2016/en/schedule/sling-context-aware-configuration.html">Sling Context-Aware Configuration - Talk from adaptTo() 2016</a></li>
 </ul>
       <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;">
-        Rev. 1771435 by sseifert on Sat, 26 Nov 2016 07:45:34 +0000
+        Rev. 1773504 by sseifert on Sat, 10 Dec 2016 08:31:43 +0000
       </div>
       <div class="trademarkFooter"> 
         Apache Sling, Sling, Apache, the Apache feather logo, and the Apache Sling project