2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018-2019 IBM.
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.
18 package org.onap.ccsdk.cds.controllerblueprints.core.service
20 import org.slf4j.LoggerFactory
21 import com.fasterxml.jackson.databind.JsonNode
22 import com.fasterxml.jackson.databind.node.NullNode
24 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
25 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
26 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
27 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
28 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintRuntimeUtils
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
30 import kotlin.test.assertEquals
31 import kotlin.test.assertNotNull
36 * @author Brinda Santh
38 class BluePrintRuntimeServiceTest {
39 private val log= LoggerFactory.getLogger(this::class.toString())
42 fun `test Resolve NodeTemplate Properties`() {
43 log.info("************************ testResolveNodeTemplateProperties **********************")
45 val bluePrintRuntimeService = getBluePrintRuntimeService()
47 val inputDataPath = "src/test/resources/data/default-context.json"
49 val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath)
50 bluePrintRuntimeService.assignInputs(inputNode)
52 val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
53 .resolveNodeTemplateProperties("activate-process")
55 assertNotNull(propContext, "Failed to populate interface property values")
59 fun `test resolve NodeTemplate Capability Properties`() {
60 log.info("************************ testResolveNodeTemplateRequirementProperties **********************")
61 val bluePrintRuntimeService = getBluePrintRuntimeService()
63 val executionContext = bluePrintRuntimeService.getExecutionContext()
65 BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),
66 "data/default-context.json", executionContext)
68 val assignmentParams = "{\n" +
69 " \"ipAddress\": \"127.0.0.1\",\n" +
70 " \"hostName\": \"vnf-host\"\n" +
73 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params",
74 JacksonUtils.jsonNode(assignmentParams))
76 val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties("sample-netconf-device",
78 assertNotNull(capProperties, "Failed to populate capability property values")
79 assertEquals(capProperties["target-ip-address"], "127.0.0.1".asJsonPrimitive(), "Failed to populate parameter target-ip-address")
80 assertEquals(capProperties["port-number"], JacksonUtils.jsonNodeFromObject(830), "Failed to populate parameter port-number")
84 fun `test Resolve NodeTemplate Interface Operation Inputs`() {
85 log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
87 val bluePrintRuntimeService = getBluePrintRuntimeService()
89 val executionContext = bluePrintRuntimeService.getExecutionContext()
91 BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),
92 "data/default-context.json", executionContext)
94 val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
95 .resolveNodeTemplateInterfaceOperationInputs("resource-assignment",
96 "ResourceResolutionComponent", "process")
98 assertNotNull(inContext, "Failed to populate interface input property values")
99 assertEquals(inContext["action-name"], JacksonUtils.jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
100 assertEquals(inContext["request-id"], JacksonUtils.jsonNodeFromObject("12345"), "Failed to populate parameter action-name")
104 fun `test Resolve NodeTemplate Interface Operation Outputs`() {
105 log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
107 val bluePrintRuntimeService = getBluePrintRuntimeService()
109 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance())
111 bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment",
112 "ResourceResolutionComponent", "process")
114 val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
115 "ResourceResolutionComponent", "process", "status")
116 assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")
118 val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
119 "ResourceResolutionComponent", "process", "resource-assignment-params")
120 assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params")
125 fun `test NodeTemplate Context Property`() {
126 log.info("************************ testNodeTemplateContextProperty **********************")
127 val bluePrintRuntimeService = getBluePrintRuntimeService()
129 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context1",
130 JacksonUtils.jsonNodeFromObject("context1-value"))
131 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context2",
132 JacksonUtils.jsonNodeFromObject("context2-value"))
134 val keys = listOf("context1", "context2")
136 val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
137 assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
138 log.info("JSON Prepared Value Context {}", jsonValueNode)
143 fun `test Resolve DSL Properties`() {
144 log.info("************************ resolveDSLExpression **********************")
146 val bluePrintRuntimeService = getBluePrintRuntimeService()
148 bluePrintRuntimeService.setInputValue("rest-user-name", PropertyDefinition(), "sample-username"
151 val resolvedJsonNode: JsonNode = bluePrintRuntimeService.resolveDSLExpression("dynamic-rest-source")
152 assertNotNull(resolvedJsonNode, "Failed to populate dsl property values")
156 fun `test Resolve Workflow Outputs`() {
157 log.info("************************ resolvePropertyAssignments **********************")
158 val bluePrintRuntimeService = getBluePrintRuntimeService()
160 val assignmentParams = "{\"ipAddress\": \"127.0.0.1\", \"hostName\": \"vnf-host\"}"
162 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params",
163 JacksonUtils.jsonNode(assignmentParams))
165 val resolvedJsonNode = bluePrintRuntimeService.resolveWorkflowOutputs("resource-assignment")
166 assertNotNull(resolvedJsonNode, "Failed to populate workflow output property values")
169 private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
170 val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
171 val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
172 val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
174 assertEquals(blueprintBasePath.asJsonPrimitive(), checkBasePath, "Failed to get base path after runtime creation")
176 return blueprintRuntime