Author: sseifert
Date: Mon Oct 13 14:41:16 2014
New Revision: 1631424

URL: http://svn.apache.org/r1631424
Log:
SLING-4042 mock documentation

Modified:
    sling/site/trunk/content/documentation/development/osgi-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=1631424&r1=1631423&r2=1631424&view=diff
==============================================================================
--- sling/site/trunk/content/documentation/development/osgi-mock.mdtext 
(original)
+++ sling/site/trunk/content/documentation/development/osgi-mock.mdtext Mon Oct 
13 14:41:16 2014
@@ -60,6 +60,7 @@ It is possible to simulate registering o
     ServiceReference ref = 
bundleContext.getServiceReference(MyClass.class.getName());
     MyClass service = bundleContext.getService(ref);
 
+
 ### Activation and Dependency Injection
 
 It is possible to simulate OSGi service activation, deactivation and 
dependency injection and the mock implementation
@@ -85,7 +86,22 @@ Example:
     // deactivate service
     MockOsgi.deactivate(service);
 
-Please note: The injectServices, activate and deactivate Methods can only work 
properly when the SCR XML metadata files
+Please note:
+
+* 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.
+* The injectServices, activate and deactivate Methods can only work properly 
when the SCR XML metadata files
 are preset in the classpath at `/OSGI-INF`. 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.
+
+
+### Usage with `SlingContext` JUnit rule
+
+If you are using the `SlingContext` JUnit rule from [sling-mock]({{ 
refs.sling-mock.path }}) it is even easier asseccing and registering OSGi 
services:
+
+    #!java
+    // register service, inject dependencies and call activate method
+    context.registerInjectActivateService(myService);
+
+    // get service instance
+    MyClass service = context.getService(MyClass.class);


Reply via email to