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 com.fasterxml.jackson.databind.JsonNode
21 import com.fasterxml.jackson.databind.node.NullNode
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
24 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
25 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
26 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
27 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintRuntimeUtils
28 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
29 import org.slf4j.LoggerFactory
30 import kotlin.test.assertEquals
31 import kotlin.test.assertNotNull
36 * @author Brinda Santh
38 class BluePrintRuntimeServiceTest {
40 private val log = LoggerFactory.getLogger(this::class.toString())
43 fun `test Resolve NodeTemplate Properties`() {
44 log.info("************************ testResolveNodeTemplateProperties **********************")
46 val bluePrintRuntimeService = getBluePrintRuntimeService()
48 val inputDataPath = "src/test/resources/data/default-context.json"
50 val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath)
51 bluePrintRuntimeService.assignInputs(inputNode)
53 val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
54 .resolveNodeTemplateProperties("activate-process")
56 assertNotNull(propContext, "Failed to populate interface property values")
60 fun `test resolve NodeTemplate Capability Properties`() {
61 log.info("************************ testResolveNodeTemplateRequirementProperties **********************")
62 val bluePrintRuntimeService = getBluePrintRuntimeService()
64 val executionContext = bluePrintRuntimeService.getExecutionContext()
66 BluePrintRuntimeUtils.assignInputsFromClassPathFile(
67 bluePrintRuntimeService.bluePrintContext(),
68 "data/default-context.json", executionContext
71 val assignmentParams = "{\n" +
72 " \"ipAddress\": \"127.0.0.1\",\n" +
73 " \"hostName\": \"vnf-host\"\n" +
76 bluePrintRuntimeService.setNodeTemplateAttributeValue(
77 "resource-assignment", "assignment-params",
78 JacksonUtils.jsonNode(assignmentParams)
81 val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(
82 "sample-netconf-device",
85 assertNotNull(capProperties, "Failed to populate capability property values")
86 assertEquals(capProperties["target-ip-address"], "127.0.0.1".asJsonPrimitive(), "Failed to populate parameter target-ip-address")
87 assertEquals(capProperties["port-number"], JacksonUtils.jsonNodeFromObject(830), "Failed to populate parameter port-number")
91 fun `test Resolve NodeTemplate Interface Operation Inputs`() {
92 log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
94 val bluePrintRuntimeService = getBluePrintRuntimeService()
96 val executionContext = bluePrintRuntimeService.getExecutionContext()
98 BluePrintRuntimeUtils.assignInputsFromClassPathFile(
99 bluePrintRuntimeService.bluePrintContext(),
100 "data/default-context.json", executionContext
103 val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
104 .resolveNodeTemplateInterfaceOperationInputs(
105 "resource-assignment",
106 "ResourceResolutionComponent", "process"
109 assertNotNull(inContext, "Failed to populate interface input property values")
110 assertEquals(inContext["action-name"], JacksonUtils.jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
111 assertEquals(inContext["request-id"], JacksonUtils.jsonNodeFromObject("12345"), "Failed to populate parameter action-name")
115 fun `test Resolve NodeTemplate Interface Operation Outputs`() {
116 log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
118 val bluePrintRuntimeService = getBluePrintRuntimeService()
120 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance())
122 bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs(
123 "resource-assignment",
124 "ResourceResolutionComponent", "process"
127 val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue(
128 "resource-assignment",
129 "ResourceResolutionComponent", "process", "status"
131 assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")
133 val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue(
134 "resource-assignment",
135 "ResourceResolutionComponent", "process", "resource-assignment-params"
137 assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params")
141 fun `test NodeTemplate Context Property`() {
142 log.info("************************ testNodeTemplateContextProperty **********************")
143 val bluePrintRuntimeService = getBluePrintRuntimeService()
145 bluePrintRuntimeService.setNodeTemplateAttributeValue(
146 "resource-assignment-ra-component", "context1",
147 JacksonUtils.jsonNodeFromObject("context1-value")
149 bluePrintRuntimeService.setNodeTemplateAttributeValue(
150 "resource-assignment-ra-component", "context2",
151 JacksonUtils.jsonNodeFromObject("context2-value")
154 val keys = listOf("context1", "context2")
156 val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
157 assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
158 log.info("JSON Prepared Value Context {}", jsonValueNode)
162 fun `test Resolve DSL Properties`() {
163 log.info("************************ resolveDSLExpression **********************")
165 val bluePrintRuntimeService = getBluePrintRuntimeService()
167 bluePrintRuntimeService.setInputValue("rest-user-name", "sample-username".asJsonPrimitive())
169 val resolvedJsonNode: JsonNode = bluePrintRuntimeService.resolveDSLExpression("dynamic-rest-source")
170 assertNotNull(resolvedJsonNode, "Failed to populate dsl property values")
174 fun `test Resolve Workflow Outputs`() {
175 log.info("************************ resolvePropertyAssignments **********************")
176 val bluePrintRuntimeService = getBluePrintRuntimeService()
178 val assignmentParams = "{\"ipAddress\": \"127.0.0.1\", \"hostName\": \"vnf-host\"}"
180 bluePrintRuntimeService.setNodeTemplateAttributeValue(
181 "resource-assignment", "assignment-params",
182 JacksonUtils.jsonNode(assignmentParams)
185 val resolvedJsonNode = bluePrintRuntimeService.resolveWorkflowOutputs("resource-assignment")
186 assertNotNull(resolvedJsonNode, "Failed to populate workflow output property values")
189 private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
190 val blueprintBasePath = normalizedPathName("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
191 val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
192 val checkProcessId = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID)
193 val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
196 "1234".asJsonPrimitive(),
197 checkProcessId, "Failed to get process id after runtime creation"
200 blueprintBasePath.asJsonPrimitive(),
201 checkBasePath, "Failed to get base path after runtime creation"
204 return blueprintRuntime