Merge "Add logger to the server"
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / utils / ResourceAssignmentUtilsTest.kt
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21
22 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils
23
24 import com.fasterxml.jackson.databind.node.TextNode
25 import org.junit.Test
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
29
30 class ResourceAssignmentUtilsTest {
31
32     @Test
33     fun `generateResourceDataForAssignments - positive test`() {
34         //given a valid resource assignment
35         val validResourceAssignment = createResourceAssignmentForTest("valid_value")
36
37         //and a list containing that resource assignment
38         val resourceAssignmentList = listOf<ResourceAssignment>(validResourceAssignment)
39
40         //when the values of the resources are evaluated
41         val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList)
42
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")
46
47     }
48
49     @Test
50     fun `generateResourceDataForAssignments - resource without value is not resolved as null`() {
51         //given a valid resource assignment
52         val resourceAssignmentWithNullValue = createResourceAssignmentForTest(null)
53
54         //and a list containing that resource assignment
55         val resourceAssignmentList = listOf<ResourceAssignment>(resourceAssignmentWithNullValue)
56
57         //when the values of the resources are evaluated
58         val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList)
59
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")
63
64     }
65
66     private fun createResourceAssignmentForTest(resourceValue: String?): ResourceAssignment {
67         val valueForTest = if (resourceValue == null) null else TextNode(resourceValue)
68         val resourceAssignmentForTest = ResourceAssignment().apply {
69             name = "pnf-id"
70             dictionaryName = "pnf-id"
71             dictionarySource = "input"
72             property = PropertyDefinition().apply {
73                 type = "string"
74                 value = valueForTest
75             }
76         }
77         return resourceAssignmentForTest
78     }
79 }