diff options
Diffstat (limited to 'ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt')
-rw-r--r-- | ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt index c5fbea80f..b404fbed6 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/scripts/AbstractComponentFunctionTest.kt @@ -21,6 +21,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.services.execution.scripts; import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.node.ObjectNode import io.mockk.every import io.mockk.mockk @@ -32,12 +33,16 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader 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.AbstractComponentFunction +import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.scripts.BluePrintScriptsServiceImpl +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.junit4.SpringRunner import kotlin.test.BeforeTest import kotlin.test.assertEquals @@ -47,10 +52,16 @@ import kotlin.test.assertNotNull * Unit test cases for abstract component function. */ @RunWith(SpringRunner::class) +@ContextConfiguration(classes = [ComponentFunctionScriptingService::class, + BluePrintScriptsServiceImpl::class,PythonExecutorProperty::class, + BlueprintJythonService::class]) class AbstractComponentFunctionTest { lateinit var blueprintContext: BluePrintContext + @Autowired + lateinit var compSvc: ComponentFunctionScriptingService + @BeforeTest fun init() { blueprintContext = mockk<BluePrintContext>() @@ -82,12 +93,56 @@ class AbstractComponentFunctionTest { } } + /** + * Tests the abstract script component functionality. + */ + @Test + fun testAbstractScriptComponent() { + runBlocking { + val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("1234") + val samp = SampleRestconfComponent(compSvc) + val comp = samp as AbstractComponentFunction + + comp.bluePrintRuntimeService = bluePrintRuntime + comp.stepName = "sample-step" + assertNotNull(comp, "failed to get kotlin instance") + + val input = getMockedInput(bluePrintRuntime) + val inp = getMockedContext() + + val output = comp.applyNB(input) + + assertEquals(output.actionIdentifiers.actionName, "activate") + assertEquals(output.commonHeader.requestId, "1234") + assertEquals(output.stepData!!.name, "activate-restconf") + assertEquals(output.status.message, "success") + } + } + + /** + * Mocked input for abstract function test. + */ + private fun getMockedContext() { + val operationOutputs = hashMapOf<String, JsonNode>() + every { + blueprintContext.name() + } returns "SampleTest" + every { + blueprintContext.version() + } returns "SampleScriptComponent" + } /** * Mocked input for abstract function test. */ private fun getMockedInput(bluePrintRuntime: DefaultBluePrintRuntimeService): ExecutionServiceInput { + + val mapper = ObjectMapper() + val rootNode = mapper.createObjectNode() + rootNode.put("ip-address", "0.0.0.0") + rootNode.put("type", "rest") + val operationInputs = hashMapOf<String, JsonNode>() operationInputs[BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE] = "activate-restconf".asJsonPrimitive() @@ -95,6 +150,8 @@ class AbstractComponentFunctionTest { "interfaceName".asJsonPrimitive() operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive() + operationInputs["dynamic-properties"] = rootNode + val stepInputData = StepData().apply { name = "activate-restconf" @@ -125,4 +182,6 @@ class AbstractComponentFunctionTest { return executionServiceInput } + } + |