Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / restconf-executor / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / restconf / executor / ComponentRestconfExecutorTest.kt
1 /*
2  *  Copyright © 2018 IBM.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.restconf.executor
18
19 import com.fasterxml.jackson.databind.JsonNode
20 import com.fasterxml.jackson.databind.node.ObjectNode
21 import io.mockk.every
22 import io.mockk.mockk
23 import kotlinx.coroutines.runBlocking
24 import org.junit.Test
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
27 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
29 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
30 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor
31 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants
32 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
33 import org.onap.ccsdk.cds.controllerblueprints.core.data.Implementation
34 import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintContext
35 import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBlueprintRuntimeService
36 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
37 import org.springframework.context.ApplicationContext
38 import kotlin.test.assertNotNull
39
40 class ComponentRestconfExecutorTest {
41
42     @Test
43     fun `test Restconf Component Instance`() {
44         runBlocking {
45
46             val applicationContext = mockk<ApplicationContext>()
47             every { applicationContext.getBean(any()) } returns mockk()
48             val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext, mockk())
49             val componentScriptExecutor = ComponentScriptExecutor(componentFunctionScriptingService)
50
51             assertNotNull(componentScriptExecutor, "failed to get ComponentRestconfExecutor instance")
52             val executionServiceInput = ExecutionServiceInput().apply {
53                 commonHeader = CommonHeader().apply {
54                     requestId = "1234"
55                 }
56                 actionIdentifiers = ActionIdentifiers().apply {
57                     actionName = "activate"
58                 }
59                 payload = JacksonUtils.jsonNode("{}") as ObjectNode
60             }
61
62             val blueprintContext = mockk<BlueprintContext>()
63             every {
64                 blueprintContext.nodeTemplateOperationImplementation(
65                     any(), any(), any()
66                 )
67             } returns Implementation()
68
69             val bluePrintRuntime = mockk<DefaultBlueprintRuntimeService>("1234")
70             every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
71
72             componentScriptExecutor.bluePrintRuntimeService = bluePrintRuntime
73             componentScriptExecutor.stepName = "sample-step"
74
75             val operationInputs = hashMapOf<String, JsonNode>()
76             operationInputs[BlueprintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-restconf".asJsonPrimitive()
77             operationInputs[BlueprintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
78             operationInputs[BlueprintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
79             operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_TYPE] =
80                 BlueprintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
81             operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE] =
82                 "internal.scripts.TestRestconfConfigure".asJsonPrimitive()
83
84             val stepInputData = StepData().apply {
85                 name = "activate-restconf"
86                 properties = operationInputs
87             }
88             executionServiceInput.stepData = stepInputData
89
90             every {
91                 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs(
92                     "activate-restconf",
93                     "interfaceName", "operationName"
94                 )
95             } returns operationInputs
96
97             val operationOutputs = hashMapOf<String, JsonNode>()
98             every {
99                 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs(
100                     "activate-restconf",
101                     "interfaceName", "operationName"
102                 )
103             } returns operationOutputs
104
105             componentScriptExecutor.applyNB(executionServiceInput)
106         }
107     }
108 }