This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag 
org.apache.sling.testing.osgi-mock-1.6.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git

commit a80c2f8759e660e897ca26861d2eb9cac257617e
Author: Stefan Seifert <[email protected]>
AuthorDate: Sat Oct 3 00:02:01 2015 +0000

    SLING-5088 deprecate activate/deactivate methods without bundleContext 
parameter because there is a small risk for memory leaks
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1706507 
13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/testing/mock/osgi/MockOsgi.java   | 38 ++++++++++++++++++++++
 .../MockBundleContextDynamicReferncesTest.java     |  2 +-
 .../testing/mock/osgi/OsgiServiceUtilTest.java     |  8 ++---
 3 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java 
b/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
index 866d8b8..f3ed656 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
@@ -129,7 +129,10 @@ public final class MockOsgi {
      * Simulate activation of service instance. Invokes the @Activate 
annotated method.
      * @param target Service instance.
      * @return true if activation method was called. False if no activate 
method is defined.
+     * @deprecated Please use {@link #activate(Object, BundleContext)}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public static boolean activate(Object target) {
         return MockOsgi.activate(target, (Dictionary<String, Object>)null);
     }
@@ -137,9 +140,22 @@ public final class MockOsgi {
     /**
      * Simulate activation of service instance. Invokes the @Activate 
annotated method.
      * @param target Service instance.
+     * @param bundleContext Bundle context
+     * @return true if activation method was called. False if no activate 
method is defined.
+     */
+    public static boolean activate(Object target, BundleContext bundleContext) 
{
+        return MockOsgi.activate(target, bundleContext, (Dictionary<String, 
Object>)null);
+    }
+
+    /**
+     * Simulate activation of service instance. Invokes the @Activate 
annotated method.
+     * @param target Service instance.
      * @param properties Properties
      * @return true if activation method was called. False if no activate 
method is defined.
+     * @deprecated Please use {@link #activate(Object, BundleContext, 
Dictionary))}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public static boolean activate(Object target, Dictionary<String, Object> 
properties) {
         Dictionary<String, Object> mergedProperties = 
propertiesMergeWithOsgiMetadata(target, properties);
         ComponentContext componentContext = 
newComponentContext(mergedProperties);
@@ -151,7 +167,10 @@ public final class MockOsgi {
      * @param target Service instance.
      * @param properties Properties
      * @return true if activation method was called. False if no activate 
method is defined.
+     * @deprecated Please use {@link #activate(Object, BundleContext, Map)))}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public static boolean activate(Object target, Map<String, Object> 
properties) {
         return activate(target, toDictionary(properties));
     }
@@ -184,7 +203,10 @@ public final class MockOsgi {
      * Simulate deactivation of service instance. Invokes the @Deactivate 
annotated method.
      * @param target Service instance.
      * @return true if deactivation method was called. False if no deactivate 
method is defined.
+     * @deprecated Please use {@link #deactivate(Object, BundleContext)}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public static boolean deactivate(Object target) {
         return MockOsgi.deactivate(target, (Dictionary<String, Object>)null);
     }
@@ -192,9 +214,22 @@ public final class MockOsgi {
     /**
      * Simulate deactivation of service instance. Invokes the @Deactivate 
annotated method.
      * @param target Service instance.
+     * @param bundleContext Bundle context.
+     * @return true if deactivation method was called. False if no deactivate 
method is defined.
+     */
+    public static boolean deactivate(Object target, BundleContext 
bundleContext) {
+        return MockOsgi.deactivate(target, bundleContext, (Dictionary<String, 
Object>)null);
+    }
+
+    /**
+     * Simulate deactivation of service instance. Invokes the @Deactivate 
annotated method.
+     * @param target Service instance.
      * @param properties Properties
      * @return true if deactivation method was called. False if no deactivate 
method is defined.
+     * @deprecated Please use {@link #deactivate(Object, BundleContext, 
Dictionary))}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public static boolean deactivate(Object target, Dictionary<String, Object> 
properties) {
         Dictionary<String, Object> mergedProperties = 
propertiesMergeWithOsgiMetadata(target, properties);
         ComponentContext componentContext = 
newComponentContext(mergedProperties);
@@ -206,7 +241,10 @@ public final class MockOsgi {
      * @param target Service instance.
      * @param properties Properties
      * @return true if deactivation method was called. False if no deactivate 
method is defined.
+     * @deprecated Please use {@link #deactivate(Object, BundleContext, Map)))}
+     *   and shutdown the bundle context after usage.
      */
+    @Deprecated
     public static boolean deactivate(Object target, Map<String, Object> 
properties) {
         return deactivate(target, toDictionary(properties));
     }
diff --git 
a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferncesTest.java
 
b/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferncesTest.java
index 9900f01..ca4dd45 100644
--- 
a/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferncesTest.java
+++ 
b/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferncesTest.java
@@ -73,7 +73,7 @@ public class MockBundleContextDynamicReferncesTest {
         
         service = new Service3();
         MockOsgi.injectServices(service, bundleContext);
-        MockOsgi.activate(service);
+        MockOsgi.activate(service, bundleContext);
         bundleContext.registerService(Service3.class.getName(), service, null);
         
         assertDependency1(dependency1a);
diff --git 
a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java 
b/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
index 521ca6f..f8b9a73 100644
--- a/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
@@ -99,7 +99,7 @@ public class OsgiServiceUtilTest {
         assertEquals(1, reference3Configs.size());
         assertEquals(200, 
reference3Configs.get(0).get(Constants.SERVICE_RANKING));
 
-        assertTrue(MockOsgi.deactivate(service3));
+        assertTrue(MockOsgi.deactivate(service3, bundleContext));
         assertNull(service3.getComponentContext());
     }
 
@@ -128,7 +128,7 @@ public class OsgiServiceUtilTest {
         Service4 service4 = new Service4();
 
         assertTrue(MockOsgi.injectServices(service4, bundleContext));
-        assertFalse(MockOsgi.activate(service4));
+        assertFalse(MockOsgi.activate(service4, bundleContext));
 
         assertSame(service1, service4.getReference1());
     }
@@ -140,12 +140,12 @@ public class OsgiServiceUtilTest {
 
     @Test(expected=NoScrMetadataException.class)
     public void testActivateNoMetadata() {
-        MockOsgi.activate(new Object());
+        MockOsgi.activate(new Object(), bundleContext);
     }
 
     @Test(expected=NoScrMetadataException.class)
     public void testDeactivateNoMetadata() {
-        MockOsgi.deactivate(new Object());
+        MockOsgi.deactivate(new Object(), bundleContext);
     }
 
     @Test(expected=NoScrMetadataException.class)

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to