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")
88 capProperties["target-ip-address"],
89 "127.0.0.1".asJsonPrimitive(),
90 "Failed to populate parameter target-ip-address"
93 capProperties["port-number"],
94 JacksonUtils.jsonNodeFromObject(830),
95 "Failed to populate parameter port-number"
100 fun `test Resolve NodeTemplate Interface Operation Inputs`() {
101 log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
103 val bluePrintRuntimeService = getBluePrintRuntimeService()
105 val executionContext = bluePrintRuntimeService.getExecutionContext()
107 BluePrintRuntimeUtils.assignInputsFromClassPathFile(
108 bluePrintRuntimeService.bluePrintContext(),
109 "data/default-context.json", executionContext
112 val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
113 .resolveNodeTemplateInterfaceOperationInputs(
114 "resource-assignment",
115 "ResourceResolutionComponent", "process"
118 assertNotNull(inContext, "Failed to populate interface input property values")
120 inContext["action-name"],
121 JacksonUtils.jsonNodeFromObject("sample-action"),
122 "Failed to populate parameter action-name"
125 inContext["request-id"],
126 JacksonUtils.jsonNodeFromObject("12345"),
127 "Failed to populate parameter action-name"
132 fun `test Resolve NodeTemplate Interface Operation Outputs`() {
133 log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
135 val bluePrintRuntimeService = getBluePrintRuntimeService()
137 bluePrintRuntimeService.setNodeTemplateAttributeValue(
138 "resource-assignment",
140 NullNode.getInstance()
143 bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs(
144 "resource-assignment",
145 "ResourceResolutionComponent", "process"
148 val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue(
149 "resource-assignment",
150 "ResourceResolutionComponent", "process", "status"
152 assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")
154 val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue(
155 "resource-assignment",
156 "ResourceResolutionComponent", "process", "resource-assignment-params"
159 NullNode.getInstance(),
161 "Failed to get operation property resource-assignment-params"
166 fun `test NodeTemplate Context Property`() {
167 log.info("************************ testNodeTemplateContextProperty **********************")
168 val bluePrintRuntimeService = getBluePrintRuntimeService()
170 bluePrintRuntimeService.setNodeTemplateAttributeValue(
171 "resource-assignment-ra-component", "context1",
172 JacksonUtils.jsonNodeFromObject("context1-value")
174 bluePrintRuntimeService.setNodeTemplateAttributeValue(
175 "resource-assignment-ra-component", "context2",
176 JacksonUtils.jsonNodeFromObject("context2-value")
179 val keys = listOf("context1", "context2")
182 bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
183 assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
184 log.info("JSON Prepared Value Context {}", jsonValueNode)
188 fun `test Resolve DSL Properties`() {
189 log.info("************************ resolveDSLExpression **********************")
191 val bluePrintRuntimeService = getBluePrintRuntimeService()
193 bluePrintRuntimeService.setInputValue("rest-user-name", "sample-username".asJsonPrimitive())
195 val resolvedJsonNode: JsonNode = bluePrintRuntimeService.resolveDSLExpression("dynamic-rest-source")
196 assertNotNull(resolvedJsonNode, "Failed to populate dsl property values")
200 fun `test Resolve Workflow Outputs`() {
201 log.info("************************ resolvePropertyAssignments **********************")
202 val bluePrintRuntimeService = getBluePrintRuntimeService()
204 val assignmentParams = "{\"ipAddress\": \"127.0.0.1\", \"hostName\": \"vnf-host\"}"
206 bluePrintRuntimeService.setNodeTemplateAttributeValue(
207 "resource-assignment", "assignment-params",
208 JacksonUtils.jsonNode(assignmentParams)
211 val resolvedJsonNode = bluePrintRuntimeService.resolveWorkflowOutputs("resource-assignment")
212 assertNotNull(resolvedJsonNode, "Failed to populate workflow output property values")
215 private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
216 val blueprintBasePath = normalizedPathName(TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG)
217 val blueprintRuntime = BluePrintMetadataUtils.bluePrintRuntime("1234", blueprintBasePath)
218 val checkProcessId = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID)
219 val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
222 "1234".asJsonPrimitive(),
223 checkProcessId, "Failed to get process id after runtime creation"
226 blueprintBasePath.asJsonPrimitive(),
227 checkBasePath, "Failed to get base path after runtime creation"
230 return blueprintRuntime