Fix FELIX-2623 @Update annotated methods should not require a Dictionary parameter.
The updated method can be parameter-less.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1001224 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 9cecf0d..70e61d7 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
@@ -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
@@ -222,7 +222,19 @@
// updated method
String upd = confs[0].getAttribute("updated");
if (upd != null) {
- m_updated = new Callback(upd, new Class[] {Dictionary.class}, false, getInstanceManager());
+ MethodMetadata method = getPojoMetadata().getMethod(upd);
+ if (method == null) {
+ throw new ConfigurationException("The updated method is not found in the class "
+ + getInstanceManager().getClassName());
+ } else if (method.getMethodArguments().length == 0) {
+ m_updated = new Callback(upd, new Class[0], false, getInstanceManager());
+ } else if (method.getMethodArguments().length == 1
+ && method.getMethodArguments()[0].equals(Dictionary.class.getName())) {
+ m_updated = new Callback(upd, new Class[] {Dictionary.class}, false, getInstanceManager());
+ } else {
+ throw new ConfigurationException("The updated method is found in the class "
+ + getInstanceManager().getClassName() + " must have either no argument or a Dictionary");
+ }
}
for (int i = 0; configurables != null && i < configurables.length; i++) {
@@ -295,14 +307,14 @@
props.put(Constants.SERVICE_PID, m_managedServicePID);
props.put("instance.name", getInstanceManager().getInstanceName());
props.put("factory.name", getInstanceManager().getFactory().getFactoryName());
-
+
// Security Check
- if (SecurityHelper.hasPermissionToRegisterService(ManagedService.class.getName(),
+ if (SecurityHelper.hasPermissionToRegisterService(ManagedService.class.getName(),
getInstanceManager().getContext())) {
m_sr = getInstanceManager().getContext().registerService(ManagedService.class.getName(), this, props);
} else {
- error("Cannot register the ManagedService - The bundle "
- + getInstanceManager().getContext().getBundle().getBundleId()
+ error("Cannot register the ManagedService - The bundle "
+ + getInstanceManager().getContext().getBundle().getBundleId()
+ " does not have the permission to register the service");
}
}
@@ -375,7 +387,7 @@
}
}
if (!found) {
- // The property is not a configurable property, aadd it to the toPropagate list.
+ // The property is not a configurable property, add it to the toPropagate list.
toPropagate.put(name, value);
}
}
@@ -463,6 +475,24 @@
if (m_updated == null) {
return;
}
+
+ if (m_updated.getArguments().length == 0) {
+ // We don't have to compute the properties,
+ // we just call the callback.
+ try {
+ if (instance == null) {
+ m_updated.call(new Object[0]);
+ } else {
+ m_updated.call(instance, new Object[0]);
+ }
+ } catch (Exception e) {
+ error("Cannot call the updated method " + m_updated.getMethod() + " : " + e.getMessage());
+ }
+ return;
+ }
+
+ // Else we must compute the properties.
+
Properties props = new Properties();
for (int i = 0; i < m_configurableProperties.size(); i++) {
String n = ((Property) m_configurableProperties.get(i)).getName();
@@ -546,6 +576,6 @@
public HandlerDescription getDescription() {
return m_description;
}
-
+
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java
index 6b83eea..fe32379 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.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
@@ -79,6 +79,8 @@
m_manager = manager;
if (args != null) {
computeArguments(args);
+ } else {
+ m_args = new String[0];
}
}
@@ -143,7 +145,7 @@
break;
}
}
- if (argIndex == m_args.length) { // No mismatch detected.
+ if (argIndex == m_args.length) { // No mismatch detected.
return methods[i]; // It is the looked method.
}
}
@@ -170,7 +172,7 @@
if (m_methodObj == null) {
throw new NoSuchMethodException(m_method);
} else {
- if (! m_methodObj.isAccessible()) {
+ if (! m_methodObj.isAccessible()) {
// If not accessible, try to set the accessibility.
m_methodObj.setAccessible(true);
}
@@ -209,7 +211,7 @@
* Invokes the method on every created objects with the specified
* arguments.
* @param arg the method arguments
- * @return the result of the invocation, <code>null</code> for
+ * @return the result of the invocation, <code>null</code> for
* <code>void</code> method, the last result for instance containing
* several objects.
* @throws NoSuchMethodException if the callback method is not found
@@ -244,7 +246,7 @@
* arguments.
* @param instance the instance on which call the method
* @param arg the argument array
- * @return the result of the invocation, <code>null</code> for
+ * @return the result of the invocation, <code>null</code> for
* <code>void</code> method
* @throws NoSuchMethodException if the callback method is not found
* @throws IllegalAccessException if the callback method cannot be called
@@ -265,4 +267,12 @@
public String getMethod() {
return m_method;
}
+
+ /**
+ * Gets the method arguments.
+ * @return the arguments.
+ */
+ public String[] getArguments() {
+ return m_args;
+ }
}
diff --git a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java
index cec3387..03ccbfc 100644
--- a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java
+++ b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.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
@@ -25,18 +25,18 @@
import org.osgi.framework.BundleContext;
public class FooProviderType1 implements FooService {
-
+
private int m_bar;
private String m_foo;
-
+
private BundleContext m_context;
-
+
private static FooProviderType1 singleton;
private static int count = 0;
-
+
private int updated;
private Dictionary lastupdated;
-
+
private static FooProviderType1 singleton(BundleContext bc) {
if (singleton == null) {
count++;
@@ -44,12 +44,12 @@
}
return singleton;
}
-
+
public static FooProviderType1 several(BundleContext bc) {
count++;
return new FooProviderType1(bc);
}
-
+
public FooProviderType1(BundleContext bc) {
if (bc ==null) {
throw new RuntimeException("Injected bundle context null");
@@ -68,41 +68,41 @@
p.put("foo", m_foo);
}
p.put("context", m_context);
-
+
p.put("count", new Integer(count));
-
+
p.put("updated", new Integer(updated));
if (lastupdated != null) {
p.put("lastupdated", lastupdated);
}
-
-
+
+
return p;
}
-
+
public void testException() throws Exception {
String a = "foobarbaz";
throw new Exception("foo"+a);
}
-
+
public void testTry() {
String a = "foo";
a.charAt(0);
}
-
+
public void testTry2(String s) {
String a = "foo";
a.charAt(0);
}
-
+
private void nexttry(String s) {
try {
s += "foo";
} catch(RuntimeException e) {
-
+
}
}
-
+
public boolean getBoolean() { return true; }
public double getDouble() { return 1.0; }
@@ -112,7 +112,7 @@
public long getLong() { return 1; }
public Boolean getObject() { return new Boolean(true); }
-
+
/**
* Custom constructor.
* @param bar
@@ -124,7 +124,7 @@
m_foo = foo;
m_context = bc;
}
-
+
public void updated(Dictionary props) {
updated++;
lastupdated = props;
diff --git a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType2.java b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType2.java
new file mode 100644
index 0000000..62db9c2
--- /dev/null
+++ b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType2.java
@@ -0,0 +1,114 @@
+/*
+ * 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
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.configuration.service.FooService;
+import org.osgi.framework.BundleContext;
+
+public class FooProviderType2 implements FooService {
+
+ private int m_bar;
+ private String m_foo;
+
+ private BundleContext m_context;
+
+ private static int count = 0;
+
+ private int updated;
+
+
+ public FooProviderType2(BundleContext bc) {
+ if (bc ==null) {
+ throw new RuntimeException("Injected bundle context null");
+ }
+ m_context = bc;
+ }
+
+ public boolean foo() {
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("bar", new Integer(m_bar));
+ if(m_foo != null) {
+ p.put("foo", m_foo);
+ }
+ p.put("context", m_context);
+
+ p.put("count", new Integer(count));
+
+ p.put("updated", new Integer(updated));
+
+
+ return p;
+ }
+
+ public void testException() throws Exception {
+ String a = "foobarbaz";
+ throw new Exception("foo"+a);
+ }
+
+ public void testTry() {
+ String a = "foo";
+ a.charAt(0);
+ }
+
+ public void testTry2(String s) {
+ String a = "foo";
+ a.charAt(0);
+ }
+
+ private void nexttry(String s) {
+ try {
+ s += "foo";
+ } catch(RuntimeException e) {
+
+ }
+ }
+
+ public boolean getBoolean() { return true; }
+
+ public double getDouble() { return 1.0; }
+
+ public int getInt() { return 1; }
+
+ public long getLong() { return 1; }
+
+ public Boolean getObject() { return new Boolean(true); }
+
+ /**
+ * Custom constructor.
+ * @param bar
+ * @param foo
+ * @param bc
+ */
+ public FooProviderType2(int bar, String foo, BundleContext bc) {
+ m_bar = bar;
+ m_foo = foo;
+ m_context = bc;
+ }
+
+ public void updated() {
+ updated++;
+ }
+
+}
diff --git a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java
index 7dc82e4..8bff9b3 100644
--- a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java
+++ b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.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
@@ -39,6 +39,8 @@
ots.addTestSuite(UpdatedMethod.class);
ots.addTestSuite(UpdatedMethodAndManagedServiceFactory.class);
ots.addTestSuite(UpdatedMethodAndManagedService.class);
+ ots.addTestSuite(UpdatedNoArgMethodAndManagedService.class);
+ ots.addTestSuite(UpdatedNoArgMethodAndManagedServiceFactory.class);
ots.addTestSuite(ArchitectureTest.class);
return ots;
}
diff --git a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedNoArgMethodAndManagedService.java b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedNoArgMethodAndManagedService.java
new file mode 100644
index 0000000..c44236b
--- /dev/null
+++ b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedNoArgMethodAndManagedService.java
@@ -0,0 +1,307 @@
+/*
+ * 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
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.configuration.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+public class UpdatedNoArgMethodAndManagedService extends OSGiTestCase {
+
+ /**
+ * Instance where the ManagedServicePID is provided by the component type.
+ */
+ ComponentInstance instance1;
+ /**
+ * Instance where the ManagedServicePID is provided by the instance.
+ */
+ ComponentInstance instance2;
+
+ /**
+ * Instance without configuration.
+ */
+ ComponentInstance instance3;
+
+ public void setUp() {
+ String type = "CONFIG-FooProviderType-4Updated2";
+ Properties p = new Properties();
+ p.put("instance.name","instance");
+ p.put("foo", "foo");
+ p.put("bar", "2");
+ p.put("baz", "baz");
+ instance1 = Utils.getComponentInstance(getContext(), type, p);
+ assertEquals("instance1 created", ComponentInstance.VALID,instance1.getState());
+
+ type = "CONFIG-FooProviderType-3Updated2";
+ Properties p1 = new Properties();
+ p1.put("instance.name","instance-2");
+ p1.put("foo", "foo");
+ p1.put("bar", "2");
+ p1.put("baz", "baz");
+ p1.put("managed.service.pid", "instance");
+ instance2 = Utils.getComponentInstance(getContext(), type, p1);
+
+ type = "CONFIG-FooProviderType-3Updated2";
+ Properties p2 = new Properties();
+ p2.put("instance.name","instance-3");
+ p2.put("managed.service.pid", "instance-3");
+ instance3 = Utils.getComponentInstance(getContext(), type, p2);
+ }
+
+ public void tearDown() {
+ instance1.dispose();
+ instance2.dispose();
+ instance3.dispose();
+ instance1 = null;
+ instance2 = null;
+ instance3 = null;
+ }
+
+ public void testStaticInstance1() {
+ ServiceReference fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance1.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 -1", fooP, "foo");
+ assertEquals("Check bar equality -1", barP, new Integer(2));
+ assertEquals("Check baz equality -1", bazP, "baz");
+
+ ServiceReference msRef = Utils.getServiceReferenceByPID(getContext(), ManagedService.class.getName(), "FooProvider-3");
+ assertNotNull("Check ManagedServiceFactory availability", msRef);
+
+ // Configuration of baz
+ Properties conf = new Properties();
+ conf.put("baz", "zab");
+ conf.put("bar", new Integer(2));
+ conf.put("foo", "foo");
+ ManagedService ms = (ManagedService) getContext().getService(msRef);
+ try {
+ ms.updated(conf);
+ } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+
+ // Re-check props
+ fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance1.getInstanceName());
+ fooP = (String) fooRef.getProperty("foo");
+ barP = (Integer) fooRef.getProperty("bar");
+ bazP = (String) fooRef.getProperty("baz");
+ 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");
+ assertEquals("Check updated", 1, updated.intValue());
+
+ context.ungetService(fooRef);
+ getContext().ungetService(msRef);
+ }
+
+ public void testStaticInstance2() {
+ ServiceReference fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance2.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 -1", fooP, "foo");
+ assertEquals("Check bar equality -1", barP, new Integer(2));
+ assertEquals("Check baz equality -1", bazP, "baz");
+
+ ServiceReference msRef = Utils.getServiceReferenceByPID(getContext(), ManagedService.class.getName(), "instance");
+ assertNotNull("Check ManagedService availability", msRef);
+
+
+ // Configuration of baz
+ Properties conf = new Properties();
+ conf.put("baz", "zab");
+ conf.put("bar", new Integer(2));
+ conf.put("foo", "foo");
+ ManagedService ms = (ManagedService) getContext().getService(msRef);
+ try {
+ ms.updated(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 -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");
+
+ assertEquals("Check updated", 1, updated.intValue());
+
+ conf.put("baz", "zab2");
+ conf.put("foo", "oof2");
+ conf.put("bar", new Integer(0));
+ ms = (ManagedService) getContext().getService(msRef);
+ try {
+ ms.updated(conf);
+ } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+
+ updated = (Integer) fs.fooProps().get("updated");
+
+ assertEquals("Check updated -2", 2, updated.intValue());
+
+ getContext().ungetService(fooRef);
+ getContext().ungetService(msRef);
+ }
+
+ public void testDynamicInstance1() {
+ ServiceReference fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance1.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.getServiceReferenceByPID(getContext(), ManagedService.class.getName(), "FooProvider-3");
+ assertNotNull("Check ManagedServiceFactory availability", msRef);
+
+ // Configuration of baz
+ Properties conf = new Properties();
+ conf.put("baz", "zab");
+ conf.put("foo", "oof");
+ conf.put("bar", new Integer(0));
+ ManagedService ms = (ManagedService) getContext().getService(msRef);
+ try {
+ ms.updated(conf);
+ } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+
+ // Re-check props
+ fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance1.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");
+
+ assertEquals("Check updated -1", 1, updated.intValue());
+
+ conf.put("baz", "zab2");
+ conf.put("foo", "oof2");
+ conf.put("bar", new Integer(0));
+ ms = (ManagedService) getContext().getService(msRef);
+ try {
+ ms.updated(conf);
+ } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+
+ updated = (Integer) fs.fooProps().get("updated");
+
+ assertEquals("Check updated -2", 2, updated.intValue());
+
+
+ getContext().ungetService(fooRef);
+ getContext().ungetService(msRef);
+
+ }
+
+ public void testDynamicInstance2() {
+ ServiceReference fooRef = Utils.getServiceReferenceByName(getContext(), FooService.class.getName(), instance2.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.getServiceReferenceByPID(getContext(), ManagedService.class.getName(), "instance");
+ assertNotNull("Check ManagedServiceFactory availability", msRef);
+
+ // Configuration of baz
+ Properties conf = new Properties();
+ conf.put("baz", "zab");
+ conf.put("foo", "oof");
+ conf.put("bar", new Integer(0));
+ ManagedService ms = (ManagedService) getContext().getService(msRef);
+ try {
+ ms.updated(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");
+
+ assertEquals("Check updated", 1, updated.intValue());
+
+ conf.put("baz", "zab2");
+ conf.put("foo", "oof2");
+ conf.put("bar", new Integer(0));
+ ms = (ManagedService) getContext().getService(msRef);
+ try {
+ ms.updated(conf);
+ } catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+
+ updated = (Integer) fs.fooProps().get("updated");
+
+ assertEquals("Check updated -2", 2, updated.intValue());
+
+ getContext().ungetService(fooRef);
+ getContext().ungetService(msRef);
+ }
+}
diff --git a/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedNoArgMethodAndManagedServiceFactory.java b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedNoArgMethodAndManagedServiceFactory.java
new file mode 100644
index 0000000..5067b93
--- /dev/null
+++ b/ipojo/tests/core/configuration/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/UpdatedNoArgMethodAndManagedServiceFactory.java
@@ -0,0 +1,300 @@
+/*
+ * 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
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.configuration.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+public class UpdatedNoArgMethodAndManagedServiceFactory extends OSGiTestCase {
+
+ ComponentInstance instance, instance2;
+
+ public void setUp() {
+ String type = "CONFIG-FooProviderType-3Updated2";
+
+ 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");
+ Integer barP = (Integer) fooRef.getProperty("bar");
+ String bazP = (String) fooRef.getProperty("baz");
+ 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");
+ conf.put("bar", new Integer(2));
+ conf.put("foo", "foo");
+ ManagedServiceFactory ms = (ManagedServiceFactory) getContext().getService(msRef);
+ 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 -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");
+
+ assertEquals("Check updated", 1, updated.intValue());
+
+ getContext().ungetService(msRef);
+
+ }
+
+ public void testStaticNoValue() {
+ 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");
+ conf.put("bar", new Integer(2));
+ conf.put("foo", "foo");
+ ManagedServiceFactory ms = (ManagedServiceFactory) getContext().getService(msRef);
+ 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 -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");
+
+ assertEquals("Check updated", 1, updated.intValue());
+
+ 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");
+ conf.put("foo", "oof");
+ conf.put("bar", new Integer(0));
+ ManagedServiceFactory ms = (ManagedServiceFactory) getContext().getService(msRef);
+ 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");
+
+ assertEquals("Check updated", 1, updated.intValue());
+
+ 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");
+ conf.put("foo", "oof");
+ conf.put("bar", new Integer(0));
+ ManagedServiceFactory ms = (ManagedServiceFactory) getContext().getService(msRef);
+ 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");
+
+ assertEquals("Check updated", 1, updated.intValue());
+
+ getContext().ungetService(fooRef);
+ getContext().ungetService(msRef);
+ }
+
+
+ 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");
+ conf.put("foo", "oof");
+ conf.put("bar", "0");
+ ManagedServiceFactory ms = (ManagedServiceFactory) getContext().getService(msRef);
+ 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");
+
+ assertEquals("Check updated", 1, updated.intValue());
+
+ getContext().ungetService(fooRef);
+ getContext().ungetService(msRef);
+ }
+
+}
diff --git a/ipojo/tests/core/configuration/src/main/resources/metadata.xml b/ipojo/tests/core/configuration/src/main/resources/metadata.xml
index e41d58a..ede1eff 100644
--- a/ipojo/tests/core/configuration/src/main/resources/metadata.xml
+++ b/ipojo/tests/core/configuration/src/main/resources/metadata.xml
@@ -289,6 +289,19 @@
<property name="bar" field="m_bar" />
</properties>
</component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType2"
+ name="CONFIG-FooProviderType-4Updated2" architecture="true">
+ <provides>
+ <property name="foo" field="m_foo" />
+ <property name="bar" field="m_bar" />
+ <property name="baz" type="java.lang.String" />
+ </provides>
+ <properties propagation="true" pid="FooProvider-3" updated="updated">
+ <property name="foo" field="m_foo" />
+ <property name="bar" field="m_bar" />
+ </properties>
+ </component>
<component
classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"
@@ -303,5 +316,18 @@
<property name="bar" field="m_bar" />
</properties>
</component>
+ <component
+ classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType2"
+ name="CONFIG-FooProviderType-3Updated2" architecture="true">
+ <provides>
+ <property name="foo" field="m_foo" />
+ <property name="bar" field="m_bar" />
+ <property name="baz" type="java.lang.String" />
+ </provides>
+ <properties propagation="true" updated="updated">
+ <property name="foo" field="m_foo" />
+ <property name="bar" field="m_bar" />
+ </properties>
+ </component>
</ipojo>