Author: pderop
Date: Tue Feb  9 21:48:32 2016
New Revision: 1729467

URL: http://svn.apache.org/viewvc?rev=1729467&view=rev
Log:
FELIX-5177: added tests when @ConfigurationDependency is applied on an updated 
method which takes as argument
a config proxy.

Added:
    
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationProxy.java
    
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationProxyTest.java
Modified:
    
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/MethodSignatures.java

Added: 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationProxy.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationProxy.java?rev=1729467&view=auto
==============================================================================
--- 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationProxy.java
 (added)
+++ 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationProxy.java
 Tue Feb  9 21:48:32 2016
@@ -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);
+        }
+    }
+}

Modified: 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/MethodSignatures.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/MethodSignatures.java?rev=1729467&r1=1729466&r2=1729467&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/MethodSignatures.java
 (original)
+++ 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/MethodSignatures.java
 Tue Feb  9 21:48:32 2016
@@ -77,11 +77,17 @@ public class MethodSignatures {
                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 @@ public class MethodSignatures {
                        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 @@ public class MethodSignatures {
                        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);
                }
        }

Added: 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationProxyTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationProxyTest.java?rev=1729467&view=auto
==============================================================================
--- 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationProxyTest.java
 (added)
+++ 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationProxyTest.java
 Tue Feb  9 21:48:32 2016
@@ -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:[email protected]";>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);
+    }
+}


Reply via email to