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.ArrayNode
21 import com.fasterxml.jackson.databind.node.ObjectNode
24 import kotlinx.coroutines.runBlocking
26 import org.junit.runner.RunWith
27 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
29 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
30 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
31 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
32 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
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.service.BluePrintContext
38 import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService
39 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
40 import org.onap.ccsdk.cds.controllerblueprints.scripts.BluePrintScriptsServiceImpl
41 import org.springframework.beans.factory.annotation.Autowired
42 import org.springframework.test.annotation.DirtiesContext
43 import org.springframework.test.context.ContextConfiguration
44 import org.springframework.test.context.TestPropertySource
45 import org.springframework.test.context.junit4.SpringRunner
46 import kotlin.test.assertNotNull
48 @RunWith(SpringRunner::class)
49 @ContextConfiguration(classes = [CliExecutorConfiguration::class,
50 ExecutionServiceConfiguration::class,
51 BluePrintSshLibConfiguration::class, BluePrintScriptsServiceImpl::class,
52 BlueprintPropertyConfiguration::class, BluePrintProperties::class])
54 @TestPropertySource(properties = [], locations = ["classpath:application-test.properties"])
55 class ComponentCliExecutorTest {
58 lateinit var componentCliExecutor: ComponentCliExecutor
61 fun `test CLI Component Instance`() {
63 assertNotNull(componentCliExecutor, "failed to get ComponentCliExecutor instance")
64 val executionServiceInput = ExecutionServiceInput().apply {
65 commonHeader = CommonHeader().apply {
68 actionIdentifiers = ActionIdentifiers().apply {
69 actionName = "activate"
71 payload = JacksonUtils.jsonNode("{}") as ObjectNode
73 val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
74 componentCliExecutor.bluePrintRuntimeService = bluePrintRuntime
75 componentCliExecutor.stepName = "sample-step"
77 val operationInputs = hashMapOf<String, JsonNode>()
78 operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-cli".asJsonPrimitive()
79 operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
80 operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
81 operationInputs[ComponentCliExecutor.SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
82 operationInputs[ComponentCliExecutor.SCRIPT_CLASS_REFERENCE] =
83 "InternalSimpleCli_cba\$TestCliScriptFunction".asJsonPrimitive()
84 operationInputs[ComponentCliExecutor.INSTANCE_DEPENDENCIES] = JacksonUtils.jsonNode("[]") as ArrayNode
86 val stepInputData = StepData().apply {
88 properties = operationInputs
90 executionServiceInput.stepData = stepInputData
92 val blueprintContext = mockk<BluePrintContext>()
93 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
95 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs("activate-cli",
96 "interfaceName", "operationName")
97 } returns operationInputs
99 val operationOutputs = hashMapOf<String, JsonNode>()
101 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs("activate-cli",
102 "interfaceName", "operationName")
103 } returns operationOutputs
105 componentCliExecutor.applyNB(executionServiceInput)