aboutsummaryrefslogtreecommitdiffstats
path: root/components/core/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeServiceTest.kt
blob: 19c6c2f9d3bd5b1123d6d961e2de218ccd6e2270 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Copyright © 2017-2018 AT&T Intellectual Property.
 * Modifications Copyright © 2018 IBM.
 *
 * 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.
 */

package org.onap.ccsdk.apps.controllerblueprints.core.service

import com.att.eelf.configuration.EELFLogger
import com.att.eelf.configuration.EELFManager
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.NullNode
import org.junit.Test
import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintRuntimeUtils
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils.jsonNodeFromFile
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils.jsonNodeFromObject
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

/**
 *
 *
 * @author Brinda Santh
 */
class BluePrintRuntimeServiceTest {
    private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())

    @Test
    fun testResolveNodeTemplateProperties() {
        log.info("************************ testResolveNodeTemplateProperties **********************")

        val bluePrintRuntimeService = getBluePrintRuntimeService()

        val inputDataPath = "src/test/resources/data/default-context.json"

        val inputNode: JsonNode = jsonNodeFromFile(inputDataPath)
        bluePrintRuntimeService.assignInputs(inputNode)

        val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService.resolveNodeTemplateProperties("activate-process")

        assertNotNull(propContext, "Failed to populate interface property values")
        assertEquals(propContext["process-name"], jsonNodeFromObject("sample-action"), "Failed to populate parameter process-name")
        assertEquals(propContext["version"], jsonNodeFromObject("sample-action"), "Failed to populate parameter version")
    }

    @Test
    fun testResolveNodeTemplateInterfaceOperationInputs() {
        log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")

        val bluePrintRuntimeService = getBluePrintRuntimeService()

        val executionContext = bluePrintRuntimeService.getExecutionContext()

        BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),
                "data/default-context.json", executionContext)

        val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationInputs("resource-assignment",
                "DefaultComponentNode", "process")

        assertNotNull(inContext, "Failed to populate interface input property values")
        assertEquals(inContext["action-name"], jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
        assertEquals(inContext["request-id"], jsonNodeFromObject("12345"), "Failed to populate parameter action-name")
        assertEquals(inContext["template-content"], jsonNodeFromObject("This is Sample Velocity Template"), "Failed to populate parameter action-name")
    }

    @Test
    fun testResolveNodeTemplateInterfaceOperationOutputs() {
        log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")

        val bluePrintRuntimeService = getBluePrintRuntimeService()

        bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance())

        bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment",
                "DefaultComponentNode", "process")

        val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
                "DefaultComponentNode", "process", "status")
        assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")

        val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
                "DefaultComponentNode", "process", "resource-assignment-params")
        assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params")

    }

    @Test
    fun testNodeTemplateContextProperty() {
        log.info("************************ testNodeTemplateContextProperty **********************")
        val bluePrintRuntimeService = getBluePrintRuntimeService()

        bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context1",
                jsonNodeFromObject("context1-value"))
        bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context2",
                jsonNodeFromObject("context2-value"))

        val keys = listOf("context1", "context2")

        val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
        assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
        log.info("JSON Prepared Value Context {}", jsonValueNode)

    }

    private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
        val blueprintBasePath: String = ("./../model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
        val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
        val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)

        assertEquals(blueprintBasePath.asJsonPrimitive(), checkBasePath, "Failed to get base path after runtime creation")

        return blueprintRuntime
    }

}