Revert "Renaming Files having BluePrint to have Blueprint"
[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(
58                 applicationContext,
59                 blueprintJythonService
60             )
61
62             val componentNetconfExecutor = ComponentNetconfExecutor(componentFunctionScriptingService)
63
64             val executionServiceInput = JacksonUtils.readValueFromClassPathFile(
65                 "requests/sample-activate-request.json",
66                 ExecutionServiceInput::class.java
67             )!!
68
69             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
70                 "1234",
71                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
72             )
73
74             val assignmentParams = """{
75                 "ipAddress" : "127.0.0.1",
76                 "hostName" : "vnf-host"
77                 }                
78             """.trimIndent()
79
80             val json = """{
81                 "hostname" : "127.0.0.1"
82                 }                
83             """.trimIndent()
84
85             bluePrintRuntimeService.assignInputs(json.asJsonType())
86             bluePrintRuntimeService.setNodeTemplateAttributeValue(
87                 "resource-assignment", "assignment-params",
88                 JacksonUtils.jsonNode(assignmentParams)
89             )
90
91             componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
92
93             // TODO("Set Attribute properties")
94             val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
95             stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-netconf")
96             stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentNetconfExecutor")
97             stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
98             // Set Step Inputs in Blueprint Runtime Service
99             componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
100             val stepInputData = StepData().apply {
101                 name = "activate-netconf"
102                 properties = stepMetaData
103             }
104             executionServiceInput.stepData = stepInputData
105             componentNetconfExecutor.applyNB(executionServiceInput)
106         }
107     }
108 }