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.data.Implementation
38 import org.onap.ccsdk.cds.controllerblueprints.core.scripts.BluePrintScriptsServiceImpl
39 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
40 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
41 import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
42 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
43 import org.springframework.beans.factory.annotation.Autowired
44 import org.springframework.test.annotation.DirtiesContext
45 import org.springframework.test.context.ContextConfiguration
46 import org.springframework.test.context.TestPropertySource
47 import org.springframework.test.context.junit4.SpringRunner
48 import kotlin.test.assertNotNull
50 @RunWith(SpringRunner::class)
51 @ContextConfiguration(
53 CliExecutorConfiguration::class,
54 ExecutionServiceConfiguration::class,
55 BluePrintSshLibConfiguration::class, BluePrintScriptsServiceImpl::class,
56 BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, BluePrintDependencyService::class
60 @TestPropertySource(properties = [], locations = ["classpath:application-test.properties"])
61 class ComponentCliExecutorTest {
64 lateinit var componentScriptExecutor: ComponentScriptExecutor
67 fun `test CLI Component Instance`() {
69 assertNotNull(componentScriptExecutor, "failed to get ComponentCliExecutor instance")
70 val executionServiceInput = ExecutionServiceInput().apply {
71 commonHeader = CommonHeader().apply {
74 actionIdentifiers = ActionIdentifiers().apply {
75 actionName = "activate"
77 payload = JacksonUtils.jsonNode("{}") as ObjectNode
79 val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
80 componentScriptExecutor.bluePrintRuntimeService = bluePrintRuntime
81 componentScriptExecutor.stepName = "sample-step"
83 val operationInputs = hashMapOf<String, JsonNode>()
84 operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-cli".asJsonPrimitive()
85 operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
86 operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
87 operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
88 operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE] =
89 "internal.scripts.TestCliScriptFunction".asJsonPrimitive()
91 val stepInputData = StepData().apply {
93 properties = operationInputs
95 executionServiceInput.stepData = stepInputData
97 val blueprintContext = mockk<BluePrintContext>()
99 blueprintContext.nodeTemplateOperationImplementation(
102 } returns Implementation()
104 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
106 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs(
108 "interfaceName", "operationName"
110 } returns operationInputs
112 val operationOutputs = hashMapOf<String, JsonNode>()
114 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs(
116 "interfaceName", "operationName"
118 } returns operationOutputs
120 componentScriptExecutor.applyNB(executionServiceInput)