You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2012/01/25 18:46:29 UTC

svn commit: r1235851 - in /karaf/cellar/branches/cellar-2.2.x/config/src: main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java test/java/org/apache/karaf/cellar/config/ConfigurationSupportTest.java

Author: jbonofre
Date: Wed Jan 25 17:46:29 2012
New Revision: 1235851

URL: http://svn.apache.org/viewvc?rev=1235851&view=rev
Log:
[KARAF-1147] Fix a ClassCastException in Cellar config module

Modified:
    karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
    karaf/cellar/branches/cellar-2.2.x/config/src/test/java/org/apache/karaf/cellar/config/ConfigurationSupportTest.java

Modified: karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java?rev=1235851&r1=1235850&r2=1235851&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/config/src/main/java/org/apache/karaf/cellar/config/ConfigurationSupport.java Wed Jan 25 17:46:29 2012
@@ -39,20 +39,18 @@ public class ConfigurationSupport extend
     public Properties dictionaryToProperties(Dictionary dictionary) {
         Properties properties = new Properties();
         if (dictionary != null && dictionary.keys() != null) {
-
             Enumeration keys = dictionary.keys();
             while (keys.hasMoreElements()) {
                 String key = (String) keys.nextElement();
                 if (key != null && dictionary.get(key) != null) {
-                    String value = (String) dictionary.get(key);
-                    properties.put(key, dictionary.get(key));
+                    String value = String.valueOf(dictionary.get(key));
+                    properties.put(key, value);
                 }
             }
         }
         return properties;
     }
 
-
     /**
      * Prepares a dictionary for push
      *
@@ -65,15 +63,14 @@ public class ConfigurationSupport extend
         while (keys.hasMoreElements()) {
             String key = (String) keys.nextElement();
             if (key != null && dictionary.get(key) != null) {
-                String value = (String) dictionary.get(key);
+                String value = String.valueOf(dictionary.get(key));
                 value = convertStrings(value, HOME, RELATIVE_HOME);
-                properties.put(key, dictionary.get(key));
+                properties.put(key, value);
             }
         }
         return properties;
     }
 
-
     /**
      * Prepares a dictionary for Pull
      *
@@ -86,9 +83,9 @@ public class ConfigurationSupport extend
         while (keys.hasMoreElements()) {
             String key = (String) keys.nextElement();
             if (key != null && dictionary.get(key) != null) {
-                String value = (String) dictionary.get(key);
+                String value = String.valueOf(dictionary.get(key));
                 value = convertStrings(value, RELATIVE_HOME, HOME);
-                properties.put(key, dictionary.get(key));
+                properties.put(key, value);
             }
         }
         return properties;
@@ -108,7 +105,6 @@ public class ConfigurationSupport extend
         return result;
     }
 
-
     public Dictionary filterDictionary(Dictionary dictionary) {
         Dictionary result = new Properties();
         if (dictionary != null) {
@@ -116,7 +112,7 @@ public class ConfigurationSupport extend
             while (enumaration.hasMoreElements()) {
                 String key = (String) enumaration.nextElement();
                 if (!isPropertyFiltered(key)) {
-                    String value = (String) dictionary.get(key);
+                    String value = String.valueOf(dictionary.get(key));
                     result.put(key, value);
                 }
             }
@@ -124,7 +120,6 @@ public class ConfigurationSupport extend
         return result;
     }
 
-
     /**
      * Returns true if dictionaries are equal.
      *
@@ -136,7 +131,6 @@ public class ConfigurationSupport extend
         return subDictionary(dict1, dict2) && subDictionary(dict2, dict1);
     }
 
-
     /**
      * Returns true if target contains all source key/value pairs.
      *

Modified: karaf/cellar/branches/cellar-2.2.x/config/src/test/java/org/apache/karaf/cellar/config/ConfigurationSupportTest.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/config/src/test/java/org/apache/karaf/cellar/config/ConfigurationSupportTest.java?rev=1235851&r1=1235850&r2=1235851&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/config/src/test/java/org/apache/karaf/cellar/config/ConfigurationSupportTest.java (original)
+++ karaf/cellar/branches/cellar-2.2.x/config/src/test/java/org/apache/karaf/cellar/config/ConfigurationSupportTest.java Wed Jan 25 17:46:29 2012
@@ -57,4 +57,46 @@ public class ConfigurationSupportTest {
         Assert.assertEquals(expectedResult, result);
     }
 
+    @Test
+    public void testPreparePull() throws Exception {
+        Dictionary result = null;
+        Dictionary source = new Properties();
+        Dictionary expectedResult = new Properties();
+
+        source.put("key1", "value1");
+        source.put("key2", 1);
+        source.put("key3", Boolean.FALSE);
+        source.put("key4", 12L);
+
+        expectedResult.put("key1", "value1");
+        expectedResult.put("key2", "1");
+        expectedResult.put("key3", "false");
+        expectedResult.put("key4", "12");
+
+        result = support.preparePull(source);
+
+        Assert.assertEquals(expectedResult, result);
+    }
+
+    @Test
+    public void testPreparePush() throws Exception {
+        Dictionary result = null;
+        Dictionary source = new Properties();
+        Dictionary expectedResult = new Properties();
+        
+        source.put("key1", "value1");
+        source.put("key2", 1);
+        source.put("key3", Boolean.FALSE);
+        source.put("key4", 12L);
+        
+        expectedResult.put("key1", "value1");
+        expectedResult.put("key2", "1");
+        expectedResult.put("key3", "false");
+        expectedResult.put("key4", "12");
+
+        result = support.preparePush(source);
+
+        Assert.assertEquals(expectedResult, result);
+    }
+
 }