Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.ds.tests/src')
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/AllTests.java29
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/BundleInstaller.java156
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/DSTestsActivator.java61
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundCountProvider.java18
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundMainProvider.java20
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundTester.java22
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BundleContextProvider.java20
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/ComponentContextProvider.java20
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/ComponentManager.java17
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSEvent.java95
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSEventsProvider.java17
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java2143
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DynamicWorker.java22
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/NamespaceProvider.java16
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/PropertiesProvider.java20
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/StaticWorker.java22
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/TestHelper.java40
17 files changed, 2738 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/AllTests.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/AllTests.java
new file mode 100644
index 000000000..7e83befb2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/AllTests.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests;
+
+import org.eclipse.equinox.ds.tests.tbc.DSTest;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Declarative Services Tests");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(DSTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/BundleInstaller.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/BundleInstaller.java
new file mode 100644
index 000000000..c155361a0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/BundleInstaller.java
@@ -0,0 +1,156 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.osgi.service.urlconversion.URLConverter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class BundleInstaller {
+ private BundleContext context;
+ private String rootLocation;
+ private HashMap bundles = new HashMap();
+ private ServiceTracker converter;
+
+ public BundleInstaller(String bundlesRoot, BundleContext context) throws InvalidSyntaxException {
+ this.context = context;
+ rootLocation = bundlesRoot;
+ converter = new ServiceTracker(context, context.createFilter("(&(objectClass=" + URLConverter.class.getName() + ")(protocol=bundleentry))"), null);
+ converter.open();
+ }
+
+ synchronized public Bundle installBundle(String name) throws BundleException {
+ return installBundle(name, true);
+ }
+
+ synchronized public Bundle installBundle(String name, boolean track) throws BundleException {
+ if (bundles == null && track)
+ return null;
+ String location = getBundleLocation(name);
+ Bundle bundle = context.installBundle(location);
+ if (track)
+ bundles.put(name, bundle);
+ return bundle;
+ }
+
+ public String getBundleLocation(String name) throws BundleException {
+ String bundleFileName = rootLocation + "/" + name;
+ URL bundleURL = context.getBundle().getEntry(bundleFileName);
+ if (bundleURL == null)
+ bundleURL = context.getBundle().getEntry(bundleFileName + ".jar");
+ if (bundleURL == null)
+ throw new BundleException("Could not find bundle to install at: " + name);
+ try {
+ bundleURL = ((URLConverter) converter.getService()).resolve(bundleURL);
+ } catch (IOException e) {
+ throw new BundleException("Converter error", e);
+ }
+ String location = bundleURL.toExternalForm();
+ if ("file".equals(bundleURL.getProtocol()))
+ location = "reference:" + location;
+ return location;
+ }
+
+ synchronized public Bundle updateBundle(String fromName, String toName) throws BundleException {
+ if (bundles == null)
+ return null;
+ Bundle fromBundle = (Bundle) bundles.get(fromName);
+ if (fromBundle == null)
+ throw new BundleException("The bundle to update does not exist!! " + fromName);
+ String bundleFileName = rootLocation + "/" + toName;
+ URL bundleURL = context.getBundle().getEntry(bundleFileName);
+ if (bundleURL == null)
+ bundleURL = context.getBundle().getEntry(bundleFileName + ".jar");
+ try {
+ bundleURL = ((URLConverter) converter.getService()).resolve(bundleURL);
+ } catch (IOException e) {
+ throw new BundleException("Converter error", e);
+ }
+ String location = bundleURL.toExternalForm();
+ if ("file".equals(bundleURL.getProtocol()))
+ location = "reference:" + location;
+ try {
+ fromBundle.update(new URL(location).openStream());
+ } catch (Exception e) {
+ throw new BundleException("Errors when updating bundle " + fromBundle, e);
+ }
+ bundles.remove(fromName);
+ bundles.put(toName, fromBundle);
+ return fromBundle;
+ }
+
+ synchronized public Bundle uninstallBundle(String name) throws BundleException {
+ if (bundles == null)
+ return null;
+ Bundle bundle = (Bundle) bundles.remove(name);
+ if (bundle == null)
+ return null;
+ bundle.uninstall();
+ return bundle;
+ }
+
+ synchronized public void uninstallBundle(Bundle b) throws BundleException {
+ if (bundles == null)
+ return;
+ if (bundles.containsValue(b)) {
+ for (Iterator it = bundles.entrySet().iterator(); it.hasNext();) {
+ Map.Entry entry = (Map.Entry) it.next();
+ if (entry.getValue().equals(b)) {
+ bundles.remove(entry.getKey());
+ break;
+ }
+ }
+ }
+ b.uninstall();
+ }
+
+ synchronized public Bundle[] uninstallAllBundles() throws BundleException {
+ if (bundles == null)
+ return null;
+ ArrayList result = new ArrayList(bundles.size());
+ for (Iterator iter = bundles.values().iterator(); iter.hasNext();) {
+ Bundle bundle = (Bundle) iter.next();
+ try {
+ bundle.uninstall();
+ } catch (IllegalStateException e) {
+ // ignore; bundle probably already uninstalled
+ }
+ result.add(bundle);
+ }
+ bundles.clear();
+ return (Bundle[]) result.toArray(new Bundle[result.size()]);
+ }
+
+ synchronized public Bundle getBundle(String name) {
+ if (bundles == null)
+ return null;
+ return (Bundle) bundles.get(name);
+ }
+
+ synchronized public Bundle[] shutdown() throws BundleException {
+ if (bundles == null)
+ return null;
+ Bundle[] result = uninstallAllBundles();
+ converter.close();
+ bundles = null;
+ return result;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/DSTestsActivator.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/DSTestsActivator.java
new file mode 100644
index 000000000..23714adbc
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/DSTestsActivator.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+public class DSTestsActivator implements BundleActivator {
+
+ private static DSTestsActivator instance;
+ private BundleContext context;
+
+ public DSTestsActivator() {
+ instance = this;
+ }
+ public void start(BundleContext context) throws Exception {
+ this.context = context;
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ this.context = null;
+ }
+
+ public static BundleContext getContext() {
+ return instance != null ? instance.context : null;
+ }
+
+ public static void activateSCR() {
+ activateBundle("org.eclipse.equinox.ds");
+ activateBundle("org.eclipse.equinox.cm");
+ activateBundle("org.eclipse.equinox.log");
+ activateBundle("org.eclipse.equinox.util");
+ }
+
+ private static void activateBundle(String symbolicName) {
+ if (instance != null) {
+ Bundle[] bundles = instance.context.getBundles();
+ for (int i = 0; i < bundles.length; i++) {
+ if (symbolicName.equals(bundles[i].getSymbolicName())) {
+ if (bundles[i].getState() != Bundle.ACTIVE)
+ try {
+ bundles[i].start(Bundle.START_TRANSIENT);
+ } catch (BundleException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundCountProvider.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundCountProvider.java
new file mode 100644
index 000000000..cc634ff08
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundCountProvider.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+public interface BoundCountProvider extends PropertiesProvider {
+
+ public int getBoundServiceCount(String service);
+
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundMainProvider.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundMainProvider.java
new file mode 100644
index 000000000..8e62ce98b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundMainProvider.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+public interface BoundMainProvider extends PropertiesProvider {
+
+ public static final String DYNAMIC_SERVICE = "DynamicWorker";
+ public static final String NAMED_SERVICE = "NamedService";
+ public static final String STATIC_SERVICE = "StaticWorker";
+ public Object getBoundService(String serviceName);
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundTester.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundTester.java
new file mode 100644
index 000000000..7498163a9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BoundTester.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+import org.osgi.framework.ServiceReference;
+
+public interface BoundTester extends PropertiesProvider {
+
+ public int getBoundObjectsCount();
+ public ServiceReference getBoundServiceRef(int index);
+ public Object getBoundService(int index);
+
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BundleContextProvider.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BundleContextProvider.java
new file mode 100644
index 000000000..9aa7ff091
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/BundleContextProvider.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+import org.osgi.framework.BundleContext;
+
+public interface BundleContextProvider extends PropertiesProvider {
+
+ public BundleContext getBundleContext();
+
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/ComponentContextProvider.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/ComponentContextProvider.java
new file mode 100644
index 000000000..9d0534cea
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/ComponentContextProvider.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+import org.osgi.service.component.ComponentContext;
+
+public interface ComponentContextProvider extends PropertiesProvider {
+
+ public ComponentContext getComponentContext();
+
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/ComponentManager.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/ComponentManager.java
new file mode 100644
index 000000000..8d69dc607
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/ComponentManager.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+public interface ComponentManager extends PropertiesProvider {
+
+ public void enableComponent(String name, boolean flag);
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSEvent.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSEvent.java
new file mode 100644
index 000000000..5ea191379
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSEvent.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+public class DSEvent implements Comparable {
+
+ public static final int ACT_BOUND = 1;
+ public static final int ACT_UNBOUND = 2;
+ public static final int ACT_ACTIVATE = 3;
+ public static final int ACT_DEACTIVATE = 4;
+
+ private static long lastTime = System.currentTimeMillis();
+ private static final Object lock = new Object();
+
+ private long time;
+ private int action;
+ private Object object;
+
+ public DSEvent(int action, Object object) {
+ synchronized (lock) { // to prevent from creating BoundServiceEvents in one and the same millisecond
+ this.action = action;
+ this.object = object;
+ while(lastTime == System.currentTimeMillis());
+ this.time = lastTime = System.currentTimeMillis();
+ }
+ }
+
+ public int getAction() {
+ return action;
+ }
+
+ public Object getObject() {
+ return object;
+ }
+
+ public long getTime() {
+ return time;
+ }
+
+ /**
+ * Returns whether this event is before the passed one
+ * @param event
+ * @return
+ */
+ public boolean before(DSEvent event) {
+ if (event.time > this.time) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object var0) {
+ DSEvent event = (DSEvent) var0;
+ if (event.time > this.time) {
+ return -1;
+ } else if (event.time < this.time) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+ protected String getActionAsString() {
+ switch(getAction()) {
+ case ACT_BOUND: return "ACT_BOUND";
+ case ACT_UNBOUND: return "ACT_UNBOUND";
+ case ACT_ACTIVATE: return "ACT_ACTIVATE";
+ case ACT_DEACTIVATE: return "ACT_DEACTIVATE";
+ default: return "UNKNOWN (" + getAction() + ")";
+ }
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer("DSEvent[");
+ buf.append("time=" + this.time + ";action=");
+ buf.append(getActionAsString());
+ buf.append(";object=" + (this.object != null ? this.object.toString() : "null"));
+ buf.append("]");
+ return buf.toString();
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSEventsProvider.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSEventsProvider.java
new file mode 100644
index 000000000..b9c86a3d7
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSEventsProvider.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+public interface DSEventsProvider extends PropertiesProvider {
+ public DSEvent[] getEvents();
+ public void resetEvents();
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java
new file mode 100644
index 000000000..b85d43af6
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java
@@ -0,0 +1,2143 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import junit.framework.TestCase;
+
+import org.eclipse.equinox.ds.tests.BundleInstaller;
+import org.eclipse.equinox.ds.tests.DSTestsActivator;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.PackagePermission;
+import org.osgi.framework.ServicePermission;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.component.ComponentConstants;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.ComponentFactory;
+import org.osgi.service.component.ComponentInstance;
+import org.osgi.service.permissionadmin.PermissionAdmin;
+import org.osgi.service.permissionadmin.PermissionInfo;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class DSTest extends TestCase {
+
+ private static final String NAMED_CLASS = "org.eclipse.equinox.ds.tests.tb4.NamedService";
+
+ private static final String EXTENDED_CLASS = "org.eclipse.equinox.ds.tests.tb1.BindUnbindSuccessor";
+
+ private static final String SAC_CLASS = "org.eclipse.equinox.ds.tests.tb1.impl.AnotherComponent";
+
+ private static final String SC_CLASS = "org.eclipse.equinox.ds.tests.tb1.impl.BaseComp";
+
+ private static final String DYN_SERVICE_CLASS = "org.eclipse.equinox.ds.tests.tb4.DynamicService";
+
+ private static final String BSRC_CLASS = "org.eclipse.equinox.ds.tests.tb4.BoundReplacer";
+
+ private static final String MBSRC_CLASS = "org.eclipse.equinox.ds.tests.tb4.AdvancedBounder";
+
+ private static final String SECURITY_CLASS = "org.eclipse.equinox.ds.tests.tb5.impl.SecurityTester";
+
+ private static final String BLOCK_ACTIVE_CLASS = "org.eclipse.equinox.ds.tests.tb2.impl.Blocker";
+
+ private static final String BLOCK_BIND_CLASS = "org.eclipse.equinox.ds.tests.tb3.impl.BindBlocker";
+
+ private static final String STATIC_CLASS = "org.eclipse.equinox.ds.tests.tb6.StaticComp";
+
+ private static final String REFERENCED_CLASS = "org.eclipse.equinox.ds.tests.tb6.ReferencedComp";
+
+ private static final String NS_CLASS = "org.eclipse.equinox.ds.tests.tbc.NamespaceProvider";
+
+ private static final String COMP_OPTIONAL_100 = "org.eclipse.equinox.ds.tests.tb11.optionalNS100";
+
+ private static final String COMP_OPTIONAL_110 = "org.eclipse.equinox.ds.tests.tb11.optionalNS110";
+
+ private static final String COMP_REQUIRE_100 = "org.eclipse.equinox.ds.tests.tb11.requireNS100";
+
+ private static final String COMP_REQUIRE_110 = "org.eclipse.equinox.ds.tests.tb11.requireNS110";
+
+ private static final String COMP_IGNORE_100 = "org.eclipse.equinox.ds.tests.tb11.ignoreNS100";
+
+ private static final String COMP_IGNORE_110 = "org.eclipse.equinox.ds.tests.tb11.ignoreNS110";
+
+ private static final String COMP_NOTSET_100 = "org.eclipse.equinox.ds.tests.tb11.notsetNS100";
+
+ private static final String COMP_NOTSET_110 = "org.eclipse.equinox.ds.tests.tb11.notsetNS110";
+
+ private static int timeout = 1000;
+
+ private Bundle tb1;
+
+ private ServiceTracker trackerNamedService;
+
+ private ServiceTracker trackerNamedServiceFactory;
+
+ private ServiceTracker trackerCM;
+
+ private ServiceTracker trackerExtendedClass;
+
+ private ServiceTracker trackerSAC;
+
+ private ServiceTracker trackerSC;
+
+ private ServiceTracker trackerDynService;
+
+ private ServiceTracker trackerDynServiceFactory;
+
+ private ServiceTracker trackerBSRC;
+
+ private ServiceTracker trackerMBSRC;
+
+ private ServiceTracker trackerSecurity;
+
+ private ServiceTracker trackerBAS;
+
+ private ServiceTracker trackerBBS;
+
+ private ServiceTracker trackerStatic;
+
+ private ServiceTracker trackerReferenced;
+
+ private ServiceTracker trackerNS;
+
+ private ServiceTracker trackerBoundServiceCounterFactory;
+
+ private ServiceTracker trackerBoundServiceCounterHelperFactory;
+
+ private ServiceTracker trackerStaticServiceCounterFactory;
+
+ private ServiceTracker trackerBaseService;
+
+ private Hashtable registeredServices = new Hashtable();
+
+ private int scr_restart_timeout = 33000;
+
+ private boolean synchronousBuild = false;
+
+ private BundleInstaller installer;
+
+ public void setUp() throws Exception {
+ DSTestsActivator.activateSCR();
+
+ timeout = getSystemProperty("scr.test.timeout", timeout);
+ scr_restart_timeout = getSystemProperty("scr.restart.timeout", scr_restart_timeout);
+
+ String synchronousBuildProp = System.getProperty("equinox.ds.synchronous_build");
+ synchronousBuild = (synchronousBuildProp == null) || !synchronousBuildProp.equalsIgnoreCase("false");
+
+ clearConfigurations();
+ // init trackers
+ BundleContext bc = getContext();
+
+ installer = new BundleInstaller("/scr_test/", bc);
+
+ // install test bundles
+ tb1 = installBundle("tb1");
+
+ // start them
+ tb1.start();
+ waitBundleStart();
+
+ trackerNamedService = new ServiceTracker(bc, NAMED_CLASS, null);
+ Filter filter = bc
+ .createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '='
+ + NAMED_CLASS + ")(" + Constants.OBJECTCLASS + '='
+ + ComponentFactory.class.getName() + "))");
+ trackerNamedServiceFactory = new ServiceTracker(bc, filter, null);
+ trackerCM = new ServiceTracker(bc, ConfigurationAdmin.class.getName(), null);
+ trackerExtendedClass = new ServiceTracker(bc, EXTENDED_CLASS, null);
+ trackerSAC = new ServiceTracker(bc, SAC_CLASS, null);
+ trackerSC = new ServiceTracker(bc, SC_CLASS, null);
+ trackerDynService = new ServiceTracker(bc, DYN_SERVICE_CLASS, null);
+ filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '='
+ + DYN_SERVICE_CLASS + ")(" + Constants.OBJECTCLASS + '='
+ + ComponentFactory.class.getName() + "))");
+ trackerDynServiceFactory = new ServiceTracker(bc, filter, null);
+ trackerBSRC = new ServiceTracker(bc, BSRC_CLASS, null);
+ trackerMBSRC = new ServiceTracker(bc, MBSRC_CLASS, null);
+ trackerSecurity = new ServiceTracker(bc, SECURITY_CLASS, null);
+ trackerBAS = new ServiceTracker(bc, BLOCK_ACTIVE_CLASS, null);
+ trackerBBS = new ServiceTracker(bc, BLOCK_BIND_CLASS, null);
+ trackerStatic = new ServiceTracker(bc, STATIC_CLASS, null);
+ trackerReferenced = new ServiceTracker(bc, REFERENCED_CLASS, null);
+ trackerNS = new ServiceTracker(bc, NS_CLASS, null);
+ filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '='
+ + "CountFactory" + ")(" + Constants.OBJECTCLASS + '=' + ComponentFactory.class.getName() + "))");
+ trackerBoundServiceCounterFactory = new ServiceTracker(bc, filter, null);
+ filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '='
+ + "CountHelperFactory" + ")(" + Constants.OBJECTCLASS + '=' + ComponentFactory.class.getName() + "))");
+ trackerBoundServiceCounterHelperFactory = new ServiceTracker(bc, filter, null);
+ filter = bc.createFilter("(&(" + ComponentConstants.COMPONENT_FACTORY + '='
+ + "StaticServiceCountFactory" + ")(" + Constants.OBJECTCLASS + '=' + ComponentFactory.class.getName() + "))");
+ trackerStaticServiceCounterFactory = new ServiceTracker(bc, filter, null);
+ trackerBaseService = new ServiceTracker(bc, PropertiesProvider.class.getName(), null);
+
+ // start listening
+ trackerNamedService.open();
+ trackerNamedServiceFactory.open();
+ trackerCM.open();
+ trackerExtendedClass.open();
+ trackerSAC.open();
+ trackerSC.open();
+ trackerDynService.open();
+ trackerDynServiceFactory.open();
+ trackerBSRC.open();
+ trackerMBSRC.open();
+ trackerSecurity.open();
+ trackerBAS.open();
+ trackerBBS.open();
+ trackerStatic.open();
+ trackerReferenced.open();
+ trackerNS.open();
+ trackerBoundServiceCounterFactory.open();
+ trackerBoundServiceCounterHelperFactory.open();
+ trackerStaticServiceCounterFactory.open();
+ trackerBaseService.open();
+ }
+
+ /**
+ * This methods takes care of the configurations related to this test
+ * @throws IOException
+ * @throws InvalidSyntaxException
+ * @throws InterruptedException
+ */
+ private void clearConfigurations() throws IOException, InvalidSyntaxException {
+ ServiceReference cmSR = getContext().getServiceReference(
+ ConfigurationAdmin.class.getName());
+ if (cmSR == null)
+ return;
+ ConfigurationAdmin cm = (ConfigurationAdmin) getContext().getService(cmSR);
+ // clean configurations from previous tests
+ // clean factory configs for named service
+ clearConfiguration(cm, "(service.factoryPid=" + NAMED_CLASS + ")");
+ // clean configs for named service
+ clearConfiguration(cm, "(service.pid=" + NAMED_CLASS + ")");
+ // clean configs for stand alone component
+ clearConfiguration(cm, "(service.pid=" + SAC_CLASS + ")");
+ // clean configs for optionalNS100
+ clearConfiguration(cm, "(service.pid=" + COMP_OPTIONAL_100 + ")");
+ // clean configs for optionalNS110
+ clearConfiguration(cm, "(service.pid=" + COMP_OPTIONAL_110 + ")");
+ // clean configs for requireNS100
+ clearConfiguration(cm, "(service.pid=" + COMP_REQUIRE_100 + ")");
+ // clean configs for requireNS110
+ clearConfiguration(cm, "(service.pid=" + COMP_REQUIRE_110 + ")");
+ // clean configs for ignoreNS100
+ clearConfiguration(cm, "(service.pid=" + COMP_IGNORE_100 + ")");
+ // clean configs for ignoreNS110
+ clearConfiguration(cm, "(service.pid=" + COMP_IGNORE_110 + ")");
+ // clean configs for notsetNS100
+ clearConfiguration(cm, "(service.pid=" + COMP_NOTSET_100 + ")");
+ // clean configs for notsetNS110
+ clearConfiguration(cm, "(service.pid=" + COMP_NOTSET_110 + ")");
+
+ getContext().ungetService(cmSR);
+ try {
+ Thread.sleep(timeout * 2);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ private void clearConfiguration(ConfigurationAdmin cm, String filter) throws IOException, InvalidSyntaxException {
+ Configuration[] configs = cm.listConfigurations(filter);
+ for (int i = 0; configs != null && i < configs.length; i++) {
+ Configuration configuration = configs[i];
+ configuration.delete();
+ }
+ }
+
+ /**
+ * @param propertyKey
+ */
+ private int getSystemProperty(String propertyKey, int defaultValue) {
+ String propertyString = System.getProperty(propertyKey);
+ int sleepTime = defaultValue;
+ if (propertyString != null) {
+ try {
+ sleepTime = Integer.parseInt(propertyString);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out
+ .println("Error while parsing sleep value! The default one will be used : "
+ + defaultValue);
+ }
+ if (sleepTime < 100) {
+ log("The sleep value is too low : " + sleepTime
+ + " ! The default one will be used : " + defaultValue);
+ return defaultValue;
+ }
+ return sleepTime;
+ }
+ return defaultValue;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.equinox.ds.tests.tbc.DSTest.#tearDown()
+ */
+ public void tearDown() throws Exception {
+ unregisterAllServices();
+
+ trackerNamedService.close();
+ trackerNamedServiceFactory.close();
+ trackerExtendedClass.close();
+ trackerSAC.close();
+ trackerSC.close();
+ trackerDynService.close();
+ trackerDynServiceFactory.close();
+ trackerBSRC.close();
+ trackerMBSRC.close();
+ trackerSecurity.close();
+ trackerBAS.close();
+ trackerBBS.close();
+ trackerStatic.close();
+ trackerReferenced.close();
+ trackerNS.close();
+ trackerBoundServiceCounterFactory.close();
+ trackerBoundServiceCounterHelperFactory.close();
+ trackerBaseService.close();
+
+ if (installer != null) {
+ BundleInstaller bi = installer;
+ installer = null;
+ bi.shutdown();
+ }
+
+ clearConfigurations();
+ }
+
+ public void testBindUnbind() throws Exception {
+
+ assertEquals("TestBundle1 must be running.", Bundle.ACTIVE, tb1.getState());
+
+ Object s = trackerExtendedClass.getService();
+ assertNotNull("The BindUnbindSuccessor component should be available", s);
+
+ assertTrue(
+ "The bind method on BindUnbindSuccessor component should be called to save the service reference",
+ ((BoundTester) s).getBoundObjectsCount() > 0);
+
+ // disable the referenced component to trigger unbind event
+ ComponentManager enabler = (ComponentManager) s;
+ enabler.enableComponent(SAC_CLASS, false);
+ Thread.sleep(timeout);
+
+ assertNull("The SAC component should be disabled (unavailable)", trackerSAC
+ .getServiceReference());
+
+ assertTrue(
+ "The unbind method on BindUnbindSuccessor component should be called to reset the service reference",
+ ((BoundTester) s).getBoundObjectsCount() < 1);
+
+ // enable the referenced component
+ enabler = (ComponentManager) trackerExtendedClass.getService();
+ enabler.enableComponent(SAC_CLASS, true);
+ Thread.sleep(timeout);
+ assertNotNull("The SAC component should be available", trackerSAC
+ .getServiceReference());
+ }
+
+ public void testUniqueComponentContext() throws Exception {
+ Bundle bundle = installBundle("tb4");
+ bundle.start();
+ waitBundleStart();
+
+ Hashtable props;
+ ComponentFactory factory = (ComponentFactory) trackerNamedServiceFactory
+ .getService();
+ assertNotNull("The NamedService component factory should be available", factory);
+
+ // create the first service
+ props = new Hashtable();
+ props.put("name", "hello");
+
+ ComponentInstance ci1 = factory.newInstance(props);
+ ComponentInstance ci2 = factory.newInstance(props);
+
+ ComponentContextProvider cce1 = (ComponentContextProvider) ci1.getInstance();
+ ComponentContextProvider cce2 = (ComponentContextProvider) ci2.getInstance();
+
+ assertNotSame("The two instances created must be different", cce1, cce2);
+
+ ComponentContext cc1 = cce1.getComponentContext();
+ ComponentContext cc2 = cce2.getComponentContext();
+
+ assertNotSame("The two component contexts must be not the same", cc1, cc2);
+
+ uninstallBundle(bundle);
+ }
+
+ public void testComponentContextMethods() throws Exception {
+
+ Object extendedClass = trackerExtendedClass.getService();
+ // check that the BindUnbindSuccessor component is available
+ assertNotNull("BindUnbindSuccessor component should be available", extendedClass);
+
+ ComponentContext ctxt = ((ComponentContextProvider) extendedClass).getComponentContext();
+ assertNotNull(
+ "The BindUnbindSuccessor component should be activated properly",
+ ctxt);
+
+ assertNotNull("The AnotherComponent should be available before we disable it",
+ trackerSAC.getServiceReferences());
+ assertTrue("The AnotherComponent should be available before we disable it",
+ trackerSAC.getServiceReferences().length > 0);
+ assertNotNull("The Worker should be available before we disable it",
+ trackerSC.getServiceReferences());
+ assertTrue("The Worker should be available before we disable it",
+ trackerSC.getServiceReferences().length > 0);
+
+ // *** test disableComponent() method
+ ((ComponentManager)extendedClass).enableComponent("InvalidParameter", true); // test for disabling unexistent
+
+ ((ComponentManager)extendedClass).enableComponent(SAC_CLASS, false);
+ Thread.sleep(timeout * 2); // let the SCR to unregister the service
+ assertNull(
+ "The service must not be available after we had disabled the component (AnotherComponent)",
+ trackerSAC.getServiceReferences());
+
+ ((ComponentManager)extendedClass).enableComponent(SC_CLASS, false);
+ Thread.sleep(timeout * 2); // let the SCR to unregister the service
+ assertNull(
+ "The service must not be available after we had disabled the component (Worker)",
+ trackerSC.getServiceReferences());
+
+ //*** test enableComponent() method
+ ((ComponentManager)extendedClass).enableComponent(SAC_CLASS, true);
+ Thread.sleep(timeout * 2); // let the SCR to register the service
+ assertNotNull(
+ "The service must be available after we had enabled the component",
+ trackerSAC.getServiceReferences());
+ assertTrue(
+ "The service must be available after we had enabled the component",
+ trackerSAC.getServiceReferences().length > 0);
+
+ ((ComponentManager)extendedClass).enableComponent(null, true);
+ Thread.sleep(timeout * 2);
+ assertNotNull(
+ "The enableComponent() with passed null parameter, must enable the remaining disabled components",
+ trackerSC.getServiceReferences());
+ assertTrue(
+ "The enableComponent() with passed null parameter, must enable the remaining disabled components",
+ trackerSC.getServiceReferences().length > 0);
+
+ //*** test getBundleContext()
+ BundleContextProvider sacBCE = (BundleContextProvider) trackerSAC
+ .getService();
+ assertNotNull("AnotherComponent should be available", sacBCE);
+ assertSame(
+ "The two bundle context (this from the activator and from the ComponentContext object must be the same",
+ sacBCE.getBundleContext(),
+ ((ComponentContextProvider)extendedClass).getComponentContext().getBundleContext()
+ );
+
+ //*** test getComponentInstance()
+ Bundle bundle = installBundle("tb4");
+ assertNotNull("Installing tb4.jar should succeed", bundle);
+ bundle.start();
+ waitBundleStart();
+
+ Hashtable props;
+ ComponentFactory factory = (ComponentFactory) trackerNamedServiceFactory
+ .getService();
+ assertNotNull("NamedService component factory should be available", factory);
+
+ props = new Hashtable();
+ props.put("name", "hello");
+
+ ComponentInstance ci = factory.newInstance(props);
+ assertNotNull("newInstance() should not return null", ci);
+ ComponentContextProvider cce = (ComponentContextProvider) ci.getInstance();
+ assertNotNull("getInstance() should not return null if we haven't disposed the component", cce);
+ assertNotNull("the component instance should be initialized correctly", cce.getComponentContext());
+ ComponentInstance ctxtInstance = cce.getComponentContext().getComponentInstance();
+ assertSame("The ComponentInstance object retrieved from the factory and from the ComponentContext must be the same",
+ ci, ctxtInstance);
+ // dispose the instance
+ ci.dispose();
+ assertNull("getInstance() should return null when disposed", ci.getInstance());
+
+ //*** test getUsingBundle()
+ ComponentContextProvider simpleComponentCCE = (ComponentContextProvider) trackerSC.getService();
+ assertNotNull("Worker should be available", simpleComponentCCE);
+ assertNotNull("Worker's context should be not null", simpleComponentCCE.getComponentContext());
+ assertNotNull("At least this bundle (TBC) must be using the Worker service", simpleComponentCCE.getComponentContext().getUsingBundle());
+
+ //*** test getProperties()
+ Dictionary p = simpleComponentCCE.getComponentContext().getProperties();
+ assertNotNull("Worker properties must be not null", p);
+ assertEquals("The properties must contain the custom property defined in the component description",
+ p.get("custom"), "customvalue");
+ assertEquals("The properties must contain the component.name property",
+ p.get(ComponentConstants.COMPONENT_NAME), SC_CLASS);
+ assertNotNull("The properties must contain the component.id property",
+ p.get(ComponentConstants.COMPONENT_ID));
+ assertEquals("The component.id property must be of type java.lang.Long",
+ p.get(ComponentConstants.COMPONENT_ID).getClass().getName(),
+ Long.class.getName());
+
+ //*** test getServiceReference()
+ ServiceReference ctxtServiceReference = ctxt.getServiceReference();
+ ServiceReference bcServiceReference = trackerExtendedClass.getServiceReference();
+ assertEquals("The two ServiceReference should be equal",ctxtServiceReference, bcServiceReference);
+
+ //*** test locateService(String)
+ Object locateSac = ctxt.locateService("StandAloneComp");
+ assertNotNull("The locateService() method should return non-null object",
+ locateSac);
+ assertEquals("The object must implement " + SAC_CLASS, locateSac.getClass().getName(), SAC_CLASS);
+
+ // test illegal call
+ assertNull("Trying to get invalid reference should return null", ctxt.locateService("InvalidReference"));
+
+ ((ComponentManager)extendedClass).enableComponent(SAC_CLASS, false); // disable component to test that the locateService() don't return disabled components
+ Thread.sleep(timeout);
+
+ assertEquals("Check that the component is correctly disabled", 0, countAvailableServices(trackerSAC));
+
+ locateSac = ctxt.locateService("StandAloneComp");
+ assertNull("The reference shouldn't be available with optional cardinality and disabled component",
+ locateSac);
+
+ ((ComponentManager)extendedClass).enableComponent(SAC_CLASS, true);
+ Thread.sleep(timeout * 2);
+ assertTrue("Check that the component is correctly enabled", countAvailableServices(trackerSAC) > 0);
+
+ //*** test locateServices(String)
+ Object[] boundObjects = ctxt.locateServices("StandAloneComp");
+ int boundCount = ((BoundTester)extendedClass).getBoundObjectsCount();
+ assertNotNull("The returned array of bound services should not be null", boundObjects);
+ assertEquals(
+ "The returned array of bound services should have the length equal to the internal count",
+ boundCount, boundObjects.length);
+ for (int i = 0; i < boundObjects.length; i++) {
+ assertNotNull(
+ "There shouldn't be null element in the bound objects array (" + i
+ + ")", boundObjects[i]);
+ }
+
+ assertNull("The locateServices() method should return null on invalid reference name",
+ ctxt.locateServices("InvalidReference"));
+
+ //*** test locateService(String, ServiceReference)
+ assertTrue("There must be at least one bound element",
+ ((BoundTester) extendedClass).getBoundObjectsCount() > 0);
+
+ ServiceReference sr1 = ((BoundTester) extendedClass).getBoundServiceRef(0);
+ assertNotNull("The ServiceReference bound to the BindUnbindSuccessor components should not be null",
+ sr1);
+ Object fromSR1 = ctxt.getBundleContext().getService(sr1);
+ Object fromCtxt = ctxt.locateService("StandAloneComp", sr1);
+ try {
+ assertNotNull("The service object from BundleContext must not be null",
+ fromSR1);
+ assertNotNull("The service object from locateService() must not be null",
+ fromCtxt);
+ assertSame(
+ "The two objects retrieved from BundleContext and from locateService(String, ServiceReference) method must be the same",
+ fromSR1, fromCtxt);
+ } finally {
+ ctxt.getBundleContext().ungetService(sr1);
+ }
+
+ assertNull(
+ "locateService() must return null when passed ServiceReference is null",
+ ctxt.locateService("StandAloneComp", null));
+
+ assertNull(
+ "locateService() must return null when passed ServiceReference isn't bound to the component",
+ ctxt.locateService("StandAloneComp", trackerExtendedClass.getServiceReference()));
+
+ assertNull(
+ "locateService() must return null when the referenceName isn't correct even if the service reference is correct",
+ ctxt.locateService("InvalidReference", sr1));
+
+ uninstallBundle(bundle);
+ }
+
+ public void testPropertiesHandling() throws Exception {
+ ConfigurationAdmin cm = (ConfigurationAdmin) trackerCM.getService();
+ ServiceReference ref;
+
+ // update the properties
+ Hashtable props = new Hashtable(10);
+ props.put("test.property.value", "setFromCM");
+ props.put("test.property.list", "setFromCM");
+ props.put("component.name", "setFromCM");
+ props.put("component.id", new Long(-1));
+ // the line below will create the configuration if it doesn't exists!
+ // see CM api for details
+ assertNotNull("The ConfigurationAdmin should be available", cm);
+ Configuration config = cm.getConfiguration(SAC_CLASS);
+ assertNotNull("The Configuration object should be created if don't exist",
+ config);
+ config.update(props);
+
+ // let SCR & CM to complete it's job
+ Thread.sleep(timeout * 3);
+
+ ref = trackerSAC.getServiceReference();
+ // check the correctness of the properties
+ assertNotNull("The AnotherComponent's reference should be available",
+ ref);
+ assertEquals("Properties not overriden from later ones should not be lost",
+ "setFromFile", ref.getProperty("test.property.array"));
+ assertEquals(
+ "Properties set through the CM should take precedence before those set from file",
+ "setFromCM", ref.getProperty("test.property.value"));
+ assertEquals(
+ "Properties overriden from later ones in definition should take precedence",
+ "setFromDefinition", ref.getProperty("test.property.name"));
+ assertEquals(
+ "Properties set through the CM should take precedence before those set from definition",
+ "setFromCM", ref.getProperty("test.property.list"));
+ assertEquals("Properties not overriden from later ones should not be lost",
+ "setFromDefinition", ref.getProperty("test.property.cont"));
+ assertEquals("Must not allow overriding the component.name property",
+ SAC_CLASS, ref.getProperty("component.name"));
+ assertNotNull("component.id property should be present", ref.getProperty(ComponentConstants.COMPONENT_ID));
+ assertTrue("Must not allow overriding the component.id property",
+ ((Long) ref.getProperty("component.id")).longValue() > 0);
+
+ Bundle bundle = installBundle("tb4");
+ bundle.start();
+ waitBundleStart();
+
+ Configuration c = cm.getConfiguration(NAMED_CLASS);
+ assertNotNull("The Configuration should be created properly", c);
+ Hashtable cmProps = new Hashtable();
+ cmProps.put("override.property.3", "setFromCM");
+ c.update(cmProps);
+
+ // let the config update reach the SCR
+ Thread.sleep(timeout * 3);
+
+ ComponentFactory factory = (ComponentFactory) trackerNamedServiceFactory
+ .getService();
+ assertNotNull("The NamedService ComponentFactory should be available",
+ factory);
+
+ Hashtable newProps = new Hashtable();
+ newProps.put("override.property.1", "setFromMethod");
+ newProps.put("override.property.2", "setFromMethod");
+ newProps.put("override.property.3", "setFromMethod");
+ newProps.put(ComponentConstants.COMPONENT_NAME, "setFromMethod");
+ newProps.put(ComponentConstants.COMPONENT_ID, new Long(-1));
+ newProps.put("name", "test");
+
+ ComponentInstance ci = factory.newInstance(newProps);
+ assertNotNull("newInstance() method shouldn't return null", ci);
+
+ ServiceReference[] refs = trackerNamedService.getServiceReferences();
+ boolean serviceFound = false;
+ for (int i = 0; refs != null && i < refs.length; i++) {
+ ServiceReference current = refs[i];
+ if ("test".equals(current.getProperty("name"))) {
+ serviceFound = true;
+ assertEquals(
+ "Properties set through newInstance method must override those from definition",
+ "setFromMethod", current.getProperty("override.property.1"));
+ assertEquals(
+ "Properties set through newInstance method must override those from file",
+ "setFromMethod", current.getProperty("override.property.2"));
+ assertEquals(
+ "Properties set through newInstance method must override those from ConfigurationAdmin",
+ "setFromMethod", current.getProperty("override.property.3"));
+ assertEquals("Must not override " + ComponentConstants.COMPONENT_NAME,
+ current.getProperty(ComponentConstants.COMPONENT_NAME), NAMED_CLASS);
+ assertTrue("Must not override " + ComponentConstants.COMPONENT_ID,
+ ((Long) current.getProperty(ComponentConstants.COMPONENT_ID))
+ .longValue() > 0);
+ }
+ }
+ assertTrue("Must have found service", serviceFound);
+
+ ci.dispose();
+ c.delete();
+ bundle.stop();
+
+ // test the conflict between factory and factoryPID
+ c = cm.createFactoryConfiguration(NAMED_CLASS);
+ assertNotNull(
+ "CM should not return null Configuration from createFactoryConfiguration()",
+ c);
+ c.update(cmProps);
+ Thread.sleep(timeout);
+
+ bundle.start();
+ waitBundleStart();
+
+ assertNull(
+ "The named service shouldn't be available when there is factory configuration for it",
+ trackerNamedServiceFactory.getService());
+
+ c.delete();
+ Thread.sleep(timeout * 3);
+
+ // create factory configs for Worker
+ Configuration scConfig1 = cm.createFactoryConfiguration(SC_CLASS);
+ Hashtable scProps1 = new Hashtable();
+ scProps1.put("name", "instance1");
+ scConfig1.update(scProps1);
+
+ Configuration scConfig2 = cm.createFactoryConfiguration(SC_CLASS);
+ Hashtable scProps2 = new Hashtable();
+ scProps2.put("name", "instance2");
+ scConfig2.update(scProps2);
+
+ Thread.sleep(timeout * 3);
+
+ try {// test factory configuration for normal component
+ assertEquals("The Worker should have two instances", 2, countAvailableServices(trackerSC));
+ } finally {
+ scConfig1.delete();
+ scConfig2.delete();
+ }
+ Thread.sleep(timeout * 3);
+
+ assertEquals("The Worker should have one instance", 1, countAvailableServices(trackerSC));
+ ServiceReference scRef = trackerSC.getServiceReference();
+ assertNull("The Worker only instance shouldn't have \"name\" property", scRef.getProperty("name"));
+
+ uninstallBundle(bundle);
+ }
+
+ public void testBoundServiceReplacement() throws Exception {
+ int beforeCount, afterCount;
+ Hashtable mandatoryProperty = new Hashtable();
+ mandatoryProperty.put("mandatory.property", "true");
+
+ Bundle tb4 = installBundle("tb4");
+ tb4.start();
+ waitBundleStart();
+ assertEquals("tb4.jar should be ACTIVE", Bundle.ACTIVE, tb4.getState());
+
+ ComponentFactory namedFactory = (ComponentFactory) trackerNamedServiceFactory
+ .getService();
+ assertNotNull("NamedService component factory should be available",
+ namedFactory);
+ ComponentFactory dynFactory = (ComponentFactory) trackerDynServiceFactory
+ .getService();
+ assertNotNull("DynamicWorker component factory should be available",
+ dynFactory);
+
+ // create the mandatory elements
+ ComponentInstance namedServiceInstance = namedFactory
+ .newInstance((Dictionary) mandatoryProperty.clone());
+ assertNotNull("NamedService component instance should not be null",
+ namedServiceInstance);
+ Object namedService = namedServiceInstance.getInstance();
+ assertNotNull("NamedService should be created properly", namedService);
+ ComponentInstance dynServiceInstance = dynFactory
+ .newInstance((Dictionary) mandatoryProperty.clone());
+ assertNotNull("DynamicWorker component instance should not be null",
+ dynServiceInstance);
+ Object dynService = dynServiceInstance.getInstance();
+ assertNotNull("DynamicWorker should be created properly", dynService);
+ Thread.sleep(timeout * 2);
+
+ Object bsrc = trackerBSRC.getService();
+ assertNotNull("BoundReplacer should be available",
+ bsrc);
+ assertSame("NamedService bound should be our first instance",
+ ((BoundMainProvider) bsrc)
+ .getBoundService(BoundMainProvider.NAMED_SERVICE), namedService);
+ assertSame("DynamicWorker bound should be our first instance",
+ ((BoundMainProvider) bsrc)
+ .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), dynService);
+
+ // provide second dynamic service
+ ComponentInstance dynServiceInstance2 = dynFactory
+ .newInstance((Dictionary) mandatoryProperty.clone());
+ assertNotNull(
+ "Second DynamicWorker component instance should not be null",
+ dynServiceInstance2);
+ Object dynService2 = dynServiceInstance2.getInstance();
+ assertNotNull("Second DynamicWorker instance should be available",
+ dynService2);
+
+ // reset the events
+ ((DSEventsProvider) bsrc).resetEvents();
+ // destroy the first instance of dynamic service
+ dynServiceInstance.dispose();
+
+ // check that service is replaced
+ assertNotSame(
+ "The bound dynamic service shouldn't be our first instance",
+ ((BoundMainProvider) bsrc)
+ .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), dynService);
+ assertSame("The bound dynamic service should be our second instance",
+ ((BoundMainProvider) bsrc)
+ .getBoundService(BoundMainProvider.DYNAMIC_SERVICE),
+ dynService2);
+
+ // check the correct order of replacing
+ DSEvent[] replacedBoundDynamicServicesEvents = ((DSEventsProvider) bsrc)
+ .getEvents();
+ assertEquals(
+ "There should two events after we have disposed the bound service",
+ 2, replacedBoundDynamicServicesEvents.length);
+ assertEquals("The first event should be bind event",
+ DSEvent.ACT_BOUND, replacedBoundDynamicServicesEvents[0]
+ .getAction());
+ assertSame(
+ "The first event should have associated object the second instance",
+ dynService2, replacedBoundDynamicServicesEvents[0].getObject());
+
+ assertEquals("The second event should be unbind event",
+ DSEvent.ACT_UNBOUND, replacedBoundDynamicServicesEvents[1]
+ .getAction());
+ assertSame(
+ "The second event should have associated object the first instance",
+ dynService, replacedBoundDynamicServicesEvents[1].getObject());
+
+ // destroy and the second service
+ dynServiceInstance2.dispose();
+
+ // check that the inspected service is deactivated
+ assertNull(
+ "The BoundReplacer should not be available as the destroyed service hasn't replacement",
+ trackerBSRC.getService());
+
+ // restore the BSRC
+ assertNotNull(
+ "The DynamicWorker component instance should be created properly",
+ dynFactory.newInstance((Dictionary) mandatoryProperty.clone()));
+ Thread.sleep(timeout);
+
+ Object bsrcObject = trackerBSRC.getService();
+ assertNotNull(
+ "The BoundReplacer should be available again",
+ bsrcObject);
+ ComponentContext bsrcCtxt1 = ((ComponentContextProvider) bsrcObject)
+ .getComponentContext();
+ assertNotNull(
+ "The BoundReplacer should be activated and ComponentContext available",
+ bsrcCtxt1);
+
+ // prepare second static service instance
+ ComponentInstance namedServiceInstance2 = namedFactory
+ .newInstance((Dictionary) mandatoryProperty.clone());
+ assertNotNull("Second NamedService instance should be created properly",
+ namedServiceInstance2);
+ Object namedService2 = namedServiceInstance2.getInstance();
+ assertNotNull("Second NamedService instance should be created properly",
+ namedService2);
+
+ // destroy the first instance
+ beforeCount = countAvailableServices(trackerNamedService);
+ namedServiceInstance.dispose();
+ afterCount = countAvailableServices(trackerNamedService);
+ assertEquals(
+ "The NamedService instance should be removed from the registry",
+ beforeCount - 1, afterCount);
+
+ // check that the BSRC has been reactivated
+ Object bsrcObject2 = trackerBSRC.getService(); // the BSRC object can be
+ // recreated
+ assertNotNull("The BoundReplacer should not be null",
+ bsrcObject2);
+ ComponentContext bsrcCtxt2 = ((ComponentContextProvider) bsrcObject2)
+ .getComponentContext();
+ assertNotNull("The second ComponentContext should not be null", bsrcCtxt2);
+ assertNotSame(
+ "The second ComponentContext should be different than the first one",
+ bsrcCtxt1, bsrcCtxt2);
+
+ // destroy the second instance
+ namedServiceInstance2.dispose();
+
+ assertNull("The BSRC should be disabled", trackerBSRC.getService());
+
+ uninstallBundle(tb4);
+ }
+
+ /**
+ * Returns the number of available services for the passed tracker
+ *
+ * @param tracker
+ * @return
+ */
+ private int countAvailableServices(ServiceTracker tracker) {
+ if (tracker == null)
+ return -1;
+ ServiceReference[] refs = tracker.getServiceReferences();
+ return refs != null ? refs.length : 0;
+ }
+
+ public void testBoundServiceReplacementOnModification() throws Exception {
+ BundleContext bc = getContext();
+ Hashtable initialProps = new Hashtable();
+ Hashtable modifiedProps = new Hashtable();
+ initialProps.put("mandatory.property", "true");
+ modifiedProps.put("mandatory.property", "false");
+
+ ServiceRegistration dynRegistration1 = registerService(DynamicWorker.class.getName(), new DynamicWorker(), (Dictionary) initialProps.clone());
+
+ ServiceRegistration staticRegistration1 = registerService(
+ StaticWorker.class.getName(), new StaticWorker(),
+ (Dictionary) initialProps.clone());
+
+ Bundle tb4 = installBundle("tb4");
+ tb4.start();
+ waitBundleStart();
+ assertEquals("tb4.jar should be ACTIVE", Bundle.ACTIVE, tb4.getState());
+
+ // assure the MBSRC is available
+ assertTrue("The AdvancedBounder must be available",
+ countAvailableServices(trackerMBSRC) > 0);
+ Object bsrc = trackerMBSRC.getService();
+ assertNotNull("MBSRC isntance should be not null", bsrc);
+
+ // register the second instances
+ ServiceRegistration dynRegistration2 = registerService(
+ DynamicWorker.class.getName(), new DynamicWorker(),
+ (Dictionary) initialProps.clone());
+
+ // reset the bound services events
+ ((DSEventsProvider) bsrc).resetEvents();
+ // change the first instance of dynamic service
+ dynRegistration1.setProperties(modifiedProps);
+ Thread.sleep(timeout);
+
+ Object instance1 = bc.getService(dynRegistration1.getReference());
+ Object instance2 = bc.getService(dynRegistration2.getReference());
+ try {
+
+ // check that service is replaced
+ assertNotSame("The bound dynamic service shouldn't be our first instance",
+ ((BoundMainProvider) bsrc)
+ .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), instance1);
+ assertSame("The bound dynamic service should be our second instance",
+ ((BoundMainProvider) bsrc)
+ .getBoundService(BoundMainProvider.DYNAMIC_SERVICE), instance2);
+
+ // check the correct order of replacing
+ DSEvent[] replacedBoundDynamicServicesEvents = ((DSEventsProvider) bsrc)
+ .getEvents();
+ assertEquals(
+ "There should two events after we have disposed the bound service", 2,
+ replacedBoundDynamicServicesEvents.length);
+
+ assertEquals("The first event should be bind event",
+ DSEvent.ACT_BOUND, replacedBoundDynamicServicesEvents[0]
+ .getAction());
+ assertSame(
+ "The first event should have associated object the second instance",
+ instance2, replacedBoundDynamicServicesEvents[0].getObject());
+
+ assertEquals("The second event should be unbind event",
+ DSEvent.ACT_UNBOUND, replacedBoundDynamicServicesEvents[1]
+ .getAction());
+ assertSame(
+ "The second event should have associated object the first instance",
+ instance1, replacedBoundDynamicServicesEvents[1].getObject());
+
+ } finally {
+ bc.ungetService(dynRegistration1.getReference());
+ bc.ungetService(dynRegistration2.getReference());
+ }
+ instance1 = instance2 = null;
+
+ ComponentContext bsrcCtxt1 = ((ComponentContextProvider) bsrc)
+ .getComponentContext();
+ assertNotNull("ComponentContext object should be available", bsrcCtxt1);
+
+ ServiceRegistration staticRegistration2 = registerService(
+ StaticWorker.class.getName(), new StaticWorker(),
+ (Dictionary) initialProps.clone());
+ // change the first instance
+ staticRegistration1.setProperties((Dictionary) modifiedProps.clone());
+ Thread.sleep(timeout);
+
+ Object bsrcObject2 = trackerMBSRC.getService(); // the BSRC object can be
+ // recreated
+ assertNotNull("The BoundReplacer should not be null",
+ bsrcObject2);
+ ComponentContext bsrcCtxt2 = ((ComponentContextProvider) bsrcObject2)
+ .getComponentContext();
+ assertNotNull("The second ComponentContext should not be null", bsrcCtxt2);
+ assertNotSame(
+ "The second ComponentContext should be different than the first one",
+ bsrcCtxt1, bsrcCtxt2);
+
+ uninstallBundle(tb4);
+
+ unregisterService(dynRegistration1);
+ unregisterService(dynRegistration2);
+ unregisterService(staticRegistration1);
+ unregisterService(staticRegistration2);
+ }
+
+ public void testSecurity() throws Exception {
+ // the method below sets the permissions of a bundle before installing it
+ // to simplify the test case
+ if (System.getSecurityManager() == null) {
+ // the security is off
+ return;
+ }
+ BundleContext bc = getContext();
+ ServiceReference padmRef = bc.getServiceReference(PermissionAdmin.class
+ .getName());
+ assertNotNull("Permission Admin service not available.", padmRef);
+
+ PermissionAdmin padm = (PermissionAdmin) bc.getService(padmRef);
+ assertNotNull("Permission Admin service should be available", padm);
+
+ assertEquals("TestBundle1 must be running.", Bundle.ACTIVE, tb1.getState());
+
+ PermissionInfo registerServiceInfo = new PermissionInfo(
+ ServicePermission.class.getName(),
+ "org.eclipse.equinox.ds.tests.tb5.impl.SecurityTester",
+ ServicePermission.REGISTER);
+ PermissionInfo getServiceInfo = new PermissionInfo(ServicePermission.class
+ .getName(), "org.eclipse.equinox.ds.tests.tb1.impl.AnotherComponent", ServicePermission.GET);
+
+ PermissionInfo importPackage = new PermissionInfo(
+ PackagePermission.class.getName(), "org.eclipse.equinox.ds.tests.tb1.impl",
+ PackagePermission.IMPORT);
+
+ // install the bundle to get the location
+ Bundle tb5 = installBundle("tb5");
+ tb5.start();
+ waitBundleStart();
+ final String bundleLocation = tb5.getLocation();
+
+ uninstallBundle(tb5);
+
+ // do the test
+
+ // set all permission needed for correct operation
+ padm.setPermissions(bundleLocation, new PermissionInfo[] {
+ registerServiceInfo, getServiceInfo, importPackage });
+
+ // install
+ tb5 = installBundle("tb5");
+ tb5.start();
+ waitBundleStart();
+ assertEquals(
+ "The bundle location should be the same as the first one registered",
+ bundleLocation, tb5.getLocation());
+
+ // check that the component is available
+ assertTrue(
+ "The SecurityTester should be present because all needed permissions are set",
+ countAvailableServices(trackerSecurity) > 0);
+
+ // uninstall
+ uninstallBundle(tb5);
+
+ // remove the register permission - the service shouldn't be available
+ padm.setPermissions(bundleLocation, new PermissionInfo[] {
+ importPackage, getServiceInfo });
+
+ // install
+ tb5 = installBundle("tb5");
+ tb5.start();
+ waitBundleStart();
+ assertEquals(
+ "The bundle location should be the same as the first one registered",
+ bundleLocation, tb5.getLocation());
+
+ // check that the service is unavailable
+ assertEquals(
+ "The SecurityTester shouldn't be present due to missing ServicePermission.REGISTER",
+ 0, countAvailableServices(trackerSecurity));
+
+ // uninstall
+ uninstallBundle(tb5);
+
+ // remove the get permission and bring back the register permission
+ padm.setPermissions(bundleLocation, new PermissionInfo[] {
+ importPackage, registerServiceInfo });
+
+ // install
+ tb5 = installBundle("tb5");
+ tb5.start();
+ waitBundleStart();
+ assertEquals(
+ "The bundle location should be the same as the first one registered",
+ bundleLocation, tb5.getLocation());
+
+ // check that the component is unavailable
+ assertEquals(
+ "The SecurityTester shouldn't be present due to missing ServicePermission.GET",
+ 0, countAvailableServices(trackerSecurity));
+
+ // uninstall
+ uninstallBundle(tb5);
+
+ // reset the permissions
+ padm.setPermissions(bundleLocation, null);
+ // release the PermissionAdmin service
+ bc.ungetService(padmRef);
+ padm = null;
+ }
+
+ public void testImmediateComponents() throws Exception {
+ Bundle tb4 = installBundle("tb4");
+ tb4.start();
+ waitBundleStart();
+
+ // check that the ServiceProvider is registered
+ assertNotNull("The ServiceProvider should be registered as service",
+ getContext().getServiceReference(
+ "org.eclipse.equinox.ds.tests.tb4.ServiceProvider"));
+ // check that the ServiceProvider is activated
+ assertTrue("The ServiceProvider should be activated", TestHelper
+ .isActivatedServiceProvider());
+
+ // check that the Stand Alone Component is activated
+ assertTrue("The AnotherComponent should be activated",
+ TestHelper.isActivatedStandAlone());
+
+ uninstallBundle(tb4);
+ }
+
+ public void testRowReference() throws Exception {
+ final String TAIL_CLASS = "org.eclipse.equinox.ds.tests.tb4.Component3";
+ final String MIDDLE_CLASS = "org.eclipse.equinox.ds.tests.tb4.Component2";
+ final String HEAD_CLASS = "org.eclipse.equinox.ds.tests.tb4.Component1";
+
+ Bundle tb4 = installBundle("tb4");
+ tb4.start();
+ waitBundleStart();
+
+ // check that all the components are present
+ assertTrue("The Component3 should be available",
+ checkAvailability(TAIL_CLASS));
+ assertTrue("The Component2 should be available",
+ checkAvailability(MIDDLE_CLASS));
+ assertTrue("The Component1 should be available",
+ checkAvailability(HEAD_CLASS));
+
+ BundleContext bc = getContext();
+ // get ComponentContext
+ ServiceReference cceRef = bc
+ .getServiceReference("org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider");
+ assertNotNull("The GiveMeContext should be available", cceRef);
+ assertEquals(
+ "The GiveMeContext should be the implementation present in tb4.jar",
+ "org.eclipse.equinox.ds.tests.tb4.GiveMeContext", cceRef
+ .getProperty("component.name"));
+
+ ComponentContextProvider cce = (ComponentContextProvider) bc
+ .getService(cceRef);
+ assertNotNull("The service object should be retrieved correctly", cce);
+ ComponentContext ctxt = cce.getComponentContext();
+ assertNotNull("The ComponentContext object should not be null", ctxt);
+
+ // disable the tail component
+ ctxt.disableComponent(TAIL_CLASS);
+ Thread.sleep(timeout);
+
+ // check that no component is available
+ assertTrue("The Component3 shouldn't be available",
+ !checkAvailability(TAIL_CLASS));
+ assertTrue("The Component2 shouldn't be available",
+ !checkAvailability(MIDDLE_CLASS));
+ assertTrue("The Component1 shouldn't be available",
+ !checkAvailability(HEAD_CLASS));
+
+ // enable the tail component
+ ctxt.enableComponent(TAIL_CLASS);
+ Thread.sleep(timeout);
+
+ // check that the components are back online
+ assertTrue("The Component3 should be available",
+ checkAvailability(TAIL_CLASS));
+ assertTrue("The Component2 should be available",
+ checkAvailability(MIDDLE_CLASS));
+ assertTrue("The Component1 should be available",
+ checkAvailability(HEAD_CLASS));
+
+ // release the GiveMeContext
+ bc.ungetService(cceRef);
+
+ // remove the bundle
+ uninstallBundle(tb4);
+ }
+
+ private boolean checkAvailability(String service) {
+ BundleContext bc = getContext();
+ ServiceReference ref = bc.getServiceReference(service);
+ return ref != null;
+ }
+
+ private boolean checkFactoryAvailability(String factory) throws InvalidSyntaxException {
+ BundleContext bc = getContext();
+ ServiceReference[] refs = bc.getServiceReferences(ComponentFactory.class.getName(), "(" + ComponentConstants.COMPONENT_FACTORY + "=" + factory + ")");
+ return refs != null && refs.length > 0;
+ }
+
+ public void testBlockingComponents() throws Exception {
+ final Bundle tb2 = installBundle("tb2");
+ final Bundle tb3 = installBundle("tb3");
+ final Bundle tb4 = installBundle("tb4");
+
+ new Thread() {
+ public void run() {
+ try {
+ tb2.start(); // start the blocking service
+ } catch (BundleException e) { }
+ }
+ }.start();
+ sleep0(scr_restart_timeout + timeout * 2);
+
+ new Thread() {
+ public void run() {
+ try {
+ tb4.start(); // start the other
+ } catch (BundleException e) { }
+ }
+ }.start();
+
+ sleep0(timeout * 3); // sleep until the services are activated
+
+ // check that the first service is missing, and the second is available
+ assertEquals("The blocking service should not be available", 0, countAvailableServices(trackerBAS));
+ assertTrue("The service in the bundle should be available", checkAvailability("org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider"));
+
+ tb2.stop();
+ tb4.stop();
+
+ // check that AnotherComponent is available
+ assertTrue("The AnotherComponent should be available", checkAvailability("org.eclipse.equinox.ds.tests.tb1.impl.AnotherComponent"));
+
+ // start the other blocking bundle
+ new Thread() {
+ public void run() {
+ try {
+ tb3.start();
+ } catch (BundleException e) { }
+ }
+ }.start();
+
+ sleep0(scr_restart_timeout + timeout * 2);
+
+ // start the non-blocking bundle
+ new Thread() {
+ public void run() {
+ try {
+ tb4.start(); // start the other
+ } catch (BundleException e) { }
+ }
+ }.start();
+
+ sleep0(timeout * 3); // sleep until the services are activated
+
+ assertEquals("The blocking service should not be available", 0, countAvailableServices(trackerBBS));
+ assertTrue("The service in the bundle should be available", checkAvailability("org.eclipse.equinox.ds.tests.tbc.ComponentContextProvider"));
+
+ uninstallBundle(tb2);
+ uninstallBundle(tb3);
+ uninstallBundle(tb4);
+ }
+
+ public void testStaticPolicyBinding() throws Exception {
+ Bundle tb6 = installBundle("tb6");
+ tb6.start();
+ waitBundleStart();
+
+ // check initial conditions
+ assertTrue("The StaticComp should be available", checkAvailability(STATIC_CLASS));
+ assertTrue("The ReferencedComp shouldn't be available (disabled)", !checkAvailability(REFERENCED_CLASS));
+
+ // reset the events list
+ Object initialStatic = trackerStatic.getService();
+ assertNotNull(STATIC_CLASS + " component should be non-null", initialStatic);
+ ComponentContext initialCtxt = ((ComponentContextProvider)initialStatic).getComponentContext();
+ ((DSEventsProvider)initialStatic).resetEvents();
+ assertEquals("There shouldn't be bound service to StaticComp", 0, ((BoundTester)initialStatic).getBoundObjectsCount());
+
+
+ // enable the ReferencedComp
+ initialCtxt.enableComponent(REFERENCED_CLASS);
+ Thread.sleep(timeout * 2);
+
+ // check the availability after enablement
+ assertTrue("The StaticComp should be available", checkAvailability(STATIC_CLASS));
+ assertTrue("The ReferencedComp should be available", checkAvailability(REFERENCED_CLASS));
+
+ // check that the SCR created new instance
+ Object enabledStatic = trackerStatic.getService();
+ assertNotNull(STATIC_CLASS + " component should be non-null", enabledStatic);
+ ComponentContext enabledCtxt = ((ComponentContextProvider)enabledStatic).getComponentContext();
+ assertNotSame("The StaticComp must have been restarted", initialCtxt, enabledCtxt);
+ assertEquals("There should be one bound service to StaticComp", 1, ((BoundTester)enabledStatic).getBoundObjectsCount());
+
+ // check the events
+ DSEvent[] initialEvents = ((DSEventsProvider)initialStatic).getEvents();
+ assertEquals("The events in the first instance of StaticComp should only one", 1, initialEvents.length);
+ assertEquals("The event should deactivate one", DSEvent.ACT_DEACTIVATE, initialEvents[0].getAction());
+
+ DSEvent[] enabledEvents = ((DSEventsProvider)enabledStatic).getEvents();
+ assertEquals("The events for the second instance of StaticComp should be two", 2, enabledEvents.length);
+ assertEquals("The first event should bind event", DSEvent.ACT_BOUND, enabledEvents[0].getAction());
+ assertEquals("The second event should be activate event", DSEvent.ACT_ACTIVATE, enabledEvents[1].getAction());
+
+ // reset the events
+ ((DSEventsProvider)enabledStatic).resetEvents();
+
+ // disable the component
+ enabledCtxt.disableComponent(REFERENCED_CLASS);
+ Thread.sleep(timeout * 2);
+
+ // check the availability
+ assertTrue("The StaticComp should be available", checkAvailability(STATIC_CLASS));
+ assertTrue("The ReferencedComp shouldn't be available", !checkAvailability(REFERENCED_CLASS));
+
+ // check that the SCR created new instance
+ Object disabledStatic = trackerStatic.getService();
+ assertNotNull(STATIC_CLASS + " component should be non-null", disabledStatic);
+ ComponentContext disabledCtxt = ((ComponentContextProvider)disabledStatic).getComponentContext();
+ assertNotSame("The StaticComp must have been restarted", enabledCtxt, disabledCtxt);
+ assertEquals("There should be one bound service to StaticComp", 0, ((BoundTester)disabledStatic).getBoundObjectsCount());
+
+ enabledEvents = ((DSEventsProvider)enabledStatic).getEvents();
+ DSEvent[] disabledEvents = ((DSEventsProvider)disabledStatic).getEvents();
+
+ assertEquals("The second instance of StaticComp should have two events after disabling ReferencedComp", 2, enabledEvents.length);
+ assertEquals("The first event should be deactivate", DSEvent.ACT_DEACTIVATE, enabledEvents[0].getAction());
+ assertEquals("The second event should be unbind", DSEvent.ACT_UNBOUND, enabledEvents[1].getAction());
+
+ assertEquals("There should only one event for the second instance of StaticComp", 1, disabledEvents.length);
+ assertEquals("The event should be activate", DSEvent.ACT_ACTIVATE, disabledEvents[0].getAction());
+
+ uninstallBundle(tb6);
+ }
+
+ public void testCircularityHandling() throws Exception {
+ Bundle tb7 = installBundle("tb7");
+ tb7.start();
+ waitBundleStart();
+
+ final String UNBREAKABLE = "org.eclipse.equinox.ds.tests.tb7.UnbreakableCircuit";
+ final String DYN_BREAKABLE = "org.eclipse.equinox.ds.tests.tb7.DynamicCircuit";
+ final String STATIC_BREAKABLE = "org.eclipse.equinox.ds.tests.tb7.StaticCircuit";
+
+ // check that the unbreakable circuit isn't available
+ assertTrue("The first service from the unbreakable circularity shouldn't be available", !checkAvailability(UNBREAKABLE + "1"));
+ assertTrue("The second service from the unbreakable circularity shouldn't be available", !checkAvailability(UNBREAKABLE + "2"));
+
+ // check that the breakable circuit with dynamic optional reference is available
+ assertTrue("The first service from the breakable circularity with dynamic optional reference should be available", checkAvailability(DYN_BREAKABLE + "1"));
+ assertTrue("The second service from the breakable circularity with dynamic optional reference should be available", checkAvailability(DYN_BREAKABLE + "2"));
+
+ // check that the breakable circuit with dynamic optional reference has bound correctly
+ ServiceReference dynBreak2Ref = getContext().getServiceReference(DYN_BREAKABLE + "2");
+ Object dynBreak2 = getContext().getService(dynBreak2Ref);
+ try {
+ assertEquals("The DynamicCircuit2 component should have one bound object", 1, ((BoundTester)dynBreak2).getBoundObjectsCount());
+ assertNotNull("The DynamicCircuit2 component should have one non-null bound object", ((BoundTester)dynBreak2).getBoundService(0));
+ } finally {
+ getContext().ungetService(dynBreak2Ref);
+ }
+ // check that the breakable circuit with static optional reference isn't available
+ assertTrue("The first service from the breakable circularity with static optional reference should be available", checkAvailability(STATIC_BREAKABLE + "1"));
+ assertTrue("The second service from the breakable circularity with static optional reference should be available", checkAvailability(STATIC_BREAKABLE + "2"));
+
+ // check that the optional reference isn't satisfied
+ ServiceReference staticBreak2Ref = getContext().getServiceReference(STATIC_BREAKABLE + "2");
+ Object staticBreak2 = getContext().getService(staticBreak2Ref);
+ try {
+ assertEquals("The StaticCircuit2 component shouldn't have bound objects", 0, ((BoundTester)staticBreak2).getBoundObjectsCount());
+ } finally {
+ getContext().ungetService(staticBreak2Ref);
+ }
+
+ // check that the worker hasn't been blocked
+ Bundle tb5 = installBundle("tb5");
+ tb5.start();
+ waitBundleStart();
+
+ // check that the AnotherComponent service is available
+ assertTrue("The AnotherComponent should be available", checkAvailability("org.eclipse.equinox.ds.tests.tb1.impl.AnotherComponent"));
+ assertTrue("The service in TB5 should be available which means that the working thread of the SCR isn't blocked", checkAvailability("org.eclipse.equinox.ds.tests.tb5.impl.SecurityTester"));
+
+ uninstallBundle(tb5);
+ uninstallBundle(tb7);
+ }
+
+ // tests namespace handling in xml component description parser
+ public void testNamespaceHandling() throws Exception {
+ Bundle tb8 = installBundle("tb8");
+ tb8.start();
+ waitBundleStart();
+
+ // check the root component handling
+ assertTrue("The root1 component should be available", isNSComponentAvailable(101));
+ assertTrue("The root2 component should be available", isNSComponentAvailable(102));
+ assertTrue("The root3 component should not be available", !isNSComponentAvailable(103));
+ assertTrue("The root4 component should be available", isNSComponentAvailable(104));
+ assertTrue("The root5 component should not be available", !isNSComponentAvailable(105));
+ // check the non root component handling
+ assertTrue("The nonroot1 component should not be available", !isNSComponentAvailable(111));
+ assertTrue("The nonroot2 component should be available", isNSComponentAvailable(112));
+ assertTrue("The nonroot3 component should not be available", !isNSComponentAvailable(113));
+ assertTrue("The nonroot4 component should be available", isNSComponentAvailable(114));
+ assertTrue("The nonroot5 component should not be available", !isNSComponentAvailable(115));
+ assertTrue("The nonroot6 component should be available", isNSComponentAvailable(116));
+ assertTrue("The nonroot7 component should not be available", !isNSComponentAvailable(117));
+ assertTrue("The nonroot8 component should not be available", !isNSComponentAvailable(118));
+ assertTrue("The nonroot9 component should not be available", !isNSComponentAvailable(119));
+ assertTrue("The nonroot10 component should not be available", !isNSComponentAvailable(120));
+ assertTrue("The nonroot11 component should be available", isNSComponentAvailable(121));
+ assertTrue("The nonroot12 component should not be available", !isNSComponentAvailable(122));
+ assertTrue("The nonroot13 component should not be available", !isNSComponentAvailable(123));
+ assertTrue("The nonroot14 component should be available", isNSComponentAvailable(124));
+ assertTrue("The nonroot15 component should be available", isNSComponentAvailable(125));
+ assertTrue("The nonroot16 component should be available", isNSComponentAvailable(126));
+ assertTrue("The nonroot17 component should be available", isNSComponentAvailable(127));
+
+ uninstallBundle(tb8);
+ }
+
+ private boolean isNSComponentAvailable(int nsid) {
+ Object[] services = trackerNS.getServices();
+ if (services == null) {
+ return false;
+ }
+ for (int i = 0; i < services.length; i++) {
+ if (services[i] instanceof NamespaceProvider) {
+ NamespaceProvider s = (NamespaceProvider)services[i];
+ if (s.getComponentNSID() == nsid) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ // tests wildcard handling in mf (e.g. Service-Component: OSGI-INF/*.xml)
+ public void testWildcardHandling() throws Exception {
+ Bundle tb9 = installBundle("tb9");
+ tb9.start();
+ waitBundleStart();
+
+ final String WILD = "org.eclipse.equinox.ds.tests.tb9.Wildcard";
+
+ // check that the both components are available
+ assertTrue("The first Wildcard component should be available", checkAvailability(WILD + "1"));
+ assertTrue("The second Wildcard component should be available", checkAvailability(WILD + "2"));
+
+ uninstallBundle(tb9);
+ }
+
+ public void testDynamicComponentFactoryServiceBinding() throws Exception {
+ Bundle tb10 = installBundle("tb10");
+ assertNotNull("Failed to install test bundle tb10.jar", tb10);
+ tb10.start();
+ waitBundleStart();
+
+ // assert that the required components are available
+ assertTrue("The referenced simple component should be available", checkAvailability(SC_CLASS));
+ assertTrue("The referenced factory component should be available", checkFactoryAvailability("CountHelperFactory"));
+ assertTrue("The dependent dynamic factory component should be available", checkFactoryAvailability("CountFactory"));
+
+ // retrieve the helper factory
+ ComponentFactory helperFactory = (ComponentFactory) trackerBoundServiceCounterHelperFactory.getService();
+ assertNotNull("The helper factory must be retrievable", helperFactory);
+
+ // retrieve the observed factory
+ ComponentFactory observedFactory = (ComponentFactory) trackerBoundServiceCounterFactory.getService();
+ assertNotNull("The observed factory must be retrievable", observedFactory);
+
+ // instantiate observed components
+ ComponentInstance observedInstance1 = observedFactory.newInstance(null);
+ assertNotNull("Cannot instantiate component from observed factory [1]", observedInstance1);
+ ComponentInstance observedInstance2 = observedFactory.newInstance(null);
+ assertNotNull("Cannot instantiate component from observed factory [2]", observedInstance2);
+
+ BoundCountProvider observedComponent1 = (BoundCountProvider) observedInstance1.getInstance();
+ BoundCountProvider observedComponent2 = (BoundCountProvider) observedInstance2.getInstance();
+ assertNotNull("The observed component must be non-null [1]", observedComponent1);
+ assertNotNull("The observed component must be non-null [2]", observedComponent2);
+
+ // check the bound services before instantiating helper factory components - both components must have 1 service bound
+ assertEquals("The bound service count must be 1 - only the simple component is available [1]", 1, observedComponent1.getBoundServiceCount(null));
+ assertEquals("The bound service count must be 1 - only the simple component is available [2]", 1, observedComponent2.getBoundServiceCount(null));
+
+ // instantiate three helper components and check the service count again
+ for (int i = 0; i < 3; i++) {
+ helperFactory.newInstance(null); // don't keep track of the created instances, they will be disposed when the bundle is stopped and uninstalled
+ }
+
+ // check the bound services count again - both components must have 4 services bound -> 1 simple component and 3 helper factory
+ assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [1]", 4, observedComponent1.getBoundServiceCount(null));
+ assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [2]", 4, observedComponent2.getBoundServiceCount(null));
+
+ uninstallBundle(tb10);
+ }
+
+ public void testStaticComponentFactoryServiceBinding() throws Exception {
+ Bundle tb10 = installBundle("tb10");
+ assertNotNull("Failed to install test bundle tb10.jar", tb10);
+ tb10.start();
+ waitBundleStart();
+
+ // assert that the required components are available
+ assertTrue("The referenced simple component should be available", checkAvailability(SC_CLASS));
+ assertTrue("The referenced factory component should be available", checkFactoryAvailability("CountHelperFactory"));
+ assertTrue("The dependent static factory component should be available", checkFactoryAvailability("StaticServiceCountFactory"));
+
+ // retrieve the helper and observer factories
+ ComponentFactory helperFactory = (ComponentFactory) trackerBoundServiceCounterHelperFactory.getService();
+ ComponentFactory observedFactory = (ComponentFactory) trackerStaticServiceCounterFactory.getService();
+ assertNotNull("The helper factory must be retrievable", helperFactory);
+ assertNotNull("The observed factory must be retrievable", observedFactory);
+
+ // instantiate observed components
+ ComponentInstance observedInstance1 = observedFactory.newInstance(null);
+ ComponentInstance observedInstance2 = observedFactory.newInstance(null);
+ assertNotNull("Cannot instantiate component from observed factory [1]", observedInstance1);
+ assertNotNull("Cannot instantiate component from observed factory [2]", observedInstance2);
+
+ BoundCountProvider observedComponent1 = (BoundCountProvider) observedInstance1.getInstance();
+ BoundCountProvider observedComponent2 = (BoundCountProvider) observedInstance2.getInstance();
+ assertNotNull("The observed component must be non-null [1]", observedComponent1);
+ assertNotNull("The observed component must be non-null [2]", observedComponent2);
+
+ // check the bound services before instantiating helper factory components - both components must have 1 service bound
+ assertEquals("The bound service count must be 1 - only the simple component is available [1]", 1, observedComponent1.getBoundServiceCount(null));
+ assertEquals("The bound service count must be 1 - only the simple component is available [2]", 1, observedComponent2.getBoundServiceCount(null));
+
+ // instantiate three helper components and check the service count again
+ for (int i = 0; i < 3; i++) {
+ helperFactory.newInstance(null); // don't keep track of the created instances, they will be disposed when the bundle is stopped and uninstalled
+ }
+
+ // check whether the factory is the same, it shouldn't be disposed
+ assertSame(observedFactory, trackerStaticServiceCounterFactory.getService());
+ observedFactory = (ComponentFactory) trackerStaticServiceCounterFactory.getService();
+
+ // check that the components are reinstantiated
+ observedInstance1 = observedFactory.newInstance(null);
+ observedInstance2 = observedFactory.newInstance(null);
+ assertNotNull("Cannot instantiate new observed component instance [1]", observedInstance1);
+ assertNotNull("Cannot instantiate new observed component instance [2]", observedInstance2);
+
+ // get the new instances
+ observedComponent1 = (BoundCountProvider) observedInstance1.getInstance();
+ observedComponent2 = (BoundCountProvider) observedInstance2.getInstance();
+ assertNotNull("The observed component instance must be non-null [1]", observedComponent1);
+ assertNotNull("The observed component instance must be non-null [2]", observedComponent2);
+
+ // check the bound services count again - both components must have 4 services bound -> 1 simple component and 3 helper factory
+ assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [1]", 4, observedComponent1.getBoundServiceCount(null));
+ assertEquals("The bound service count must be 4 - 1 simple component, 3 helper factory components [2]", 4, observedComponent2.getBoundServiceCount(null));
+
+ uninstallBundle(tb10);
+ }
+
+ public void testConfigurationPolicy() throws Exception {
+ ConfigurationAdmin cm = (ConfigurationAdmin) trackerCM.getService();
+ assertNotNull("The ConfigurationAdmin should be available", cm);
+
+ Bundle tb11 = installBundle("tb11");
+ tb11.start();
+ waitBundleStart();
+
+ Hashtable props = new Hashtable(10);
+ props.put("config.base.data", new Integer(1));
+
+ // component notsetNS100 - property not set by Configuration Admin; XML NS 1.0.0
+ assertEquals("Configuration data should not be available for notsetNS100", 0, getBaseConfigData(COMP_NOTSET_100));
+ // component notsetNS100 - property set by Configuration Admin; XML NS 1.0.0
+ Configuration config = cm.getConfiguration(COMP_NOTSET_100);
+ config.update(props);
+ Thread.sleep(timeout * 3);
+ assertEquals("Configuration data should be available for notsetNS100 and equal to 1", 1, getBaseConfigData(COMP_NOTSET_100));
+
+ // component notsetNS110 - property not set by Configuration Admin; XML NS 1.1.0
+ assertEquals("Configuration data should not be available for notsetNS110", 0, getBaseConfigData(COMP_NOTSET_110));
+ // component notsetNS110 - property set by Configuration Admin; XML NS 1.1.0
+ config = cm.getConfiguration(COMP_NOTSET_110);
+ config.update(props);
+ Thread.sleep(timeout * 3);
+ assertEquals("Configuration data should be available for notsetNS110 and equal to 1", 1, getBaseConfigData(COMP_NOTSET_110));
+
+ // component optionalNS100 - property not set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT
+ assertEquals("Component optionalNS100 should not be activated", -1, getBaseConfigData(COMP_OPTIONAL_100));
+ // component optionalNS100 - property set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT
+ config = cm.getConfiguration(COMP_OPTIONAL_100);
+ config.update(props);
+ Thread.sleep(timeout * 3);
+ assertEquals("Component optionalNS100 should not be activated", -1, getBaseConfigData(COMP_OPTIONAL_100));
+
+ // component optionalNS110 - property not set by Configuration Admin; XML NS 1.1.0
+ assertEquals("Configuration data should not be available for optionalNS110", 0, getBaseConfigData(COMP_OPTIONAL_110));
+ // component optionalNS110 - property set by Configuration Admin; XML NS 1.1.0
+ config = cm.getConfiguration(COMP_OPTIONAL_110);
+ config.update(props);
+ Thread.sleep(timeout * 3);
+ assertEquals("Configuration data should be available for optionalNS110 and equal to 1", 1, getBaseConfigData(COMP_OPTIONAL_110));
+
+ // component requireNS100 - property not set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT
+ assertEquals("Component requireNS100 should not be activated", -1, getBaseConfigData(COMP_REQUIRE_100));
+ // component requireNS100 - property set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT
+ config = cm.getConfiguration(COMP_REQUIRE_100);
+ config.update(props);
+ Thread.sleep(timeout * 3);
+ assertEquals("Component requireNS100 should not be activated", -1, getBaseConfigData(COMP_REQUIRE_100));
+
+ // component requireNS110 - property not set by Configuration Admin; XML NS 1.1.0
+ assertEquals("Configuration data should not be available for requireNS110, and it should not be satisfied", -1, getBaseConfigData(COMP_REQUIRE_110));
+ // component requireNS110 - property set by Configuration Admin; XML NS 1.1.0
+ config = cm.getConfiguration(COMP_REQUIRE_110);
+ config.update(props);
+ Thread.sleep(timeout * 3);
+ assertEquals("Configuration data should be available for requireNS110 and equal to 1", 1, getBaseConfigData(COMP_REQUIRE_110));
+
+ // component ignoreNS100 - property not set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT
+ assertEquals("Component ignoreNS100 should not be activated", -1, getBaseConfigData(COMP_IGNORE_100));
+ // component ignoreNS100 - property set by Configuration Admin; XML NS 1.0.0 - INVALID COMPONENT
+ config = cm.getConfiguration(COMP_IGNORE_100);
+ config.update(props);
+ Thread.sleep(timeout * 3);
+ assertEquals("Component ignoreNS100 should not be activated", -1, getBaseConfigData(COMP_IGNORE_100));
+
+ // component ignoreNS110 - property not set by Configuration Admin; XML NS 1.1.0
+ assertEquals("Configuration data should not be available for ignoreNS110, but it should be satisfied", 0, getBaseConfigData(COMP_IGNORE_110));
+ // component ignoreNS110 - property set by Configuration Admin; XML NS 1.1.0
+ config = cm.getConfiguration(COMP_IGNORE_110);
+ config.update(props);
+ Thread.sleep(timeout * 3);
+ assertEquals("Configuration data should not be available for ignoreNS110, but it should be satisfied", 0, getBaseConfigData(COMP_IGNORE_110));
+
+ uninstallBundle(tb11);
+ }
+
+ public void testActivateDeactivate() throws Exception {
+ Bundle tb12 = installBundle("tb12");
+ tb12.start();
+ waitBundleStart();
+
+ final String NOTSET_NS100 = "org.eclipse.equinox.ds.tests.tb12.notsetNS100";
+ final String NOTSET_NS110 = "org.eclipse.equinox.ds.tests.tb12.notsetNS110";
+ final String NOARGS_NS100 = "org.eclipse.equinox.ds.tests.tb12.NoArgs100";
+ final String NOARGS_NS110 = "org.eclipse.equinox.ds.tests.tb12.NoArgs110";
+ final String CC_NS100 = "org.eclipse.equinox.ds.tests.tb12.CcNS100";
+ final String CC_NS110 = "org.eclipse.equinox.ds.tests.tb12.CcNS110";
+ final String BC_NS100 = "org.eclipse.equinox.ds.tests.tb12.Bc100";
+ final String BC_NS110 = "org.eclipse.equinox.ds.tests.tb12.Bc110";
+ final String MAP_NS100 = "org.eclipse.equinox.ds.tests.tb12.MapNS100";
+ final String MAP_NS110 = "org.eclipse.equinox.ds.tests.tb12.MapNS110";
+ final String CC_BC_MAP_NS100 = "org.eclipse.equinox.ds.tests.tb12.CcBcMapNS100";
+ final String CC_BC_MAP_NS110 = "org.eclipse.equinox.ds.tests.tb12.CcBcMapNS110";
+ final String INT_NS110 = "org.eclipse.equinox.ds.tests.tb12.IntNS110";
+ final String CC_BC_MAP_INT_NS110 = "org.eclipse.equinox.ds.tests.tb12.CcBcMapIntNS110";
+
+ PropertiesProvider bs = getBaseService(NOTSET_NS100);
+ ComponentContext cc = (bs instanceof ComponentContextProvider) ?
+ ((ComponentContextProvider) bs).getComponentContext() : null;
+ assertNotNull("Component context should be available", cc);
+
+ assertEquals("Activate method of " + NOTSET_NS100 + " should be called", 1 << 0, (1 << 0) & getBaseConfigData(bs));
+ cc.disableComponent(NOTSET_NS100);
+ Thread.sleep(timeout * 3);
+ assertEquals("Deactivate method of " + NOTSET_NS100 + " should be called", 1 << 1, (1 << 1) & getBaseConfigData(bs));
+
+ bs = getBaseService(NOTSET_NS110);
+ assertNotNull(bs);
+ assertEquals("Activate method of " + NOTSET_NS110 + " should be called", 1 << 0, (1 << 0) & getBaseConfigData(bs));
+ cc.disableComponent(NOTSET_NS110);
+ Thread.sleep(timeout * 3);
+ assertEquals("Deactivate method of " + NOTSET_NS110 + " should be called", 1 << 1, (1 << 1) & getBaseConfigData(bs));
+
+ bs = getBaseService(NOARGS_NS100); // INVALID COMPONENT FOR XML NS 1.0.0
+ assertEquals("Component " + NOARGS_NS100 + " should not be activated", -1, getBaseConfigData(bs));
+
+ bs = getBaseService(NOARGS_NS110);
+ assertNotNull(bs);
+ assertEquals("Activate method of " + NOARGS_NS110 + " should be called", 1 << 2, (1 << 2) & getBaseConfigData(bs));
+ cc.disableComponent(NOARGS_NS110);
+ Thread.sleep(timeout * 3);
+ assertEquals("Deactivate method of " + NOARGS_NS110 + " should be called", 1 << 3, (1 << 3) & getBaseConfigData(bs));
+
+ bs = getBaseService(CC_NS100); // INVALID COMPONENT FOR XML NS 1.0.0
+ assertEquals("Component " + CC_NS100 + " should not be activated", -1, getBaseConfigData(bs));
+
+ bs = getBaseService(CC_NS110);
+ assertNotNull(bs);
+ assertEquals("Activate method of " + CC_NS110 + " should be called", 1 << 4, (1 << 4) & getBaseConfigData(bs));
+ cc.disableComponent(CC_NS110);
+ Thread.sleep(timeout * 3);
+ assertEquals("Deactivate method of " + CC_NS110 + " should be called", 1 << 5, (1 << 5) & getBaseConfigData(bs));
+
+ bs = getBaseService(BC_NS100); // INVALID COMPONENT FOR XML NS 1.0.0
+ assertEquals("Component " + BC_NS100 + " should not be activated", -1, getBaseConfigData(bs));
+
+ bs = getBaseService(BC_NS110);
+ assertNotNull(bs);
+ assertEquals("Activate method of " + BC_NS110 + " should be called", 1 << 6, (1 << 6) & getBaseConfigData(bs));
+ cc.disableComponent(BC_NS110);
+ Thread.sleep(timeout * 3);
+ assertEquals("Deactivate method of " + BC_NS110 + " should be called", 1 << 7, (1 << 7) & getBaseConfigData(bs));
+
+ bs = getBaseService(MAP_NS100); // INVALID COMPONENT FOR XML NS 1.0.0
+ assertEquals("Component " + MAP_NS100 + " should not be activated", -1, getBaseConfigData(bs));
+
+ bs = getBaseService(MAP_NS110);
+ assertNotNull(bs);
+ assertEquals("Activate method of " + MAP_NS110 + " should be called", 1 << 8, (1 << 8) & getBaseConfigData(bs));
+ cc.disableComponent(MAP_NS110);
+ Thread.sleep(timeout * 3);
+ assertEquals("Deactivate method of " + MAP_NS110 + " should be called", 1 << 9, (1 << 9) & getBaseConfigData(bs));
+
+ bs = getBaseService(CC_BC_MAP_NS100); // INVALID COMPONENT FOR XML NS 1.0.0
+ assertEquals("Component " + CC_BC_MAP_NS100 + " should not be activated", -1, getBaseConfigData(bs));
+
+ bs = getBaseService(CC_BC_MAP_NS110);
+ assertNotNull(bs);
+ assertEquals("Activate method of " + CC_BC_MAP_NS110 + " should be called", 1 << 10, (1 << 10) & getBaseConfigData(bs));
+ cc.disableComponent(CC_BC_MAP_NS110);
+ Thread.sleep(timeout * 3);
+ assertEquals("Deactivate method of " + CC_BC_MAP_NS110 + " should be called", 1 << 11, (1 << 11) & getBaseConfigData(bs));
+
+ bs = getBaseService(INT_NS110);
+ assertNotNull(bs);
+ cc.disableComponent(INT_NS110);
+ Thread.sleep(timeout * 3);
+ assertEquals("Deactivate method of " + INT_NS110 + " should be called", 1 << 12, (1 << 12) & getBaseConfigData(bs));
+
+ bs = getBaseService(CC_BC_MAP_INT_NS110);
+ assertNotNull(bs);
+ cc.disableComponent(CC_BC_MAP_INT_NS110);
+ Thread.sleep(timeout * 3);
+ int data = getBaseConfigData(bs);
+ assertEquals("Deactivate method of " + CC_BC_MAP_INT_NS110 + " should be called", 1 << 13, (1 << 13) & data);
+
+ //// Testing Deactivation reasons ////
+ assertEquals("Deactivation reason shall be DEACTIVATION_REASON_DISABLED", 1, 0xFF & (data >> 16));
+
+ final String CONT_EXP = "org.eclipse.equinox.ds.tests.tb12.ContextExp";
+
+ cc.enableComponent(CC_BC_MAP_INT_NS110);
+ Thread.sleep(timeout * 3);
+ bs = getBaseService(CC_BC_MAP_INT_NS110);
+ assertNotNull(bs);
+ cc.disableComponent(CONT_EXP);
+ Thread.sleep(timeout * 3);
+ assertEquals("Deactivation reason shall be DEACTIVATION_REASON_REFERENCE", 2, 0xFF & (getBaseConfigData(bs) >> 16));
+
+ cc.enableComponent(CONT_EXP);
+ Thread.sleep(timeout * 3);
+
+ bs = getBaseService(CC_BC_MAP_INT_NS110);
+ assertNotNull(bs);
+ ConfigurationAdmin cm = (ConfigurationAdmin) trackerCM.getService();
+ assertNotNull("The ConfigurationAdmin should be available", cm);
+ Configuration config = cm.getConfiguration(CC_BC_MAP_INT_NS110);
+ Dictionary properties = config.getProperties();
+ if (properties == null) {
+ properties = new Hashtable();
+ }
+ properties.put("configuration.dummy", "dummy");
+ config.update(properties);
+ Thread.sleep(timeout * 3);
+ assertEquals("Deactivation reason shall be DEACTIVATION_REASON_CONFIGURATION_MODIFIED", 3, 0xFF & (getBaseConfigData(bs) >> 16));
+
+ cc.enableComponent(CC_BC_MAP_INT_NS110);
+ Thread.sleep(timeout * 3);
+
+ bs = getBaseService(CC_BC_MAP_INT_NS110);
+ assertNotNull(bs);
+ config = cm.getConfiguration(CC_BC_MAP_INT_NS110);
+ config.delete();
+ Thread.sleep(timeout * 3);
+ assertEquals("Deactivation reason shall be DEACTIVATION_REASON_CONFIGURATION_DELETED", 4, 0xFF & (getBaseConfigData(bs) >> 16));
+
+ cc.enableComponent(CC_BC_MAP_INT_NS110);
+ Thread.sleep(timeout * 3);
+
+ cc.enableComponent(INT_NS110);
+ Thread.sleep(timeout * 3);
+
+ bs = getBaseService(INT_NS110);
+ assertNotNull(bs);
+ ComponentContext ccIntNS110 = (bs instanceof ComponentContextProvider) ?
+ ((ComponentContextProvider) bs).getComponentContext() : null;
+ assertNotNull("Component context should be available for " + INT_NS110, ccIntNS110);
+ ccIntNS110.getComponentInstance().dispose();
+ assertEquals("Deactivation reason shall be DEACTIVATION_REASON_DISPOSED", 5, 0xFF & (getBaseConfigData(bs) >> 16));
+
+ bs = getBaseService(CC_BC_MAP_INT_NS110);
+ assertNotNull(bs);
+ tb12.stop();
+ assertEquals("Deactivation reason shall be DEACTIVATION_REASON_BUNDLE_STOPPED", 6, 0xFF & (getBaseConfigData(bs) >> 16));
+
+ uninstallBundle(tb12);
+ }
+
+ public void testBindUnbindParams() throws Exception {
+ Bundle tb13 = installBundle("tb13");
+ tb13.start();
+ waitBundleStart();
+
+ final String SR_NS100 = "org.eclipse.equinox.ds.tests.tb13.SrNS100";
+ final String SR_NS110 = "org.eclipse.equinox.ds.tests.tb13.SrNS110";
+ final String CE_NS100 = "org.eclipse.equinox.ds.tests.tb13.CeNS100";
+ final String CE_NS110 = "org.eclipse.equinox.ds.tests.tb13.CeNS110";
+ final String CE_MAP_NS100 = "org.eclipse.equinox.ds.tests.tb13.CeMapNS100";
+ final String CE_MAP_NS110 = "org.eclipse.equinox.ds.tests.tb13.CeMapNS110";
+
+ ServiceReference ref = getContext().getServiceReference(ComponentManager.class.getName());
+ assertNotNull("Component Enabler Service Reference should be available", ref);
+ ComponentManager enabler = (ComponentManager) getContext().getService(ref);
+ assertNotNull("Component Enabler Service should be available", enabler);
+
+ PropertiesProvider bs = getBaseService(SR_NS100);
+ assertNotNull("Component " + SR_NS100 + " should be activated", bs);
+ assertEquals("Bind method of " + SR_NS100 + " should be called", 1 << 0, (1 << 0) & getBaseConfigData(bs));
+ enabler.enableComponent(SR_NS100, false);
+ Thread.sleep(timeout * 3);
+ assertEquals("Unbind method of " + SR_NS100 + " should be called", 1 << 1, (1 << 1) & getBaseConfigData(bs));
+
+ bs = getBaseService(SR_NS110);
+ assertNotNull("Component " + SR_NS110 + " should be activated", bs);
+ assertEquals("Bind method of " + SR_NS110 + " should be called", 1 << 0, (1 << 0) & getBaseConfigData(bs));
+ enabler.enableComponent(SR_NS110, false);
+ Thread.sleep(timeout * 3);
+ assertEquals("Unbind method of " + SR_NS110 + " should be called", 1 << 1, (1 << 1) & getBaseConfigData(bs));
+
+ bs = getBaseService(CE_NS100);
+ assertNotNull("Component " + CE_NS100 + " should be activated", bs);
+ assertEquals("Bind method of " + CE_NS100 + " should be called", 1 << 2, (1 << 2) & getBaseConfigData(bs));
+ enabler.enableComponent(CE_NS100, false);
+ Thread.sleep(timeout * 3);
+ assertEquals("Unbind method of " + CE_NS100 + " should be called", 1 << 3, (1 << 3) & getBaseConfigData(bs));
+
+ bs = getBaseService(CE_NS110);
+ assertNotNull("Component " + CE_NS110 + " should be activated", bs);
+ assertEquals("Bind method of " + CE_NS110 + " should be called", 1 << 2, (1 << 2) & getBaseConfigData(bs));
+ enabler.enableComponent(CE_NS110, false);
+ Thread.sleep(timeout * 3);
+ assertEquals("Unbind method of " + CE_NS110 + " should be called", 1 << 3, (1 << 3) & getBaseConfigData(bs));
+
+ bs = getBaseService(CE_MAP_NS100);
+ assertNull("Component " + CE_MAP_NS100 + " should not be activated", bs);
+
+ bs = getBaseService(CE_MAP_NS110);
+ assertNotNull("Component " + CE_MAP_NS110 + " should be activated", bs);
+ assertEquals("Bind method of " + CE_MAP_NS110 + " should be called", 1 << 4, (1 << 4) & getBaseConfigData(bs));
+ enabler.enableComponent(CE_MAP_NS110, false);
+ Thread.sleep(timeout * 3);
+ assertEquals("Unbind method of " + CE_MAP_NS110 + " should be called", 1 << 5, (1 << 5) & getBaseConfigData(bs));
+
+ getContext().ungetService(ref);
+ uninstallBundle(tb13);
+ }
+
+ public void testOptionalNames() throws Exception {
+ Bundle tb14 = installBundle("tb14");
+ tb14.start();
+ waitBundleStart();
+ PropertiesProvider bs;
+
+ final String OPT_NAME_100 = "org.eclipse.equinox.ds.tests.tb14.Optional";
+ final String OPT_NAME_110 = "org.eclipse.equinox.ds.tests.tb14.Optional2";
+ final String OPT_REF_100 = "org.eclipse.equinox.ds.tests.tb14.OptRef100";
+ final String OPT_REF_110 = "org.eclipse.equinox.ds.tests.tb14.OptRef110";
+
+ assertNull("Component " + OPT_NAME_100 + " should not be activated", getBaseService(OPT_NAME_100));
+ assertNotNull("Component " + OPT_NAME_110 + " should be activated", getBaseService(OPT_NAME_110));
+
+ assertNull("Component " + OPT_REF_100 + " should not be activated", getBaseService(OPT_REF_100));
+ assertNotNull("Component " + OPT_REF_110 + " should be activated", bs = getBaseService(OPT_REF_110));
+
+ ComponentContext cc = (bs instanceof ComponentContextProvider) ?
+ ((ComponentContextProvider) bs).getComponentContext() : null;
+ assertNotNull("Component context should be available", cc);
+ assertNotNull("Optional reference name should be set to interface attribute", cc.locateService(ComponentContextProvider.class.getName()));
+
+ uninstallBundle(tb14);
+ }
+
+ public void testDisposingMultipleDependencies() throws Exception {
+ Bundle tb15 = installBundle("tb15");
+ tb15.start();
+ waitBundleStart();
+
+ final String C1 = "org.eclipse.equinox.ds.tests.tb15.Component1";
+ final String C2 = "org.eclipse.equinox.ds.tests.tb15.Component2";
+ final String C3 = "org.eclipse.equinox.ds.tests.tb15.Component3";
+
+ PropertiesProvider serviceC1 = getBaseService(C1);
+ assertNotNull("Component " + C1 + " should be activated", serviceC1);
+ PropertiesProvider serviceC2 = getBaseService(C2);
+ assertNotNull("Component " + C2 + " should be activated", serviceC2);
+ PropertiesProvider serviceC3 = getBaseService(C3);
+ assertNotNull("Component " + C3 + " should be activated", serviceC3);
+
+ ComponentContext cc = (serviceC1 instanceof ComponentContextProvider) ?
+ ((ComponentContextProvider) serviceC1).getComponentContext() : null;
+ assertNotNull("Component context should be available", cc);
+
+ cc.disableComponent(C1);
+ Thread.sleep(timeout * 3);
+
+ assertEquals("Component " + C3 + " should be deactivated first", 0, getBaseConfigData(serviceC3));
+ assertEquals("Component " + C2 + " should be deactivated second", 1, getBaseConfigData(serviceC2));
+ assertEquals("Component " + C1 + " should be deactivated third", 2, getBaseConfigData(serviceC1));
+
+ uninstallBundle(tb15);
+ }
+
+ public void testReferenceTargetProperty() throws Exception {
+ Bundle tb16 = installBundle("tb16");
+ tb16.start();
+ waitBundleStart();
+
+ final String EXPOSER = "org.eclipse.equinox.ds.tests.tb16.Exposer";
+ final String C1 = "org.eclipse.equinox.ds.tests.tb16.C1";
+ final String C2 = "org.eclipse.equinox.ds.tests.tb16.C2";
+
+ PropertiesProvider bs = getBaseService(EXPOSER);
+ ComponentContext cc = (bs instanceof ComponentContextProvider) ?
+ ((ComponentContextProvider) bs).getComponentContext() : null;
+ assertNotNull("Component context should be available", cc);
+
+ PropertiesProvider serviceC2 = getBaseService(C2);
+ // target property of referenced service of component Component2 should not be satisfied
+ assertNull("Component " + C2 + " should not be activated because of unsatisfied reference", serviceC2);
+
+ cc.enableComponent(C1);
+ Thread.sleep(timeout * 3);
+ assertNotNull("Component " + C1 + " should be available", getBaseService(C1));
+
+ serviceC2 = getBaseService(C2);
+ // target property of referenced service of component Component2 should now be satisfied
+ assertNotNull("Component " + C2 + " should be activated", serviceC2);
+
+ uninstallBundle(tb16);
+ }
+
+ class OverloadManager extends Thread {
+ private String compPrefix;
+ private int firstComp;
+ private int lastComp;
+
+ public OverloadManager(String compPrefix, int first, int last) {
+ this.compPrefix = compPrefix;
+ this.firstComp = first;
+ this.lastComp = last;
+ }
+
+ public void run() {
+ ConfigurationAdmin cm = (ConfigurationAdmin) trackerCM.getService();
+ assertNotNull("The ConfigurationAdmin should be available", cm);
+
+ try {
+ for (int i = firstComp; i <= lastComp; i++) {
+ Configuration config = cm.getConfiguration(compPrefix + i);
+ Dictionary properties = config.getProperties();
+ if (properties == null) {
+ properties = new Hashtable();
+ }
+ properties.put("component.index", new Integer(i));
+ config.update(properties);
+
+ sleep0(100);
+ }
+ } catch (IOException e) {
+ return;
+ }
+ }
+
+ public boolean isAllComponentsRunning() {
+ for (int i = firstComp; i <= lastComp; i++) {
+ if (getBaseService(compPrefix + i) == null) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ public void testOverload() throws Exception {
+ Bundle tb17 = installBundle("tb17");
+ Bundle tb18 = installBundle("tb18");
+ Bundle tb19 = installBundle("tb19");
+ tb17.start();
+ tb18.start();
+ tb19.start();
+ waitBundleStart();
+
+ final String SCR = "org.eclipse.equinox.ds.tests";
+ final int startComp = 1;
+ final int lastComp = 10;
+ final int OVERLOAD_TIMEOUT = 60000; // max time allowed for processing in ms
+
+ OverloadManager manager17 = new OverloadManager(SCR + ".tb17.C", startComp, lastComp);
+ OverloadManager manager18 = new OverloadManager(SCR + ".tb18.C", startComp, lastComp);
+ OverloadManager manager19 = new OverloadManager(SCR + ".tb19.C", startComp, lastComp);
+
+ long startTime = System.currentTimeMillis();
+ manager17.start();
+ manager18.start();
+ manager19.start();
+
+ manager17.join();
+ manager18.join();
+ manager19.join();
+
+ // waiting SCR to process events
+ int successCount = 0;
+ while ((successCount < 5) && (System.currentTimeMillis() - startTime < OVERLOAD_TIMEOUT)) {
+ Thread.sleep(100);
+ if (!manager17.isAllComponentsRunning() || !manager18.isAllComponentsRunning() || !manager19.isAllComponentsRunning()) {
+ successCount = 0;
+ continue;
+ }
+ successCount++;
+ }
+
+ long elapsed = System.currentTimeMillis() - startTime;
+ log("testOverload(): Overload processing finished for " + elapsed + " ms.");
+
+ assertTrue("All components of tb17 should be activated", manager17.isAllComponentsRunning());
+ assertTrue("All components of tb18 should be activated", manager18.isAllComponentsRunning());
+ assertTrue("All components of tb19 should be activated", manager19.isAllComponentsRunning());
+
+ uninstallBundle(tb17);
+ uninstallBundle(tb18);
+ uninstallBundle(tb19);
+ }
+
+ /**
+ * Searches for component with name componentName which provides PropertiesProvider. Returns value of its
+ * "config.base.data" property.
+ *
+ * @param componentName - the name of the component to get data
+ * @return the value of property "config.base.data", provided by PropertiesProvider.getProperties().
+ * Returned value is -1 when component which provides PropertiesProvider and has specified name is
+ * not activated. Returned value is 0 when component with specified name is active but doesn't
+ * have property "config.base.data".
+ */
+ private int getBaseConfigData(String componentName) {
+ PropertiesProvider s = getBaseService(componentName);
+ return getBaseConfigData(s);
+ }
+
+ private int getBaseConfigData(PropertiesProvider s) {
+ Dictionary props = null;
+ int value = -1;
+ if (s != null) {
+ value = 0;
+ if ((props = s.getProperties()) != null) {
+ Object prop = props.get("config.base.data");
+ if (prop instanceof Integer) {
+ value = ((Integer)prop).intValue();
+ }
+ }
+ }
+ return value;
+ }
+
+ private PropertiesProvider getBaseService(String componentName) {
+ Object[] services = trackerBaseService.getServices();
+ if (services == null) {
+ return null;
+ }
+ for (int i = 0; i < services.length; i++) {
+ if (services[i] instanceof PropertiesProvider) {
+ PropertiesProvider s = (PropertiesProvider)services[i];
+ Dictionary props = s.getProperties();
+ if (props != null && ((String)props.get(ComponentConstants.COMPONENT_NAME)).equals(componentName)) {
+ return s;
+ }
+ }
+ }
+ return null;
+ }
+
+ private BundleContext getContext() {
+ return DSTestsActivator.getContext();
+ }
+
+ private Bundle installBundle(String bundle) throws BundleException {
+ Bundle b = installer.installBundle(bundle);
+ return b;
+ }
+
+ private void uninstallBundle(Bundle bundle) throws BundleException {
+ installer.uninstallBundle(bundle);
+ }
+
+ private ServiceRegistration registerService(String className, Object service, Dictionary props) {
+ ServiceRegistration sr = getContext().registerService(className, service, props);
+
+ registeredServices.put(service, sr);
+
+ return sr;
+ }
+
+ private void unregisterService(Object service) {
+ ServiceRegistration sr = (ServiceRegistration) registeredServices.get(service);
+ if (sr != null) {
+ sr.unregister();
+ registeredServices.remove(sr);
+ }
+ }
+
+ private void unregisterService(ServiceRegistration reg) {
+ Enumeration e = registeredServices.elements();
+ while(e.hasMoreElements()) {
+ Object service = e.nextElement();
+ if (reg == null || registeredServices.get(service) == reg) {
+ unregisterService(service);
+ }
+ }
+ }
+
+ private void unregisterAllServices() {
+ Enumeration e = registeredServices.elements();
+ while (e.hasMoreElements()) {
+ Object service = e.nextElement();
+ unregisterService(service);
+ }
+ }
+
+ private void log(String msg) {
+// System.out.println("[Declarative Service TC] " + msg);
+ }
+
+ public void sleep0(long millisToSleep) {
+ long start = System.currentTimeMillis();
+ do {
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException e) {
+ }
+ } while (System.currentTimeMillis() - start < millisToSleep);
+ }
+
+ private void waitBundleStart() {
+ if (!synchronousBuild) {
+ sleep0(2 * timeout);
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DynamicWorker.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DynamicWorker.java
new file mode 100644
index 000000000..16cbfdab6
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DynamicWorker.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+import java.util.Dictionary;
+
+public class DynamicWorker implements PropertiesProvider {
+
+ public Dictionary getProperties() {
+ return null;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/NamespaceProvider.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/NamespaceProvider.java
new file mode 100644
index 000000000..187c8ecf0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/NamespaceProvider.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+public interface NamespaceProvider {
+ public int getComponentNSID();
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/PropertiesProvider.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/PropertiesProvider.java
new file mode 100644
index 000000000..d9c253c6f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/PropertiesProvider.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+import java.util.Dictionary;
+
+public interface PropertiesProvider {
+
+ public Dictionary getProperties();
+
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/StaticWorker.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/StaticWorker.java
new file mode 100644
index 000000000..617efa495
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/StaticWorker.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+import java.util.Dictionary;
+
+public class StaticWorker implements PropertiesProvider {
+
+ public Dictionary getProperties() {
+ return null;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/TestHelper.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/TestHelper.java
new file mode 100644
index 000000000..f8324b072
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/TestHelper.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 1997-2009 by ProSyst Software GmbH
+ * http://www.prosyst.com
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * ProSyst Software GmbH - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.ds.tests.tbc;
+
+public class TestHelper {
+
+ private static boolean activatedStandAlone = false;
+ private static boolean activatedServiceProvider = false;
+
+ public static void reset() {
+ activatedStandAlone = false;
+ activatedServiceProvider = false;
+ }
+
+ public static boolean isActivatedServiceProvider() {
+ return activatedServiceProvider;
+ }
+
+ public static void setActivatedServiceProvider(boolean activatedServiceProvider) {
+ TestHelper.activatedServiceProvider = activatedServiceProvider;
+ }
+
+ public static boolean isActivatedStandAlone() {
+ return activatedStandAlone;
+ }
+
+ public static void setActivatedStandAlone(boolean activatedStandAlone) {
+ TestHelper.activatedStandAlone = activatedStandAlone;
+ }
+
+}

Back to the top