Convert component functions IT to UT.
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / netconf-executor / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / netconf / executor / ComponentNetconfExecutorTest.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Modifications Copyright © 2019 IBM, Bell Canada.
5  * Modifications Copyright © 2019 IBM.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor
21
22 import com.fasterxml.jackson.databind.JsonNode
23 import io.mockk.coEvery
24 import io.mockk.every
25 import io.mockk.mockk
26 import io.mockk.spyk
27 import kotlinx.coroutines.runBlocking
28 import org.junit.Test
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.blueprintsprocessor.services.execution.AbstractScriptComponentFunction
32 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
33 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
34 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
35 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
36 import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement
37 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
38 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
39 import org.springframework.context.ApplicationContext
40
41 class ComponentNetconfExecutorTest {
42
43     @Test
44     fun testComponentNetconfExecutor() {
45
46         runBlocking {
47
48             val applicationContext = mockk<ApplicationContext>()
49             every { applicationContext.getBean(any()) } returns mockk()
50
51             val blueprintJythonService = mockk<BlueprintJythonService>()
52             val mockAbstractScriptComponentFunction = spyk<AbstractScriptComponentFunction>()
53             coEvery { mockAbstractScriptComponentFunction.executeScript(any()) } returns mockk()
54
55             coEvery { blueprintJythonService.jythonComponentInstance(any(), any()) } returns mockAbstractScriptComponentFunction
56
57             val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext,
58                     blueprintJythonService)
59
60             val componentNetconfExecutor = ComponentNetconfExecutor(componentFunctionScriptingService)
61
62             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("requests/sample-activate-request.json",
63                     ExecutionServiceInput::class.java)!!
64
65             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
66                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
67
68             val assignmentParams = """{
69                 "ipAddress" : "127.0.0.1",
70                 "hostName" : "vnf-host"
71                 }                
72             """.trimIndent()
73
74             val json = """{
75                 "hostname" : "127.0.0.1"
76                 }                
77             """.trimIndent()
78
79             bluePrintRuntimeService.assignInputs(json.asJsonType())
80             bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params",
81                     JacksonUtils.jsonNode(assignmentParams))
82
83             componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
84
85             //TODO("Set Attribute properties")
86             val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
87             stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-netconf")
88             stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentNetconfExecutor")
89             stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
90             // Set Step Inputs in Blueprint Runtime Service
91             componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
92             val stepInputData = StepData().apply {
93                 name = "activate-netconf"
94                 properties = stepMetaData
95             }
96             executionServiceInput.stepData = stepInputData
97             componentNetconfExecutor.applyNB(executionServiceInput)
98         }
99     }
100 }
101