X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ms%2Fblueprintsprocessor%2Ffunctions%2Fpython-executor%2Fsrc%2Ftest%2Fkotlin%2Forg%2Fonap%2Fccsdk%2Fcds%2Fblueprintsprocessor%2Ffunctions%2Fpython%2Fexecutor%2FComponentRemotePythonExecutorTest.kt;h=3d58afad8daee6750f732c0b99ccaaf0ba4f6551;hb=d4fadc988246eb172ce8333bb3a06443591c5f19;hp=31aa7c7c1f18fc6c5294f209598821c71bcbc1d7;hpb=61672376481804b037a92d77042bac84eca0adf8;p=ccsdk%2Fcds.git diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt index 31aa7c7c1..3d58afad8 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt @@ -31,6 +31,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.RemoteScriptExecutionService import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement import org.onap.ccsdk.cds.controllerblueprints.core.service.DefaultBluePrintRuntimeService import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils @@ -38,7 +39,6 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import kotlin.test.assertEquals import kotlin.test.assertNotNull - class ComponentRemotePythonExecutorTest { @Test @@ -49,11 +49,21 @@ class ComponentRemotePythonExecutorTest { val componentRemotePythonExecutor = ComponentRemotePythonExecutor(remoteScriptExecutionService) val executionServiceInput = - JacksonUtils.readValueFromClassPathFile("payload/requests/sample-activate-request.json", - ExecutionServiceInput::class.java)!! - - val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("123456-1000", - "./../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts") + JacksonUtils.readValueFromClassPathFile( + "payload/requests/sample-remote-python-request.json", + ExecutionServiceInput::class.java + )!! + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime( + "123456-1000", + "./../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts" + ) + + /** Load Workflow Inputs */ + bluePrintRuntimeService.assignWorkflowInputs( + "execute-remote-python", + executionServiceInput.payload.get("execute-remote-python-request") + ) val stepMetaData: MutableMap = hashMapOf() stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "execute-remote-python") @@ -76,18 +86,14 @@ class ComponentRemotePythonExecutorTest { @Test fun testComponentRemotePythonExecutorProcessNB() { runBlocking { - val remoteScriptExecutionService = - MockRemoteScriptExecutionService() - val componentRemotePythonExecutor = ComponentRemotePythonExecutor( - remoteScriptExecutionService) - val bluePrintRuntime = mockk( - "123456-1000") + val remoteScriptExecutionService = MockRemoteScriptExecutionService() + val componentRemotePythonExecutor = ComponentRemotePythonExecutor(remoteScriptExecutionService) + val bluePrintRuntime = mockk("123456-1000") every { bluePrintRuntime.setNodeTemplateAttributeValue(any(), any(), any()) } answers {} val input = getMockedOutput(bluePrintRuntime) - componentRemotePythonExecutor.bluePrintRuntimeService = - bluePrintRuntime + componentRemotePythonExecutor.bluePrintRuntimeService = bluePrintRuntime componentRemotePythonExecutor.applyNB(input) } } @@ -96,17 +102,20 @@ class ComponentRemotePythonExecutorTest { * Mocked input information for remote python executor. */ fun getMockedOutput(svc: DefaultBluePrintRuntimeService): - ExecutionServiceInput { + ExecutionServiceInput { val stepMetaData: MutableMap = hashMapOf() stepMetaData.putJsonElement( BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, - "execute-remote-python") + "execute-remote-python" + ) stepMetaData.putJsonElement( BluePrintConstants.PROPERTY_CURRENT_INTERFACE, - "ComponentRemotePythonExecutor") + "ComponentRemotePythonExecutor" + ) stepMetaData.putJsonElement( - BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process") + BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process" + ) val mapper = ObjectMapper() val rootNode = mapper.createObjectNode() @@ -116,12 +125,15 @@ class ComponentRemotePythonExecutorTest { val operationalInputs: MutableMap = hashMapOf() operationalInputs.putJsonElement( BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, - "execute-remote-python") + "execute-remote-python" + ) operationalInputs.putJsonElement( BluePrintConstants.PROPERTY_CURRENT_INTERFACE, - "ComponentRemotePythonExecutor") + "ComponentRemotePythonExecutor" + ) operationalInputs.putJsonElement( - BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process") + BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process" + ) operationalInputs.putJsonElement("endpoint-selector", "aai") operationalInputs.putJsonElement("dynamic-properties", rootNode) operationalInputs.putJsonElement("command", "./run.sh") @@ -130,7 +142,8 @@ class ComponentRemotePythonExecutorTest { every { svc.resolveNodeTemplateInterfaceOperationInputs( "execute-remote-python", - "ComponentRemotePythonExecutor", "process") + "ComponentRemotePythonExecutor", "process" + ) } returns operationalInputs val stepInputData = StepData().apply { @@ -141,42 +154,54 @@ class ComponentRemotePythonExecutorTest { val executionServiceInput = JacksonUtils .readValueFromClassPathFile( "payload/requests/sample-remote-python-request.json", - ExecutionServiceInput::class.java)!! + ExecutionServiceInput::class.java + )!! executionServiceInput.stepData = stepInputData val operationOutputs = hashMapOf() every { svc.resolveNodeTemplateInterfaceOperationOutputs( "execute-remote-python", - "ComponentRemotePythonExecutor", "process") + "ComponentRemotePythonExecutor", "process" + ) } returns operationOutputs - val bluePrintRuntimeService = BluePrintMetadataUtils - .getBluePrintRuntime("123456-1000", - "./../../../../components/model-" + - "catalog/blueprint-model/test-blueprint/" + - "remote_scripts") + val bluePrintRuntimeService = BluePrintMetadataUtils.bluePrintRuntime( + "123456-1000", + "./../../../../components/model-" + + "catalog/blueprint-model/test-blueprint/" + + "remote_scripts" + ) every { svc.resolveNodeTemplateArtifactDefinition( - "execute-remote-python", "component-script") + "execute-remote-python", "component-script" + ) } returns bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition( - "execute-remote-python", "component-script") + "execute-remote-python", "component-script" + ) every { svc.setNodeTemplateAttributeValue( "execute-remote-python", "prepare-environment-logs", - "prepared successfully".asJsonPrimitive()) + "prepared successfully".asJsonPrimitive() + ) } returns Unit every { svc.setNodeTemplateAttributeValue( "execute-remote-python", - "execute-command-logs", "N/A".asJsonPrimitive()) + "execute-command-logs", "N/A".asJsonPrimitive() + ) } returns Unit every { svc.setNodeTemplateAttributeValue( "execute-remote-python", "execute-command-logs", - "processed successfully".asJsonPrimitive()) + "processed successfully".asJsonPrimitive() + ) } returns Unit + every { + svc.resolveDSLExpression("aai") + } returns """{"url" : "http://xxx.com"}""".asJsonType() + every { svc.bluePrintContext() } returns bluePrintRuntimeService.bluePrintContext() @@ -185,7 +210,7 @@ class ComponentRemotePythonExecutorTest { } class MockRemoteScriptExecutionService : RemoteScriptExecutionService { - override suspend fun init(selector: String) { + override suspend fun init(selector: Any) { } override suspend fun prepareEnv(prepareEnvInput: PrepareRemoteEnvInput): RemoteScriptExecutionOutput { @@ -193,6 +218,7 @@ class MockRemoteScriptExecutionService : RemoteScriptExecutionService { assertNotNull(prepareEnvInput.packages, "failed to get packages") val remoteScriptExecutionOutput = mockk() + every { remoteScriptExecutionOutput.payload } returns "payload".asJsonPrimitive() every { remoteScriptExecutionOutput.response } returns listOf("prepared successfully") every { remoteScriptExecutionOutput.status } returns StatusType.SUCCESS return remoteScriptExecutionOutput @@ -202,12 +228,12 @@ class MockRemoteScriptExecutionService : RemoteScriptExecutionService { assertEquals(remoteExecutionInput.requestId, "123456-1000", "failed to match request id") val remoteScriptExecutionOutput = mockk() + every { remoteScriptExecutionOutput.payload } returns "payload".asJsonPrimitive() every { remoteScriptExecutionOutput.response } returns listOf("processed successfully") every { remoteScriptExecutionOutput.status } returns StatusType.SUCCESS return remoteScriptExecutionOutput } override suspend fun close() { - } }