Author: pderop
Date: Sun Nov  6 22:28:30 2016
New Revision: 1768396

URL: http://svn.apache.org/viewvc?rev=1768396&view=rev
Log:
FELIX-5399: Added test cases for 5399 issue.

Added:
    
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5399_DefaultListConfigType.java
    
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5399_DefaultMapConfigType.java
Modified:
    
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/ConfigurationCreator.java

Modified: 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/ConfigurationCreator.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/ConfigurationCreator.java?rev=1768396&r1=1768395&r2=1768396&view=diff
==============================================================================
--- 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/ConfigurationCreator.java
 (original)
+++ 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/ConfigurationCreator.java
 Sun Nov  6 22:28:30 2016
@@ -19,7 +19,10 @@
 package org.apache.felix.dm.itest.api;
 
 import java.io.IOException;
+import java.util.Dictionary;
+import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.Map;
 import java.util.Properties;
 
 import org.apache.felix.dm.itest.util.Ensure;
@@ -36,22 +39,33 @@ public class ConfigurationCreator {
     Configuration m_conf;
     final String m_pid;
     final int m_initStep;
+    final Dictionary<String, Object> m_parameters = new Hashtable<>();
     
     public ConfigurationCreator(Ensure e, String pid, int initStep) {
+        this(e, pid, initStep, new String[] {});
+    }
+
+    public ConfigurationCreator(Ensure e, String pid, int initStep, String ... 
keyvalues) {
         m_ensure = e;
         m_pid = pid;
         m_initStep = initStep;
+        for (int i = 0; i < keyvalues.length; i ++) {
+            String[] tokens = keyvalues[i].split("=");
+            String k = tokens[0].trim();
+            Object v = tokens[1].trim();
+            m_parameters.put(k, v);
+        }        
     }
 
-    @SuppressWarnings({ "rawtypes", "unchecked" })
        public void init() {
         try {
                Assert.assertNotNull(m_ca);
             m_ensure.step(m_initStep);
-            m_conf = m_ca.getConfiguration(m_pid, null);
-            Hashtable props = new Properties();
-            props.put("testkey", "testvalue");
-            m_conf.update(props);
+            m_conf = m_ca.getConfiguration(m_pid, null);            
+            if (m_parameters.size() == 0) {
+                m_parameters.put("testkey", "testvalue");
+            }
+            m_conf.update(m_parameters);
         }
         catch (IOException e) {
             Assert.fail("Could not create configuration: " + e.getMessage());

Added: 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5399_DefaultListConfigType.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5399_DefaultListConfigType.java?rev=1768396&view=auto
==============================================================================
--- 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5399_DefaultListConfigType.java
 (added)
+++ 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5399_DefaultListConfigType.java
 Sun Nov  6 22:28:30 2016
@@ -0,0 +1,68 @@
+/*
+ * 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.itest.api;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.itest.util.Ensure;
+import org.apache.felix.dm.itest.util.TestBase;
+import org.junit.Assert;
+
+/**
+ * This test validates that a list specified by default from a configuration 
type is used when
+ * the configuration is unavailable or when the configuration is available but 
the key is not present in the
+ * configuration dictionary.
+ */
+public class FELIX5399_DefaultListConfigType extends TestBase
+{
+    Ensure m_ensure = new Ensure();
+    
+    public void testDefaulValues() {
+        DependencyManager m = getDM();
+        
+        Component myComponent = m.createComponent()
+            .setImplementation(new MyComponent())
+            .add(m.createConfigurationDependency().setCallback("updated", 
MyConfig.class).setRequired(false));
+        
+        // create the component: since there is no value for the map in the 
actual configuration, then default map 
+        // provided by the configuration type default method should be 
returned.
+        m.add(myComponent);
+        m_ensure.waitForStep(1, 5000);        
+      
+    }
+    
+    public interface MyConfig {
+        public default List<String> getList() { 
+               return Arrays.asList("default1", "default2");
+        }              
+    }
+    
+    public class MyComponent {
+        void updated(MyConfig cnf) {
+               List<String> list = cnf.getList();
+               Assert.assertEquals("default1", list.get(0));
+               Assert.assertEquals("default2", list.get(1));
+               m_ensure.step(1);
+        }
+    }
+
+}

Added: 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5399_DefaultMapConfigType.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5399_DefaultMapConfigType.java?rev=1768396&view=auto
==============================================================================
--- 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5399_DefaultMapConfigType.java
 (added)
+++ 
felix/trunk/dependencymanager/org.apache.felix.dependencymanager.itest/src/org/apache/felix/dm/itest/api/FELIX5399_DefaultMapConfigType.java
 Sun Nov  6 22:28:30 2016
@@ -0,0 +1,70 @@
+/*
+ * 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.itest.api;
+
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.itest.util.Ensure;
+import org.apache.felix.dm.itest.util.TestBase;
+import org.junit.Assert;
+
+/**
+ * This test validates that a map specified by default from a configuration 
type is used when
+ * the configuration is unavailable or when the configuration is available but 
the key is not present in the
+ * configuration dictionary.
+ */
+public class FELIX5399_DefaultMapConfigType extends TestBase
+{
+    Ensure m_ensure = new Ensure();
+    
+    public void testDefaulValues() {
+        DependencyManager m = getDM();
+        
+        Component myComponent = m.createComponent()
+            .setImplementation(new MyComponent())
+            .add(m.createConfigurationDependency().setCallback("updated", 
MyConfig.class).setRequired(false));
+
+        
+        m.add(myComponent);
+        m_ensure.waitForStep(1, 5000);        
+    }
+    
+    public interface MyConfig {
+        public default SortedMap<String, String> getMap() { 
+               SortedMap<String, String> defaultMap = new TreeMap<>();
+               defaultMap.put("key1", "default1");
+               defaultMap.put("key2", "default2");
+               return defaultMap;
+        }        
+    }
+    
+    public class MyComponent {
+        void updated(MyConfig cnf) {
+               Map<String, String> map = cnf.getMap();
+               Assert.assertEquals("default1", map.get("key1"));
+               Assert.assertEquals("default2", map.get("key2"));
+               m_ensure.step(1);
+        }
+    }
+
+}


Reply via email to