7a178758addd6af7d10e29e404fd41a3169ab423
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2018 IBM.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 package org.onap.ccsdk.apps.controllerblueprints.core.service
19
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
24 import org.junit.Test
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
32
33 /**
34  *
35  *
36  * @author Brinda Santh
37  */
38 class BluePrintRuntimeServiceTest {
39     private val log: EELFLogger = EELFManager.getInstance().getLogger(this::class.toString())
40
41     @Test
42     fun `test Resolve NodeTemplate Properties`() {
43         log.info("************************ testResolveNodeTemplateProperties **********************")
44
45         val bluePrintRuntimeService = getBluePrintRuntimeService()
46
47         val inputDataPath = "src/test/resources/data/default-context.json"
48
49         val inputNode: JsonNode = JacksonUtils.jsonNodeFromFile(inputDataPath)
50         bluePrintRuntimeService.assignInputs(inputNode)
51
52         val propContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
53                 .resolveNodeTemplateProperties("activate-process")
54
55         assertNotNull(propContext, "Failed to populate interface property values")
56     }
57
58     @Test
59     fun `test resolve NodeTemplate Capability Properties`() {
60         log.info("************************ testResolveNodeTemplateRequirementProperties **********************")
61         val bluePrintRuntimeService = getBluePrintRuntimeService()
62
63         val executionContext = bluePrintRuntimeService.getExecutionContext()
64
65         BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),
66                 "data/default-context.json", executionContext)
67
68         val capProperties = bluePrintRuntimeService.resolveNodeTemplateCapabilityProperties("sample-netconf-device",
69                 "netconf")
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")
73     }
74
75     @Test
76     fun `test Resolve NodeTemplate Interface Operation Inputs`() {
77         log.info("************************ testResolveNodeTemplateInterfaceOperationInputs **********************")
78
79         val bluePrintRuntimeService = getBluePrintRuntimeService()
80
81         val executionContext = bluePrintRuntimeService.getExecutionContext()
82
83         BluePrintRuntimeUtils.assignInputsFromClassPathFile(bluePrintRuntimeService.bluePrintContext(),
84                 "data/default-context.json", executionContext)
85
86         val inContext: MutableMap<String, JsonNode> = bluePrintRuntimeService
87                 .resolveNodeTemplateInterfaceOperationInputs("resource-assignment",
88                         "ResourceAssignmentComponent", "process")
89
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")
93     }
94
95     @Test
96     fun `test Resolve NodeTemplate Interface Operation Outputs`() {
97         log.info("************************ testResolveNodeTemplateInterfaceOperationOutputs **********************")
98
99         val bluePrintRuntimeService = getBluePrintRuntimeService()
100
101         bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", NullNode.getInstance())
102
103         bluePrintRuntimeService.resolveNodeTemplateInterfaceOperationOutputs("resource-assignment",
104                 "ResourceAssignmentComponent", "process")
105
106         val outputStatus = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
107                 "ResourceAssignmentComponent", "process", "status")
108         assertEquals("success".asJsonPrimitive(), outputStatus, "Failed to get operation property status")
109
110         val outputParams = bluePrintRuntimeService.getNodeTemplateOperationOutputValue("resource-assignment",
111                 "ResourceAssignmentComponent", "process", "resource-assignment-params")
112         assertEquals(NullNode.getInstance(), outputParams, "Failed to get operation property resource-assignment-params")
113
114     }
115
116     @Test
117     fun `test NodeTemplate Context Property`() {
118         log.info("************************ testNodeTemplateContextProperty **********************")
119         val bluePrintRuntimeService = getBluePrintRuntimeService()
120
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"))
125
126         val keys = listOf("context1", "context2")
127
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)
131
132     }
133
134     private fun getBluePrintRuntimeService(): BluePrintRuntimeService<MutableMap<String, JsonNode>> {
135         val blueprintBasePath: String = ("./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
136         val blueprintRuntime = BluePrintMetadataUtils.getBluePrintRuntime("1234", blueprintBasePath)
137         val checkBasePath = blueprintRuntime.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)
138
139         assertEquals(blueprintBasePath.asJsonPrimitive(), checkBasePath, "Failed to get base path after runtime creation")
140
141         return blueprintRuntime
142     }
143
144 }