2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Modifications Copyright © 2019 IBM, Bell Canada.
5 * Modifications Copyright © 2019 IBM.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor
22 import com.fasterxml.jackson.databind.JsonNode
23 import io.mockk.coEvery
27 import kotlinx.coroutines.runBlocking
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
41 class ComponentNetconfExecutorTest {
44 fun testComponentNetconfExecutor() {
48 val applicationContext = mockk<ApplicationContext>()
49 every { applicationContext.getBean(any()) } returns mockk()
51 val blueprintJythonService = mockk<BlueprintJythonService>()
52 val mockAbstractScriptComponentFunction = spyk<AbstractScriptComponentFunction>()
53 coEvery { mockAbstractScriptComponentFunction.executeScript(any()) } returns mockk()
55 coEvery { blueprintJythonService.jythonComponentInstance(any(), any()) } returns mockAbstractScriptComponentFunction
57 val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext,
58 blueprintJythonService)
60 val componentNetconfExecutor = ComponentNetconfExecutor(componentFunctionScriptingService)
62 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("requests/sample-activate-request.json",
63 ExecutionServiceInput::class.java)!!
65 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
66 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
68 val assignmentParams = """{
69 "ipAddress" : "127.0.0.1",
70 "hostName" : "vnf-host"
75 "hostname" : "127.0.0.1"
79 bluePrintRuntimeService.assignInputs(json.asJsonType())
80 bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params",
81 JacksonUtils.jsonNode(assignmentParams))
83 componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
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
96 executionServiceInput.stepData = stepInputData
97 componentNetconfExecutor.applyNB(executionServiceInput)