Controller Blueprints Microservice
[ccsdk/cds.git] / components / core / src / test / kotlin / org / onap / ccsdk / apps / controllerblueprints / core / service / BluePrintRuntimeServiceTest.kt
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  *\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
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 package org.onap.ccsdk.apps.controllerblueprints.core.service\r
18 \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 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
32 \r
33 /**\r
34  *\r
35  *\r
36  * @author Brinda Santh\r
37  */\r
38 class BluePrintRuntimeServiceTest {\r
39     private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())\r
40     val basepath = "load/blueprints"\r
41 \r
42 \r
43     @Before\r
44     fun setUp(): Unit {\r
45 \r
46     }\r
47 \r
48     @Test\r
49     fun testResolveNodeTemplateProperties() {\r
50         log.info("************************ testResolveNodeTemplateProperties **********************")\r
51         val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!\r
52                 .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)\r
53 \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
57 \r
58         val inputDataPath = "src/test/resources/data/default-context.json"\r
59 \r
60         val inputNode: JsonNode = jsonNodeFromFile(inputDataPath)\r
61         bluePrintRuntimeService.assignInputs(inputNode)\r
62 \r
63         val propContext: MutableMap<String, Any?> = bluePrintRuntimeService.resolveNodeTemplateProperties("resource-assignment-action")\r
64         log.info("Context {}", bluePrintRuntimeService.context)\r
65 \r
66         assertNotNull(propContext, "Failed to populate interface property values")\r
67         assertEquals(propContext.get("mode"), jsonNodeFromObject("sync"), "Failed to populate parameter process-name")\r
68         assertEquals(propContext.get("version"), jsonNodeFromObject("1.0.0"), "Failed to populate parameter version")\r
69     }\r
70 \r
71     @Test\r
72     fun testResolveNodeTemplateInterfaceOperationInputs() {\r
73         log.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
77 \r
78         val context: MutableMap<String, Any> = hashMapOf()\r
79         context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")\r
80 \r
81         val inputDataPath = "src/test/resources/data/default-context.json"\r
82         BluePrintRuntimeUtils.assignInputsFromFile(bluePrintContext, inputDataPath, context)\r
83 \r
84 \r
85         val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)\r
86 \r
87         log.info("Prepared Context {}", context)\r
88 \r
89         val inContext: MutableMap<String, Any?> = bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationInputs("resource-assignment-ra-component",\r
90                 "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process")\r
91 \r
92         log.info("In Context {}", inContext)\r
93 \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     }\r
98 \r
99     @Test\r
100     fun testResolveNodeTemplateInterfaceOperationOutputs() {\r
101         log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")\r
102         val bluePrintContext: BluePrintContext = BluePrintParserFactory.instance(BluePrintConstants.TYPE_DEFAULT)!!\r
103                 .readBlueprintFile("baseconfiguration/Definitions/activation-blueprint.json", basepath)\r
104         assertNotNull(bluePrintContext, "Failed to populate Blueprint context")\r
105 \r
106         val context: MutableMap<String, Any> = hashMapOf()\r
107         context[BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH] = basepath.plus("/simple-baseconfig")\r
108 \r
109         val bluePrintRuntimeService = BluePrintRuntimeService(bluePrintContext, context)\r
110 \r
111         val componentContext: MutableMap<String, Any?> = hashMapOf()\r
112         val successValue: JsonNode = jsonNodeFromObject("Success")\r
113         componentContext["resource-assignment-ra-component.org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode.process.status"] = successValue\r
114         componentContext["resource-assignment-ra-component.org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode.process.resource-assignment-params"] = null\r
115 \r
116         bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment-ra-component",\r
117                 "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode", "process", componentContext)\r
118 \r
119         assertEquals(NullNode.instance,\r
120                 context.get("node_templates/resource-assignment-ra-component/interfaces/org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode/operations/process/properties/resource-assignment-params"),\r
121                 "Failed to get operation property resource-assignment-params")\r
122 \r
123         assertEquals(successValue,\r
124                 context.get("node_templates/resource-assignment-ra-component/interfaces/org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode/operations/process/properties/status"),\r
125                 "Failed to get operation property status")\r
126 \r
127 \r
128     }\r
129 }