felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1762535 - in /felix/trunk/converter: converter/src/test/java/org/apache/felix/converter/impl/ serializer/src/main/java/org/apache/felix/serializer/impl/yaml/ serializer/src/test/java/org/apache/felix/serializer/impl/yaml/
Date Tue, 27 Sep 2016 18:48:03 GMT
Author: davidb
Date: Tue Sep 27 18:48:03 2016
New Revision: 1762535

URL: http://svn.apache.org/viewvc?rev=1762535&view=rev
Log:
Felix Converter - additional YAML serializer testing.

Added:
    felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/yaml/YamlSerializerTest.java
Modified:
    felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java
    felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
    felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializingImpl.java

Modified: felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java?rev=1762535&r1=1762534&r2=1762535&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java
(original)
+++ felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterServiceTest.java
Tue Sep 27 18:48:03 2016
@@ -526,8 +526,6 @@ public class ConverterServiceTest {
             }
         }
 
-        System.out.println(m);
-
         // convert back
         MyDTO2 dto2 = converter.convert(m).to(MyDTO2.class);
         assertEquals(dto.longList, dto2.longList);

Modified: felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java?rev=1762535&r1=1762534&r2=1762535&view=diff
==============================================================================
--- felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
(original)
+++ felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
Tue Sep 27 18:48:03 2016
@@ -32,7 +32,7 @@ public class YamlDeserializingImpl<T> im
     private volatile Converter converter;
     private final Class<T> clazz;
 
-    public YamlDeserializingImpl(Converter c, Class<T> cls) {
+    YamlDeserializingImpl(Converter c, Class<T> cls) {
         converter = c;
         clazz = cls;
     }

Modified: felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializingImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializingImpl.java?rev=1762535&r1=1762534&r2=1762535&view=diff
==============================================================================
--- felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializingImpl.java
(original)
+++ felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializingImpl.java
Tue Sep 27 18:48:03 2016
@@ -75,7 +75,7 @@ public class YamlSerializingImpl impleme
     }
 
     private String encode(Object obj) {
-        return encode(obj, 0);
+        return encode(obj, 0).trim();
     }
 
     @SuppressWarnings("rawtypes")

Added: felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/yaml/YamlSerializerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/yaml/YamlSerializerTest.java?rev=1762535&view=auto
==============================================================================
--- felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/yaml/YamlSerializerTest.java
(added)
+++ felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/yaml/YamlSerializerTest.java
Tue Sep 27 18:48:03 2016
@@ -0,0 +1,71 @@
+/*
+ * 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.serializer.impl.yaml;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.service.converter.Converter;
+import org.osgi.service.converter.StandardConverter;
+
+import static org.junit.Assert.assertEquals;
+
+public class YamlSerializerTest {
+    private Converter converter;
+
+    @Before
+    public void setUp() {
+        converter = new StandardConverter();
+    }
+
+    @After
+    public void tearDown() {
+        converter = null;
+    }
+
+    @Test
+    public void testJSONCodec() throws Exception {
+        Map<Object, Object> m1 = new HashMap<>();
+        m1.put("x", true);
+        m1.put("y", null);
+        Map<Object, Object> m = new HashMap<>();
+        m.put(1, 11L);
+        m.put("ab", "cd");
+        m.put(true, m1);
+
+        YamlSerializerImpl yamlCodec = new YamlSerializerImpl();
+        String yaml = yamlCodec.serialize(m).toString();
+
+        assertEquals("1: 11\n" +
+                "ab: 'cd'\n" +
+                "true: \n" +
+                "  x: true\n" +
+                "  y:", yaml);
+
+        @SuppressWarnings("rawtypes")
+        Map m2 = yamlCodec.deserialize(Map.class).from(yaml);
+        // m2 is not exactly equal to m, as the keys are all strings now, this is unavoidable
with JSON
+        assertEquals(m.size(), m2.size());
+        assertEquals(converter.convert(m.get(1)).to(int.class),
+                converter.convert(m2.get(1)).to(int.class));
+        assertEquals(m.get("ab"), m2.get("ab"));
+        assertEquals(m.get(true), m2.get(true));
+    }
+}



Mime
View raw message