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 07:59:19 UTC

svn commit: r1773500 - in /sling/site/trunk/content/documentation/development: osgi-mock.mdtext sling-mock.mdtext

Author: sseifert
Date: Sat Dec 10 07:59:19 2016
New Revision: 1773500

URL: http://svn.apache.org/viewvc?rev=1773500&view=rev
Log:
document mocks context plugins

Modified:
    sling/site/trunk/content/documentation/development/osgi-mock.mdtext
    sling/site/trunk/content/documentation/development/sling-mock.mdtext

Modified: sling/site/trunk/content/documentation/development/osgi-mock.mdtext
URL: http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/development/osgi-mock.mdtext?rev=1773500&r1=1773499&r2=1773500&view=diff
==============================================================================
--- sling/site/trunk/content/documentation/development/osgi-mock.mdtext (original)
+++ sling/site/trunk/content/documentation/development/osgi-mock.mdtext Sat Dec 10 07:59:19 2016
@@ -35,6 +35,7 @@ The mock implementation supports:
 * Mock implementation of `LogService` which logs to SLF4J in JUnit context
 * Mock implementation of `EventAdmin` which supports `EventHandler` services
 * Mock implementation of `ConfigAdmin`
+* Context Plugins
 
 Since osgi-mock 2.0.0:
 
@@ -144,5 +145,27 @@ missing if your clean and build the proj
 project again with maven and can run the tests - or use a Maven IDE Integration like m2eclipse.
 
 
+### Context Plugins
+
+OSGi Mocks supports "Context Plugins" that hook into the lifecycle of each test run and can prepare test setup before or after the other setUp actions, and execute test tear down code before or after the other tearDown action.
+
+To define a plugin implement the `org.apache.sling.testing.mock.osgi.context.ContextPlugin<OsgiContextImpl>` interface. For convenience it is recommended to extend the abstract class `org.apache.sling.testing.mock.osgi.context.AbstractContextPlugin<OsgiContextImpl>`. These plugins can be used with OSGi Mock context, but also with context instances deriving from it like Sling Mocks and AEM Mocks. In most cases you would just override the `afterSetUp` method. In this method you can register additional OSGi services or do other preparation work. It is recommended to define a constant pointing to a singleton of a plugin instance for using it.
+
+To use a plugin in your unit test class, use the `OsgiContextBuilder` class instead of directly instantiating the `OsgiContext`class. This allows you in a fluent style to configure more options, with the `plugin(...)` method you can add one or more plugins.
+
+Example: 
+
+    #!java
+    @Rule
+    public OsgiContext context = new OsgiContextBuilder().plugin(MY_PLUGIN).build();
+
+More examples:
+
+* [Apache Sling Context-Aware Configuration Mock Plugin][caconfig-mock-plugin]
+* [Apache Sling Context-Aware Configuration Mock Plugin Test][caconfig-mock-plugin-test]
+
+
 
 [mockito-testrunner]: http://mockito.github.io/mockito/docs/current/org/mockito/runners/MockitoJUnitRunner.html
+[caconfig-mock-plugin]: https://github.com/apache/sling/blob/trunk/contrib/extensions/contextaware-config/testing/mocks/caconfig-mock-plugin/src/main/java/org/apache/sling/testing/mock/caconfig/ContextPlugins.java
+[caconfig-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

Modified: sling/site/trunk/content/documentation/development/sling-mock.mdtext
URL: http://svn.apache.org/viewvc/sling/site/trunk/content/documentation/development/sling-mock.mdtext?rev=1773500&r1=1773499&r2=1773500&view=diff
==============================================================================
--- sling/site/trunk/content/documentation/development/sling-mock.mdtext (original)
+++ sling/site/trunk/content/documentation/development/sling-mock.mdtext Sat Dec 10 07:59:19 2016
@@ -38,7 +38,8 @@ The mock implementation supports:
 * Implementations of the servlet-related Sling API classes like `SlingHttpServletRequest` and `SlingHttpServletRequest`
     * It is possible to set request data to simulate a certain Sling HTTP request
 * Support for Sling Models (Sling Models API 1.1 and Impl 1.1 or higher required)
-* Additional services `MimeTypeService` 
+* Additional services `MimeTypeService`
+* Context Plugins
 
 The following features are *not supported*:
 
@@ -416,6 +417,26 @@ Example:
 See JavaDocs of the class `org.apache.sling.resourcebuilder.api.ResourceBuilder` for a detailed documentation.
 
 
+### Context Plugins
+
+Sling Mocks supports "Context Plugins" that hook into the lifecycle of each test run and can prepare test setup before or after the other setUp actions, and execute test tear down code before or after the other tearDown action.
+
+To define a plugin implement the `org.apache.sling.testing.mock.osgi.context.ContextPlugin<SlingContextImpl>` interface. For convenience it is recommended to extend the abstract class `org.apache.sling.testing.mock.osgi.context.AbstractContextPlugin<SlingContextImpl>`. These plugins can be used with Sling Mock context, but also with context instances deriving from it like AEM Mocks. In most cases you would just override the `afterSetUp` method. In this method you can register additional OSGi services or do other preparation work. It is recommended to define a constant pointing to a singleton of a plugin instance for using it.
+
+To use a plugin in your unit test class, use the `SlingContextBuilder` class instead of directly instantiating the `SlingContext`class. This allows you in a fluent style to configure more options, with the `plugin(...)` method you can add one or more plugins.
+
+Example: 
+
+    #!java
+    @Rule
+    public SlingContext context = new SlingContextBuilder().plugin(MY_PLUGIN).build();
+
+More examples:
+
+* [Apache Sling Context-Aware Configuration Mock Plugin][caconfig-mock-plugin]
+* [Apache Sling Context-Aware Configuration Mock Plugin Test][caconfig-mock-plugin-test]
+
+
 
 [osgi-mock]: {{ refs.osgi-mock.path }}
 [jcr-mock]: {{ refs.jcr-mock.path }}
@@ -423,3 +444,5 @@ See JavaDocs of the class `org.apache.sl
 [jcr-resource]: http://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/resource
 [sling-commons-testing]: http://svn.apache.org/repos/asf/sling/trunk/bundles/commons/testing
 [mockito-testrunner]: http://mockito.github.io/mockito/docs/current/org/mockito/runners/MockitoJUnitRunner.html
+[caconfig-mock-plugin]: https://github.com/apache/sling/blob/trunk/contrib/extensions/contextaware-config/testing/mocks/caconfig-mock-plugin/src/main/java/org/apache/sling/testing/mock/caconfig/ContextPlugins.java
+[caconfig-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