2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2018 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.apps.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.apps.controllerblueprints.core.BluePrintConstants
26 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
27 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
28 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintRuntimeUtils
29 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
30 import kotlin.test.assertEquals
31 import kotlin.test.assertNotNull
36 * @author Brinda Santh
38 class BluePrintRuntimeServiceTest {
39 private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
42 fun `test Resolve NodeTemplate Properties`() {
43 log.info("************************ testResolveNodeTemplateProperties **********************")
45 val bluePrintRuntimeService = getBluePrintRuntimeService()
47 val inputDataPath = "src/test/resources/data/default-context.json"
49 val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath)
50 bluePrintRuntimeService.assignInputs(inputNode)
52 val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
53 .resolveNodeTemplateProperties("activate-process")
55 assertNotNull(propContext, "Failed to populate interface property values")
59 fun `test resolve NodeTemplate Capability Properties`() {
60 log.info("************************ testResolveNodeTemplateRequirementProperties **********************")
61 val bluePrintRuntimeService = getBluePrintRuntimeService()
63 val executionContext = bluePrintRuntimeService.getExecutionContext()
65 BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),
66 "data/default-context.json", executionContext)
68 val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties("sample-netconf-device",
70 assertNotNull(capProperties, "Failed to populate capability property values")
71 assertEquals(capProperties["target-ip-address"], JacksonUtils.jsonNodeFromObject("localhost"), "Failed to populate parameter target-ip-address")
72 assertEquals(capProperties["port-number"], JacksonUtils.jsonNodeFromObject(830), "Failed to populate parameter port-number")
76 fun `test Resolve NodeTemplate Interface Operation Inputs`() {
77 log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
79 val bluePrintRuntimeService = getBluePrintRuntimeService()
81 val executionContext = bluePrintRuntimeService.getExecutionContext()
83 BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),
84 "data/default-context.json", executionContext)
86 val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
87 .resolveNodeTemplateInterfaceOperationInputs("resource-assignment",
88 "ResourceResolutionComponent", "process")
90 assertNotNull(inContext, "Failed to populate interface input property values")
91 assertEquals(inContext["action-name"], JacksonUtils.jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
92 assertEquals(inContext["request-id"], JacksonUtils.jsonNodeFromObject("12345"), "Failed to populate parameter action-name")
96 fun `test Resolve NodeTemplate Interface Operation Outputs`() {
97 log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
99 val bluePrintRuntimeService = getBluePrintRuntimeService()
101 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance())
103 bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment",
104 "ResourceResolutionComponent", "process")
106 val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
107 "ResourceResolutionComponent", "process", "status")
108 assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")
110 val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
111 "ResourceResolutionComponent", "process", "resource-assignment-params")
112 assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params")
117 fun `test NodeTemplate Context Property`() {
118 log.info("************************ testNodeTemplateContextProperty **********************")
119 val bluePrintRuntimeService = getBluePrintRuntimeService()
121 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context1",
122 JacksonUtils.jsonNodeFromObject("context1-value"))
123 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context2",
124 JacksonUtils.jsonNodeFromObject("context2-value"))
126 val keys = listOf("context1", "context2")
128 val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
129 assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
130 log.info("JSON Prepared Value Context {}", jsonValueNode)
134 private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
135 val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
136 val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
137 val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
139 assertEquals(blueprintBasePath.asJsonPrimitive(), checkBasePath, "Failed to get base path after runtime creation")
141 return blueprintRuntime