diff options
author | Jim Hahn <jrh3@att.com> | 2019-09-13 12:14:25 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-09-13 17:40:29 -0400 |
commit | af2e4018c92b0fb311f60dfe507335b12e2935a4 (patch) | |
tree | 62705712e2a88682e17bdd9fef248e866c7407e4 /utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java | |
parent | 63922e3dc9101f019cb490f6c5d02991c10fcdf5 (diff) |
Extract YamlJsonTranslator from StandardYamlCoder
Refactored StandardYamlCoder, extracting a new class, YamlJsonTranslator,
from it. This facilitates performing yaml translation when not using a
standard "gson" coder.
Added YamlJacksonHandler which supports YAML translation layered on
top of a JacksonHandler instead of a GsonMessageBodyHandler.
Also added junit tests to complete coverage of StandardCoder.
Also added public APPLICATION_YAML to YamlMessageBodyHandler.
Change-Id: Ia470fa194661fbf1aebeaf0f18b57f2a984cb64b
Issue-ID: POLICY-2081
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java')
-rw-r--r-- | utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java b/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java index 2992933f..2a70f85a 100644 --- a/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java +++ b/utils/src/test/java/org/onap/policy/common/utils/coder/StandardCoderTest.java @@ -44,6 +44,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Arrays; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.junit.Before; @@ -201,6 +202,22 @@ public class StandardCoderTest { } @Test + public void testToJsonTree_testFromJsonJsonElementClassT() throws Exception { + MyMap map = new MyMap(); + map.props = new LinkedHashMap<>(); + map.props.put("jel keyA", "jel valueA"); + map.props.put("jel keyB", "jel valueB"); + + JsonElement json = coder.toJsonTree(map); + assertEquals("{'props':{'jel keyA':'jel valueA','jel keyB':'jel valueB'}}".replace('\'', '"'), json.toString()); + + Object result = coder.fromJson(json, MyMap.class); + + assertNotNull(result); + assertEquals("{jel keyA=jel valueA, jel keyB=jel valueB}", result.toString()); + } + + @Test public void testConvertFromDouble() throws Exception { String text = "[listA, {keyA=100}, 200]"; assertEquals(text, coder.decode(text, Object.class).toString()); @@ -276,7 +293,12 @@ public class StandardCoderTest { } } - private static class MyMap { + public static class MyMap { private Map<String, Object> props; + + @Override + public String toString() { + return props.toString(); + } } } |