2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils
24 import com.fasterxml.jackson.databind.node.TextNode
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
27 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
28 import kotlin.test.assertEquals
30 class ResourceAssignmentUtilsTest {
33 fun `generateResourceDataForAssignments - positive test`() {
34 //given a valid resource assignment
35 val validResourceAssignment = createResourceAssignmentForTest("valid_value")
37 //and a list containing that resource assignment
38 val resourceAssignmentList = listOf<ResourceAssignment>(validResourceAssignment)
40 //when the values of the resources are evaluated
41 val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList)
43 //then the assignment should produce a valid result
44 val expected = "{\n" + " \"pnf-id\" : \"valid_value\"\n" + "}"
45 assertEquals(expected, outcome, "unexpected outcome generated")
50 fun `generateResourceDataForAssignments - resource without value is not resolved as null`() {
51 //given a valid resource assignment
52 val resourceAssignmentWithNullValue = createResourceAssignmentForTest(null)
54 //and a list containing that resource assignment
55 val resourceAssignmentList = listOf<ResourceAssignment>(resourceAssignmentWithNullValue)
57 //when the values of the resources are evaluated
58 val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList)
60 //then the assignment should produce a valid result
61 val expected = "{\n" + " \"pnf-id\" : \"\${pnf-id}\"\n" + "}"
62 assertEquals(expected, outcome, "unexpected outcome generated")
66 private fun createResourceAssignmentForTest(resourceValue: String?): ResourceAssignment {
67 val valueForTest = if (resourceValue == null) null else TextNode(resourceValue)
68 val resourceAssignmentForTest = ResourceAssignment().apply {
70 dictionaryName = "pnf-id"
71 dictionarySource = "input"
72 property = PropertyDefinition().apply {
77 return resourceAssignmentForTest