From d425c6319a995402163c8868e9fe40f3d88f02ea Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sat, 9 Nov 2019 20:35:47 -0500 Subject: Convert component functions IT to UT. Issue-ID: CCSDK-1735 Convert Netconf and Restconf Executor IT to UT. Remove duplicate BluePrintProperties. Signed-off-by: Brinda Santh Change-Id: I2eafdbabb17a4df72541ab93c46e7fc9eb0fe8d7 --- .../executor/ComponentNetconfExecutorTest.kt | 56 +++++++++++----------- 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'ms/blueprintsprocessor/functions/netconf-executor') diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt index 8a08268d8..be3ee4614 100644 --- a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt @@ -20,51 +20,56 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor import com.fasterxml.jackson.databind.JsonNode +import io.mockk.coEvery +import io.mockk.every +import io.mockk.mockk +import io.mockk.spyk import kotlinx.coroutines.runBlocking import org.junit.Test -import org.junit.runner.RunWith import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractScriptComponentFunction +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts.BlueprintJythonService import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.annotation.DirtiesContext -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner - -@RunWith(SpringRunner::class) -@EnableAutoConfiguration -@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) -@DirtiesContext -@TestPropertySource(properties = -["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf,./../../../../components/scripts/python/ccsdk_blueprints", - "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_netconf"], - locations = ["classpath:application-test.properties"]) -class ComponentNetconfExecutorTest { - - @Autowired - lateinit var componentNetconfExecutor: ComponentNetconfExecutor +import org.springframework.context.ApplicationContext +class ComponentNetconfExecutorTest { @Test fun testComponentNetconfExecutor() { runBlocking { + + val applicationContext = mockk() + every { applicationContext.getBean(any()) } returns mockk() + + val blueprintJythonService = mockk() + val mockAbstractScriptComponentFunction = spyk() + coEvery { mockAbstractScriptComponentFunction.executeScript(any()) } returns mockk() + + coEvery { blueprintJythonService.jythonComponentInstance(any(), any()) } returns mockAbstractScriptComponentFunction + + val componentFunctionScriptingService = ComponentFunctionScriptingService(applicationContext, + blueprintJythonService) + + val componentNetconfExecutor = ComponentNetconfExecutor(componentFunctionScriptingService) + val executionServiceInput = JacksonUtils.readValueFromClassPathFile("requests/sample-activate-request.json", ExecutionServiceInput::class.java)!! val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234", "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") - val assignmentParams = "{\n" + - " \"ipAddress\": \"127.0.0.1\",\n" + - " \"hostName\": \"vnf-host\"\n" + - " }" + val assignmentParams = """{ + "ipAddress" : "127.0.0.1", + "hostName" : "vnf-host" + } + """.trimIndent() val json = """{ "hostname" : "127.0.0.1" @@ -75,8 +80,6 @@ class ComponentNetconfExecutorTest { bluePrintRuntimeService.setNodeTemplateAttributeValue("resource-assignment", "assignment-params", JacksonUtils.jsonNode(assignmentParams)) - val executionContext = bluePrintRuntimeService.getExecutionContext() - componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService //TODO("Set Attribute properties") @@ -93,7 +96,6 @@ class ComponentNetconfExecutorTest { executionServiceInput.stepData = stepInputData componentNetconfExecutor.applyNB(executionServiceInput) } - } } -- cgit 1.2.3-korg