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(
59 blueprintJythonService
62 val componentNetconfExecutor = ComponentNetconfExecutor(componentFunctionScriptingService)
64 val executionServiceInput = JacksonUtils.readValueFromClassPathFile(
65 "requests/sample-activate-request.json",
66 ExecutionServiceInput::class.java
69 val bluePrintRuntimeService = BlueprintMetadataUtils.getBlueprintRuntime(
71 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
74 val assignmentParams = """{
75 "ipAddress" : "127.0.0.1",
76 "hostName" : "vnf-host"
81 "hostname" : "127.0.0.1"
85 bluePrintRuntimeService.assignInputs(json.asJsonType())
86 bluePrintRuntimeService.setNodeTemplateAttributeValue(
87 "resource-assignment", "assignment-params",
88 JacksonUtils.jsonNode(assignmentParams)
91 componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
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
104 executionServiceInput.stepData = stepInputData
105 componentNetconfExecutor.applyNB(executionServiceInput)