You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:19:46 UTC
[sling-org-apache-sling-testing-osgi-mock] 04/12: SLING-5089
mock-osgi: Deactivate all services on shutdown
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 ee4eeb27be831d7c9323406b1ee3b6a9db2443bc
Author: Stefan Seifert <ss...@apache.org>
AuthorDate: Fri Oct 2 17:01:49 2015 +0000
SLING-5089 mock-osgi: Deactivate all services on shutdown
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/osgi-mock@1706447 13f79535-47bb-0310-9956-ffa450edef68
---
.../apache/sling/testing/mock/osgi/MockBundleContext.java | 14 ++++++++++++++
.../java/org/apache/sling/testing/mock/osgi/MockOsgi.java | 7 +++++++
.../sling/testing/mock/osgi/context/OsgiContextImpl.java | 7 ++++++-
.../org/apache/sling/testing/mock/osgi/package-info.java | 2 +-
4 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
index 7f4ab50..e6136aa 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
@@ -290,6 +290,20 @@ class MockBundleContext implements BundleContext {
// no mock implementation, simulate that no property is found and return null
return null;
}
+
+ /**
+ * Deactivates all bundles registered in this mocked bundle context.
+ */
+ public void shutdown() {
+ for (MockServiceRegistration serviceRegistration : ImmutableList.copyOf(registeredServices)) {
+ try {
+ MockOsgi.deactivate(serviceRegistration.getService(), this, serviceRegistration.getProperties());
+ }
+ catch (NoScrMetadataException ex) {
+ // ignore, no deactivate method is available then
+ }
+ }
+ }
// --- unsupported operations ---
@Override
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 8d74aac..866d8b8 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
@@ -258,4 +258,11 @@ public final class MockOsgi {
return OsgiServiceUtil.modified(target, bundleContext, mergedProperties);
}
+ /**
+ * Deactivates all bundles registered in the mocked bundle context.
+ */
+ public static void shutdown(BundleContext bundleContext) {
+ ((MockBundleContext)bundleContext).shutdown();
+ }
+
}
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java b/src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java
index c200f8e..4847a2d 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/context/OsgiContextImpl.java
@@ -53,7 +53,12 @@ public class OsgiContextImpl {
* Teardown actions after test method execution
*/
protected void tearDown() {
- // can be overridden by subclasses
+ if (componentContext != null) {
+ // deactivate all services
+ MockOsgi.shutdown(componentContext.getBundleContext());
+ }
+
+ this.componentContext = null;
}
/**
diff --git a/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java b/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
index dbaa66f..fe5f126 100644
--- a/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
+++ b/src/main/java/org/apache/sling/testing/mock/osgi/package-info.java
@@ -19,5 +19,5 @@
/**
* Mock implementation of selected OSGi APIs.
*/
-@aQute.bnd.annotation.Version("2.3")
+@aQute.bnd.annotation.Version("2.4")
package org.apache.sling.testing.mock.osgi;
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.