You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2016/12/10 08:31:43 UTC

svn commit: r1773504 - /sling/site/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.mdtext

Author: sseifert
Date: Sat Dec 10 08:31:43 2016
New Revision: 1773504

URL: http://svn.apache.org/viewvc?rev=1773504&view=rev
Log:
add documentation for slighty bindings values provider and unit test context mock plugin

Modified:
    sling/site/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.mdtext

Modified: sling/site/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.mdtext
URL: http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.mdtext?rev=1773504&r1=1773503&r2=1773504&view=diff
==============================================================================
--- sling/site/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.mdtext (original)
+++ sling/site/trunk/content/documentation/bundles/context-aware-configuration/context-aware-configuration.mdtext Sat Dec 10 08:31:43 2016
@@ -126,6 +126,26 @@ If you provide your own configuration an
 To automate this you can use the Context-Aware Configuration bnd plugin (see next chapter). 	
 
 
+# Accessing configuration from HTL/Sightly templates
+
+Context-Aware configuration contains a Scripting Binding Values provider with automatically registeres a `caconfig` 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).
+
+Example for accessing a property of a singleton configuration (with a config name `x.y.z.ConfigSample`):
+
+	#!html
+	<dl>
+		<dt>stringParam:</dt>
+		<dd>${caconfig['x.y.z.ConfigSample'].stringParam}</dd>
+	</dl>
+
+Example for accessing a property of a configuration list (with a config name `x.y.z.ConfigSampleList`):
+
+	#!html
+	<ul data-sly-list.item="${caconfig['x.y.z.ConfigSampleList']}">
+		<li>stringParam: ${item.stringParam}</li>
+	</ul>
+
+
 # Context-Aware Configuration bnd plugin
 
 A [bnd](http://bnd.bndtools.org/) plugin is provided that scans the classpath of a bundle Maven project at build time and automatically generates a `Sling-ContextAware-Configuration-Classes` bundle header for all annotation classes annotated with `@Configuration`. It can be used by both [maven-bundle-plugin](http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html) and [bnd-maven-plugin](https://github.com/bndtools/bnd/tree/master/maven), as both use the bnd library internally.
@@ -153,6 +173,30 @@ Example configuration:
     </plugin>
 
 
+# Unit Tests with Context-Aware Configuration
+
+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.
+
+Example for setting up the unit test context rule:
+
+	#!java
+	import static org.apache.sling.testing.mock.caconfig.ContextPlugins.CACONFIG;
+
+	public class MyTest {
+
+		@Rule
+		public SlingContext context = new SlingContextBuilder().plugin(CACONFIG).build();
+
+		@Before
+		public void setUp() {
+			// register configuration annotation class
+			MockContextAwareConfig.registerAnnotationClasses(context, SimpleConfig.class);
+		}
+	...
+
+Full example: [Apache Sling Context-Aware Configuration Mock Plugin Test](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)
+
+
 # Customizing the configuration lookup
 
 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.
@@ -178,4 +222,4 @@ To use the web console plugin you need t
 * [Context-Aware Configuration - SPI](http://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration-spi.html)
 * [Context-Aware Configuration - Override](http://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configuration-override.html)
 * [Sling Context-Aware Configuration - Talk from adaptTo() 2016](https://adapt.to/2016/en/schedule/sling-context-aware-configuration.html)
-
+