summaryrefslogtreecommitdiffstats
path: root/common-be/src/test
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-07-07 17:17:52 +0100
committerMichael Morris <michael.morris@est.tech>2022-07-18 14:22:12 +0000
commit68733163804ed2efed8223a04ab0a7a0714a8b33 (patch)
tree013f4d25042aa776120971a612a52d64db52f7a7 /common-be/src/test
parent4e4ec8e9c21acf7f9210aaebf8f13a60542737fc (diff)
Support for concat TOSCA function
Adds support for the concat TOSCA function in an instance property. Refactors the TOSCA function structure so it can be more generic to support other functions in the future. Change-Id: I338e4138d26afe21779da57c4eeb3f2d486c20a9 Issue-ID: SDC-4095 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'common-be/src/test')
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinitionTest.java203
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializerTest.java156
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java13
3 files changed, 299 insertions, 73 deletions
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinitionTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinitionTest.java
index 2e8b26fcb4..2d73faf41e 100644
--- a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinitionTest.java
+++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinitionTest.java
@@ -20,33 +20,32 @@
package org.openecomp.sdc.be.datatypes.elements;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
-
-import java.util.List;
-
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.MatcherAssert.assertThat;
+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 java.util.List;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
-public class PropertyDataDefinitionTest {
+class PropertyDataDefinitionTest {
private PropertyDataDefinition propDef;
- @Before
+ @BeforeEach
public void setUp() {
propDef = new PropertyDataDefinition();
}
@Test
- public void setStringField() {
+ void setStringField() {
final String name = "name";
assertNull(propDef.getName());
assertNull(propDef.getToscaPresentationValue(JsonPresentationFields.NAME));
@@ -56,7 +55,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void setDefaultValue() {
+ void setDefaultValue() {
final String defaultValue = "text";
assertNull(propDef.getDefaultValue());
assertNull(propDef.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
@@ -66,7 +65,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void setValueNotDefinedInPropDataDefinition() {
+ void setValueNotDefinedInPropDataDefinition() {
final String defaultValue = "VF";
assertNull(propDef.getToscaPresentationValue(JsonPresentationFields.COMPONENT_TYPE));
propDef.setToscaPresentationValue(JsonPresentationFields.COMPONENT_TYPE, defaultValue);
@@ -74,7 +73,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void setBooleanField() {
+ void setBooleanField() {
assertFalse((Boolean) propDef.getToscaPresentationValue(JsonPresentationFields.PASSWORD));
assertFalse(propDef.isPassword());
propDef.setToscaPresentationValue(JsonPresentationFields.PASSWORD, Boolean.TRUE);
@@ -83,7 +82,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void mergeDefaultValueWhenItWasNullBeforeMerge() {
+ void mergeDefaultValueWhenItWasNullBeforeMerge() {
final String defaultValue = "12345";
final String type = "1";
PropertyDataDefinition propForMerge = new PropertyDataDefinition();
@@ -99,7 +98,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void mergeDefaultValueAndOverrideIt() {
+ void mergeDefaultValueAndOverrideIt() {
final String defaultValue = "12345";
final String defaultValueForOther = "7890";
final String type = "1";
@@ -117,7 +116,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void mergeDefaultValueWhenOverridingIsNotAllowed() {
+ void mergeDefaultValueWhenOverridingIsNotAllowed() {
final String defaultValue = "12345";
final String defaultValueForOther = "7890";
final String type = "1";
@@ -139,7 +138,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void testConstructor() throws Exception {
+ void testConstructor() {
PropertyDataDefinition testSubject;
String result;
@@ -149,7 +148,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void testGetInputPath() throws Exception {
+ void testGetInputPath() {
PropertyDataDefinition testSubject;
String result;
@@ -160,7 +159,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetInputPath() throws Exception {
+ void testSetInputPath() {
PropertyDataDefinition testSubject;
String inputPath = "";
@@ -171,7 +170,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetName() throws Exception {
+ void testGetName() {
PropertyDataDefinition testSubject;
String result;
@@ -182,7 +181,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetName() throws Exception {
+ void testSetName() {
PropertyDataDefinition testSubject;
String name = "";
@@ -193,7 +192,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetValue() throws Exception {
+ void testGetValue() {
PropertyDataDefinition testSubject;
String result;
@@ -204,7 +203,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetValue() throws Exception {
+ void testSetValue() {
PropertyDataDefinition testSubject;
String value = "";
@@ -215,7 +214,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testIsDefinition() throws Exception {
+ void testIsDefinition() {
PropertyDataDefinition testSubject;
boolean result;
@@ -226,7 +225,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetDefinition() throws Exception {
+ void testSetDefinition() {
PropertyDataDefinition testSubject;
boolean definition = false;
@@ -237,7 +236,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetType() throws Exception {
+ void testGetType() {
PropertyDataDefinition testSubject;
String result;
@@ -248,7 +247,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetDefaultValue() throws Exception {
+ void testGetDefaultValue() {
PropertyDataDefinition testSubject;
String result;
@@ -259,7 +258,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetDefaultValue() throws Exception {
+ void testSetDefaultValue() {
PropertyDataDefinition testSubject;
String defaultValue = "";
@@ -270,7 +269,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetType() throws Exception {
+ void testSetType() {
PropertyDataDefinition testSubject;
String type = "";
@@ -281,7 +280,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testIsRequired() throws Exception {
+ void testIsRequired() {
PropertyDataDefinition testSubject;
Boolean result;
@@ -292,7 +291,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetRequired() throws Exception {
+ void testSetRequired() {
PropertyDataDefinition testSubject;
Boolean required = null;
@@ -303,7 +302,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetDescription() throws Exception {
+ void testGetDescription() {
PropertyDataDefinition testSubject;
String result;
@@ -314,7 +313,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetDescription() throws Exception {
+ void testSetDescription() {
PropertyDataDefinition testSubject;
String description = "";
@@ -325,7 +324,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testIsPassword() throws Exception {
+ void testIsPassword() {
PropertyDataDefinition testSubject;
boolean result;
@@ -336,7 +335,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetPassword() throws Exception {
+ void testSetPassword() {
PropertyDataDefinition testSubject;
boolean password = false;
@@ -347,7 +346,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetUniqueId() throws Exception {
+ void testGetUniqueId() {
PropertyDataDefinition testSubject;
String result;
@@ -358,7 +357,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetUniqueId() throws Exception {
+ void testSetUniqueId() {
PropertyDataDefinition testSubject;
String uniqueId = "";
@@ -369,7 +368,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetSchema() throws Exception {
+ void testGetSchema() {
PropertyDataDefinition testSubject;
SchemaDefinition result;
@@ -380,7 +379,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetSchema() throws Exception {
+ void testSetSchema() {
PropertyDataDefinition testSubject;
SchemaDefinition entrySchema = null;
@@ -391,7 +390,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetLabel() throws Exception {
+ void testGetLabel() {
PropertyDataDefinition testSubject;
String result;
@@ -402,7 +401,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetLabel() throws Exception {
+ void testSetLabel() {
PropertyDataDefinition testSubject;
String label = "";
@@ -413,7 +412,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testIsHidden() throws Exception {
+ void testIsHidden() {
PropertyDataDefinition testSubject;
Boolean result;
@@ -424,7 +423,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetHidden() throws Exception {
+ void testSetHidden() {
PropertyDataDefinition testSubject;
Boolean hidden = null;
@@ -435,7 +434,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testIsImmutable() throws Exception {
+ void testIsImmutable() {
PropertyDataDefinition testSubject;
Boolean result;
@@ -446,7 +445,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetImmutable() throws Exception {
+ void testSetImmutable() {
PropertyDataDefinition testSubject;
Boolean immutable = null;
@@ -457,7 +456,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetParentUniqueId() throws Exception {
+ void testGetParentUniqueId() {
PropertyDataDefinition testSubject;
String result;
@@ -468,7 +467,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetParentUniqueId() throws Exception {
+ void testSetParentUniqueId() {
PropertyDataDefinition testSubject;
String parentUniqueId = "";
@@ -479,7 +478,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetGetInputValues() throws Exception {
+ void testGetGetInputValues() {
PropertyDataDefinition testSubject;
List<GetInputValueDataDefinition> result;
@@ -490,7 +489,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetGetInputValues() throws Exception {
+ void testSetGetInputValues() {
PropertyDataDefinition testSubject;
List<GetInputValueDataDefinition> getInputValues = null;
@@ -501,7 +500,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetStatus() throws Exception {
+ void testGetStatus() {
PropertyDataDefinition testSubject;
String result;
@@ -512,7 +511,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetStatus() throws Exception {
+ void testSetStatus() {
PropertyDataDefinition testSubject;
String status = "";
@@ -523,7 +522,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetInputId() throws Exception {
+ void testGetInputId() {
PropertyDataDefinition testSubject;
String result;
@@ -534,7 +533,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetInputId() throws Exception {
+ void testSetInputId() {
PropertyDataDefinition testSubject;
String inputId = "";
@@ -545,7 +544,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetInstanceUniqueId() throws Exception {
+ void testGetInstanceUniqueId() {
PropertyDataDefinition testSubject;
String result;
@@ -556,7 +555,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetInstanceUniqueId() throws Exception {
+ void testSetInstanceUniqueId() {
PropertyDataDefinition testSubject;
String instanceUniqueId = "";
@@ -567,7 +566,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testGetPropertyId() throws Exception {
+ void testGetPropertyId() {
PropertyDataDefinition testSubject;
String result;
@@ -578,7 +577,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testSetPropertyId() throws Exception {
+ void testSetPropertyId() {
PropertyDataDefinition testSubject;
String propertyId = "";
@@ -589,7 +588,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testToString() throws Exception {
+ void testToString() {
PropertyDataDefinition testSubject;
String result;
@@ -600,7 +599,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testHashCode() throws Exception {
+ void testHashCode() {
PropertyDataDefinition testSubject;
int result;
@@ -611,7 +610,7 @@ public class PropertyDataDefinitionTest {
@Test
- public void testEquals() throws Exception {
+ void testEquals() {
PropertyDataDefinition testSubject;
Object obj = null;
boolean result;
@@ -620,16 +619,16 @@ public class PropertyDataDefinitionTest {
testSubject = createTestSubject();
obj = null;
result = testSubject.equals(obj);
- Assert.assertEquals(false, result);
+ assertEquals(false, result);
result = testSubject.equals(testSubject);
- Assert.assertEquals(true, result);
+ assertEquals(true, result);
PropertyDataDefinition other = createTestSubject();
result = testSubject.equals(other);
- Assert.assertEquals(true, result);
+ assertEquals(true, result);
}
@Test
- public void testConvertPropertyDataToInstancePropertyData() throws Exception {
+ void testConvertPropertyDataToInstancePropertyData() {
PropertyDataDefinition testSubject;
// default test
@@ -638,7 +637,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void testTypeEquals() throws Exception {
+ void testTypeEquals() {
PropertyDataDefinition testSubject;
// default test
@@ -649,7 +648,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void testMergeFunction() throws Exception {
+ void testMergeFunction() {
PropertyDataDefinition testSubject;
// default test
@@ -659,7 +658,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void schemaTypeNullWhenSchemaIsNull() {
+ void schemaTypeNullWhenSchemaIsNull() {
String sampleSchemaType = "sampleSchemaType";
PropertyDataDefinition testSubject = createTestSubject();
testSubject.setSchemaType(sampleSchemaType);
@@ -667,7 +666,7 @@ public class PropertyDataDefinitionTest {
}
@Test
- public void schemaTypeIsReturnedWhenSchemaisPresent() {
+ void schemaTypeIsReturnedWhenSchemaIsPresent() {
String sampleSchemaType = "sampleSchemaType";
SchemaDefinition schemaDefinition = new SchemaDefinition();
schemaDefinition.setProperty(new PropertyDataDefinition());
@@ -678,4 +677,62 @@ public class PropertyDataDefinitionTest {
assertThat(testSubject.getSchemaType(), is(equalTo(sampleSchemaType)));
}
+
+ @Test
+ void getToscaGetFunctionTypeTest() {
+ var propertyDataDefinition = new PropertyDataDefinition();
+ assertNull(propertyDataDefinition.getToscaGetFunctionType());
+
+ final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
+ propertyDataDefinition.setToscaFunction(toscaGetFunction);
+
+ toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_INPUT);
+ assertEquals(ToscaGetFunctionType.GET_INPUT, propertyDataDefinition.getToscaGetFunctionType());
+
+ toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_PROPERTY);
+ assertEquals(ToscaGetFunctionType.GET_PROPERTY, propertyDataDefinition.getToscaGetFunctionType());
+
+ toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_ATTRIBUTE);
+ assertEquals(ToscaGetFunctionType.GET_ATTRIBUTE, propertyDataDefinition.getToscaGetFunctionType());
+
+ propertyDataDefinition = new PropertyDataDefinition();
+ propertyDataDefinition.setToscaGetFunctionType(ToscaGetFunctionType.GET_INPUT);
+ assertEquals(ToscaGetFunctionType.GET_INPUT, propertyDataDefinition.getToscaGetFunctionType());
+
+ propertyDataDefinition.setToscaGetFunctionType(ToscaGetFunctionType.GET_PROPERTY);
+ assertEquals(ToscaGetFunctionType.GET_PROPERTY, propertyDataDefinition.getToscaGetFunctionType());
+
+ propertyDataDefinition.setToscaGetFunctionType(ToscaGetFunctionType.GET_ATTRIBUTE);
+ assertEquals(ToscaGetFunctionType.GET_ATTRIBUTE, propertyDataDefinition.getToscaGetFunctionType());
+ }
+
+ @Test
+ void isToscaFunctionTest() {
+ var propertyDataDefinition = new PropertyDataDefinition();
+ assertFalse(propertyDataDefinition.isToscaFunction());
+
+ propertyDataDefinition.setToscaGetFunctionType(ToscaGetFunctionType.GET_PROPERTY);
+ assertTrue(propertyDataDefinition.isToscaFunction());
+
+ propertyDataDefinition = new PropertyDataDefinition();
+ propertyDataDefinition.setToscaFunction(new ToscaConcatFunction());
+ assertTrue(propertyDataDefinition.isToscaFunction());
+ }
+
+ @Test
+ void isToscaGetFunctionTest() {
+ var propertyDataDefinition = new PropertyDataDefinition();
+ propertyDataDefinition.setToscaGetFunctionType(ToscaGetFunctionType.GET_PROPERTY);
+ assertTrue(propertyDataDefinition.isToscaGetFunction());
+
+ propertyDataDefinition = new PropertyDataDefinition();
+ final ToscaGetFunctionDataDefinition toscaGetFunction = new ToscaGetFunctionDataDefinition();
+ toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_INPUT);
+ propertyDataDefinition.setToscaFunction(toscaGetFunction);
+ assertTrue(propertyDataDefinition.isToscaGetFunction());
+
+ propertyDataDefinition.setToscaFunction(new ToscaConcatFunction());
+ assertFalse(propertyDataDefinition.isToscaGetFunction());
+ }
+
}
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializerTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializerTest.java
new file mode 100644
index 0000000000..e11b661098
--- /dev/null
+++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializerTest.java
@@ -0,0 +1,156 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.datatypes.elements;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.exc.ValueInstantiationException;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.be.datatypes.enums.PropertySource;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
+
+class ToscaFunctionJsonDeserializerTest {
+
+ @Test
+ void testGetInputToscaFunction() throws JsonProcessingException {
+ final String toscaGetInputFunction = "{\n"
+ + " \"propertyUniqueId\": \"e57525d7-2115-4934-9ba4-9cebfa22bad2.nf_naming\",\n"
+ + " \"type\": \"GET_INPUT\",\n"
+ + " \"propertySource\": \"SELF\",\n"
+ + " \"propertyName\": \"instance_name\",\n"
+ + " \"sourceName\": \"ciResVFc26a0b30ec20\",\n"
+ + " \"sourceUniqueId\": \"aee643c9-6c8e-4a24-af7a-a9aff5c072c0\",\n"
+ + " \"propertyPathFromSource\": [\n"
+ + " \"nf_naming\",\n"
+ + " \"instance_name\"\n"
+ + " ]\n"
+ + " }";
+ ToscaFunction toscaFunction = parseToscaFunction(toscaGetInputFunction);
+ assertTrue(toscaFunction instanceof ToscaGetFunctionDataDefinition);
+ final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) toscaFunction;
+ assertEquals(ToscaFunctionType.GET_INPUT, toscaGetFunction.getType());
+ assertEquals(ToscaGetFunctionType.GET_INPUT, toscaGetFunction.getFunctionType());
+ assertEquals("e57525d7-2115-4934-9ba4-9cebfa22bad2.nf_naming", toscaGetFunction.getPropertyUniqueId());
+ assertEquals(PropertySource.SELF, toscaGetFunction.getPropertySource());
+ assertEquals("instance_name", toscaGetFunction.getPropertyName());
+ assertEquals("ciResVFc26a0b30ec20", toscaGetFunction.getSourceName());
+ assertEquals("aee643c9-6c8e-4a24-af7a-a9aff5c072c0", toscaGetFunction.getSourceUniqueId());
+ assertEquals(List.of("nf_naming", "instance_name"), toscaGetFunction.getPropertyPathFromSource());
+ }
+
+ @Test
+ void testGetInputToscaFunctionLegacyConversion() throws JsonProcessingException {
+ final String toscaGetInputFunction = "{\n"
+ + " \"propertyUniqueId\": \"e57525d7-2115-4934-9ba4-9cebfa22bad2.nf_naming\",\n"
+ + " \"functionType\": \"GET_INPUT\",\n"
+ + " \"propertySource\": \"SELF\",\n"
+ + " \"propertyName\": \"instance_name\",\n"
+ + " \"sourceName\": \"ciResVFc26a0b30ec20\",\n"
+ + " \"sourceUniqueId\": \"aee643c9-6c8e-4a24-af7a-a9aff5c072c0\",\n"
+ + " \"propertyPathFromSource\": [\n"
+ + " \"nf_naming\",\n"
+ + " \"instance_name\"\n"
+ + " ]\n"
+ + " }";
+ ToscaFunction toscaFunction = parseToscaFunction(toscaGetInputFunction);
+ assertTrue(toscaFunction instanceof ToscaGetFunctionDataDefinition);
+ final ToscaGetFunctionDataDefinition toscaGetFunction = (ToscaGetFunctionDataDefinition) toscaFunction;
+ assertEquals(ToscaFunctionType.GET_INPUT, toscaGetFunction.getType());
+ assertEquals(ToscaGetFunctionType.GET_INPUT, toscaGetFunction.getFunctionType());
+ }
+
+ @Test
+ void testNoFunctionTypeProvided() {
+ final String toscaGetInputFunction = "{\n"
+ + " \"propertyUniqueId\": \"e57525d7-2115-4934-9ba4-9cebfa22bad2.nf_naming\",\n"
+ + " \"propertySource\": \"SELF\",\n"
+ + " \"propertyName\": \"instance_name\",\n"
+ + " \"sourceName\": \"ciResVFc26a0b30ec20\",\n"
+ + " \"sourceUniqueId\": \"aee643c9-6c8e-4a24-af7a-a9aff5c072c0\",\n"
+ + " \"propertyPathFromSource\": [\n"
+ + " \"nf_naming\",\n"
+ + " \"instance_name\"\n"
+ + " ]\n"
+ + " }";
+ final ValueInstantiationException actualException =
+ assertThrows(ValueInstantiationException.class, () -> parseToscaFunction(toscaGetInputFunction));
+ assertTrue(actualException.getMessage().contains("Attribute type not provided"));
+ }
+
+ @Test
+ void testConcatToscaFunction() throws JsonProcessingException {
+ final String toscaGetInputFunction = "{\n"
+ + " \"type\": \"CONCAT\",\n"
+ + " \"parameters\": [\n"
+ + " {\n"
+ + " \"propertyUniqueId\": \"e57525d7-2115-4934-9ba4-9cebfa22bad2.nf_naming\",\n"
+ + " \"type\": \"GET_INPUT\",\n"
+ + " \"propertySource\": \"SELF\",\n"
+ + " \"propertyName\": \"instance_name\",\n"
+ + " \"sourceName\": \"ciResVFc26a0b30ec20\",\n"
+ + " \"sourceUniqueId\": \"aee643c9-6c8e-4a24-af7a-a9aff5c072c0\",\n"
+ + " \"propertyPathFromSource\": [\n"
+ + " \"nf_naming\",\n"
+ + " \"instance_name\"\n"
+ + " ]\n"
+ + " }, {\n"
+ + " \"type\": \"STRING\",\n"
+ + " \"value\": \"my string\"\n"
+ + " },\n"
+ + " {\n"
+ + " \"type\": \"CONCAT\",\n"
+ + " \"parameters\": [\n"
+ + " {\n"
+ + " \"type\": \"STRING\",\n"
+ + " \"value\": \"string1\"\n"
+ + " },\n"
+ + " {\n"
+ + " \"type\": \"STRING\",\n"
+ + " \"value\": \"string2\"\n"
+ + " }\n"
+ + " ]\n"
+ + " }\n"
+ + " ]\n"
+ + "}";
+ ToscaFunction toscaFunction = parseToscaFunction(toscaGetInputFunction);
+ assertTrue(toscaFunction instanceof ToscaConcatFunction);
+ }
+
+ @Test
+ void testYamlFunction() throws JsonProcessingException {
+ String yamlFunction = "{\n"
+ + " \"type\": \"YAML\",\n"
+ + " \"value\": \"tosca_definitions_version: tosca_simple_yaml_1_0_0\\nnode_types: \\n tosca.nodes.Compute:\\n derived_from: tosca.nodes.Root\\n attributes:\\n private_address:\\n type: string\\n public_address:\\n type: string\\n networks:\\n type: map\\n entry_schema:\\n type: tosca.datatypes.network.NetworkInfo\\n ports:\\n type: map\\n entry_schema:\\n type: tosca.datatypes.network.PortInfo\\n requirements:\\n - local_storage: \\n capability: tosca.capabilities.Attachment\\n node: tosca.nodes.BlockStorage\\n relationship: tosca.relationships.AttachesTo\\n occurrences: [0, UNBOUNDED] \\n capabilities:\\n host: \\n type: tosca.capabilities.Container\\n valid_source_types: [tosca.nodes.SoftwareComponent] \\n endpoint :\\n type: tosca.capabilities.Endpoint.Admin \\n os: \\n type: tosca.capabilities.OperatingSystem\\n scalable:\\n type: tosca.capabilities.Scalable\\n binding:\\n type: tosca.capabilities.network.Bindable\\n\"\n"
+ + "}";
+ ToscaFunction toscaFunction = parseToscaFunction(yamlFunction);
+ assertTrue(toscaFunction instanceof CustomYamlFunction);
+ }
+
+ private ToscaFunction parseToscaFunction(final String toscaFunctionJson) throws JsonProcessingException {
+ return new ObjectMapper().readValue(toscaFunctionJson, ToscaFunction.class);
+ }
+} \ No newline at end of file
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java
index a199f5ec97..5daeaa5aad 100644
--- a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java
+++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinitionTest.java
@@ -23,6 +23,7 @@ package org.openecomp.sdc.be.datatypes.elements;
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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -185,6 +186,18 @@ class ToscaGetFunctionDataDefinitionTest {
assertEquals("sourceName is required in order to generate the get_property from INSTANCE value", actualException.getMessage());
}
+ @Test
+ void getTypeTest() {
+ final ToscaGetFunctionDataDefinition toscaGetFunctionDataDefinition = new ToscaGetFunctionDataDefinition();
+ assertNull(toscaGetFunctionDataDefinition.getType());
+ toscaGetFunctionDataDefinition.setFunctionType(ToscaGetFunctionType.GET_INPUT);
+ assertEquals(ToscaFunctionType.GET_INPUT, toscaGetFunctionDataDefinition.getType());
+ toscaGetFunctionDataDefinition.setFunctionType(ToscaGetFunctionType.GET_ATTRIBUTE);
+ assertEquals(ToscaFunctionType.GET_ATTRIBUTE, toscaGetFunctionDataDefinition.getType());
+ toscaGetFunctionDataDefinition.setFunctionType(ToscaGetFunctionType.GET_PROPERTY);
+ assertEquals(ToscaFunctionType.GET_PROPERTY, toscaGetFunctionDataDefinition.getType());
+ }
+
private ToscaGetFunctionDataDefinition createGetFunction(final ToscaGetFunctionType toscaGetFunctionType,
final PropertySource propertySource,
final List<String> propertyPath, String sourceName) {