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.att.eelf.configuration.EELFLogger
21 import com.att.eelf.configuration.EELFManager
22 import com.fasterxml.jackson.databind.JsonNode
23 import com.fasterxml.jackson.databind.node.NullNode
25 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
26 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
27 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
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 kotlin.test.assertEquals
32 import kotlin.test.assertNotNull
37 * @author Brinda Santh
39 class BluePrintRuntimeServiceTest {
40 private val log: EELFLogger = EELFManager.getInstance().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(bluePrintRuntimeService.bluePrintContext(),
67 "data/default-context.json", executionContext)
69 val assignmentParams = "{\n" +
70 " \"ipAddress\": \"127.0.0.1\",\n" +
71 " \"hostName\": \"vnf-host\"\n" +
74 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params",
75 JacksonUtils.jsonNode(assignmentParams))
77 val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties("sample-netconf-device",
79 assertNotNull(capProperties, "Failed to populate capability property values")
80 assertEquals(capProperties["target-ip-address"], "127.0.0.1".asJsonPrimitive(), "Failed to populate parameter target-ip-address")
81 assertEquals(capProperties["port-number"], JacksonUtils.jsonNodeFromObject(830), "Failed to populate parameter port-number")
85 fun `test Resolve NodeTemplate Interface Operation Inputs`() {
86 log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
88 val bluePrintRuntimeService = getBluePrintRuntimeService()
90 val executionContext = bluePrintRuntimeService.getExecutionContext()
92 BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),
93 "data/default-context.json", executionContext)
95 val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
96 .resolveNodeTemplateInterfaceOperationInputs("resource-assignment",
97 "ResourceResolutionComponent", "process")
99 assertNotNull(inContext, "Failed to populate interface input property values")
100 assertEquals(inContext["action-name"], JacksonUtils.jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
101 assertEquals(inContext["request-id"], JacksonUtils.jsonNodeFromObject("12345"), "Failed to populate parameter action-name")
105 fun `test Resolve NodeTemplate Interface Operation Outputs`() {
106 log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
108 val bluePrintRuntimeService = getBluePrintRuntimeService()
110 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance())
112 bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment",
113 "ResourceResolutionComponent", "process")
115 val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
116 "ResourceResolutionComponent", "process", "status")
117 assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")
119 val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
120 "ResourceResolutionComponent", "process", "resource-assignment-params")
121 assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params")
126 fun `test NodeTemplate Context Property`() {
127 log.info("************************ testNodeTemplateContextProperty **********************")
128 val bluePrintRuntimeService = getBluePrintRuntimeService()
130 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context1",
131 JacksonUtils.jsonNodeFromObject("context1-value"))
132 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context2",
133 JacksonUtils.jsonNodeFromObject("context2-value"))
135 val keys = listOf("context1", "context2")
137 val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
138 assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
139 log.info("JSON Prepared Value Context {}", jsonValueNode)
144 fun `test Resolve DSL Properties`() {
145 log.info("************************ resolveDSLExpression **********************")
147 val bluePrintRuntimeService = getBluePrintRuntimeService()
149 bluePrintRuntimeService.setInputValue("rest-user-name", PropertyDefinition(), "sample-username"
152 val resolvedJsonNode: JsonNode = bluePrintRuntimeService.resolveDSLExpression("dynamic-rest-source")
153 assertNotNull(resolvedJsonNode, "Failed to populate dsl property values")
157 fun `test Resolve Workflow Outputs`() {
158 log.info("************************ resolvePropertyAssignments **********************")
159 val bluePrintRuntimeService = getBluePrintRuntimeService()
161 val assignmentParams = "{\"ipAddress\": \"127.0.0.1\", \"hostName\": \"vnf-host\"}"
163 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params",
164 JacksonUtils.jsonNode(assignmentParams))
166 val resolvedJsonNode = bluePrintRuntimeService.resolveWorkflowOutputs("resource-assignment")
167 assertNotNull(resolvedJsonNode, "Failed to populate workflow output property values")
170 private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
171 val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
172 val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
173 val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
175 assertEquals(blueprintBasePath.asJsonPrimitive(), checkBasePath, "Failed to get base path after runtime creation")
177 return blueprintRuntime