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.normalizedPathName
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 org.slf4j.LoggerFactory
31 import kotlin.test.assertEquals
32 import kotlin.test.assertNotNull
37 * @author Brinda Santh
39 class BluePrintRuntimeServiceTest {
41 private val log = LoggerFactory.getLogger(this::class.toString())
44 fun `test Resolve NodeTemplate Properties`() {
45 log.info("************************ testResolveNodeTemplateProperties **********************")
47 val bluePrintRuntimeService = getBluePrintRuntimeService()
49 val inputDataPath = "src/test/resources/data/default-context.json"
51 val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath)
52 bluePrintRuntimeService.assignInputs(inputNode)
54 val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
55 .resolveNodeTemplateProperties("activate-process")
57 assertNotNull(propContext, "Failed to populate interface property values")
61 fun `test resolve NodeTemplate Capability Properties`() {
62 log.info("************************ testResolveNodeTemplateRequirementProperties **********************")
63 val bluePrintRuntimeService = getBluePrintRuntimeService()
65 val executionContext = bluePrintRuntimeService.getExecutionContext()
67 BluePrintRuntimeUtils.assignInputsFromClassPathFile(
68 bluePrintRuntimeService.bluePrintContext(),
69 "data/default-context.json", executionContext
72 val assignmentParams = "{\n" +
73 " \"ipAddress\": \"127.0.0.1\",\n" +
74 " \"hostName\": \"vnf-host\"\n" +
77 bluePrintRuntimeService.setNodeTemplateAttributeValue(
78 "resource-assignment", "assignment-params",
79 JacksonUtils.jsonNode(assignmentParams)
82 val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(
83 "sample-netconf-device",
86 assertNotNull(capProperties, "Failed to populate capability property values")
87 assertEquals(capProperties["target-ip-address"], "127.0.0.1".asJsonPrimitive(), "Failed to populate parameter target-ip-address")
88 assertEquals(capProperties["port-number"], JacksonUtils.jsonNodeFromObject(830), "Failed to populate parameter port-number")
92 fun `test Resolve NodeTemplate Interface Operation Inputs`() {
93 log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
95 val bluePrintRuntimeService = getBluePrintRuntimeService()
97 val executionContext = bluePrintRuntimeService.getExecutionContext()
99 BluePrintRuntimeUtils.assignInputsFromClassPathFile(
100 bluePrintRuntimeService.bluePrintContext(),
101 "data/default-context.json", executionContext
104 val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
105 .resolveNodeTemplateInterfaceOperationInputs(
106 "resource-assignment",
107 "ResourceResolutionComponent", "process"
110 assertNotNull(inContext, "Failed to populate interface input property values")
111 assertEquals(inContext["action-name"], JacksonUtils.jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
112 assertEquals(inContext["request-id"], JacksonUtils.jsonNodeFromObject("12345"), "Failed to populate parameter action-name")
116 fun `test Resolve NodeTemplate Interface Operation Outputs`() {
117 log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
119 val bluePrintRuntimeService = getBluePrintRuntimeService()
121 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance())
123 bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs(
124 "resource-assignment",
125 "ResourceResolutionComponent", "process"
128 val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue(
129 "resource-assignment",
130 "ResourceResolutionComponent", "process", "status"
132 assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")
134 val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue(
135 "resource-assignment",
136 "ResourceResolutionComponent", "process", "resource-assignment-params"
138 assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params")
142 fun `test NodeTemplate Context Property`() {
143 log.info("************************ testNodeTemplateContextProperty **********************")
144 val bluePrintRuntimeService = getBluePrintRuntimeService()
146 bluePrintRuntimeService.setNodeTemplateAttributeValue(
147 "resource-assignment-ra-component", "context1",
148 JacksonUtils.jsonNodeFromObject("context1-value")
150 bluePrintRuntimeService.setNodeTemplateAttributeValue(
151 "resource-assignment-ra-component", "context2",
152 JacksonUtils.jsonNodeFromObject("context2-value")
155 val keys = listOf("context1", "context2")
157 val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
158 assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
159 log.info("JSON Prepared Value Context {}", jsonValueNode)
163 fun `test Resolve DSL Properties`() {
164 log.info("************************ resolveDSLExpression **********************")
166 val bluePrintRuntimeService = getBluePrintRuntimeService()
168 bluePrintRuntimeService.setInputValue("rest-user-name", "sample-username".asJsonPrimitive())
170 val resolvedJsonNode: JsonNode = bluePrintRuntimeService.resolveDSLExpression("dynamic-rest-source")
171 assertNotNull(resolvedJsonNode, "Failed to populate dsl property values")
175 fun `test Resolve Workflow Outputs`() {
176 log.info("************************ resolvePropertyAssignments **********************")
177 val bluePrintRuntimeService = getBluePrintRuntimeService()
179 val assignmentParams = "{\"ipAddress\": \"127.0.0.1\", \"hostName\": \"vnf-host\"}"
181 bluePrintRuntimeService.setNodeTemplateAttributeValue(
182 "resource-assignment", "assignment-params",
183 JacksonUtils.jsonNode(assignmentParams)
186 val resolvedJsonNode = bluePrintRuntimeService.resolveWorkflowOutputs("resource-assignment")
187 assertNotNull(resolvedJsonNode, "Failed to populate workflow output property values")
190 private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
191 val blueprintBasePath = normalizedPathName(TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG)
192 val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
193 val checkProcessId = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID)
194 val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
197 "1234".asJsonPrimitive(),
198 checkProcessId, "Failed to get process id after runtime creation"
201 blueprintBasePath.asJsonPrimitive(),
202 checkBasePath, "Failed to get base path after runtime creation"
205 return blueprintRuntime