2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.ccsdk.apps.controllerblueprints.core.service
\r
19 import com.fasterxml.jackson.databind.JsonNode
\r
20 import com.fasterxml.jackson.databind.node.NullNode
\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 org.slf4j.Logger
\r
29 import org.slf4j.LoggerFactory
\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 logger: Logger = LoggerFactory.getLogger(this::class.toString())
\r
40 val basepath = "load/blueprints"
\r
49 fun testResolveNodeTemplateProperties() {
\r
50 logger.info("************************ testResolveNodeTemplateProperties **********************")
\r
51 val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!
\r
52 .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)
\r
54 val context: MutableMap<String, Any> = hashMapOf()
\r
55 context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")
\r
56 val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)
\r
58 val inputDataPath = "src/test/resources/data/default-context.json"
\r
60 val inputNode: JsonNode = jsonNodeFromFile(inputDataPath)
\r
61 bluePrintRuntimeService.assignInputs(inputNode)
\r
63 val propContext: MutableMap<String, Any?> = bluePrintRuntimeService.resolveNodeTemplateProperties("activate-process")
\r
64 logger.info("Context {}" ,bluePrintRuntimeService.context)
\r
66 assertNotNull(propContext, "Failed to populate interface property values")
\r
67 assertEquals(propContext.get("process-name"), jsonNodeFromObject("sample-action"), "Failed to populate parameter process-name")
\r
68 assertEquals(propContext.get("version"), jsonNodeFromObject("sample-action"), "Failed to populate parameter version")
\r
72 fun testResolveNodeTemplateInterfaceOperationInputs() {
\r
73 logger.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
\r
74 val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!
\r
75 .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)
\r
76 assertNotNull(bluePrintContext, "Failed to populate Blueprint context")
\r
78 val context: MutableMap<String, Any> = hashMapOf()
\r
79 context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")
\r
81 val inputDataPath = "src/test/resources/data/default-context.json"
\r
82 BluePrintRuntimeUtils.assignInputsFromFile(bluePrintContext, inputDataPath, context)
\r
85 val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)
\r
87 logger.info("Prepared Context {}" ,context)
\r
89 val inContext: MutableMap<String, Any?> = bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationInputs("resource-assignment",
\r
90 "DefaultComponentNode", "process")
\r
92 logger.trace("In Context {}" ,inContext)
\r
94 assertNotNull(inContext, "Failed to populate interface input property values")
\r
95 assertEquals(inContext.get("action-name"), jsonNodeFromObject("sample-action"), "Failed to populate parameter action-name")
\r
96 assertEquals(inContext.get("request-id"), jsonNodeFromObject("12345"), "Failed to populate parameter action-name")
\r
97 assertEquals(inContext.get("template-content"), jsonNodeFromObject("This is Sample Velocity Template"), "Failed to populate parameter action-name")
\r
102 fun testResolveNodeTemplateInterfaceOperationOutputs() {
\r
103 logger.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
\r
104 val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!
\r
105 .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)
\r
106 assertNotNull(bluePrintContext, "Failed to populate Blueprint context")
\r
108 val context: MutableMap<String, Any> = hashMapOf()
\r
109 context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")
\r
111 val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)
\r
113 val componentContext: MutableMap<String, Any?> = hashMapOf()
\r
114 val successValue : JsonNode= jsonNodeFromObject("Success")
\r
115 componentContext["resource-assignment.DefaultComponentNode.process.status"] = successValue
\r
116 componentContext["resource-assignment.DefaultComponentNode.process.resource-assignment-params"] = null
\r
118 bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment",
\r
119 "DefaultComponentNode", "process", componentContext)
\r
121 assertEquals(NullNode.instance,
\r
122 context.get("node_templates/resource-assignment/interfaces/DefaultComponentNode/operations/process/properties/resource-assignment-params"),
\r
123 "Failed to get operation property resource-assignment-params")
\r
125 assertEquals(successValue,
\r
126 context.get("node_templates/resource-assignment/interfaces/DefaultComponentNode/operations/process/properties/status"),
\r
127 "Failed to get operation property status")
\r