c8a2090b1ae89454e3b36de05c8be01db5aa453e
[ccsdk/apps.git] /
1 /*
2  *  Copyright © 2018 IBM.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
18
19 import com.fasterxml.jackson.databind.JsonNode
20 import com.fasterxml.jackson.databind.node.ArrayNode
21 import com.fasterxml.jackson.databind.node.ObjectNode
22 import io.mockk.every
23 import io.mockk.mockk
24 import org.junit.Test
25 import org.junit.runner.RunWith
26 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
27 import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfiguration
28 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers
29 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader
30 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
31 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionServiceImpl
32 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
33 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
34 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
35 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty
36 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
37 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
38 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
39 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
40 import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
41 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
42 import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl
43 import org.springframework.beans.factory.annotation.Autowired
44 import org.springframework.test.context.ContextConfiguration
45 import org.springframework.test.context.TestPropertySource
46 import org.springframework.test.context.junit4.SpringRunner
47 import kotlin.test.assertNotNull
48
49
50 @RunWith(SpringRunner::class)
51 @ContextConfiguration(classes = [RestconfExecutorConfiguration::class, ComponentRestconfExecutor::class,
52     BlueprintJythonService::class, PythonExecutorProperty::class, BluePrintRestLibPropertyService::class,
53     BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintScriptsServiceImpl::class,
54     ResourceResolutionServiceImpl::class, ComponentFunctionScriptingService::class])
55 @TestPropertySource(properties =
56 ["server.port=9111",
57     "blueprintsprocessor.restconfEnabled=true",
58     "blueprintsprocessor.restclient.odlPrimary.type=basic-auth",
59     "blueprintsprocessor.restclient.odlPrimary.url=http://127.0.0.1:9111",
60     "blueprintsprocessor.restclient.odlPrimary.userId=sampleuser",
61     "blueprintsprocessor.restclient.odlPrimary.token=sampletoken"])
62 class ComponentRestconfExecutorTest {
63
64     @Autowired
65     lateinit var componentRestconfExecutor: ComponentRestconfExecutor
66
67     @Test
68     fun `test Restconf Component Instance`() {
69         assertNotNull(componentRestconfExecutor, "failed to get ComponentRestconfExecutor instance")
70         val executionServiceInput = ExecutionServiceInput().apply {
71             commonHeader = CommonHeader().apply {
72                 requestId = "1234"
73             }
74             actionIdentifiers = ActionIdentifiers().apply {
75                 actionName = "activate"
76             }
77             payload = JacksonUtils.jsonNode("{}") as ObjectNode
78         }
79         val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234")
80         componentRestconfExecutor.bluePrintRuntimeService = bluePrintRuntime
81         componentRestconfExecutor.stepName = "sample-step"
82
83         val operationInputs = hashMapOf<String, JsonNode>()
84         operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-restconf".asJsonPrimitive()
85         operationInputs[BluePrintConstants.PROPERTY_CURRENT_INTERFACE] = "interfaceName".asJsonPrimitive()
86         operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
87         operationInputs[ComponentRestconfExecutor.SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
88         operationInputs[ComponentRestconfExecutor.SCRIPT_CLASS_REFERENCE] = "InternalSimpleRestconf_cba\$TestRestconfConfigure".asJsonPrimitive()
89         operationInputs[ComponentRestconfExecutor.INSTANCE_DEPENDENCIES] = JacksonUtils.jsonNode("[]") as ArrayNode
90
91         val blueprintContext = mockk<BluePrintContext>()
92         every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
93         every { bluePrintRuntime.get("sample-step-step-inputs") } returns operationInputs.asJsonNode()
94         every {
95             bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs("activate-restconf",
96                     "interfaceName", "operationName")
97         } returns operationInputs
98
99         val operationOutputs = hashMapOf<String, JsonNode>()
100         every {
101             bluePrintRuntime.resolveNodeTemplateInterfaceOperationOutputs("activate-restconf",
102                     "interfaceName", "operationName")
103         } returns operationOutputs
104         every { bluePrintRuntime.put("sample-step-step-outputs", any()) } returns Unit
105
106         componentRestconfExecutor.apply(executionServiceInput)
107     }
108 }