2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
3 * Modifications Copyright © 2018 IBM.
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
18 package org.onap.ccsdk.apps.controllerblueprints.core.service
\r
20 import com.fasterxml.jackson.databind.JsonNode
\r
21 import org.junit.Before
\r
22 import org.junit.Test
\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
\r
24 import org.onap.ccsdk.apps.controllerblueprints.core.factory.BluePrintParserFactory
\r
25 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintRuntimeUtils
\r
26 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils.jsonNodeFromFile
\r
27 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils.jsonNodeFromObject
\r
28 import com.att.eelf.configuration.EELFLogger
\r
29 import com.att.eelf.configuration.EELFManager
\r
30 import kotlin.test.assertEquals
\r
31 import kotlin.test.assertNotNull
\r
36 * @author Brinda Santh
\r
38 class BluePrintRuntimeServiceTest {
\r
39 private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
\r
40 val basepath = "load/blueprints"
\r
49 fun testResolveNodeTemplateProperties() {
\r
50 log.info("************************ testResolveNodeTemplateProperties **********************")
\r
52 val bluePrintRuntimeService = getBluePrintRuntimeService()
\r
54 val inputDataPath = "src/test/resources/data/default-context.json"
\r
56 val inputNode: JsonNode = jsonNodeFromFile(inputDataPath)
\r
57 bluePrintRuntimeService.assignInputs(inputNode)
\r
59 val propContext: MutableMap<String, Any?> = bluePrintRuntimeService.resolveNodeTemplateProperties("resource-assignment-action")
\r
60 log.info("Context {}", bluePrintRuntimeService.context)
\r
62 assertNotNull(propContext, "Failed to populate interface property values")
\r
63 assertEquals(propContext.get("mode"), jsonNodeFromObject("sync"), "Failed to populate parameter process-name")
\r
64 assertEquals(propContext.get("version"), jsonNodeFromObject("1.0.0"), "Failed to populate parameter version")
\r
68 fun testResolveNodeTemplateInterfaceOperationInputs() {
\r
69 log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
\r
70 val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!
\r
71 .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)
\r
72 assertNotNull(bluePrintContext, "Failed to populate Blueprint context")
\r
74 val context: MutableMap<String, Any> = hashMapOf()
\r
75 context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")
\r
77 val inputDataPath = "src/test/resources/data/default-context.json"
\r
78 BluePrintRuntimeUtils.assignInputsFromFile(bluePrintContext, inputDataPath, context)
\r
81 val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)
\r
83 log.info("Prepared Context {}", context)
\r
85 val inContext: MutableMap<String, Any?> = bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationInputs("resource-assignment-ra-component",
\r
86 "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process")
\r
88 log.info("In Context {}", inContext)
\r
90 assertNotNull(inContext, "Failed to populate interface input property values")
\r
91 assertEquals(inContext.get("action-name"), jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
\r
92 assertEquals(inContext.get("request-id"), jsonNodeFromObject("12345"), "Failed to populate parameter action-name")
\r
96 fun testResolveNodeTemplateInterfaceOperationOutputs() {
\r
97 log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
\r
99 val bluePrintRuntimeService = getBluePrintRuntimeService()
\r
101 val successValue: JsonNode = jsonNodeFromObject("Success")
\r
102 val paramValue: JsonNode = jsonNodeFromObject("param-content")
\r
104 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "params", paramValue)
\r
106 bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment-ra-component",
\r
107 "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process")
\r
109 val resourceAssignmentParamsNode = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment-ra-component",
\r
110 "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process", "resource-assignment-params")
\r
112 val statusNode = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment-ra-component",
\r
113 "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process", "status")
\r
115 assertEquals(paramValue, resourceAssignmentParamsNode, "Failed to get operation property resource-assignment-params")
\r
117 assertEquals(successValue, statusNode, "Failed to get operation property status")
\r
123 fun testNodeTemplateContextProperty() {
\r
124 log.info("************************ testNodeTemplateContextProperty **********************")
\r
125 val bluePrintRuntimeService = getBluePrintRuntimeService()
\r
127 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context1",
\r
128 jsonNodeFromObject("context1-value"))
\r
129 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment-ra-component", "context2",
\r
130 jsonNodeFromObject("context2-value"))
\r
132 log.info("Context {}", bluePrintRuntimeService.context)
\r
134 val keys = listOf("context1", "context2")
\r
136 val jsonValueNode = bluePrintRuntimeService.getJsonForNodeTemplateAttributeProperties("resource-assignment-ra-component", keys)
\r
137 assertNotNull(jsonValueNode, "Failed to get Json for Node Template Context Properties")
\r
138 log.info("JSON Prepared Value Context {}", jsonValueNode)
\r
142 private fun getBluePrintRuntimeService(): BluePrintRuntimeService {
\r
143 val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!
\r
144 .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)
\r
145 assertNotNull(bluePrintContext, "Failed to populate Blueprint context")
\r
147 val context: MutableMap<String, Any> = hashMapOf()
\r
148 context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")
\r
150 return BluePrintRuntimeService(bluePrintContext, context)
\r