felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1750629 - in /felix/sandbox/cziegeler/configurator/src: main/java/org/apache/felix/configurator/impl/ test/java/org/apache/felix/configurator/impl/ test/java/org/apache/felix/configurator/impl/yaml/
Date Wed, 29 Jun 2016 12:58:21 GMT
Author: cziegeler
Date: Wed Jun 29 12:58:21 2016
New Revision: 1750629

URL: http://svn.apache.org/viewvc?rev=1750629&view=rev
Log:
Move type conversion into separate module

Modified:
    felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/TypeConverter.java
    felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/Util.java
    felix/sandbox/cziegeler/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java
    felix/sandbox/cziegeler/configurator/src/test/java/org/apache/felix/configurator/impl/yaml/YAMLUtilTest.java

Modified: felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/TypeConverter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/TypeConverter.java?rev=1750629&r1=1750628&r2=1750629&view=diff
==============================================================================
--- felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/TypeConverter.java
(original)
+++ felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/TypeConverter.java
Wed Jun 29 12:58:21 2016
@@ -65,6 +65,10 @@ public class TypeConverter {
                 return value;
             } else if ( value instanceof Integer ) {
                 return ((Integer)value).longValue();
+            } else if ( value instanceof Short ) {
+                return ((Short)value).longValue();
+            } else if ( value instanceof Byte ) {
+                return ((Byte)value).longValue();
             } else if ( value instanceof Float ) {
                 return ((Float)value).doubleValue();
             }

Modified: felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/Util.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/Util.java?rev=1750629&r1=1750628&r2=1750629&view=diff
==============================================================================
--- felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/Util.java
(original)
+++ felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/Util.java
Wed Jun 29 12:58:21 2016
@@ -56,7 +56,7 @@ public class Util {
     public static volatile File binDirectory;
 
     /**
-     * Check if the bundle contains configurations for the configurer
+     * Check if the bundle contains configurations for the configurator
      * @param bundle The bundle
      * @return Set of locations or {@code null}
      */

Modified: felix/sandbox/cziegeler/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java?rev=1750629&r1=1750628&r2=1750629&view=diff
==============================================================================
--- felix/sandbox/cziegeler/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java
(original)
+++ felix/sandbox/cziegeler/configurator/src/test/java/org/apache/felix/configurator/impl/TypeConverterTest.java
Wed Jun 29 12:58:21 2016
@@ -18,9 +18,11 @@
  */
 package org.apache.felix.configurator.impl;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
 import java.lang.reflect.Array;
 import java.util.Collection;
 import java.util.Map;
@@ -31,6 +33,77 @@ import org.junit.Test;
 
 public class TypeConverterTest {
 
+    @Test public void testStringConversionNoTypeInfo() throws IOException {
+        final String v_String = "world";
+        final TypeConverter converter = new TypeConverter(null);
+        final Object result = converter.convert(v_String, null, null);
+        assertTrue(result instanceof String);
+        assertEquals(v_String, result);
+    }
+
+    @Test public void testLongConversionNoTypeInfo() throws IOException {
+        final long v_long = 3;
+        final TypeConverter converter = new TypeConverter(null);
+        final Object result = converter.convert(v_long, null, null);
+        assertTrue(result instanceof Long);
+        assertEquals(v_long, result);
+    }
+
+    @Test public void testIntegerConversionNoTypeInfo() throws IOException {
+        final int v_int = 3;
+        final TypeConverter converter = new TypeConverter(null);
+        final Object result = converter.convert(v_int, null, null);
+        assertTrue(result instanceof Long);
+        assertEquals(3L, result);
+    }
+
+    @Test public void testShortConversionNoTypeInfo() throws IOException {
+        final short v_short = 3;
+        final TypeConverter converter = new TypeConverter(null);
+        final Object result = converter.convert(v_short, null, null);
+        assertTrue(result instanceof Long);
+        assertEquals(3L, result);
+    }
+
+    @Test public void testByteConversionNoTypeInfo() throws IOException {
+        final byte v_byte = 3;
+        final TypeConverter converter = new TypeConverter(null);
+        final Object result = converter.convert(v_byte, null, null);
+        assertTrue(result instanceof Long);
+        assertEquals(3L, result);
+    }
+
+    @Test public void testCharConversionNoTypeInfo() throws IOException {
+        final char v_char = 'a';
+        final TypeConverter converter = new TypeConverter(null);
+        final Object result = converter.convert(v_char, "a", null);
+        assertTrue(result instanceof String);
+        assertEquals("a", result);
+    }
+
+    @Test public void testCharacterConversionNoTypeInfo() throws IOException {
+        final Character v_Character = new Character('a');
+        final TypeConverter converter = new TypeConverter(null);
+        final Object result = converter.convert(v_Character, "a", null);
+        assertTrue(result instanceof String);
+        assertEquals("a", result);
+    }
+
+    @Test public void testFloatConversionNoTypeInfo() throws IOException {
+        final float v_float = 3.1f;
+        final TypeConverter converter = new TypeConverter(null);
+        final Object result = converter.convert(v_float, null, null);
+        assertTrue(result instanceof Double);
+    }
+
+    @Test public void testDoubleConversionNoTypeInfo() throws IOException {
+        final double v_double = 3.0;
+        final TypeConverter converter = new TypeConverter(null);
+        final Object result = converter.convert(v_double, null, null);
+        assertTrue(result instanceof Double);
+        assertEquals(v_double, result);
+    }
+
     @Test public void testSimpleTypeConversions() throws Exception {
         final TypeConverter converter = new TypeConverter(null);
 

Modified: felix/sandbox/cziegeler/configurator/src/test/java/org/apache/felix/configurator/impl/yaml/YAMLUtilTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/configurator/src/test/java/org/apache/felix/configurator/impl/yaml/YAMLUtilTest.java?rev=1750629&r1=1750628&r2=1750629&view=diff
==============================================================================
--- felix/sandbox/cziegeler/configurator/src/test/java/org/apache/felix/configurator/impl/yaml/YAMLUtilTest.java
(original)
+++ felix/sandbox/cziegeler/configurator/src/test/java/org/apache/felix/configurator/impl/yaml/YAMLUtilTest.java
Wed Jun 29 12:58:21 2016
@@ -20,12 +20,15 @@ package org.apache.felix.configurator.im
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.net.URL;
+import java.util.List;
+import java.util.Map;
 
 import org.apache.felix.configurator.impl.TypeConverter;
 import org.apache.felix.configurator.impl.model.ConfigurationFile;
@@ -56,4 +59,32 @@ public class YAMLUtilTest {
         assertEquals(2, cg.getConfigurations().size());
     }
 
+    @SuppressWarnings("unchecked")
+    @Test public void testTypes() throws Exception {
+        final Object obj = YAMLUtil.parseYAML("a", YAMLUtilTest.readYAML("yaml/simple-types.yaml"));
+        final Map<String, Object> config = (Map<String, Object>)obj;
+        final Map<String, Object> properties = (Map<String, Object>)config.get("config");
+
+        assertTrue(properties.get("string") instanceof String);
+        assertTrue(properties.get("boolean") instanceof Boolean);
+        assertTrue(properties.get("number") instanceof Integer);
+        assertTrue(properties.get("float") instanceof Double);
+
+        // arrays
+        assertTrue(properties.get("string.array") instanceof List<?>);
+        assertTrue(((List<Object>)properties.get("string.array")).get(0) instanceof
String);
+        assertTrue(((List<Object>)properties.get("string.array")).get(1) instanceof
String);
+
+        assertTrue((List<Object>)properties.get("boolean.array") instanceof List<?>);
+        assertTrue(((List<Object>)properties.get("boolean.array")).get(0) instanceof
Boolean);
+        assertTrue(((List<Object>)properties.get("boolean.array")).get(1) instanceof
Boolean);
+
+        assertTrue((List<Object>)properties.get("number.array") instanceof List<?>);
+        assertTrue(((List<Object>)properties.get("number.array")).get(0) instanceof
Integer);
+        assertTrue(((List<Object>)properties.get("number.array")).get(1) instanceof
Integer);
+
+        assertTrue((List<Object>)properties.get("float.array") instanceof List<?>);
+        assertTrue(((List<Object>)properties.get("float.array")).get(0) instanceof
Double);
+        assertTrue(((List<Object>)properties.get("float.array")).get(1) instanceof
Double);
+    }
 }
\ No newline at end of file



Mime
View raw message