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 2015/10/03 02:02:02 UTC
svn commit: r1706507 - in /sling/trunk/testing/mocks/osgi-mock/src:
main/java/org/apache/sling/testing/mock/osgi/
test/java/org/apache/sling/testing/mock/osgi/
Author: sseifert
Date: Sat Oct 3 00:02:01 2015
New Revision: 1706507
URL: http://svn.apache.org/viewvc?rev=1706507&view=rev
Log:
SLING-5088 deprecate activate/deactivate methods without bundleContext parameter because there is a small risk for memory leaks
Modified:
sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferncesTest.java
sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
Modified: sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java?rev=1706507&r1=1706506&r2=1706507&view=diff
==============================================================================
--- sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java (original)
+++ sling/trunk/testing/mocks/osgi-mock/src/main/java/org/apache/sling/testing/mock/osgi/MockOsgi.java Sat Oct 3 00:02:01 2015
@@ -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));
}
Modified: sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferncesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferncesTest.java?rev=1706507&r1=1706506&r2=1706507&view=diff
==============================================================================
--- sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferncesTest.java (original)
+++ sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/MockBundleContextDynamicReferncesTest.java Sat Oct 3 00:02:01 2015
@@ -73,7 +73,7 @@ public class MockBundleContextDynamicRef
service = new Service3();
MockOsgi.injectServices(service, bundleContext);
- MockOsgi.activate(service);
+ MockOsgi.activate(service, bundleContext);
bundleContext.registerService(Service3.class.getName(), service, null);
assertDependency1(dependency1a);
Modified: sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java?rev=1706507&r1=1706506&r2=1706507&view=diff
==============================================================================
--- sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java (original)
+++ sling/trunk/testing/mocks/osgi-mock/src/test/java/org/apache/sling/testing/mock/osgi/OsgiServiceUtilTest.java Sat Oct 3 00:02:01 2015
@@ -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)