aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-05-29 18:42:58 +0000
committerGerrit Code Review <gerrit@onap.org>2019-05-29 18:42:58 +0000
commit2bb065a5f965087c58828a5a8b690838d63da65c (patch)
treee1bb9df278858bee112d72371b3917bba4fb7845 /ms/blueprintsprocessor/functions/resource-resolution
parent31d2c64ad5be592ded39e5cd19c364e13ebe2345 (diff)
parentbef9ae59c3911a39f0e94f4dd44f128fe8b73706 (diff)
Merge "Returning null for unresolved variables" into dublin
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt12
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt79
2 files changed, 90 insertions, 1 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
index 656e86169..1a943d110 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
@@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.NullNode
import com.fasterxml.jackson.databind.node.ObjectNode
+import com.fasterxml.jackson.databind.node.TextNode
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
import org.onap.ccsdk.cds.controllerblueprints.core.*
@@ -122,7 +123,7 @@ class ResourceAssignmentUtils {
if (isNotEmpty(it.name) && it.property != null) {
val rName = it.name
val type = nullToEmpty(it.property?.type).toLowerCase()
- val value = it.property?.value
+ val value = useDefaultValueIfNull(it, rName)
logger.info("Generating Resource name ($rName), type ($type), value ($value)")
root.set(rName, value)
}
@@ -136,6 +137,15 @@ class ResourceAssignmentUtils {
return result
}
+ private fun useDefaultValueIfNull(resourceAssignment: ResourceAssignment, resourceAssignmentName: String): JsonNode {
+ if (resourceAssignment.property?.value == null) {
+ val defaultValue = "\${$resourceAssignmentName}"
+ return TextNode(defaultValue)
+ } else {
+ return resourceAssignment.property!!.value!!
+ }
+ }
+
fun transformToRARuntimeService(blueprintRuntimeService: BluePrintRuntimeService<*>,
templateArtifactName: String): ResourceAssignmentRuntimeService {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt
new file mode 100644
index 000000000..9b87c12eb
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils
+
+import com.fasterxml.jackson.databind.node.TextNode
+import org.junit.Test
+import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import kotlin.test.assertEquals
+
+class ResourceAssignmentUtilsTest {
+
+ @Test
+ fun `generateResourceDataForAssignments - positive test`() {
+ //given a valid resource assignment
+ val validResourceAssignment = createResourceAssignmentForTest("valid_value")
+
+ //and a list containing that resource assignment
+ val resourceAssignmentList = listOf<ResourceAssignment>(validResourceAssignment)
+
+ //when the values of the resources are evaluated
+ val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList)
+
+ //then the assignment should produce a valid result
+ val expected = "{\n" + " \"pnf-id\" : \"valid_value\"\n" + "}"
+ assertEquals(expected, outcome, "unexpected outcome generated")
+
+ }
+
+ @Test
+ fun `generateResourceDataForAssignments - resource without value is not resolved as null`() {
+ //given a valid resource assignment
+ val resourceAssignmentWithNullValue = createResourceAssignmentForTest(null)
+
+ //and a list containing that resource assignment
+ val resourceAssignmentList = listOf<ResourceAssignment>(resourceAssignmentWithNullValue)
+
+ //when the values of the resources are evaluated
+ val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList)
+
+ //then the assignment should produce a valid result
+ val expected = "{\n" + " \"pnf-id\" : \"\${pnf-id}\"\n" + "}"
+ assertEquals(expected, outcome, "unexpected outcome generated")
+
+ }
+
+ private fun createResourceAssignmentForTest(resourceValue: String?): ResourceAssignment {
+ val valueForTest = if (resourceValue == null) null else TextNode(resourceValue)
+ val resourceAssignmentForTest = ResourceAssignment().apply {
+ name = "pnf-id"
+ dictionaryName = "pnf-id"
+ dictionarySource = "input"
+ property = PropertyDefinition().apply {
+ type = "string"
+ value = valueForTest
+ }
+ }
+ return resourceAssignmentForTest
+ }
+} \ No newline at end of file