summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test/java/org
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-02-09 19:00:35 +0000
committerMichael Morris <michael.morris@est.tech>2022-03-11 15:25:28 +0000
commitf13f58eb867c763e6ed1c3b674fd99b1081a0664 (patch)
treec0ccc70b8fdf4362bce26efa0a5bb1c435f98575 /catalog-model/src/test/java/org
parent767b122ea026099e17a2ffde30e6718d2abf150f (diff)
Support complex types in interface operation inputs
Issue-ID: SDC-3897 Change-Id: Ieac2d74ad340de1d9f6e4cd3ac830e2ec8c35d5b Signed-off-by: andre.schmid <andre.schmid@est.tech> Signed-off-by: vasraz <vasyl.razinkov@est.tech> Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'catalog-model/src/test/java/org')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java87
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/ToscaValueBaseConverterTest.java95
2 files changed, 131 insertions, 51 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java
index cf2172d2b0..5d933ea3f6 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/tosca/converters/DataTypePropertyConverterTest.java
@@ -20,31 +20,36 @@
package org.openecomp.sdc.be.model.tosca.converters;
-import com.google.gson.JsonObject;
-import org.junit.Before;
-import org.junit.Test;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
-import org.openecomp.sdc.be.model.PropertyDefinition;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import com.google.gson.JsonObject;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyDefinition;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-public class DataTypePropertyConverterTest {
+class DataTypePropertyConverterTest {
- private static final String EMPTY_JSON_STR = "{}";
- public static final String PROPERTY2_DEFAULT = "{\"prop1\":\"def1\",\"prop3\":\"def3\"}";
- private DataTypePropertyConverter testInstance = DataTypePropertyConverter.getInstance();
- private Map<String, DataTypeDefinition> dataTypes;
- private DataTypeDefinition noDefaultValue, dataType1, dataType2, dataType3;
- private PropertyDefinition prop1, prop2, prop3, noDefaultProp;
+ private static final DataTypePropertyConverter dataTypePropertyConverter = DataTypePropertyConverter.getInstance();
+ private static final String PROPERTY2_DEFAULT = "{\"prop1\":\"def1\",\"prop3\":\"def3\"}";
- @Before
- public void setUp() throws Exception {
+ private Map<String, DataTypeDefinition> dataTypes;
+ private DataTypeDefinition noDefaultValue;
+ private DataTypeDefinition dataType2;
+ private DataTypeDefinition dataType3;
+ private PropertyDefinition prop1;
+ private PropertyDefinition prop2;
+ private PropertyDefinition prop3;
+ private PropertyDefinition noDefaultProp;
+
+ @BeforeEach
+ void setUp() {
dataTypes = new HashMap<>();
prop1 = new PropertyDefinition();
@@ -65,7 +70,7 @@ public class DataTypePropertyConverterTest {
noDefaultValue = new DataTypeDefinition();
noDefaultValue.setProperties(Collections.singletonList(noDefaultProp));
- dataType1 = new DataTypeDefinition();
+ DataTypeDefinition dataType1 = new DataTypeDefinition();
dataType1.setProperties(Arrays.asList(prop1, prop3));
dataType2 = new DataTypeDefinition();
@@ -82,51 +87,51 @@ public class DataTypePropertyConverterTest {
}
@Test
- public void testGetPropertyDefaultValuesRec_dataTypeNotExist() throws Exception {
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("someType", dataTypes);
+ void testGetPropertyDefaultValuesRec_dataTypeNotExist() {
+ String defaultValue = dataTypePropertyConverter.getDataTypePropertiesDefaultValuesRec("someType", dataTypes);
assertNull(defaultValue);
}
@Test
- public void testGetPropertyDefaultValuesRec_NoDefaultValue() throws Exception {
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("noDefault", dataTypes);
+ void testGetPropertyDefaultValuesRec_NoDefaultValue() {
+ String defaultValue = dataTypePropertyConverter.getDataTypePropertiesDefaultValuesRec("noDefault", dataTypes);
assertNull(defaultValue);
}
@Test
- public void testGetPropertyDefaultValuesRec() throws Exception {
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType1", dataTypes);
+ void testGetPropertyDefaultValuesRec() {
+ String defaultValue = dataTypePropertyConverter.getDataTypePropertiesDefaultValuesRec("dataType1", dataTypes);
assertEquals(PROPERTY2_DEFAULT, defaultValue);
}
@Test
- public void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType_derivedDataTypeHasNoDefaults() throws Exception {
+ void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType_derivedDataTypeHasNoDefaults() {
dataType2.setDerivedFrom(noDefaultValue);
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes);
+ String defaultValue = dataTypePropertyConverter.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes);
assertNull(defaultValue);
}
@Test
- public void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType() throws Exception {
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes);
+ void testGetPropertyDefaultValuesRec_defaultFromDerivedDataType() {
+ String defaultValue = dataTypePropertyConverter.getDataTypePropertiesDefaultValuesRec("dataType2", dataTypes);
assertEquals(PROPERTY2_DEFAULT, defaultValue);
}
@Test
- public void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties_dataTypeOfPropertyHasNoDefault() throws Exception {
+ void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties_dataTypeOfPropertyHasNoDefault() {
dataType3.getProperties().get(0).setType(noDefaultValue.getName());
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes);
+ String defaultValue = dataTypePropertyConverter.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes);
assertNull(defaultValue);
}
@Test
- public void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties() throws Exception {
- String defaultValue = testInstance.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes);
+ void testGetPropertyDefaultValuesRec_defaultFromDataTypesOfProperties() {
+ String defaultValue = dataTypePropertyConverter.getDataTypePropertiesDefaultValuesRec("dataType3", dataTypes);
assertEquals("{\"prop2\":" + PROPERTY2_DEFAULT + "}", defaultValue);//data type 3 has property prop2 which has a data type with property prop1 which has a default value
}
@Test
- public void testMergeDefaultValues_allDefaultValuesAreOverridden() throws Exception {
+ void testMergeDefaultValues_allDefaultValuesAreOverridden() {
JsonObject value = new JsonObject();
value.addProperty(noDefaultProp.getName(), "override1");
@@ -144,12 +149,12 @@ public class DataTypePropertyConverterTest {
String valBeforeMerge = value.toString();
- testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
+ dataTypePropertyConverter.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
assertEquals(valBeforeMerge, value.toString());
}
@Test
- public void testMergeDefaultValues() throws Exception {
+ void testMergeDefaultValues() {
JsonObject value = new JsonObject();
value.addProperty(noDefaultProp.getName(), "override1");
@@ -158,23 +163,23 @@ public class DataTypePropertyConverterTest {
value.add(prop2.getName(), prop1Val);
- testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
+ dataTypePropertyConverter.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
assertEquals("{\"noDefaultProp\":\"override1\",\"prop2\":{\"prop1\":\"prop1Override\",\"prop3\":\"def3\"}}",
value.toString());//expect to merge prop 3 default as it was not overridden
}
@Test
- public void testMergeDefaultValues_mergeAll() throws Exception {
+ void testMergeDefaultValues_mergeAll() {
JsonObject value = new JsonObject();
- testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
+ dataTypePropertyConverter.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
assertEquals("{\"prop2\":" + PROPERTY2_DEFAULT + "}",
value.toString());//expect to merge prop 3 default as it was not overridden
}
@Test
- public void testMergeDefaultValues_doNotAddDefaultsForGetInputValues() throws Exception {
+ void testMergeDefaultValues_doNotAddDefaultsForGetInputValues() {
JsonObject getInputValue = new JsonObject();
getInputValue.addProperty("get_input", "in1");
@@ -182,13 +187,13 @@ public class DataTypePropertyConverterTest {
JsonObject value = new JsonObject();
value.add(prop2.getName(), getInputValue);
- testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
+ dataTypePropertyConverter.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
assertEquals("{\"prop2\":{\"get_input\":\"in1\"}}", value.toString());
}
@Test
- public void testMergeDefaultValues_doNotAddDefaultsForGetInputInnerValues() throws Exception {
+ void testMergeDefaultValues_doNotAddDefaultsForGetInputInnerValues() {
JsonObject getInputValue = new JsonObject();
getInputValue.addProperty("get_input", "in1");
@@ -198,7 +203,7 @@ public class DataTypePropertyConverterTest {
JsonObject value = new JsonObject();
value.add(prop2.getName(), prop1Val);
- testInstance.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
+ dataTypePropertyConverter.mergeDataTypeDefaultValuesWithPropertyValue(value, "dataType3", dataTypes);
assertEquals("{\"prop2\":{\"prop1\":{\"get_input\":\"in1\"},\"prop3\":\"def3\"}}", value.toString());
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 0923f8e49f..179d3cf7a1 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
@@ -20,41 +20,46 @@
package org.openecomp.sdc.be.model.tosca.converters;
-import com.google.gson.JsonPrimitive;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.jupiter.api.Test;
-
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonPrimitive;
import java.util.HashMap;
import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
-public class ToscaValueBaseConverterTest {
+class ToscaValueBaseConverterTest {
- private ToscaValueBaseConverter converter = new ToscaValueBaseConverter();
+ private final ToscaValueBaseConverter converter = new ToscaValueBaseConverter();
@Test
- public void testJson2JavaPrimitive() throws Exception {
+ void testJson2JavaPrimitive() {
JsonPrimitive prim1 = new JsonPrimitive(Boolean.FALSE);
Object res1 = converter.json2JavaPrimitive(prim1);
assertFalse((Boolean)res1);
JsonPrimitive prim2 = new JsonPrimitive("Test");
Object res2 = converter.json2JavaPrimitive(prim2);
- assertTrue(res2.equals("Test"));
+ assertEquals("Test", res2);
JsonPrimitive prim3 = new JsonPrimitive(3);
Object res3 = converter.json2JavaPrimitive(prim3);
- assertTrue((Integer)res3 == 3);
+ assertEquals(3, (int) (Integer) res3);
JsonPrimitive prim4 = new JsonPrimitive(3.6);
Object res4 = converter.json2JavaPrimitive(prim4);
- assertTrue((Double)res4 == 3.6);
+ assertEquals(3.6, (Double) res4);
}
@Test
- public void testIsEmptyObjectValue() throws Exception {
+ void testIsEmptyObjectValue() {
boolean res1 = ToscaValueBaseConverter.isEmptyObjectValue(null);
assertTrue(res1);
@@ -70,4 +75,74 @@ public class ToscaValueBaseConverterTest {
boolean res5 = ToscaValueBaseConverter.isEmptyObjectValue("test");
assertFalse(res5);
}
+
+ @Test
+ void testHandleComplexJsonValue() {
+ JsonObject innerObject = new JsonObject();
+ innerObject.addProperty("string", "stringValue");
+ innerObject.addProperty("int", 1);
+ innerObject.addProperty("float", 1.1);
+ innerObject.add("null", null);
+
+ JsonArray jsonArray1 = new JsonArray();
+ jsonArray1.add(innerObject);
+ jsonArray1.add(innerObject);
+ jsonArray1.add(innerObject);
+
+ JsonArray jsonArray2 = new JsonArray();
+ jsonArray2.add("value0");
+ jsonArray2.add("value1");
+ jsonArray2.add("value2");
+
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.add("objectProperty", innerObject);
+ jsonObject.add("arrayProperty1", jsonArray1);
+ jsonObject.add("arrayProperty2", jsonArray2);
+ jsonObject.addProperty("stringProperty", "stringPropertyValue");
+
+ final Object resultingObject = converter.handleComplexJsonValue(jsonObject);
+ assertTrue(resultingObject instanceof Map);
+ final Map<String, Object> jsonObjectAsMap = (Map<String, Object>) resultingObject;
+ assertEquals(4, jsonObjectAsMap.keySet().size());
+ assertTrue(jsonObjectAsMap.containsKey("objectProperty"));
+ assertTrue(jsonObjectAsMap.containsKey("arrayProperty1"));
+ assertTrue(jsonObjectAsMap.containsKey("arrayProperty2"));
+ assertTrue(jsonObjectAsMap.containsKey("stringProperty"));
+
+ final String stringProperty = (String) jsonObjectAsMap.get("stringProperty");
+ assertEquals(jsonObject.get("stringProperty").getAsString(), stringProperty);
+
+ final Object arrayProperty1 = jsonObjectAsMap.get("arrayProperty1");
+ assertTrue(arrayProperty1 instanceof List);
+ final List<Object> arrayProperty1AsList = (List<Object>) arrayProperty1;
+ assertEquals(3, arrayProperty1AsList.size());
+ for (int i = 0; i < arrayProperty1AsList.size(); i++) {
+ final Object actualElement = arrayProperty1AsList.get(i);
+ assertTrue(actualElement instanceof Map);
+ final Map<String, Object> actualElementAsMap = (Map<String, Object>) actualElement;
+ final JsonObject expectedJsonObject = jsonArray1.get(i).getAsJsonObject();
+ assertEquals(expectedJsonObject.get("string").getAsString(), actualElementAsMap.get("string"));
+ assertEquals(expectedJsonObject.get("int").getAsInt(), actualElementAsMap.get("int"));
+ assertEquals(expectedJsonObject.get("float").getAsDouble(), actualElementAsMap.get("float"));
+ assertNull(actualElementAsMap.get("null"));
+ }
+
+ final Object arrayProperty2 = jsonObjectAsMap.get("arrayProperty2");
+ assertTrue(arrayProperty2 instanceof List);
+ final List<String> arrayProperty2AsList = (List<String>) arrayProperty2;
+ assertEquals(3, arrayProperty2AsList.size());
+ for (int i = 0; i < arrayProperty2AsList.size(); i++) {
+ assertEquals("value" + i, arrayProperty2AsList.get(i));
+ }
+
+ final Object objectProperty = jsonObjectAsMap.get("objectProperty");
+ assertTrue(objectProperty instanceof Map);
+ final Map<String, Object> objectPropertyAsMap = (Map<String, Object>) objectProperty;
+ assertEquals(4, objectPropertyAsMap.keySet().size());
+ assertTrue(objectPropertyAsMap.containsKey("string"));
+ assertEquals(innerObject.get("string").getAsString(), objectPropertyAsMap.get("string"));
+ assertEquals(innerObject.get("int").getAsInt(), objectPropertyAsMap.get("int"));
+ assertEquals(innerObject.get("float").getAsDouble(), objectPropertyAsMap.get("float"));
+ assertNull(objectPropertyAsMap.get("null"));
+ }
}