Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / restful-executor / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / restful / executor / ComponentRestfulExecutorTest.kt
1 /*
2  * Copyright © 2020 Huawei Intellectual Property.
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.restful.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.controllerblueprints.core.BlueprintConstants
31 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
32 import org.onap.ccsdk.cds.controllerblueprints.core.data.Implementation
33 import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintContext
34 import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBlueprintRuntimeService
35 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
36 import org.springframework.context.ApplicationContext
37
38 class ComponentRestfulExecutorTest {
39
40     @Test
41     fun testComponentRestfulExecutor() {
42         runBlocking {
43
44             val applicationContext = mockk<ApplicationContext>()
45             every { applicationContext.getBean(any()) } returns mockk()
46
47             val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext, mockk())
48
49             val componentRestfulExecutor = ComponentRestfulExecutor(componentFunctionScriptingService)
50
51             val executionServiceInput = ExecutionServiceInput().apply {
52                 commonHeader = CommonHeader().apply {
53                     requestId = "1234"
54                 }
55                 actionIdentifiers = ActionIdentifiers().apply {
56                     actionName = "config-deploy"
57                 }
58                 payload = JacksonUtils.jsonNode("{}") as ObjectNode
59             }
60
61             val blueprintContext = mockk<BlueprintContext>()
62             every {
63                 blueprintContext.nodeTemplateOperationImplementation(
64                     any(), any(), any()
65                 )
66             } returns Implementation()
67
68             val bluePrintRuntime = mockk<DefaultBlueprintRuntimeService>("1234")
69             every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
70
71             componentRestfulExecutor.bluePrintRuntimeService = bluePrintRuntime
72             componentRestfulExecutor.stepName = "sample-step"
73
74             val operationInputs = hashMapOf<String, JsonNode>()
75             operationInputs[BlueprintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "config-deploy-process".asJsonPrimitive()
76             operationInputs[BlueprintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
77             operationInputs[BlueprintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
78             operationInputs["script-type"] = BlueprintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
79             operationInputs["script-class-reference"] = "internal.scripts.TestRestfulConfigure".asJsonPrimitive()
80
81             val stepInputData = StepData().apply {
82                 name = "call-config-deploy-process"
83                 properties = operationInputs
84             }
85             executionServiceInput.stepData = stepInputData
86
87             every {
88                 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs(
89                     "config-deploy-process",
90                     "interfaceName", "operationName"
91                 )
92             } returns operationInputs
93
94             val operationOutputs = hashMapOf<String, JsonNode>()
95             every {
96                 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs(
97                     "config-deploy-process",
98                     "interfaceName", "operationName"
99                 )
100             } returns operationOutputs
101
102             componentRestfulExecutor.applyNB(executionServiceInput)
103         }
104     }
105 }