felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r1661581 - in /felix/sandbox/pderop/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest: components/ConfigurationDependencyAnnotation.java tests/ConfigurationDependencyAnnotationTest.java
Date Sun, 22 Feb 2015 23:35:39 GMT
Author: pderop
Date: Sun Feb 22 23:35:38 2015
New Revision: 1661581

URL: http://svn.apache.org/r1661581
Log:
Added test for FELIX-4777

Added:
    felix/sandbox/pderop/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationDependencyAnnotation.java
    felix/sandbox/pderop/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationDependencyAnnotationTest.java

Added: felix/sandbox/pderop/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationDependencyAnnotation.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationDependencyAnnotation.java?rev=1661581&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationDependencyAnnotation.java
(added)
+++ felix/sandbox/pderop/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/components/ConfigurationDependencyAnnotation.java
Sun Feb 22 23:35:38 2015
@@ -0,0 +1,97 @@
+package org.apache.felix.dm.runtime.itest.components;
+
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.dm.annotation.api.Component;
+import org.apache.felix.dm.annotation.api.ConfigurationDependency;
+import org.apache.felix.dm.annotation.api.Init;
+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;
+
+public class ConfigurationDependencyAnnotation {
+    @Component
+    public static class ConfigurableComponent {
+        public final static String ENSURE = "ConfigurableComponent";
+        
+        volatile Ensure m_ensure;
+        volatile Dictionary<String, String> m_conf;
+
+        @ConfigurationDependency
+        void updated(Dictionary<String, String> conf) {
+            m_conf = conf;
+        }
+        
+        @ServiceDependency(filter="(name=" + ENSURE + ")")
+        void bind(Ensure ensure) {
+            m_ensure = ensure;
+            Assert.assertNotNull(m_conf);
+            Assert.assertEquals("bar", m_conf.get("foo"));
+            m_ensure.step(1);
+        }
+        
+        @Start
+        void start() {
+            m_ensure.step(2);
+        }
+        
+        @Stop
+        void stop() {
+            m_ensure.step(3);
+        }
+    }
+    
+    @Component
+    public static class ConfigurableComponentWithDynamicExtraConfiguration {
+        public final static String ENSURE = "ConfigurableComponentWithDynamicExtraConfiguration";
+        
+        volatile Ensure m_ensure;
+        volatile Dictionary<String, String> m_conf;
+
+        @ConfigurationDependency
+        void updated(Dictionary<String, String> conf) {
+            m_conf = conf;
+        }
+        
+        @ServiceDependency(filter="(name=" + ENSURE + ")")
+        void bind(Ensure ensure) {
+            m_ensure = ensure;
+            Assert.assertNotNull(m_conf);
+            Assert.assertEquals("bar", m_conf.get("foo"));
+            m_ensure.step(1);
+        }
+        
+        @Init
+        Map<String, String> init() {
+            Assert.assertNotNull(m_conf);
+            String dynamicPid = m_conf.get("dynamicPid");
+            Assert.assertNotNull(dynamicPid);
+            Map<String, String> map = new HashMap<>();
+            map.put("dynamicConfig.pid", m_conf.get("dynamicPid"));
+            m_ensure.step(2);
+            return map;
+        }
+        
+        @ConfigurationDependency(name="dynamicConfig")
+        void extraConfiguration(Dictionary<String, String> dynamicConf) {
+            if (dynamicConf != null) {
+                Assert.assertEquals("bar2", dynamicConf.get("foo2"));
+                m_ensure.step(3);
+            }
+        }        
+        
+        @Start
+        void start() {
+            m_ensure.step(4);
+        }
+        
+        @Stop
+        void stop() {
+            m_ensure.step(5);
+        }
+    }
+}

Added: felix/sandbox/pderop/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationDependencyAnnotationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationDependencyAnnotationTest.java?rev=1661581&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationDependencyAnnotationTest.java
(added)
+++ felix/sandbox/pderop/dependencymanager/org.apache.felix.dependencymanager.runtime.itest/src/org/apache/felix/dm/runtime/itest/tests/ConfigurationDependencyAnnotationTest.java
Sun Feb 22 23:35:38 2015
@@ -0,0 +1,81 @@
+package org.apache.felix.dm.runtime.itest.tests;
+
+import java.io.IOException;
+import java.util.Hashtable;
+
+import org.apache.felix.dm.itest.util.Ensure;
+import org.apache.felix.dm.itest.util.TestBase;
+import org.apache.felix.dm.runtime.itest.components.ConfigurationDependencyAnnotation.ConfigurableComponent;
+import org.apache.felix.dm.runtime.itest.components.ConfigurationDependencyAnnotation.ConfigurableComponentWithDynamicExtraConfiguration;
+import org.junit.Assert;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public class ConfigurationDependencyAnnotationTest extends TestBase {
+
+    private final static int MAXWAIT = 5000;
+
+    
+    /**
+     * Tests the ConfigurationDependency annotation.
+     */
+    @SuppressWarnings({ "serial", "rawtypes", "unchecked" })
+    public void testConfigurationDependencyAnnotation() throws Throwable {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ConfigurableComponent.ENSURE);
+        ConfigurationAdmin cm = (ConfigurationAdmin) context.getService(context.getServiceReference(ConfigurationAdmin.class.getName()));
+        try {
+            org.osgi.service.cm.Configuration cf = cm.getConfiguration(ConfigurableComponent.class.getName(),
null);
+            cf.update(new Hashtable() {
+                {
+                    put("foo", "bar");
+                }
+            });
+            e.waitForStep(1, MAXWAIT);
+            cf.delete();
+            e.waitForStep(3, MAXWAIT);
+            e.ensure();
+            sr.unregister();
+        } catch (IOException err) {
+            err.printStackTrace();
+            Assert.fail("can't create factory configuration");
+        }
+    }
+    
+    /**
+     * Tests a Component two ConfigurationDependency (the second one is "instance bound"

+     * and its pid is declared from the init method).
+     */
+   @SuppressWarnings({ "serial", "rawtypes", "unchecked" })
+    public void testConfigurationDependencyWithAnotherExtraDynamicConfigurationAnnotation()
throws Throwable {
+        Ensure e = new Ensure();
+        ServiceRegistration sr = register(e, ConfigurableComponentWithDynamicExtraConfiguration.ENSURE);
+        ConfigurationAdmin cm = (ConfigurationAdmin) context.getService(context.getServiceReference(ConfigurationAdmin.class.getName()));
+        try {
+            org.osgi.service.cm.Configuration cf = cm.getConfiguration(ConfigurableComponentWithDynamicExtraConfiguration.class.getName(),
null);
+            cf.update(new Hashtable() {
+                {
+                    put("foo", "bar");
+                    put("dynamicPid", "dynamicPid"); // Pid of the second Configuration Dependency.
+                }
+            });
+            org.osgi.service.cm.Configuration extraCf = cm.getConfiguration("dynamicPid",
null);
+            extraCf.update(new Hashtable() {
+                {
+                    put("foo2", "bar2");
+                }
+            });
+
+            e.waitForStep(4, MAXWAIT);
+            cf.delete();
+            extraCf.delete();
+            e.waitForStep(5, MAXWAIT);
+            e.ensure();
+            sr.unregister();
+        } catch (IOException err) {
+            err.printStackTrace();
+            Assert.fail("can't create factory configuration");
+        }
+    }
+
+}



Mime
View raw message