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.functions.resource.resolution.ResourceResolutionServiceImpl
33 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
34 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
35 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
36 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
37 import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
38 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
39 import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl
40 import org.springframework.beans.factory.annotation.Autowired
41 import org.springframework.test.context.ContextConfiguration
42 import org.springframework.test.context.TestPropertySource
43 import org.springframework.test.context.junit4.SpringRunner
44 import kotlin.test.assertNotNull
47 @RunWith(SpringRunner::class)
48 @ContextConfiguration(classes = [RestconfExecutorConfiguration::class, ComponentRestconfExecutor::class,
49 BlueprintJythonService::class, PythonExecutorProperty::class, BluePrintRestLibPropertyService::class,
50 BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintScriptsServiceImpl::class,
51 ResourceResolutionServiceImpl::class])
52 @TestPropertySource(properties =
54 "blueprintsprocessor.restconfEnabled=true",
55 "blueprintsprocessor.restclient.odlPrimary.type=basic-auth",
56 "blueprintsprocessor.restclient.odlPrimary.url=http://127.0.0.1:9111",
57 "blueprintsprocessor.restclient.odlPrimary.userId=sampleuser",
58 "blueprintsprocessor.restclient.odlPrimary.token=sampletoken"])
59 class ComponentRestconfExecutorTest {
62 lateinit var componentRestconfExecutor: ComponentRestconfExecutor
65 fun `test Restconf Component Instance`() {
66 assertNotNull(componentRestconfExecutor, "failed to get ComponentRestconfExecutor instance")
67 val executionServiceInput = ExecutionServiceInput().apply {
68 commonHeader = CommonHeader().apply {
71 actionIdentifiers = ActionIdentifiers().apply {
72 actionName = "activate"
74 payload = JacksonUtils.jsonNode("{}") as ObjectNode
76 val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
77 componentRestconfExecutor.bluePrintRuntimeService = bluePrintRuntime
78 componentRestconfExecutor.stepName = "sample-step"
80 val operationInputs = hashMapOf<String, JsonNode>()
81 operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-restconf".asJsonPrimitive()
82 operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
83 operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
84 operationInputs[ComponentRestconfExecutor.SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
85 operationInputs[ComponentRestconfExecutor.SCRIPT_CLASS_REFERENCE] = "InternalSimpleRestconf_cba\$TestRestconfConfigure".asJsonPrimitive()
87 every { bluePrintRuntime.get("sample-step-step-inputs") } returns operationInputs.asJsonNode()
89 bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs("activate-restconf",
90 "interfaceName", "operationName")
91 } returns operationInputs
93 val operationOutputs = hashMapOf<String, JsonNode>()
95 bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs("activate-restconf",
96 "interfaceName", "operationName")
97 } returns operationOutputs
98 every { bluePrintRuntime.put("sample-step-step-outputs", any()) } returns Unit
100 componentRestconfExecutor.apply(executionServiceInput)