From 50368411fba4fca7efdc5341f9d485ff821eee2c Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Fri, 8 Mar 2019 00:23:11 -0500 Subject: only convert object type json when String only convert object type json when input is a String Change-Id: I465dfe905f5d85de583b6232640dc4dc13a09c7a Issue-ID: SO-1610 Signed-off-by: Benjamin, Max (mb388a) --- .../org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java | 13 +++++++++++-- .../onap/so/openstack/utils/MsoHeatUtilsUnitTest.java | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'adapters/mso-adapter-utils/src/test/java/org') diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java index f63aab7ce1..833b4ab760 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java @@ -24,6 +24,7 @@ package org.onap.so.cloudify.utils; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -70,6 +71,7 @@ import org.skyscreamer.jsonassert.JSONAssert; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public class MsoCloudifyUtilsTest { @@ -305,11 +307,18 @@ public class MsoCloudifyUtilsTest { paramJson.setParamType("json"); paramJson.setParamName("my-json"); - Map jsonMap = mapper.readValue(getJson("free-form.json"), new TypeReference>(){}); + HeatTemplateParam paramJsonEscaped = new HeatTemplateParam(); + paramJsonEscaped.setParamType("json"); + paramJsonEscaped.setParamName("my-json-escaped"); + Map jsonMap = mapper.readValue(getJson("free-form.json"), new TypeReference>(){}); + assertEquals(3, utils.convertInputValue("3", paramNum)); assertEquals("hello", utils.convertInputValue("hello", paramString)); - JSONAssert.assertEquals(getJson("free-form.json"), utils.convertInputValue(jsonMap, paramJson).toString(), false); + assertTrue("expect no change in type", utils.convertInputValue(jsonMap, paramJson) instanceof Map); + assertTrue("expect string to become jsonNode", utils.convertInputValue(getJson("free-form.json"), paramJsonEscaped) instanceof JsonNode); + + JSONAssert.assertEquals(getJson("free-form.json"), mapper.writeValueAsString(utils.convertInputValue(getJson("free-form.json"), paramJsonEscaped)), false); } diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsUnitTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsUnitTest.java index 40bbe90218..66d6f59e79 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsUnitTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsUnitTest.java @@ -1,6 +1,7 @@ package org.onap.so.openstack.utils; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.IOException; import java.nio.file.Files; @@ -17,6 +18,7 @@ import org.skyscreamer.jsonassert.JSONAssert; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public class MsoHeatUtilsUnitTest { @@ -45,18 +47,28 @@ public class MsoHeatUtilsUnitTest { paramJson.setParamType("json"); paramJson.setParamName("my-json"); + HeatTemplateParam paramJsonEscaped = new HeatTemplateParam(); + paramJsonEscaped.setParamType("json"); + paramJsonEscaped.setParamName("my-json-escaped"); + Map jsonMap = mapper.readValue(getJson("free-form.json"), new TypeReference>(){}); input.put("my-json", jsonMap); + input.put("my-json-escaped", getJson("free-form.json")); + parameters.add(paramNum); parameters.add(paramString); parameters.add(paramJson); - + parameters.add(paramJsonEscaped); + Map output = utils.convertInputMap(input, template); assertEquals(3, output.get("my-number")); assertEquals("hello", output.get("my-string")); - JSONAssert.assertEquals(getJson("free-form.json"), (String)output.get("my-json"), false); + assertTrue("expect no change in type", output.get("my-json") instanceof Map); + assertTrue("expect string to become jsonNode", output.get("my-json-escaped") instanceof JsonNode); + + JSONAssert.assertEquals(getJson("free-form.json"), mapper.writeValueAsString(output.get("my-json-escaped")), false); } -- cgit 1.2.3-korg