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.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
40 class ComponentRestconfExecutorTest {
43 fun `test Restconf Component Instance`() {
46 val applicationContext = mockk<ApplicationContext>()
47 every { applicationContext.getBean(any()) } returns mockk()
48 val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext, mockk())
49 val componentScriptExecutor = ComponentScriptExecutor(componentFunctionScriptingService)
51 assertNotNull(componentScriptExecutor, "failed to get ComponentRestconfExecutor instance")
52 val executionServiceInput = ExecutionServiceInput().apply {
53 commonHeader = CommonHeader().apply {
56 actionIdentifiers = ActionIdentifiers().apply {
57 actionName = "activate"
59 payload = JacksonUtils.jsonNode("{}") as ObjectNode
62 val blueprintContext = mockk<BluePrintContext>()
64 blueprintContext.nodeTemplateOperationImplementation(
67 } returns Implementation()
69 val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
70 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
72 componentScriptExecutor.bluePrintRuntimeService = bluePrintRuntime
73 componentScriptExecutor.stepName = "sample-step"
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()
84 val stepInputData = StepData().apply {
85 name = "activate-restconf"
86 properties = operationInputs
88 executionServiceInput.stepData = stepInputData
91 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs(
93 "interfaceName", "operationName"
95 } returns operationInputs
97 val operationOutputs = hashMapOf<String, JsonNode>()
99 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs(
101 "interfaceName", "operationName"
103 } returns operationOutputs
105 componentScriptExecutor.applyNB(executionServiceInput)