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.TestConstants
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.normalizedPathName
28 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintMetadataUtils
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BlueprintRuntimeUtils
30 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
31 import org.slf4j.LoggerFactory
32 import kotlin.test.assertEquals
33 import kotlin.test.assertNotNull
38 * @author Brinda Santh
40 class BlueprintRuntimeServiceTest {
42 private val log = LoggerFactory.getLogger(this::class.toString())
45 fun `test Resolve NodeTemplate Properties`() {
46 log.info("************************ testResolveNodeTemplateProperties **********************")
48 val bluePrintRuntimeService = getBlueprintRuntimeService()
50 val inputDataPath = "src/test/resources/data/default-context.json"
52 val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath)
53 bluePrintRuntimeService.assignInputs(inputNode)
55 val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
56 .resolveNodeTemplateProperties("activate-process")
58 assertNotNull(propContext, "Failed to populate interface property values")
62 fun `test Resolve Relationship Properties`() {
63 log.info("************************ testResolveRelationshipTemplateProperties **********************")
65 val bluePrintRuntimeService = getBlueprintRuntimeService()
67 val inputDataPath = "src/test/resources/data/default-context.json"
69 val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath)
70 bluePrintRuntimeService.assignInputs(inputNode)
72 val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
73 .resolveRelationshipTemplateProperties("cli-device-properties")
75 assertNotNull(propContext, "Failed to populate relationship property values")
77 "localhost".asJsonPrimitive(),
78 propContext["connection-config"]!!.get("host"),
79 "failed to resolve expression"
84 fun `test resolve NodeTemplate Capability Properties`() {
85 log.info("************************ testResolveNodeTemplateRequirementProperties **********************")
86 val bluePrintRuntimeService = getBlueprintRuntimeService()
88 val executionContext = bluePrintRuntimeService.getExecutionContext()
90 BlueprintRuntimeUtils.assignInputsFromClassPathFile(
91 bluePrintRuntimeService.bluePrintContext(),
92 "data/default-context.json", executionContext
95 val assignmentParams = "{\n" +
96 " \"ipAddress\": \"127.0.0.1\",\n" +
97 " \"hostName\": \"vnf-host\"\n" +
100 bluePrintRuntimeService.setNodeTemplateAttributeValue(
101 "resource-assignment", "assignment-params",
102 JacksonUtils.jsonNode(assignmentParams)
105 val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(
106 "sample-netconf-device",
109 assertNotNull(capProperties, "Failed to populate capability property values")
111 capProperties["target-ip-address"],
112 "127.0.0.1".asJsonPrimitive(),
113 "Failed to populate parameter target-ip-address"
116 capProperties["port-number"],
117 JacksonUtils.jsonNodeFromObject(830),
118 "Failed to populate parameter port-number"
123 fun `test Resolve NodeTemplate Interface Operation Inputs`() {
124 log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
126 val bluePrintRuntimeService = getBlueprintRuntimeService()
128 val executionContext = bluePrintRuntimeService.getExecutionContext()
130 BlueprintRuntimeUtils.assignInputsFromClassPathFile(
131 bluePrintRuntimeService.bluePrintContext(),
132 "data/default-context.json", executionContext
135 val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
136 .resolveNodeTemplateInterfaceOperationInputs(
137 "resource-assignment",
138 "ResourceResolutionComponent", "process"
141 assertNotNull(inContext, "Failed to populate interface input property values")
143 inContext["action-name"],
144 JacksonUtils.jsonNodeFromObject("sample-action"),
145 "Failed to populate parameter action-name"
148 inContext["request-id"],
149 JacksonUtils.jsonNodeFromObject("12345"),
150 "Failed to populate parameter action-name"
155 fun `test Resolve NodeTemplate Interface Operation Outputs`() {
156 log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
158 val bluePrintRuntimeService = getBlueprintRuntimeService()
160 bluePrintRuntimeService.setNodeTemplateAttributeValue(
161 "resource-assignment",
163 NullNode.getInstance()
166 bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs(
167 "resource-assignment",
168 "ResourceResolutionComponent", "process"
171 val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue(
172 "resource-assignment",
173 "ResourceResolutionComponent", "process", "status"
175 assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")
177 val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue(
178 "resource-assignment",
179 "ResourceResolutionComponent", "process", "resource-assignment-params"
182 NullNode.getInstance(),
184 "Failed to get operation property resource-assignment-params"
189 fun `test NodeTemplate Context Property`() {
190 log.info("************************ testNodeTemplateContextProperty **********************")
191 val bluePrintRuntimeService = getBlueprintRuntimeService()
193 bluePrintRuntimeService.setNodeTemplateAttributeValue(
194 "resource-assignment-ra-component", "context1",
195 JacksonUtils.jsonNodeFromObject("context1-value")
197 bluePrintRuntimeService.setNodeTemplateAttributeValue(
198 "resource-assignment-ra-component", "context2",
199 JacksonUtils.jsonNodeFromObject("context2-value")
202 val keys = listOf("context1", "context2")
205 bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
206 assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
207 log.info("JSON Prepared Value Context {}", jsonValueNode)
211 fun `test Resolve DSL Properties`() {
212 log.info("************************ resolveDSLExpression **********************")
214 val bluePrintRuntimeService = getBlueprintRuntimeService()
216 bluePrintRuntimeService.setInputValue("rest-user-name", "sample-username".asJsonPrimitive())
218 val resolvedJsonNode: JsonNode = bluePrintRuntimeService.resolveDSLExpression("dynamic-rest-source")
219 assertNotNull(resolvedJsonNode, "Failed to populate dsl property values")
223 fun `test Resolve Workflow Outputs`() {
224 log.info("************************ resolvePropertyAssignments **********************")
225 val bluePrintRuntimeService = getBlueprintRuntimeService()
227 val assignmentParams = "{\"ipAddress\": \"127.0.0.1\", \"hostName\": \"vnf-host\"}"
229 bluePrintRuntimeService.setNodeTemplateAttributeValue(
230 "resource-assignment", "assignment-params",
231 JacksonUtils.jsonNode(assignmentParams)
234 val resolvedJsonNode = bluePrintRuntimeService.resolveWorkflowOutputs("resource-assignment")
235 assertNotNull(resolvedJsonNode, "Failed to populate workflow output property values")
239 fun `test resolvePropertyDefinitions using sub attributes`() {
240 val bluePrintRuntimeService = getBlueprintRuntimeService()
242 bluePrintRuntimeService.setNodeTemplateAttributeValue(
243 "resource-assignment", "assignment-map",
244 JacksonUtils.jsonNode(
257 val propertyDefinitions = mutableMapOf<String, PropertyDefinition>(
258 "resolution" to PropertyDefinition().apply {
260 this.value = JacksonUtils.jsonNode(
264 "resource-assignment",
277 val result = bluePrintRuntimeService.resolvePropertyDefinitions("workflow", "WORKFLOW", propertyDefinitions)
279 assertEquals("123", result["resolution"]!!.asText())
282 private fun getBlueprintRuntimeService(): BlueprintRuntimeService<MutableMap<String, JsonNode>> {
283 val blueprintBasePath = normalizedPathName(TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG)
284 val blueprintRuntime = BlueprintMetadataUtils.bluePrintRuntime("1234", blueprintBasePath)
285 val checkProcessId = blueprintRuntime.get(BlueprintConstants.PROPERTY_BLUEPRINT_PROCESS_ID)
286 val checkBasePath = blueprintRuntime.get(BlueprintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
289 "1234".asJsonPrimitive(),
290 checkProcessId, "Failed to get process id after runtime creation"
293 blueprintBasePath.asJsonPrimitive(),
294 checkBasePath, "Failed to get base path after runtime creation"
297 return blueprintRuntime