Fix issue Felix-1182.
The updated method of the properties handler is now called with propagated properties (if the propagation is enabled).
Adapt the test to check this beheavor.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@780222 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
index 300482a..7c745ed 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/configuration/ConfigurationHandler.java
@@ -443,9 +443,11 @@
/**
* Invokes the updated method.
- * This method build the dictionary containing all valued properties.
+ * This method build the dictionary containing all valued properties,
+ * as well as properties propagated to the provided service handler (
+ * only if the propagation is enabled).
* @param instance the instance on which the callback must be called.
- * If <code>null</code> the callback is called on all the exisiting
+ * If <code>null</code> the callback is called on all the existing
* object.
*/
private void notifyUpdated(Object instance) {
@@ -460,6 +462,31 @@
props.put(n, v);
}
}
+ // add propagated properties to the list if propagation enable
+ if (m_mustPropagate) {
+ // Start by properties from the configuration admin,
+ if (m_propagatedFromCA != null) {
+
+ Enumeration e = m_propagatedFromCA.keys();
+ while (e.hasMoreElements()) {
+ String k = (String) e.nextElement();
+ if (! k.equals("instance.name")) {
+ props.put(k, m_propagatedFromCA.get(k));
+ }
+ }
+ }
+ // Do also the one from the instance configuration
+ if (m_propagatedFromInstance != null) {
+ Enumeration e = m_propagatedFromInstance.keys();
+ while (e.hasMoreElements()) {
+ String k = (String) e.nextElement();
+ if (! k.equals("instance.name")) { // Skip instance.name
+ props.put(k, m_propagatedFromInstance.get(k));
+ }
+ }
+ }
+ }
+
try {
if (instance == null) {
m_updated.call(new Object[] {props});
diff --git a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethod.java b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethod.java
index 9ec6af2..a204deb 100644
--- a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethod.java
+++ b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethod.java
@@ -1,4 +1,4 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -28,18 +28,18 @@
import org.osgi.framework.ServiceReference;
public class UpdatedMethod extends OSGiTestCase {
-
+
ComponentInstance fooProvider1;
ComponentInstance fooProvider2;
ComponentInstance fooProvider3;
-
+
public void setUp() {
String type = "CONFIG-FooProviderType-ConfUpdated";
-
+
Properties p1 = new Properties();
p1.put("instance.name","FooProvider-1");
fooProvider1 = Utils.getComponentInstance(getContext(), type, p1);
-
+
Properties p2 = new Properties();
p2.put("instance.name","FooProvider-2");
p2.put("int", new Integer(4));
@@ -48,12 +48,12 @@
p2.put("strAProp", new String[] {"bar", "foo"});
p2.put("intAProp", new int[] {1, 2, 3});
fooProvider2 = Utils.getComponentInstance(getContext(), type, p2);
-
+
Properties p3 = new Properties();
p3.put("instance.name","FooProvider-3");
fooProvider3 = Utils.getComponentInstance(getContext(), "CONFIG-FooProviderType-ConfNoValueUpdated", p3);
}
-
+
public void tearDown() {
fooProvider1.dispose();
fooProvider2.dispose();
@@ -62,23 +62,23 @@
fooProvider2 = null;
fooProvider3 = null;
}
-
+
public void testComponentTypeConfiguration() {
ServiceReference ref = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), fooProvider1.getInstanceName());
assertNotNull("Check FooService availability", ref);
FooService fs = (FooService) getContext().getService(ref);
Properties toCheck = fs.fooProps();
-
+
Integer intProp = (Integer) toCheck.get("intProp");
Boolean boolProp = (Boolean) toCheck.get("boolProp");
String strProp = (String) toCheck.get("strProp");
String[] strAProp = (String[]) toCheck.get("strAProp");
int[] intAProp = (int[]) toCheck.get("intAProp");
-
+
// Check updated
Integer updated = (Integer) toCheck.get("updated");
Dictionary dict = (Dictionary) toCheck.get("lastupdated");
-
+
assertEquals("Check intProp equality (1)", intProp, new Integer(2));
assertEquals("Check longProp equality (1)", boolProp, new Boolean(false));
assertEquals("Check strProp equality (1)", strProp, new String("foo"));
@@ -92,26 +92,26 @@
for (int i = 0; i < intAProp.length; i++) {
if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality (1) : " + intAProp[i] + " != " + v2[i]); }
}
-
+
assertEquals("updated count ", 1, updated.intValue());
assertEquals("Last updated", 5, dict.size());
-
+
// change the field value
assertTrue("Invoke the fs service", fs.foo());
toCheck = fs.fooProps();
-
-
+
+
// Re-check the property (change)
intProp = (Integer) toCheck.get("intProp");
boolProp = (Boolean) toCheck.get("boolProp");
strProp = (String) toCheck.get("strProp");
strAProp = (String[]) toCheck.get("strAProp");
intAProp = (int[]) toCheck.get("intAProp");
-
+
// Check updated
updated = (Integer) toCheck.get("updated");
dict = (Dictionary) toCheck.get("lastupdated");
-
+
assertEquals("Check intProp equality (2) ("+intProp+")", intProp, new Integer(3));
assertEquals("Check longProp equality (2)", boolProp, new Boolean(true));
assertEquals("Check strProp equality (2)", strProp, new String("bar"));
@@ -125,55 +125,55 @@
for (int i = 0; i < intAProp.length; i++) {
if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality (2) : " + intAProp[i] + " != " + v2[i]); }
}
-
+
// This does not reconfigure...
assertEquals("updated count -2 ", 1, updated.intValue());
assertEquals("Last update - 2", 5, dict.size());
-
+
fs = null;
getContext().ungetService(ref);
}
-
+
public void testNoValue() {
ServiceReference sr = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), "FooProvider-3");
assertNotNull("Check the availability of the FS service", sr);
-
+
FooService fs = (FooService) getContext().getService(sr);
Properties toCheck = fs.fooProps();
-
+
// Check service properties
Integer intProp = (Integer) toCheck.get("intProp");
Boolean boolProp = (Boolean) toCheck.get("boolProp");
String strProp = (String) toCheck.get("strProp");
String[] strAProp = (String[]) toCheck.get("strAProp");
int[] intAProp = (int[]) toCheck.get("intAProp");
-
+
// Check updated
Integer updated = (Integer) toCheck.get("updated");
Dictionary dict = (Dictionary) toCheck.get("lastupdated");
-
+
assertEquals("Check intProp equality", intProp, new Integer(0));
assertEquals("Check longProp equality", boolProp, new Boolean(false));
assertEquals("Check strProp equality", strProp, null);
assertNull("Check strAProp nullity", strAProp);
assertNull("Check intAProp nullity", intAProp);
-
+
assertEquals("updated count ", 1, updated.intValue());
assertEquals("Last update", 0, dict.size());
-
+
assertTrue("invoke fs", fs.foo());
toCheck = fs.fooProps();
-
+
// Re-check the property (change)
intProp = (Integer) toCheck.get("intProp");
boolProp = (Boolean) toCheck.get("boolProp");
strProp = (String) toCheck.get("strProp");
strAProp = (String[]) toCheck.get("strAProp");
intAProp = (int[]) toCheck.get("intAProp");
-
+
updated = (Integer) toCheck.get("updated");
dict = (Dictionary) toCheck.get("lastupdated");
-
+
assertEquals("Check intProp equality", intProp, new Integer(3));
assertEquals("Check longProp equality", boolProp, new Boolean(true));
assertEquals("Check strProp equality", strProp, new String("bar"));
@@ -187,9 +187,10 @@
for (int i = 0; i < intAProp.length; i++) {
if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
}
-
+
fs = null;
- getContext().ungetService(sr);
+ getContext().ungetService(sr);
}
+
}
diff --git a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethodAndManagedService.java b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethodAndManagedService.java
index fe70f31..0c78e26 100644
--- a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethodAndManagedService.java
+++ b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethodAndManagedService.java
@@ -118,7 +118,7 @@
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
assertEquals("Check updated", 1, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
+ assertEquals("Check last updated", 3, dict.size());
context.ungetService(fooRef);
getContext().ungetService(msRef);
@@ -163,7 +163,7 @@
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
assertEquals("Check updated", 1, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
+ assertEquals("Check last updated", 3, dict.size());
conf.put("baz", "zab2");
conf.put("foo", "oof2");
@@ -177,7 +177,7 @@
dict = (Dictionary) fs.fooProps().get("lastupdated");
assertEquals("Check updated -2", 2, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
+ assertEquals("Check last updated", 3, dict.size());
getContext().ungetService(fooRef);
getContext().ungetService(msRef);
@@ -231,7 +231,7 @@
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
assertEquals("Check updated -1", 1, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
+ assertEquals("Check last updated", 3, dict.size());
conf.put("baz", "zab2");
conf.put("foo", "oof2");
@@ -245,7 +245,7 @@
dict = (Dictionary) fs.fooProps().get("lastupdated");
assertEquals("Check updated -2", 2, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
+ assertEquals("Check last updated", 3, dict.size());
getContext().ungetService(fooRef);
@@ -301,7 +301,7 @@
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
assertEquals("Check updated", 1, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
+ assertEquals("Check last updated", 3, dict.size());
conf.put("baz", "zab2");
conf.put("foo", "oof2");
@@ -315,7 +315,7 @@
dict = (Dictionary) fs.fooProps().get("lastupdated");
assertEquals("Check updated -2", 2, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
+ assertEquals("Check last updated", 3, dict.size());
getContext().ungetService(fooRef);
getContext().ungetService(msRef);
diff --git a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethodAndManagedServiceFactory.java b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethodAndManagedServiceFactory.java
index 4a8e5c1..f9289c7 100644
--- a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethodAndManagedServiceFactory.java
+++ b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedMethodAndManagedServiceFactory.java
@@ -1,4 +1,4 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -32,31 +32,32 @@
public class UpdatedMethodAndManagedServiceFactory extends OSGiTestCase {
ComponentInstance instance, instance2;
-
+
public void setUp() {
String type = "CONFIG-FooProviderType-3Updated";
-
+
Properties p1 = new Properties();
p1.put("instance.name","instance");
p1.put("foo", "foo");
p1.put("bar", "2");
p1.put("baz", "baz");
instance = Utils.getComponentInstance(getContext(), type, p1);
-
+
Properties p2 = new Properties();
p2.put("instance.name","instance2");
instance2 = Utils.getComponentInstance(getContext(), type, p2);
}
-
+
public void tearDown() {
instance.dispose();
instance2.dispose();
instance2 = null;
instance = null;
}
-
+
public void testStatic() {
+
ServiceReference fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance.getInstanceName());
assertNotNull("Check FS availability", fooRef);
String fooP = (String) fooRef.getProperty("foo");
@@ -65,11 +66,11 @@
assertEquals("Check foo equality -1", fooP, "foo");
assertEquals("Check bar equality -1", barP, new Integer(2));
assertEquals("Check baz equality -1", bazP, "baz");
-
+
ServiceReference msRef = Utils.getServiceReferenceByName(getContext(), ManagedServiceFactory.class.getName(), instance.getFactory().getName());
assertNotNull("Check ManagedServiceFactory availability", msRef);
-
-
+
+
// Configuration of baz
Properties conf = new Properties();
conf.put("baz", "zab");
@@ -79,7 +80,7 @@
try {
ms.updated(instance.getInstanceName(), conf);
} catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
-
+
// Recheck props
fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
@@ -88,18 +89,20 @@
assertEquals("Check foo equality -2", fooP, "foo");
assertEquals("Check bar equality -2", barP, new Integer(2));
assertEquals("Check baz equality -2", bazP, "zab");
-
+
// Get Service
FooService fs = (FooService) context.getService(fooRef);
Integer updated = (Integer) fs.fooProps().get("updated");
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
-
+
assertEquals("Check updated", 1, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
-
+ System.out.println("Dictionary : " + dict);
+ assertEquals("Check last updated", 3, dict.size()); // foo bar and baz as a service prooperties.
+
getContext().ungetService(msRef);
+
}
-
+
public void testStaticNoValue() {
ServiceReference fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance2.getInstanceName());
assertNotNull("Check FS availability", fooRef);
@@ -109,11 +112,11 @@
assertEquals("Check foo equality -1", fooP, null);
assertEquals("Check bar equality -1", barP, null);
assertEquals("Check baz equality -1", bazP, null);
-
+
ServiceReference msRef = Utils.getServiceReferenceByName(getContext(), ManagedServiceFactory.class.getName(), instance2.getFactory().getName());
assertNotNull("Check ManagedServiceFactory availability", msRef);
-
-
+
+
// Configuration of baz
Properties conf = new Properties();
conf.put("baz", "zab");
@@ -123,7 +126,7 @@
try {
ms.updated(instance2.getInstanceName(), conf);
} catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
-
+
// Recheck props
fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance2.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
@@ -132,33 +135,33 @@
assertEquals("Check foo equality -2", fooP, "foo");
assertEquals("Check bar equality -2", barP, new Integer(2));
assertEquals("Check baz equality -2", bazP, "zab");
-
+
// Get Service
FooService fs = (FooService) context.getService(fooRef);
Integer updated = (Integer) fs.fooProps().get("updated");
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
-
+
assertEquals("Check updated", 1, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
-
+ assertEquals("Check last updated", 3, dict.size());
+
getContext().ungetService(msRef);
}
-
+
public void testDynamic() {
ServiceReference fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance.getInstanceName());
assertNotNull("Check FS availability", fooRef);
-
+
String fooP = (String) fooRef.getProperty("foo");
Integer barP = (Integer) fooRef.getProperty("bar");
String bazP = (String) fooRef.getProperty("baz");
-
+
assertEquals("Check foo equality", fooP, "foo");
assertEquals("Check bar equality", barP, new Integer(2));
assertEquals("Check baz equality", bazP, "baz");
-
+
ServiceReference msRef = Utils.getServiceReferenceByName(getContext(), ManagedServiceFactory.class.getName(), instance.getFactory().getName());
assertNotNull("Check ManagedServiceFactory availability", msRef);
-
+
// Configuration of baz
Properties conf = new Properties();
conf.put("baz", "zab");
@@ -168,50 +171,50 @@
try {
ms.updated(instance.getInstanceName(), conf);
} catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
-
+
// Recheck props
fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
-
+
assertEquals("Check foo equality", fooP, "oof");
assertEquals("Check bar equality", barP, new Integer(0));
assertEquals("Check baz equality", bazP, "zab");
-
+
// Check field value
FooService fs = (FooService) getContext().getService(fooRef);
Properties p = fs.fooProps();
fooP = (String) p.get("foo");
barP = (Integer) p.get("bar");
-
+
assertEquals("Check foo field equality", fooP, "oof");
assertEquals("Check bar field equality", barP, new Integer(0));
-
+
Integer updated = (Integer) fs.fooProps().get("updated");
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
-
+
assertEquals("Check updated", 1, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
-
+ assertEquals("Check last updated", 3, dict.size());
+
getContext().ungetService(fooRef);
getContext().ungetService(msRef);
}
-
+
public void testDynamicNoValue() {
ServiceReference fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance2.getInstanceName());
assertNotNull("Check FS availability", fooRef);
-
+
Object fooP = fooRef.getProperty("foo");
Object barP = fooRef.getProperty("bar");
Object bazP = fooRef.getProperty("baz");
assertEquals("Check foo equality -1", fooP, null);
assertEquals("Check bar equality -1", barP, null);
assertEquals("Check baz equality -1", bazP, null);
-
+
ServiceReference msRef = Utils.getServiceReferenceByName(getContext(), ManagedServiceFactory.class.getName(), instance2.getFactory().getName());
assertNotNull("Check ManagedServiceFactory availability", msRef);
-
+
// Configuration of baz
Properties conf = new Properties();
conf.put("baz", "zab");
@@ -221,33 +224,33 @@
try {
ms.updated(instance2.getInstanceName(), conf);
} catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
-
+
// Recheck props
fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance2.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
-
+
assertEquals("Check foo equality", fooP, "oof");
assertEquals("Check bar equality", barP, new Integer(0));
assertEquals("Check baz equality", bazP, "zab");
-
+
// Check field value
FooService fs = (FooService) getContext().getService(fooRef);
Properties p = fs.fooProps();
fooP = (String) p.get("foo");
barP = (Integer) p.get("bar");
-
+
assertEquals("Check foo field equality", fooP, "oof");
assertEquals("Check bar field equality", barP, new Integer(0));
-
+
Integer updated = (Integer) fs.fooProps().get("updated");
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
-
+
assertEquals("Check updated", 1, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
-
-
+ assertEquals("Check last updated", 3, dict.size());
+
+
getContext().ungetService(fooRef);
getContext().ungetService(msRef);
}
@@ -256,18 +259,18 @@
public void testDynamicString() {
ServiceReference fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance.getInstanceName());
assertNotNull("Check FS availability", fooRef);
-
+
String fooP = (String) fooRef.getProperty("foo");
Integer barP = (Integer) fooRef.getProperty("bar");
String bazP = (String) fooRef.getProperty("baz");
-
+
assertEquals("Check foo equality", fooP, "foo");
assertEquals("Check bar equality", barP, new Integer(2));
assertEquals("Check baz equality", bazP, "baz");
-
+
ServiceReference msRef = Utils.getServiceReferenceByName(getContext(), ManagedServiceFactory.class.getName(), instance.getFactory().getName());
assertNotNull("Check ManagedServiceFactory availability", msRef);
-
+
// Configuration of baz
Properties conf = new Properties();
conf.put("baz", "zab");
@@ -277,33 +280,33 @@
try {
ms.updated(instance.getInstanceName(), conf);
} catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
-
+
// Recheck props
fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
-
+
assertEquals("Check foo equality", fooP, "oof");
assertEquals("Check bar equality", barP, new Integer(0));
assertEquals("Check baz equality", bazP, "zab");
-
+
// Check field value
FooService fs = (FooService) getContext().getService(fooRef);
Properties p = fs.fooProps();
fooP = (String) p.get("foo");
barP = (Integer) p.get("bar");
-
+
assertEquals("Check foo field equality", fooP, "oof");
assertEquals("Check bar field equality", barP, new Integer(0));
-
+
Integer updated = (Integer) fs.fooProps().get("updated");
Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
-
+
assertEquals("Check updated", 1, updated.intValue());
- assertEquals("Check last updated", 2, dict.size());
-
-
+ assertEquals("Check last updated", 3, dict.size());
+
+
getContext().ungetService(fooRef);
getContext().ungetService(msRef);
}