FELIX-5177: added tests when @ConfigurationDependency is applied on an updated method which takes as argument
a config proxy.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1729467 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationProxy.java b/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationProxy.java
new file mode 100644
index 0000000..1218e0a
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationProxy.java
@@ -0,0 +1,111 @@
+/*
+ * 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.dm.runtime.itest.components;
+
+import java.io.IOException;
+import java.util.Hashtable;
+
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.ConfigurationDependency;
+import org.apache.felix.dm.annotation.api.ServiceDependency;
+import org.apache.felix.dm.annotation.api.Start;
+import org.apache.felix.dm.annotation.api.Stop;
+import org.apache.felix.dm.itest.util.Ensure;
+import org.junit.Assert;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * Tests for new Configuration Proxy Types (FELIX-5177)
+ */
+public class ConfigurationProxy {
+    // For ConfigurationDependency service
+    public final static String ENSURE_CONFIG_DEPENDENCY = "ConfigurationProxy.Ensure.Configuration";
+    
+    public interface Config {
+        String getFoo();
+    }
+    
+    // This component configures the Consumer component.
+    @Component
+    public static class ConsumerConfigurator {
+        @ServiceDependency(filter="(name=" + ENSURE_CONFIG_DEPENDENCY + ")")
+        Ensure m_ensure;
+        
+        @ServiceDependency
+        ConfigurationAdmin m_cm;
+
+        private Configuration m_conf;
+        
+        @Start
+        void start() throws IOException {
+            m_conf = m_cm.getConfiguration(Config.class.getName());
+            Hashtable<String, Object> props = new Hashtable<>();
+            props.put("foo", "bar");
+            m_conf.update(props);
+        }
+        
+        @Stop
+        void stop() throws IOException {
+            m_conf.delete();
+        }
+    }
+        
+    // This consumer depends on the configuration and on the provider, using multiple method signatures.
+    @Component
+    public static class Consumer {
+        Config m_config;
+        Config m_config2;
+
+        @ConfigurationDependency
+        void updated(Config cnf) {
+            if (cnf != null) {
+                Assert.assertNotNull(cnf);
+                m_config = cnf;
+            } else {
+                m_config = null;
+                m_ensure.step();
+            }
+        }
+
+        @ConfigurationDependency
+        void updated2(org.apache.felix.dm.Component comp, Config cnf) {
+            if (cnf != null) {
+                Assert.assertNotNull(comp);
+                Assert.assertNotNull(cnf);
+                m_config2 = cnf;
+            } else {
+                m_config2 = null;
+                m_ensure.step();
+            }
+        }
+
+        @ServiceDependency(filter="(name=" + ENSURE_CONFIG_DEPENDENCY + ")")
+        Ensure m_ensure;
+        
+        @Start
+        void start() {
+            Assert.assertNotNull(m_config);
+            Assert.assertNotNull(m_config2);
+            Assert.assertEquals("bar", m_config.getFoo());
+            Assert.assertEquals("bar", m_config2.getFoo());
+            m_ensure.step(1);
+        }
+    }
+}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/MethodSignatures.java b/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/MethodSignatures.java
index d340ec9..9a8b950 100644
--- a/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/MethodSignatures.java
+++ b/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/MethodSignatures.java
@@ -77,11 +77,17 @@
 		Ensure m_ensure;
 	}
 	
+	public interface ConsumerConfig {
+	    String getFoo();
+	}
+	
 	// This consumer depends on the configuration and on the provider, using multiple method signatures.
 	@Component
 	public static class Consumer {
 		Dictionary<String, Object> m_properties;
 		Dictionary<String, Object> m_properties2;
+		ConsumerConfig m_config;
+        ConsumerConfig m_config2;
 
 		@ConfigurationDependency
 		void updated(Dictionary<String, Object> properties) {
@@ -93,6 +99,19 @@
 			Assert.assertNotNull(component);
 			m_properties2 = properties;			
 		}
+		
+		@ConfigurationDependency(pidClass=Consumer.class)
+		void updated3(ConsumerConfig cnf) {
+		    Assert.assertNotNull(cnf);
+		    m_config = cnf;         
+		}
+
+		@ConfigurationDependency(pidClass=Consumer.class)
+		void updated4(org.apache.felix.dm.Component comp, ConsumerConfig cnf) {
+		    Assert.assertNotNull(comp);
+		    Assert.assertNotNull(cnf);
+		    m_config2 = cnf;         
+		}
 
 		@ServiceDependency(filter="(name=" + ENSURE_SERVICE_DEPENDENCY + ")")
 		Ensure m_ensure;
@@ -167,6 +186,9 @@
 			Assert.assertNotNull(m_properties2);
 			Assert.assertEquals("bar", m_properties.get("foo"));
 			Assert.assertEquals("bar", m_properties2.get("foo"));
+			Assert.assertNotNull(m_config);
+			Assert.assertEquals("bar", m_config.getFoo());
+			Assert.assertEquals("bar", m_config2.getFoo());
 			m_ensure.step(10);
 		}
 	}
diff --git a/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationProxyTest.java b/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationProxyTest.java
new file mode 100644
index 0000000..5606fad
--- /dev/null
+++ b/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationProxyTest.java
@@ -0,0 +1,42 @@
+/*
+* 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.dm.runtime.itest.tests;
+
+import org.apache.felix.dm.itest.util.Ensure;
+import org.apache.felix.dm.itest.util.TestBase;
+import org.apache.felix.dm.runtime.itest.components.ConfigurationProxy;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * Tests for new Configuration Proxy Types (FELIX-5177)
+ * 
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ConfigurationProxyTest extends TestBase {
+    /**
+     * Validates ServiceDependency method signatures.
+     */
+    public void testConfigurationProxy() {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ConfigurationProxy.ENSURE_CONFIG_DEPENDENCY);
+        e.waitForStep(1, 5000);
+        sr.unregister();
+        e.waitForStep(3, 5000);
+    }
+}