aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStoyan Boshev2012-01-12 11:21:53 (EST)
committerStoyan Boshev2012-01-12 11:21:53 (EST)
commitf9e9301010b0f1452ffb5c7e930f02697308c2ab (patch)
tree7f5213475cdc57c31c510fdadaefcad2422409de
parentbed7fe2c74ad8c6d5f419e737795a579dc586645 (diff)
downloadrt.equinox.bundles-f9e9301010b0f1452ffb5c7e930f02697308c2ab.zip
rt.equinox.bundles-f9e9301010b0f1452ffb5c7e930f02697308c2ab.tar.gz
rt.equinox.bundles-f9e9301010b0f1452ffb5c7e930f02697308c2ab.tar.bz2
Implemented tests for DS 1.2 featuresv20120112-1621
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/.classpath1
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/build.properties6
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/META-INF/MANIFEST.MF8
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ConfigPIDComp.java37
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/PolicyOptionComp.java97
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ServicePropertiesComp.java82
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/components.xml191
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DSTest.java354
-rw-r--r--bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DefaultPropertiesProvider.java28
10 files changed, 803 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.ds.tests/.classpath b/bundles/org.eclipse.equinox.ds.tests/.classpath
index 6b6a14b..7fe05fa 100644
--- a/bundles/org.eclipse.equinox.ds.tests/.classpath
+++ b/bundles/org.eclipse.equinox.ds.tests/.classpath
@@ -29,5 +29,6 @@
<classpathentry kind="src" output="scr_test/tb21a" path="bundles_src/tb21a"/>
<classpathentry kind="src" output="scr_test/tb22" path="bundles_src/tb22"/>
<classpathentry kind="src" output="scr_test/tb23" path="bundles_src/tb23"/>
+ <classpathentry kind="src" output="scr_test/tb25" path="bundles_src/tb25"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/bundles/org.eclipse.equinox.ds.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.ds.tests/META-INF/MANIFEST.MF
index 66282e3..84f89bf 100644
--- a/bundles/org.eclipse.equinox.ds.tests/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.ds.tests/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: Declarative Services Tests
Bundle-Category: test
Bundle-SymbolicName: org.eclipse.equinox.ds.tests
-Bundle-Version: 1.1.0.qualifier
+Bundle-Version: 1.2.0.qualifier
Bundle-Activator: org.eclipse.equinox.ds.tests.DSTestsActivator
Bundle-ActivationPolicy: lazy
Require-Bundle: org.junit
@@ -13,7 +13,6 @@ Import-Package:
org.osgi.service.cm;version="1.2.0",
org.osgi.service.component;version="1.0.0",
org.osgi.service.log;version="1.3.0",
- org.osgi.service.packageadmin;version="1.2.0",
org.osgi.service.permissionadmin;version="1.2.0",
org.osgi.util.tracker;version="1.4.2"
Export-Package: org.eclipse.equinox.ds.tests.tbc
diff --git a/bundles/org.eclipse.equinox.ds.tests/build.properties b/bundles/org.eclipse.equinox.ds.tests/build.properties
index cd188e0..8b6a057 100644
--- a/bundles/org.eclipse.equinox.ds.tests/build.properties
+++ b/bundles/org.eclipse.equinox.ds.tests/build.properties
@@ -38,6 +38,7 @@ bin.includes = META-INF/,\
scr_test/tb22.jar,\
scr_test/tb23.jar,\
scr_test/tb24.jar,\
+ scr_test/tb25.jar,\
test.xml
jars.compile.order = .,\
scr_test/tb1.jar,\
@@ -65,7 +66,8 @@ jars.compile.order = .,\
scr_test/tb21a.jar,\
scr_test/tb22.jar,\
scr_test/tb23.jar,\
- scr_test/tb24.jar
+ scr_test/tb24.jar,\
+ scr_test/tb25.jar
source.scr_test/tb1.jar = bundles_src/tb1/
manifest.scr_test/tb1.jar = META-INF/MANIFEST.MF
source.scr_test/tb1a.jar = bundles_src/tb1a/
@@ -118,3 +120,5 @@ source.scr_test/tb23.jar = bundles_src/tb23/
manifest.scr_test/tb23.jar = META-INF/MANIFEST.MF
source.scr_test/tb24.jar = bundles_src/tb24/
manifest.scr_test/tb24.jar = META-INF/MANIFEST.MF
+source.scr_test/tb25.jar = bundles_src/tb25/
+manifest.scr_test/tb25.jar = META-INF/MANIFEST.MF
diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e89357d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/META-INF/MANIFEST.MF
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-Name: Declaritive services test
+Bundle-Description: Declaritive services TB25
+Bundle-Category: test
+Import-Package: org.eclipse.equinox.ds.tests.tbc,
+ org.osgi.framework,
+ org.osgi.service.component;version="1.0.0"
+Service-Component: org/eclipse/equinox/ds/tests/tb25/components.xml
diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ConfigPIDComp.java b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ConfigPIDComp.java
new file mode 100644
index 0000000..317dba0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ConfigPIDComp.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 1997, 2012 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.tb25;
+
+import java.util.Dictionary;
+
+import org.eclipse.equinox.ds.tests.tbc.PropertiesProvider;
+import org.osgi.service.component.ComponentContext;
+
+public class ConfigPIDComp implements PropertiesProvider {
+ private ComponentContext ctxt;
+
+ protected void activate(ComponentContext ctxt) {
+ this.ctxt = ctxt;
+ }
+
+ protected void deactivate(ComponentContext ctxt) {
+
+ }
+
+ public Dictionary getProperties() {
+ if (ctxt == null) {
+ return null;
+ }
+
+ return ctxt.getProperties();
+ }
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/PolicyOptionComp.java b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/PolicyOptionComp.java
new file mode 100644
index 0000000..1256690
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/PolicyOptionComp.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 1997, 2012 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.tb25;
+
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.equinox.ds.tests.tbc.PropertiesProvider;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.ComponentContext;
+
+public class PolicyOptionComp implements PropertiesProvider {
+ private static final String RANK_MISSING_VALUE = "property.is.missing";
+
+ private ComponentContext ctxt;
+ private Map newProps;
+
+ protected void activate(ComponentContext ctxt) {
+ this.ctxt = ctxt;
+ }
+
+ protected void deactivate(ComponentContext ctxt) {
+
+ }
+
+ public void bind01(PropertiesProvider service, Map properties) {
+ registerMethodCall("bind01", properties);
+ }
+
+ public void bind11(PropertiesProvider service, Map properties) {
+ registerMethodCall("bind11", properties);
+ }
+
+ public void bind0n(PropertiesProvider service, Map properties) {
+ registerMethodCall("bind0n", properties);
+ }
+
+ public void bind1n(PropertiesProvider service, Map properties) {
+ registerMethodCall("bind1n", properties);
+ }
+
+ public synchronized Dictionary getProperties() {
+ if (ctxt == null) {
+ return null;
+ }
+
+ Dictionary result = new Hashtable();
+
+ Dictionary ctxtProps = ctxt.getProperties();
+ if (ctxtProps != null) {
+ for (Enumeration en = ctxtProps.keys(); en.hasMoreElements();) {
+ Object key = en.nextElement();
+ result.put(key, ctxtProps.get(key));
+ }
+ }
+
+ if (newProps != null) {
+ for (Iterator it = newProps.keySet().iterator(); it.hasNext();) {
+ Object key = it.next();
+ result.put(key, newProps.get(key));
+ }
+ }
+
+ return result;
+ }
+
+ private synchronized void registerMethodCall(String name, Map properties) {
+ if (newProps == null) {
+ newProps = new Hashtable();
+ }
+ Object rankValue = null;
+ if (properties != null) {
+ newProps.putAll(properties);
+ rankValue = properties.get(Constants.SERVICE_RANKING);
+ }
+ List list = (List) newProps.get(name);
+ if (list == null) {
+ list = new ArrayList();
+ newProps.put(name, list);
+ }
+ list.add(rankValue != null ? rankValue : RANK_MISSING_VALUE);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ServicePropertiesComp.java b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ServicePropertiesComp.java
new file mode 100644
index 0000000..236dd5a
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/ServicePropertiesComp.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 1997, 2012 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.tb25;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.equinox.ds.tests.tbc.PropertiesProvider;
+import org.osgi.service.component.ComponentContext;
+
+public class ServicePropertiesComp implements PropertiesProvider {
+ private ComponentContext ctxt;
+ private Map newProps;
+
+ protected void activate(ComponentContext ctxt) {
+ this.ctxt = ctxt;
+ }
+
+ protected void deactivate(ComponentContext ctxt) {
+
+ }
+
+ public void bindRef(PropertiesProvider service, Map properties) {
+ }
+
+ public synchronized void serviceUpdatedStatic(PropertiesProvider service, Map properties) {
+ if (newProps == null) {
+ newProps = new Hashtable();
+ }
+ if (properties != null) {
+ newProps.putAll(properties);
+ }
+ newProps.put("serviceUpdatedStatic", Boolean.TRUE);
+ }
+
+ public synchronized void serviceUpdatedDynamic(PropertiesProvider service, Map properties) {
+ if (newProps == null) {
+ newProps = new Hashtable();
+ }
+ if (properties != null) {
+ newProps.putAll(properties);
+ }
+ newProps.put("serviceUpdatedDynamic", Boolean.TRUE);
+ }
+
+ public synchronized Dictionary getProperties() {
+ if (ctxt == null) {
+ return null;
+ }
+
+ Dictionary result = new Hashtable();
+
+ Dictionary ctxtProps = ctxt.getProperties();
+ if (ctxtProps != null) {
+ for (Enumeration en = ctxtProps.keys(); en.hasMoreElements();) {
+ Object key = en.nextElement();
+ result.put(key, ctxtProps.get(key));
+ }
+ }
+
+ if (newProps != null) {
+ for (Iterator it = newProps.keySet().iterator(); it.hasNext();) {
+ Object key = it.next();
+ result.put(key, newProps.get(key));
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/components.xml b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/components.xml
new file mode 100644
index 0000000..32a308b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/bundles_src/tb25/org/eclipse/equinox/ds/tests/tb25/components.xml
@@ -0,0 +1,191 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components>
+
+ <!-- This component tests updating of service properties -->
+ <component
+ xmlns="http://www.osgi.org/xmlns/scr/v1.2.0"
+ name="org.eclipse.equinox.ds.tests.tb25.ServicePropertiesComp"
+ immediate="true">
+ <implementation
+ class="org.eclipse.equinox.ds.tests.tb25.ServicePropertiesComp"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=service.properties.update.test)"
+ bind="bindRef"
+ updated="serviceUpdatedStatic"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=service.properties.update.test)"
+ policy="dynamic"
+ bind="bindRef"
+ updated="serviceUpdatedDynamic"/>
+ <service>
+ <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/>
+ </service>
+ </component>
+
+ <!-- This component tests Reluctant policy option with static reference binding -->
+ <component
+ xmlns="http://www.osgi.org/xmlns/scr/v1.2.0"
+ name="org.eclipse.equinox.ds.tests.tb25.PolicyReluctantStaticComp"
+ immediate="true">
+ <implementation
+ class="org.eclipse.equinox.ds.tests.tb25.PolicyOptionComp"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=reluctant.policy.option.test)"
+ cardinality="0..1"
+ bind="bind01"
+ policy-option="reluctant"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=reluctant.policy.option.test)"
+ cardinality="1..1"
+ bind="bind11"
+ policy-option="reluctant"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=reluctant.policy.option.test)"
+ cardinality="0..n"
+ bind="bind0n"
+ policy-option="reluctant"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=reluctant.policy.option.test)"
+ cardinality="1..n"
+ bind="bind1n"
+ policy-option="reluctant"/>
+ <service>
+ <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/>
+ </service>
+ </component>
+
+ <!-- This component tests Reluctant policy option with dynamic reference binding -->
+ <component
+ xmlns="http://www.osgi.org/xmlns/scr/v1.2.0"
+ name="org.eclipse.equinox.ds.tests.tb25.PolicyReluctantDynamicComp"
+ immediate="true">
+ <implementation
+ class="org.eclipse.equinox.ds.tests.tb25.PolicyOptionComp"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=reluctant.policy.option.test)"
+ cardinality="0..1"
+ bind="bind01"
+ policy="dynamic"
+ policy-option="reluctant"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=reluctant.policy.option.test)"
+ cardinality="1..1"
+ bind="bind11"
+ policy="dynamic"
+ policy-option="reluctant"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=reluctant.policy.option.test)"
+ cardinality="0..n"
+ bind="bind0n"
+ policy="dynamic"
+ policy-option="reluctant"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=reluctant.policy.option.test)"
+ cardinality="1..n"
+ bind="bind1n"
+ policy="dynamic"
+ policy-option="reluctant"/>
+ <service>
+ <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/>
+ </service>
+ </component>
+
+ <!-- This component tests Greedy policy option with static reference binding -->
+ <component
+ xmlns="http://www.osgi.org/xmlns/scr/v1.2.0"
+ name="org.eclipse.equinox.ds.tests.tb25.PolicyGreedyStaticComp"
+ immediate="true">
+ <implementation
+ class="org.eclipse.equinox.ds.tests.tb25.PolicyOptionComp"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=greedy.policy.option.test)"
+ cardinality="0..1"
+ bind="bind01"
+ policy-option="greedy"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=greedy.policy.option.test)"
+ cardinality="1..1"
+ bind="bind11"
+ policy-option="greedy"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=greedy.policy.option.test)"
+ cardinality="0..n"
+ bind="bind0n"
+ policy-option="greedy"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=greedy.policy.option.test)"
+ cardinality="1..n"
+ bind="bind1n"
+ policy-option="greedy"/>
+ <service>
+ <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/>
+ </service>
+ </component>
+
+ <!-- This component tests Greedy policy option with dynamic reference binding -->
+ <component
+ xmlns="http://www.osgi.org/xmlns/scr/v1.2.0"
+ name="org.eclipse.equinox.ds.tests.tb25.PolicyGreedyDynamicComp"
+ immediate="true">
+ <implementation
+ class="org.eclipse.equinox.ds.tests.tb25.PolicyOptionComp"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=greedy.policy.option.test)"
+ cardinality="0..1"
+ bind="bind01"
+ policy="dynamic"
+ policy-option="greedy"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=greedy.policy.option.test)"
+ cardinality="1..1"
+ bind="bind11"
+ policy="dynamic"
+ policy-option="greedy"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=greedy.policy.option.test)"
+ cardinality="0..n"
+ bind="bind0n"
+ policy="dynamic"
+ policy-option="greedy"/>
+ <reference
+ interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"
+ target="(service.provider=greedy.policy.option.test)"
+ cardinality="1..n"
+ bind="bind1n"
+ policy="dynamic"
+ policy-option="greedy"/>
+ <service>
+ <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/>
+ </service>
+ </component>
+
+ <!-- This component tests component configuration's PID -->
+ <component
+ xmlns="http://www.osgi.org/xmlns/scr/v1.2.0"
+ name="org.eclipse.equinox.ds.tests.tb25.ConfigPIDComp"
+ immediate="true"
+ configuration-pid="test.changed.configuration.pid">
+ <implementation
+ class="org.eclipse.equinox.ds.tests.tb25.ConfigPIDComp"/>
+ <service>
+ <provide interface="org.eclipse.equinox.ds.tests.tbc.PropertiesProvider"/>
+ </service>
+ </component>
+</components>
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
index 49c1f6a..36b9730 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1997, 2011 by ProSyst Software GmbH
+ * Copyright (c) 1997, 2012 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
@@ -12,9 +12,12 @@
package org.eclipse.equinox.ds.tests.tbc;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
import junit.framework.TestCase;
@@ -2496,6 +2499,9 @@ public class DSTest extends TestCase {
//start again the config admin
cmBundle.start();
+
+ //wait for processing components that depend on configurations
+ Thread.sleep(timeout * 2);
// component with optional configuration should be available and initialized by configuration
assertEquals("Component with optional configuration should be activated and inited by configuration", 1, getBaseConfigData(COMP_OPTIONAL));
@@ -2521,6 +2527,352 @@ public class DSTest extends TestCase {
}
}
+ // Tests update of service properties
+ public void testServicePropertiesUpdate() throws Exception {
+ Bundle tb25 = installBundle("tb25");
+ ServiceRegistration sr = null;
+ try {
+ final String COMP_NAME = "org.eclipse.equinox.ds.tests.tb25.ServicePropertiesComp";
+ final String PROP = "test.property";
+ final String PROP_STATIC = "serviceUpdatedStatic";
+ final String PROP_DYNAMIC = "serviceUpdatedDynamic";
+ tb25.start();
+ waitBundleStart();
+
+ Hashtable props = new Hashtable();
+ props.put("service.provider", "service.properties.update.test");
+ props.put(PROP, Boolean.FALSE);
+
+ // register service referenced by the component
+ sr = registerService(PropertiesProvider.class.getName(), new DefaultPropertiesProvider(null),
+ (Dictionary) props.clone());
+ Thread.sleep(timeout);
+
+ PropertiesProvider bs = getBaseService(COMP_NAME);
+ assertNotNull("Component " + COMP_NAME + " should be activated", bs);
+
+ // update service properties
+ props.put(PROP, Boolean.TRUE);
+ sr.setProperties((Dictionary) props.clone());
+ Thread.sleep(timeout);
+
+ bs = getBaseService(COMP_NAME);
+ assertNotNull("Component " + COMP_NAME + " should still be active", bs);
+ Dictionary compProps = bs.getProperties();
+ assertNotNull("Component properties should be available.", compProps);
+ assertEquals("Test property should be updated.", Boolean.TRUE, compProps.get(PROP));
+ assertEquals("Updated method for static reference should be called.", Boolean.TRUE, compProps.get(PROP_STATIC));
+ assertEquals("Updated method for dynamic reference should be called.", Boolean.TRUE, compProps.get(PROP_DYNAMIC));
+ } finally {
+ uninstallBundle(tb25);
+ if (sr != null) {
+ unregisterService(sr);
+ }
+ }
+ }
+
+ // Tests Reluctant policy option of service references
+ public void testPolicyOptionReluctant() throws Exception {
+ Bundle tb25 = installBundle("tb25");
+ ServiceRegistration sr = null;
+ ServiceRegistration srLower = null;
+ ServiceRegistration srHigher = null;
+ try {
+ final String COMP_NAME_STATIC = "org.eclipse.equinox.ds.tests.tb25.PolicyReluctantStaticComp";
+ final String COMP_NAME_DYNAMIC = "org.eclipse.equinox.ds.tests.tb25.PolicyReluctantDynamicComp";
+ final String PROP_BIND_01 = "bind01";
+ final String PROP_BIND_11 = "bind11";
+ final String PROP_BIND_0n = "bind0n";
+ final String PROP_BIND_1n = "bind1n";
+ final Integer RANK_1 = new Integer(1);
+ final Integer RANK_2 = new Integer(2);
+ final Integer RANK_3 = new Integer(3);
+ tb25.start();
+ waitBundleStart();
+
+ Hashtable props = new Hashtable();
+ props.put("service.provider", "reluctant.policy.option.test");
+ props.put(Constants.SERVICE_RANKING, RANK_2);
+
+ // register service referenced by the component
+ sr = registerService(PropertiesProvider.class.getName(), new DefaultPropertiesProvider(null),
+ (Dictionary) props.clone());
+ Thread.sleep(timeout);
+
+ PropertiesProvider bsStatic = getBaseService(COMP_NAME_STATIC);
+ assertNotNull("Component " + COMP_NAME_STATIC + " should be activated", bsStatic);
+ PropertiesProvider bsDynamic = getBaseService(COMP_NAME_DYNAMIC);
+ assertNotNull("Component " + COMP_NAME_DYNAMIC + " should be activated", bsDynamic);
+
+ // register service with lower ranking
+ props.put(Constants.SERVICE_RANKING, RANK_1);
+ srLower = registerService(PropertiesProvider.class.getName(), new DefaultPropertiesProvider(null),
+ (Dictionary) props.clone());
+ Thread.sleep(timeout);
+
+ // check bound references
+ bsStatic = getBaseService(COMP_NAME_STATIC);
+ assertNotNull("Component " + COMP_NAME_STATIC + " should still be active", bsStatic);
+ Dictionary compProps = bsStatic.getProperties();
+ assertNotNull("Component properties should be available.", compProps);
+ assertEqualElements("New target service with lower ranking should be ignored for static 0..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_01));
+ assertEqualElements("New target service with lower ranking should be ignored for static 1..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_11));
+ assertEqualElements("New target service with lower ranking should be ignored for static 0..n.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_0n));
+ assertEqualElements("New target service with lower ranking should be ignored for static 1..n.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_1n));
+ bsDynamic = getBaseService(COMP_NAME_DYNAMIC);
+ assertNotNull("Component " + COMP_NAME_DYNAMIC + " should still be active", bsDynamic);
+ compProps = bsDynamic.getProperties();
+ assertNotNull("Component properties should be available.", compProps);
+ assertEqualElements("New target service with lower ranking should be ignored for dynamic 0..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_01));
+ assertEqualElements("New target service with lower ranking should be ignored for dynamic 1..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_11));
+ assertEqualElements("New target service with lower ranking should be bound for dynamic 0..n.",
+ toList(RANK_1, RANK_2), (List) compProps.get(PROP_BIND_0n));
+ assertEqualElements("New target service with lower ranking should be bound for dynamic 1..n.",
+ toList(RANK_1, RANK_2), (List) compProps.get(PROP_BIND_1n));
+
+ // register service with higher ranking
+ props.put(Constants.SERVICE_RANKING, RANK_3);
+ srHigher = registerService(PropertiesProvider.class.getName(), new DefaultPropertiesProvider(null),
+ (Dictionary) props.clone());
+ Thread.sleep(timeout);
+
+ // check bound references
+ bsStatic = getBaseService(COMP_NAME_STATIC);
+ assertNotNull("Component " + COMP_NAME_STATIC + " should still be active", bsStatic);
+ compProps = bsStatic.getProperties();
+ assertNotNull("Component properties should be available.", compProps);
+ assertEqualElements("New target service with higher ranking should be ignored for static 0..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_01));
+ assertEqualElements("New target service with higher ranking should be ignored for static 1..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_11));
+ assertEqualElements("New target service with higher ranking should be ignored for static 0..n.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_0n));
+ assertEqualElements("New target service with higher ranking should be ignored for static 1..n.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_1n));
+ bsDynamic = getBaseService(COMP_NAME_DYNAMIC);
+ assertNotNull("Component " + COMP_NAME_DYNAMIC + " should still be active", bsDynamic);
+ compProps = bsDynamic.getProperties();
+ assertNotNull("Component properties should be available.", compProps);
+ assertEqualElements("New target service with higher ranking should be ignored for dynamic 0..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_01));
+ assertEqualElements("New target service with higher ranking should be ignored for dynamic 1..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_11));
+ assertEqualElements("New target service with higher ranking should be bound for dynamic 0..n.",
+ toList(RANK_1, RANK_2, RANK_3), (List) compProps.get(PROP_BIND_0n));
+ assertEqualElements("New target service with higher ranking should be bound for dynamic 1..n.",
+ toList(RANK_1, RANK_2, RANK_3), (List) compProps.get(PROP_BIND_1n));
+ } finally {
+ uninstallBundle(tb25);
+ if (sr != null) {
+ unregisterService(sr);
+ }
+ if (srLower != null) {
+ unregisterService(srLower);
+ }
+ if (srHigher != null) {
+ unregisterService(srHigher);
+ }
+ }
+ }
+
+ // Tests Greedy policy option of service references
+ public void testPolicyOptionGreedy() throws Exception {
+ Bundle tb25 = installBundle("tb25");
+ ServiceRegistration sr = null;
+ ServiceRegistration srLower = null;
+ ServiceRegistration srHigher = null;
+ try {
+ final String COMP_NAME_STATIC = "org.eclipse.equinox.ds.tests.tb25.PolicyGreedyStaticComp";
+ final String COMP_NAME_DYNAMIC = "org.eclipse.equinox.ds.tests.tb25.PolicyGreedyDynamicComp";
+ final String PROP_BIND_01 = "bind01";
+ final String PROP_BIND_11 = "bind11";
+ final String PROP_BIND_0n = "bind0n";
+ final String PROP_BIND_1n = "bind1n";
+ final Integer RANK_1 = new Integer(1);
+ final Integer RANK_2 = new Integer(2);
+ final Integer RANK_3 = new Integer(3);
+ tb25.start();
+ waitBundleStart();
+
+ Hashtable props = new Hashtable();
+ props.put("service.provider", "greedy.policy.option.test");
+ props.put(Constants.SERVICE_RANKING, RANK_2);
+
+ // register service referenced by the component
+ sr = registerService(PropertiesProvider.class.getName(), new DefaultPropertiesProvider(null),
+ (Dictionary) props.clone());
+ Thread.sleep(timeout);
+
+ PropertiesProvider bsStatic = getBaseService(COMP_NAME_STATIC);
+ assertNotNull("Component " + COMP_NAME_STATIC + " should be activated", bsStatic);
+ PropertiesProvider bsDynamic = getBaseService(COMP_NAME_DYNAMIC);
+ assertNotNull("Component " + COMP_NAME_DYNAMIC + " should be activated", bsDynamic);
+
+ // register service with lower ranking
+ props.put(Constants.SERVICE_RANKING, RANK_1);
+ srLower = registerService(PropertiesProvider.class.getName(), new DefaultPropertiesProvider(null),
+ (Dictionary) props.clone());
+ Thread.sleep(timeout);
+
+ // check bound references
+ bsStatic = getBaseService(COMP_NAME_STATIC);
+ assertNotNull("Component " + COMP_NAME_STATIC + " should still be active", bsStatic);
+ Dictionary compProps = bsStatic.getProperties();
+ assertNotNull("Component properties should be available.", compProps);
+ assertEqualElements("New target service with lower ranking should be ignored for static 0..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_01));
+ assertEqualElements("New target service with lower ranking should be ignored for static 1..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_11));
+ assertEqualElements("New target service with lower ranking should be bound for static 0..n.",
+ toList(RANK_1, RANK_2), (List) compProps.get(PROP_BIND_0n));
+ assertEqualElements("New target service with lower ranking should be bound for static 1..n.",
+ toList(RANK_1, RANK_2), (List) compProps.get(PROP_BIND_1n));
+ bsDynamic = getBaseService(COMP_NAME_DYNAMIC);
+ assertNotNull("Component " + COMP_NAME_DYNAMIC + " should still be active", bsDynamic);
+ compProps = bsDynamic.getProperties();
+ assertNotNull("Component properties should be available.", compProps);
+ assertEqualElements("New target service with lower ranking should be ignored for dynamic 0..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_01));
+ assertEqualElements("New target service with lower ranking should be ignored for dynamic 1..1.", toList(RANK_2),
+ (List) compProps.get(PROP_BIND_11));
+ assertEqualElements("New target service with lower ranking should be bound for dynamic 0..n.",
+ toList(RANK_1, RANK_2), (List) compProps.get(PROP_BIND_0n));
+ assertEqualElements("New target service with lower ranking should be bound for dynamic 1..n.",
+ toList(RANK_1, RANK_2), (List) compProps.get(PROP_BIND_1n));
+
+ // register service with higher ranking
+ props.put(Constants.SERVICE_RANKING, RANK_3);
+ srHigher = registerService(PropertiesProvider.class.getName(), new DefaultPropertiesProvider(null),
+ (Dictionary) props.clone());
+ Thread.sleep(timeout);
+
+ // check bound references
+ bsStatic = getBaseService(COMP_NAME_STATIC);
+ assertNotNull("Component " + COMP_NAME_STATIC + " should still be active", bsStatic);
+ compProps = bsStatic.getProperties();
+ assertNotNull("Component properties should be available.", compProps);
+ assertEqualElements("New target service with higher ranking should be bound for static 0..1.", toList(RANK_3),
+ (List) compProps.get(PROP_BIND_01));
+ assertEqualElements("New target service with higher ranking should be bound for static 1..1.", toList(RANK_3),
+ (List) compProps.get(PROP_BIND_11));
+ assertEqualElements("New target service with higher ranking should be bound for static 0..n.",
+ toList(RANK_1, RANK_2, RANK_3), (List) compProps.get(PROP_BIND_0n));
+ assertEqualElements("New target service with higher ranking should be bound for static 1..n.",
+ toList(RANK_1, RANK_2, RANK_3), (List) compProps.get(PROP_BIND_1n));
+ bsDynamic = getBaseService(COMP_NAME_DYNAMIC);
+ assertNotNull("Component " + COMP_NAME_DYNAMIC + " should still be active", bsDynamic);
+ compProps = bsDynamic.getProperties();
+ assertNotNull("Component properties should be available.", compProps);
+ assertEqualElements("New target service with higher ranking should be bound for dynamic 0..1.",
+ toList(RANK_2, RANK_3), (List) compProps.get(PROP_BIND_01));
+ assertEqualElements("New target service with higher ranking should be bound for dynamic 1..1.",
+ toList(RANK_2, RANK_3), (List) compProps.get(PROP_BIND_11));
+ assertEqualElements("New target service with higher ranking should be bound for dynamic 0..n.",
+ toList(RANK_1, RANK_2, RANK_3), (List) compProps.get(PROP_BIND_0n));
+ assertEqualElements("New target service with higher ranking should be bound for dynamic 1..n.",
+ toList(RANK_1, RANK_2, RANK_3), (List) compProps.get(PROP_BIND_1n));
+ } finally {
+ uninstallBundle(tb25);
+ if (sr != null) {
+ unregisterService(sr);
+ }
+ if (srLower != null) {
+ unregisterService(srLower);
+ }
+ if (srHigher != null) {
+ unregisterService(srHigher);
+ }
+ }
+ }
+
+ // Tests PID of Component configuration
+ public void testComponentConfigurationPID() throws Exception {
+ ConfigurationAdmin cm = (ConfigurationAdmin) trackerCM.getService();
+ if (cm == null) {
+ return;
+ }
+
+ Bundle tb25 = installBundle("tb25");
+ Configuration config = null;
+ try {
+ final String COMP_NAME = "org.eclipse.equinox.ds.tests.tb25.ConfigPIDComp";
+ final String CONFIG_PID = "test.changed.configuration.pid";
+ final String PROP = "test.property";
+
+ // set component configuration
+ config = cm.getConfiguration(CONFIG_PID);
+ Dictionary configProperties = config.getProperties();
+ if (configProperties == null) {
+ configProperties = new Hashtable();
+ }
+ configProperties.put(PROP, Boolean.TRUE);
+ config.update(configProperties);
+ Thread.sleep(timeout);
+
+ tb25.start();
+ waitBundleStart();
+
+ // check component properties
+ PropertiesProvider bs = getBaseService(COMP_NAME);
+ assertNotNull("Component " + COMP_NAME + " should be activated", bs);
+ Dictionary compProps = bs.getProperties();
+ assertNotNull("Component properties should be available.", compProps);
+ assertEquals("Test property should be set.", Boolean.TRUE, compProps.get(PROP));
+ } finally {
+ uninstallBundle(tb25);
+ if (config != null) {
+ config.delete();
+ }
+ }
+ }
+
+ /**
+ * Asserts that two lists contain equal elements (the order doesn't matter).
+ */
+ private static void assertEqualElements(String message, List list1, List list2) {
+ if (list1 == null || list2 == null) {
+ fail(message);
+ }
+ if (list1.size() != list2.size()) {
+ fail(message);
+ }
+ List tmp = new ArrayList(list2);
+ for (Iterator it = list1.iterator(); it.hasNext();) {
+ Object el = it.next();
+ if (!tmp.contains(el)) {
+ fail(message);
+ }
+ tmp.remove(el);
+ }
+ }
+
+ private List toList(Object el) {
+ List list = new ArrayList();
+ list.add(el);
+ return list;
+ }
+
+ private List toList(Object el1, Object el2) {
+ List list = new ArrayList();
+ list.add(el1);
+ list.add(el2);
+ return list;
+ }
+
+ private List toList(Object el1, Object el2, Object el3) {
+ List list = new ArrayList();
+ list.add(el1);
+ list.add(el2);
+ list.add(el3);
+ return list;
+ }
+
/**
* Searches for component with name componentName which provides
* PropertiesProvider. Returns value of its "config.base.data" property.
diff --git a/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DefaultPropertiesProvider.java b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DefaultPropertiesProvider.java
new file mode 100644
index 0000000..dd06fac
--- /dev/null
+++ b/bundles/org.eclipse.equinox.ds.tests/src/org/eclipse/equinox/ds/tests/tbc/DefaultPropertiesProvider.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 1997, 2012 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 DefaultPropertiesProvider implements PropertiesProvider {
+
+ private Dictionary properties;
+
+ public DefaultPropertiesProvider(Dictionary properties) {
+ this.properties = properties;
+ }
+
+ public Dictionary getProperties() {
+ return properties;
+ }
+
+}