aboutsummaryrefslogtreecommitdiffstats
path: root/common-be
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
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')
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java46
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java40
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaConcatFunction.java56
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunction.java32
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java151
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionParameter.java30
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionType.java45
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java34
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaStringParameter.java44
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/PropertySource.java6
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaGetFunctionType.java21
-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
14 files changed, 791 insertions, 86 deletions
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java
new file mode 100644
index 0000000000..84543e29f7
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/CustomYamlFunction.java
@@ -0,0 +1,46 @@
+/*
+ * -
+ * ============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 lombok.Setter;
+import org.yaml.snakeyaml.Yaml;
+
+@Setter
+public class CustomYamlFunction implements ToscaFunction, ToscaFunctionParameter {
+
+ private Object yamlValue;
+
+ @Override
+ public ToscaFunctionType getType() {
+ return ToscaFunctionType.YAML;
+ }
+
+ @Override
+ public String getValue() {
+ return new Yaml().dump(yamlValue);
+ }
+
+ @Override
+ public Object getJsonObjectValue() {
+ return yamlValue;
+ }
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java
index 845eee808a..f88514ac49 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/PropertyDataDefinition.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.datatypes.elements;
import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -56,11 +57,16 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
private Boolean immutable = Boolean.FALSE;
private Boolean mappedToComponentProperty = Boolean.TRUE;
/**
- * @deprecated use {@link #toscaGetFunction#functionType} instead
+ * @deprecated use {@link #toscaFunction} instead
*/
@Deprecated
private ToscaGetFunctionType toscaGetFunctionType;
+ /**
+ * @deprecated use {@link #toscaFunction} instead
+ */
+ @Deprecated
private ToscaGetFunctionDataDefinition toscaGetFunction;
+ private ToscaFunction toscaFunction;
private String inputPath;
private String status;
@@ -115,8 +121,9 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
this.setModel(propertyDataDefinition.getModel());
this.setPropertyId(propertyDataDefinition.getPropertyId());
- this.setToscaGetFunctionType(propertyDataDefinition.getToscaGetFunctionType());
this.setToscaGetFunction(propertyDataDefinition.getToscaGetFunction());
+ this.setToscaGetFunctionType(propertyDataDefinition.getToscaGetFunctionType());
+ this.setToscaFunction(propertyDataDefinition.getToscaFunction());
this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
if (isNotEmpty(propertyDataDefinition.annotations)) {
@@ -166,10 +173,14 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
}
public ToscaGetFunctionType getToscaGetFunctionType() {
- if (toscaGetFunction != null) {
- return toscaGetFunction.getFunctionType();
+ if (isToscaGetFunction()) {
+ if (toscaFunction != null) {
+ return ((ToscaGetFunctionDataDefinition) toscaFunction).getFunctionType();
+ }
+ return toscaGetFunctionType;
}
- return toscaGetFunctionType;
+
+ return null;
}
public Boolean isHidden() {
@@ -318,12 +329,23 @@ public class PropertyDataDefinition extends ToscaDataDefinition {
return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);
}
- public boolean isGetFunction() {
- return this.toscaGetFunctionType != null || this.toscaGetFunction != null;
+ @JsonIgnoreProperties
+ public boolean isToscaFunction() {
+ return this.toscaGetFunctionType != null || this.toscaFunction != null;
+ }
+
+
+ @JsonIgnoreProperties
+ public boolean isToscaGetFunction() {
+ return this.toscaGetFunctionType != null || (this.toscaFunction != null
+ && (this.toscaFunction.getType() == ToscaFunctionType.GET_ATTRIBUTE
+ || this.toscaFunction.getType() == ToscaFunctionType.GET_INPUT
+ || this.toscaFunction.getType() == ToscaFunctionType.GET_PROPERTY));
}
- public boolean hasGetFunction() {
- return this.toscaGetFunction != null;
+ @JsonIgnoreProperties
+ public boolean hasToscaFunction() {
+ return this.toscaFunction != null;
}
}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaConcatFunction.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaConcatFunction.java
new file mode 100644
index 0000000000..62307fb4be
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaConcatFunction.java
@@ -0,0 +1,56 @@
+/*
+ * -
+ * ============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 com.google.gson.Gson;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class ToscaConcatFunction implements ToscaFunction, ToscaFunctionParameter {
+
+ private List<ToscaFunctionParameter> parameters = new ArrayList<>();
+
+ @Override
+ public ToscaFunctionType getType() {
+ return ToscaFunctionType.CONCAT;
+ }
+
+ @Override
+ public String getValue() {
+ return new Gson().toJson(getJsonObjectValue());
+ }
+
+ @Override
+ public Object getJsonObjectValue() {
+ return Map.of(
+ ToscaFunctionType.CONCAT.getName(),
+ parameters.stream().map(ToscaFunctionParameter::getJsonObjectValue).collect(Collectors.toList())
+ );
+ }
+
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunction.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunction.java
new file mode 100644
index 0000000000..40664a133c
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunction.java
@@ -0,0 +1,32 @@
+/*
+ * -
+ * ============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 com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+
+@JsonDeserialize(using = ToscaFunctionJsonDeserializer.class)
+public interface ToscaFunction {
+
+ ToscaFunctionType getType();
+ String getValue();
+
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java
new file mode 100644
index 0000000000..74aed12471
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionJsonDeserializer.java
@@ -0,0 +1,151 @@
+/*
+ * -
+ * ============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 com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.sdc.be.datatypes.enums.PropertySource;
+import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
+import org.yaml.snakeyaml.Yaml;
+
+public class ToscaFunctionJsonDeserializer extends StdDeserializer<ToscaFunction> {
+
+ public ToscaFunctionJsonDeserializer() {
+ this(null);
+ }
+
+ public ToscaFunctionJsonDeserializer(Class<?> vc) {
+ super(vc);
+ }
+
+ @Override
+ public ToscaFunction deserialize(final JsonParser jsonParser, final DeserializationContext context) throws IOException {
+ final JsonNode node = jsonParser.getCodec().readTree(jsonParser);
+ return deserializeToscaFunction(node, context);
+ }
+
+ private ToscaFunction deserializeToscaFunction(final JsonNode node, final DeserializationContext context) throws IOException {
+ final String functionType;
+ if (node.get("type") != null) {
+ functionType = node.get("type").asText();
+ } else if (node.get("functionType") != null) {
+ //support for legacy tosca function
+ functionType = node.get("functionType").asText();
+ } else {
+ throw context.instantiationException(ToscaFunction.class, "Attribute type not provided");
+ }
+ final ToscaFunctionType toscaFunctionType = ToscaFunctionType.findType(functionType)
+ .orElseThrow(() -> context.instantiationException(ToscaFunction.class,
+ String.format("Invalid function type '%s' or attribute type not provided", functionType))
+ );
+ if (toscaFunctionType == ToscaFunctionType.GET_INPUT || toscaFunctionType == ToscaFunctionType.GET_ATTRIBUTE
+ || toscaFunctionType == ToscaFunctionType.GET_PROPERTY) {
+ return deserializeToscaGetFunction(toscaFunctionType, node, context);
+ }
+
+ if (toscaFunctionType == ToscaFunctionType.CONCAT) {
+ return this.deserializeConcatFunction(node, context);
+ }
+
+ if (toscaFunctionType == ToscaFunctionType.YAML) {
+ return this.deserializeYamlFunction(node);
+ }
+
+ return null;
+ }
+
+ private ToscaFunction deserializeYamlFunction(JsonNode node) {
+ var yamlFunction = new CustomYamlFunction();
+ final Object value = new Yaml().load(node.get("value").asText());
+ yamlFunction.setYamlValue(value);
+ return yamlFunction;
+ }
+
+ private ToscaGetFunctionDataDefinition deserializeToscaGetFunction(final ToscaFunctionType toscaFunctionType, final JsonNode node,
+ final DeserializationContext context) throws JsonMappingException {
+ final ToscaGetFunctionDataDefinition toscaGetFunction = new ToscaGetFunctionDataDefinition();
+ toscaGetFunction.setFunctionType(ToscaGetFunctionType.fromToscaFunctionType(toscaFunctionType).orElse(null));
+ toscaGetFunction.setSourceName(node.get("sourceName").asText());
+ toscaGetFunction.setPropertyUniqueId(node.get("propertyUniqueId").asText());
+ final String propertySource = node.get("propertySource").asText();
+ if (StringUtils.isNotEmpty(propertySource)) {
+ final PropertySource propertySource1 = PropertySource.findType(propertySource).orElseThrow(() ->
+ context.instantiationException(ToscaGetFunctionDataDefinition.class,
+ String.format("Invalid propertySource '%s'", propertySource))
+ );
+ toscaGetFunction.setPropertySource(propertySource1);
+ }
+ toscaGetFunction.setPropertyName(node.get("propertyName").asText());
+ toscaGetFunction.setSourceName(node.get("sourceName").asText());
+ toscaGetFunction.setSourceUniqueId(node.get("sourceUniqueId").asText());
+ final JsonNode propertyPathFromSourceNode = node.get("propertyPathFromSource");
+ if (propertyPathFromSourceNode != null) {
+ if (!propertyPathFromSourceNode.isArray()) {
+ throw context.instantiationException(ToscaGetFunctionDataDefinition.class, "Expecting an array for propertyPathFromSource attribute");
+ }
+ final List<String> pathFromSource = new ArrayList<>();
+ propertyPathFromSourceNode.forEach(jsonNode -> pathFromSource.add(jsonNode.asText()));
+ toscaGetFunction.setPropertyPathFromSource(pathFromSource);
+ }
+
+ return toscaGetFunction;
+ }
+
+ private ToscaConcatFunction deserializeConcatFunction(final JsonNode concatFunctionJsonNode,
+ final DeserializationContext context) throws IOException {
+ final var toscaConcatFunction = new ToscaConcatFunction();
+ final List<ToscaFunctionParameter> functionParameterList = new ArrayList<>();
+ final JsonNode parametersNode = concatFunctionJsonNode.get("parameters");
+ if (!parametersNode.isArray()) {
+ throw context.instantiationException(List.class, "");
+ }
+ for (final JsonNode parameterNode : parametersNode) {
+ final JsonNode typeJsonNode = parameterNode.get("type");
+ if (typeJsonNode == null) {
+ throw context.instantiationException(ToscaConcatFunction.class, "TOSCA concat function parameter type attribute not provided");
+ }
+ final String parameterType = typeJsonNode.asText();
+ final ToscaFunctionType toscaFunctionType = ToscaFunctionType.findType(parameterType)
+ .orElseThrow(() -> context.instantiationException(ToscaConcatFunction.class,
+ String.format("Invalid TOSCA concat function parameter type '%s'", parameterType))
+ );
+ if (toscaFunctionType == ToscaFunctionType.STRING) {
+ final ToscaStringParameter toscaStringParameter = new ToscaStringParameter();
+ toscaStringParameter.setValue(parameterNode.get("value").asText());
+ functionParameterList.add(toscaStringParameter);
+ } else {
+ final ToscaFunction toscaFunction = this.deserializeToscaFunction(parameterNode, context);
+ functionParameterList.add((ToscaFunctionParameter) toscaFunction);
+ }
+ }
+ toscaConcatFunction.setParameters(functionParameterList);
+ return toscaConcatFunction;
+ }
+
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionParameter.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionParameter.java
new file mode 100644
index 0000000000..4d4c7b0a68
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionParameter.java
@@ -0,0 +1,30 @@
+/*
+ * -
+ * ============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;
+
+public interface ToscaFunctionParameter {
+
+ String getValue();
+ ToscaFunctionType getType();
+ Object getJsonObjectValue();
+
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionType.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionType.java
new file mode 100644
index 0000000000..4579ac2410
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaFunctionType.java
@@ -0,0 +1,45 @@
+/*
+ * -
+ * ============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 java.util.Arrays;
+import java.util.Optional;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@AllArgsConstructor
+@Getter
+public enum ToscaFunctionType {
+
+ GET_INPUT("get_input"),
+ GET_PROPERTY("get_property"),
+ GET_ATTRIBUTE("get_attribute"),
+ CONCAT("concat"),
+ YAML("yaml"),
+ STRING("string");
+
+ private final String name;
+
+ public static Optional<ToscaFunctionType> findType(final String functionType) {
+ return Arrays.stream(values()).filter(toscaFunctionType -> toscaFunctionType.getName().equalsIgnoreCase(functionType)).findFirst();
+ }
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java
index 0741d6849e..f19217e69c 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaGetFunctionDataDefinition.java
@@ -33,7 +33,7 @@ import org.openecomp.sdc.be.datatypes.enums.PropertySource;
import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
@Data
-public class ToscaGetFunctionDataDefinition {
+public class ToscaGetFunctionDataDefinition implements ToscaFunction, ToscaFunctionParameter {
private String propertyUniqueId;
private String propertyName;
@@ -55,6 +55,11 @@ public class ToscaGetFunctionDataDefinition {
* Builds the value of a property based on the TOSCA get function information.
*/
public String generatePropertyValue() {
+ return new Gson().toJson(getJsonObjectValue());
+ }
+
+ @Override
+ public Object getJsonObjectValue() {
if (functionType == null) {
throw new IllegalStateException("functionType is required in order to generate the get function value");
}
@@ -62,12 +67,11 @@ public class ToscaGetFunctionDataDefinition {
throw new IllegalStateException("propertyPathFromSource is required in order to generate the get function value");
}
- final var gson = new Gson();
if (functionType == ToscaGetFunctionType.GET_PROPERTY || functionType == ToscaGetFunctionType.GET_ATTRIBUTE) {
- return gson.toJson(buildFunctionValueWithPropertySource());
+ return buildFunctionValueWithPropertySource();
}
if (functionType == ToscaGetFunctionType.GET_INPUT) {
- return gson.toJson(buildGetInputFunctionValue());
+ return buildGetInputFunctionValue();
}
throw new UnsupportedOperationException(String.format("ToscaGetFunctionType '%s' is not supported yet", functionType));
@@ -105,4 +109,26 @@ public class ToscaGetFunctionDataDefinition {
return Map.of(this.functionType.getFunctionName(), this.propertyPathFromSource);
}
+ @Override
+ public ToscaFunctionType getType() {
+ if (functionType == null) {
+ return null;
+ }
+ switch (functionType) {
+ case GET_INPUT:
+ return ToscaFunctionType.GET_INPUT;
+ case GET_PROPERTY:
+ return ToscaFunctionType.GET_PROPERTY;
+ case GET_ATTRIBUTE:
+ return ToscaFunctionType.GET_ATTRIBUTE;
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public String getValue() {
+ return this.generatePropertyValue();
+ }
+
}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaStringParameter.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaStringParameter.java
new file mode 100644
index 0000000000..d6d5d9f8ad
--- /dev/null
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/elements/ToscaStringParameter.java
@@ -0,0 +1,44 @@
+/*
+ * -
+ * ============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 lombok.Setter;
+
+@Setter
+public class ToscaStringParameter implements ToscaFunctionParameter {
+ private String value;
+
+ @Override
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public ToscaFunctionType getType() {
+ return ToscaFunctionType.STRING;
+ }
+
+ @Override
+ public Object getJsonObjectValue() {
+ return getValue();
+ }
+}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/PropertySource.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/PropertySource.java
index 8086d22815..d2e15039d3 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/PropertySource.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/PropertySource.java
@@ -21,6 +21,8 @@
package org.openecomp.sdc.be.datatypes.enums;
+import java.util.Arrays;
+import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -31,4 +33,8 @@ public enum PropertySource {
private final String name;
+ public static Optional<PropertySource> findType(final String propertySource) {
+ return Arrays.stream(values()).filter(propertySource1 -> propertySource1.getName().equalsIgnoreCase(propertySource)).findFirst();
+ }
+
}
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaGetFunctionType.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaGetFunctionType.java
index bb85ceb0fc..d84c86a38d 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaGetFunctionType.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/tosca/ToscaGetFunctionType.java
@@ -19,8 +19,10 @@
package org.openecomp.sdc.be.datatypes.tosca;
+import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.Getter;
+import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
@AllArgsConstructor
@Getter
@@ -31,4 +33,23 @@ public enum ToscaGetFunctionType {
private final String functionName;
private final String propertyType;
+
+ /**
+ * Converts a {@link ToscaFunctionType} to a {@link ToscaGetFunctionType}
+ * @param toscaFunctionType the tosca function type to convert
+ * @return the respective {@link ToscaGetFunctionType}
+ */
+ public static Optional<ToscaGetFunctionType> fromToscaFunctionType(final ToscaFunctionType toscaFunctionType) {
+ switch (toscaFunctionType) {
+ case GET_INPUT:
+ return Optional.of(GET_INPUT);
+ case GET_PROPERTY:
+ return Optional.of(GET_PROPERTY);
+ case GET_ATTRIBUTE:
+ return Optional.of(GET_ATTRIBUTE);
+ default:
+ return Optional.empty();
+ }
+ }
+
}
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) {