From 89d7125d6ae8a3f172ce7d6dc9546443d9477f5b Mon Sep 17 00:00:00 2001 From: JvD_Ericsson Date: Tue, 14 Feb 2023 11:53:07 +0000 Subject: Support for copy/paste tosca functions into operation inputs Issue-ID: SDC-4394 Signed-off-by: JvD_Ericsson Change-Id: I4aedb641e950419677d2509f4944fcf778c2efd8 --- .../converters/ToscaValueBaseConverterTest.java | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'catalog-model/src/test/java') diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/ToscaValueBaseConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/ToscaValueBaseConverterTest.java index 5387b46dd6..13b2be5ce5 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/ToscaValueBaseConverterTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/ToscaValueBaseConverterTest.java @@ -26,6 +26,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import java.util.HashMap; @@ -145,4 +147,62 @@ class ToscaValueBaseConverterTest { assertEquals(innerObject.get("float").getAsDouble(), objectPropertyAsMap.get("float")); assertNull(objectPropertyAsMap.get("null")); } + + @Test + void testParseToJson() { + final JsonElement result1 = converter.parseToJson(""); + assertTrue(result1.isJsonNull()); + + final JsonElement result2 = converter.parseToJson("testString"); + assertTrue(result2.isJsonPrimitive()); + + final JsonElement result3 = converter.parseToJson("1"); + assertTrue(result3.isJsonPrimitive()); + + final JsonElement result4 = converter.parseToJson("true"); + assertTrue(result4.isJsonPrimitive()); + + final JsonElement result5 = converter.parseToJson("{\"get_property\":[\"relatedParty_0\",\"name\"]}"); + assertTrue(result5.isJsonObject()); + + final JsonElement result6 = converter.parseToJson("[\"relatedParty_0\",\"name\"]"); + assertTrue(result6.isJsonArray()); + + } + + @Test + void testIsJsonElementAJsonPrimitive() { + + JsonElement emptyStringEle = new JsonPrimitive(""); + final Boolean result1 = converter.isJsonElementAJsonPrimitive(emptyStringEle); + assertTrue(result1); + + JsonElement stringEle = new JsonPrimitive("testString"); + final Boolean result2 = converter.isJsonElementAJsonPrimitive(stringEle); + assertTrue(result2); + + JsonElement toscaFunctionEle = new JsonPrimitive("{\"get_property\":[\"relatedParty_0\",\"name\"]}"); + final Boolean result3 = converter.isJsonElementAJsonPrimitive(toscaFunctionEle); + assertFalse(result3); + + JsonElement jsonObjectEle = new JsonObject(); + final Boolean result4 = converter.isJsonElementAJsonPrimitive(jsonObjectEle); + assertFalse(result4); + + JsonElement jsonArrayEle = new JsonArray(); + final Boolean result5 = converter.isJsonElementAJsonPrimitive(jsonArrayEle); + assertFalse(result5); + + JsonElement intEle = new JsonPrimitive(123); + final Boolean result6 = converter.isJsonElementAJsonPrimitive(intEle); + assertTrue(result6); + + JsonElement boolEle = new JsonPrimitive(true); + final Boolean result7 = converter.isJsonElementAJsonPrimitive(boolEle); + assertTrue(result7); + + JsonElement nullEle = new JsonNull(); + final Boolean result8 = converter.isJsonElementAJsonPrimitive(nullEle); + assertFalse(result8); + } } -- cgit 1.2.3-korg