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.apps.blueprintsprocessor.functions.restconf.executor
19 import com.fasterxml.jackson.databind.JsonNode
20 import com.fasterxml.jackson.databind.node.ObjectNode
24 import org.junit.runner.RunWith
25 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
26 import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration
27 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers
28 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader
29 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
30 import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
31 import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
32 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
33 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
34 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
35 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
36 import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
37 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
38 import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl
39 import org.springframework.beans.factory.annotation.Autowired
40 import org.springframework.test.context.ContextConfiguration
41 import org.springframework.test.context.TestPropertySource
42 import org.springframework.test.context.junit4.SpringRunner
43 import kotlin.test.assertNotNull
46 @RunWith(SpringRunner::class)
47 @ContextConfiguration(classes = [RestconfExecutorConfiguration::class, ComponentRestconfExecutor::class,
48 BlueprintJythonService::class, PythonExecutorProperty::class, BluePrintRestLibPropertyService::class,
49 BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintScriptsServiceImpl::class])
50 @TestPropertySource(properties =
52 "blueprintsprocessor.restconfEnabled=true",
53 "blueprintsprocessor.restclient.odlPrimary.type=basic-auth",
54 "blueprintsprocessor.restclient.odlPrimary.url=http://127.0.0.1:9111",
55 "blueprintsprocessor.restclient.odlPrimary.userId=sampleuser",
56 "blueprintsprocessor.restclient.odlPrimary.token=sampletoken"])
57 class ComponentRestconfExecutorTest {
60 lateinit var componentRestconfExecutor: ComponentRestconfExecutor
63 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] = "InternalSimpleRestconf_cba\$TestRestconfConfigure".asJsonPrimitive()
85 every { bluePrintRuntime.get("sample-step-step-inputs") } returns operationInputs.asJsonNode()
87 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs("activate-restconf",
88 "interfaceName", "operationName")
89 } returns operationInputs
91 val operationOutputs = hashMapOf<String, JsonNode>()
93 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs("activate-restconf",
94 "interfaceName", "operationName")
95 } returns operationOutputs
96 every { bluePrintRuntime.put("sample-step-step-outputs", any()) } returns Unit
98 componentRestconfExecutor.apply(executionServiceInput)