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@1706507 13f79535-47bb-0310-9956-ffa450edef68
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 @@
* 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 @@
/**
* Simulate activation of service instance. Invokes the @Activate annotated method.
* @param target Service instance.
- * @param properties Properties
+ * @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 @@
* @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 @@
* 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 @@
/**
* Simulate deactivation of service instance. Invokes the @Deactivate annotated method.
* @param target Service instance.
- * @param properties Properties
+ * @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 @@
* @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 @@
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 @@
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 @@
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 @@
@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)