2 * Copyright © 2018 IBM.
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.restconf.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.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.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 import kotlin.test.assertNotNull
39 class ComponentRestconfExecutorTest {
42 fun `test Restconf Component Instance`() {
45 val applicationContext = mockk<ApplicationContext>()
46 every { applicationContext.getBean(any()) } returns mockk()
47 val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext, mockk())
48 val componentScriptExecutor = ComponentScriptExecutor(componentFunctionScriptingService)
50 assertNotNull(componentScriptExecutor, "failed to get ComponentRestconfExecutor instance")
51 val executionServiceInput = ExecutionServiceInput().apply {
52 commonHeader = CommonHeader().apply {
55 actionIdentifiers = ActionIdentifiers().apply {
56 actionName = "activate"
58 payload = JacksonUtils.jsonNode("{}") as ObjectNode
60 val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
61 componentScriptExecutor.bluePrintRuntimeService = bluePrintRuntime
62 componentScriptExecutor.stepName = "sample-step"
64 val operationInputs = hashMapOf<String, JsonNode>()
65 operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-restconf".asJsonPrimitive()
66 operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
67 operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
68 operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
69 operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE] =
70 "internal.scripts.TestRestconfConfigure".asJsonPrimitive()
72 val stepInputData = StepData().apply {
73 name = "activate-restconf"
74 properties = operationInputs
76 executionServiceInput.stepData = stepInputData
78 val blueprintContext = mockk<BluePrintContext>()
79 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
81 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs("activate-restconf",
82 "interfaceName", "operationName")
83 } returns operationInputs
85 val operationOutputs = hashMapOf<String, JsonNode>()
87 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs("activate-restconf",
88 "interfaceName", "operationName")
89 } returns operationOutputs
91 componentScriptExecutor.applyNB(executionServiceInput)