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 Relationship Properties`() {
62 log.info("************************ testResolveRelationshipTemplateProperties **********************")
64 val bluePrintRuntimeService = getBluePrintRuntimeService()
66 val inputDataPath = "src/test/resources/data/default-context.json"
68 val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath)
69 bluePrintRuntimeService.assignInputs(inputNode)
71 val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
72 .resolveRelationshipTemplateProperties("cli-device-properties")
74 assertNotNull(propContext, "Failed to populate relationship property values")
76 "localhost".asJsonPrimitive(),
77 propContext["connection-config"]!!.get("host"),
78 "failed to resolve expression"
83 fun `test resolve NodeTemplate Capability Properties`() {
84 log.info("************************ testResolveNodeTemplateRequirementProperties **********************")
85 val bluePrintRuntimeService = getBluePrintRuntimeService()
87 val executionContext = bluePrintRuntimeService.getExecutionContext()
89 BluePrintRuntimeUtils.assignInputsFromClassPathFile(
90 bluePrintRuntimeService.bluePrintContext(),
91 "data/default-context.json", executionContext
94 val assignmentParams = "{\n" +
95 " \"ipAddress\": \"127.0.0.1\",\n" +
96 " \"hostName\": \"vnf-host\"\n" +
99 bluePrintRuntimeService.setNodeTemplateAttributeValue(
100 "resource-assignment", "assignment-params",
101 JacksonUtils.jsonNode(assignmentParams)
104 val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties(
105 "sample-netconf-device",
108 assertNotNull(capProperties, "Failed to populate capability property values")
110 capProperties["target-ip-address"],
111 "127.0.0.1".asJsonPrimitive(),
112 "Failed to populate parameter target-ip-address"
115 capProperties["port-number"],
116 JacksonUtils.jsonNodeFromObject(830),
117 "Failed to populate parameter port-number"
122 fun `test Resolve NodeTemplate Interface Operation Inputs`() {
123 log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
125 val bluePrintRuntimeService = getBluePrintRuntimeService()
127 val executionContext = bluePrintRuntimeService.getExecutionContext()
129 BluePrintRuntimeUtils.assignInputsFromClassPathFile(
130 bluePrintRuntimeService.bluePrintContext(),
131 "data/default-context.json", executionContext
134 val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
135 .resolveNodeTemplateInterfaceOperationInputs(
136 "resource-assignment",
137 "ResourceResolutionComponent", "process"
140 assertNotNull(inContext, "Failed to populate interface input property values")
142 inContext["action-name"],
143 JacksonUtils.jsonNodeFromObject("sample-action"),
144 "Failed to populate parameter action-name"
147 inContext["request-id"],
148 JacksonUtils.jsonNodeFromObject("12345"),
149 "Failed to populate parameter action-name"
154 fun `test Resolve NodeTemplate Interface Operation Outputs`() {
155 log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
157 val bluePrintRuntimeService = getBluePrintRuntimeService()
159 bluePrintRuntimeService.setNodeTemplateAttributeValue(
160 "resource-assignment",
162 NullNode.getInstance()
165 bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs(
166 "resource-assignment",
167 "ResourceResolutionComponent", "process"
170 val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue(
171 "resource-assignment",
172 "ResourceResolutionComponent", "process", "status"
174 assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")
176 val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue(
177 "resource-assignment",
178 "ResourceResolutionComponent", "process", "resource-assignment-params"
181 NullNode.getInstance(),
183 "Failed to get operation property resource-assignment-params"
188 fun `test NodeTemplate Context Property`() {
189 log.info("************************ testNodeTemplateContextProperty **********************")
190 val bluePrintRuntimeService = getBluePrintRuntimeService()
192 bluePrintRuntimeService.setNodeTemplateAttributeValue(
193 "resource-assignment-ra-component", "context1",
194 JacksonUtils.jsonNodeFromObject("context1-value")
196 bluePrintRuntimeService.setNodeTemplateAttributeValue(
197 "resource-assignment-ra-component", "context2",
198 JacksonUtils.jsonNodeFromObject("context2-value")
201 val keys = listOf("context1", "context2")
204 bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
205 assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
206 log.info("JSON Prepared Value Context {}", jsonValueNode)
210 fun `test Resolve DSL Properties`() {
211 log.info("************************ resolveDSLExpression **********************")
213 val bluePrintRuntimeService = getBluePrintRuntimeService()
215 bluePrintRuntimeService.setInputValue("rest-user-name", "sample-username".asJsonPrimitive())
217 val resolvedJsonNode: JsonNode = bluePrintRuntimeService.resolveDSLExpression("dynamic-rest-source")
218 assertNotNull(resolvedJsonNode, "Failed to populate dsl property values")
222 fun `test Resolve Workflow Outputs`() {
223 log.info("************************ resolvePropertyAssignments **********************")
224 val bluePrintRuntimeService = getBluePrintRuntimeService()
226 val assignmentParams = "{\"ipAddress\": \"127.0.0.1\", \"hostName\": \"vnf-host\"}"
228 bluePrintRuntimeService.setNodeTemplateAttributeValue(
229 "resource-assignment", "assignment-params",
230 JacksonUtils.jsonNode(assignmentParams)
233 val resolvedJsonNode = bluePrintRuntimeService.resolveWorkflowOutputs("resource-assignment")
234 assertNotNull(resolvedJsonNode, "Failed to populate workflow output property values")
237 private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
238 val blueprintBasePath = normalizedPathName(TestConstants.PATH_TEST_BLUEPRINTS_BASECONFIG)
239 val blueprintRuntime = BluePrintMetadataUtils.bluePrintRuntime("1234", blueprintBasePath)
240 val checkProcessId = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID)
241 val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
244 "1234".asJsonPrimitive(),
245 checkProcessId, "Failed to get process id after runtime creation"
248 blueprintBasePath.asJsonPrimitive(),
249 checkBasePath, "Failed to get base path after runtime creation"
252 return blueprintRuntime