2 * Copyright © 2019 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.cli.executor
19 import com.fasterxml.jackson.databind.JsonNode
20 import com.fasterxml.jackson.databind.node.ObjectNode
23 import kotlinx.coroutines.runBlocking
25 import org.junit.runner.RunWith
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService
27 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
29 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
30 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
31 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
32 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor
33 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ExecutionServiceConfiguration
34 import org.onap.ccsdk.cds.blueprintsprocessor.ssh.BluePrintSshLibConfiguration
35 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
36 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
37 import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl
38 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
39 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
40 import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
41 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
42 import org.springframework.beans.factory.annotation.Autowired
43 import org.springframework.test.annotation.DirtiesContext
44 import org.springframework.test.context.ContextConfiguration
45 import org.springframework.test.context.TestPropertySource
46 import org.springframework.test.context.junit4.SpringRunner
47 import kotlin.test.assertNotNull
49 @RunWith(SpringRunner::class)
50 @ContextConfiguration(
51 classes = [CliExecutorConfiguration::class,
52 ExecutionServiceConfiguration::class,
53 BluePrintSshLibConfiguration::class, BluePrintScriptsServiceImpl::class,
54 BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDependencyService::class]
57 @TestPropertySource(properties = [], locations = ["classpath:application-test.properties"])
58 class ComponentCliExecutorTest {
61 lateinit var componentScriptExecutor: ComponentScriptExecutor
64 fun `test CLI Component Instance`() {
66 assertNotNull(componentScriptExecutor, "failed to get ComponentCliExecutor instance")
67 val executionServiceInput = ExecutionServiceInput().apply {
68 commonHeader = CommonHeader().apply {
71 actionIdentifiers = ActionIdentifiers().apply {
72 actionName = "activate"
74 payload = JacksonUtils.jsonNode("{}") as ObjectNode
76 val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
77 componentScriptExecutor.bluePrintRuntimeService = bluePrintRuntime
78 componentScriptExecutor.stepName = "sample-step"
80 val operationInputs = hashMapOf<String, JsonNode>()
81 operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-cli".asJsonPrimitive()
82 operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
83 operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
84 operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
85 operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE] =
86 "internal.scripts.TestCliScriptFunction".asJsonPrimitive()
88 val stepInputData = StepData().apply {
90 properties = operationInputs
92 executionServiceInput.stepData = stepInputData
94 val blueprintContext = mockk<BluePrintContext>()
95 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
97 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs(
99 "interfaceName", "operationName"
101 } returns operationInputs
103 val operationOutputs = hashMapOf<String, JsonNode>()
105 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs(
107 "interfaceName", "operationName"
109 } returns operationOutputs
111 componentScriptExecutor.applyNB(executionServiceInput)