2 * Copyright © 2020 Huawei Intellectual Property.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.restful.executor
19 import com.fasterxml.jackson.databind.JsonNode
20 import com.fasterxml.jackson.databind.node.ObjectNode
23 import kotlinx.coroutines.runBlocking
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
38 class ComponentRestfulExecutorTest {
41 fun testComponentRestfulExecutor() {
44 val applicationContext = mockk<ApplicationContext>()
45 every { applicationContext.getBean(any()) } returns mockk()
47 val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext, mockk())
49 val componentRestfulExecutor = ComponentRestfulExecutor(componentFunctionScriptingService)
51 val executionServiceInput = ExecutionServiceInput().apply {
52 commonHeader = CommonHeader().apply {
55 actionIdentifiers = ActionIdentifiers().apply {
56 actionName = "config-deploy"
58 payload = JacksonUtils.jsonNode("{}") as ObjectNode
61 val blueprintContext = mockk<BlueprintContext>()
63 blueprintContext.nodeTemplateOperationImplementation(
66 } returns Implementation()
68 val bluePrintRuntime = mockk<DefaultBlueprintRuntimeService>("1234")
69 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
71 componentRestfulExecutor.bluePrintRuntimeService = bluePrintRuntime
72 componentRestfulExecutor.stepName = "sample-step"
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()
81 val stepInputData = StepData().apply {
82 name = "call-config-deploy-process"
83 properties = operationInputs
85 executionServiceInput.stepData = stepInputData
88 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs(
89 "config-deploy-process",
90 "interfaceName", "operationName"
92 } returns operationInputs
94 val operationOutputs = hashMapOf<String, JsonNode>()
96 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs(
97 "config-deploy-process",
98 "interfaceName", "operationName"
100 } returns operationOutputs
102 componentRestfulExecutor.applyNB(executionServiceInput)