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.junit.runner.RunWith
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
27 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
29 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
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.beans.factory.annotation.Autowired
37 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
38 import org.springframework.context.annotation.ComponentScan
39 import org.springframework.test.annotation.DirtiesContext
40 import org.springframework.test.context.TestPropertySource
41 import org.springframework.test.context.junit4.SpringRunner
42 import kotlin.test.assertNotNull
44 @RunWith(SpringRunner::class)
45 @EnableAutoConfiguration
46 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
48 @TestPropertySource(properties =
50 "blueprintsprocessor.restconfEnabled=true",
51 "blueprintsprocessor.restclient.odlPrimary.type=basic-auth",
52 "blueprintsprocessor.restclient.odlPrimary.url=http://127.0.0.1:9111",
53 "blueprintsprocessor.restclient.odlPrimary.userId=sampleuser",
54 "blueprintsprocessor.restclient.odlPrimary.token=sampletoken"],
55 locations = ["classpath:application-test.properties"])
56 class ComponentRestconfExecutorTest {
59 lateinit var componentScriptExecutor: ComponentScriptExecutor
62 fun `test Restconf Component Instance`() {
64 assertNotNull(componentScriptExecutor, "failed to get ComponentRestconfExecutor instance")
65 val executionServiceInput = ExecutionServiceInput().apply {
66 commonHeader = CommonHeader().apply {
69 actionIdentifiers = ActionIdentifiers().apply {
70 actionName = "activate"
72 payload = JacksonUtils.jsonNode("{}") as ObjectNode
74 val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
75 componentScriptExecutor.bluePrintRuntimeService = bluePrintRuntime
76 componentScriptExecutor.stepName = "sample-step"
78 val operationInputs = hashMapOf<String, JsonNode>()
79 operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-restconf".asJsonPrimitive()
80 operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
81 operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
82 operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
83 operationInputs[ComponentScriptExecutor.INPUT_SCRIPT_CLASS_REFERENCE] =
84 "internal.scripts.TestRestconfConfigure".asJsonPrimitive()
86 val stepInputData = StepData().apply {
87 name = "activate-restconf"
88 properties = operationInputs
90 executionServiceInput.stepData = stepInputData
92 val blueprintContext = mockk<BluePrintContext>()
93 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
95 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs("activate-restconf",
96 "interfaceName", "operationName")
97 } returns operationInputs
99 val operationOutputs = hashMapOf<String, JsonNode>()
101 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs("activate-restconf",
102 "interfaceName", "operationName")
103 } returns operationOutputs
105 componentScriptExecutor.applyNB(executionServiceInput)