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.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.api.data.ActionIdentifiers
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
29 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
30 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData
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 componentRestconfExecutor: ComponentRestconfExecutor
62 fun `test Restconf Component Instance`() {
64 assertNotNull(componentRestconfExecutor, "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 componentRestconfExecutor.bluePrintRuntimeService = bluePrintRuntime
76 componentRestconfExecutor.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[ComponentRestconfExecutor.SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
83 operationInputs[ComponentRestconfExecutor.SCRIPT_CLASS_REFERENCE] =
84 "InternalSimpleRestconf_cba\$TestRestconfConfigure".asJsonPrimitive()
85 operationInputs[ComponentRestconfExecutor.INSTANCE_DEPENDENCIES] = JacksonUtils.jsonNode("[]") as ArrayNode
87 val stepInputData = StepData().apply {
88 name = "activate-restconf"
89 properties = operationInputs
91 executionServiceInput.stepData = stepInputData
93 val blueprintContext = mockk<BluePrintContext>()
94 every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
96 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs("activate-restconf",
97 "interfaceName", "operationName")
98 } returns operationInputs
100 val operationOutputs = hashMapOf<String, JsonNode>()
102 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs("activate-restconf",
103 "interfaceName", "operationName")
104 } returns operationOutputs
106 componentRestconfExecutor.applyNB(executionServiceInput)