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
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
-
class ComponentRemotePythonExecutorTest {
@Test
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<String, JsonNode> = hashMapOf()
stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "execute-remote-python")
@Test
fun testComponentRemotePythonExecutorProcessNB() {
runBlocking {
- val remoteScriptExecutionService =
- MockRemoteScriptExecutionService()
- val componentRemotePythonExecutor = ComponentRemotePythonExecutor(
- remoteScriptExecutionService)
- val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>(
- "123456-1000")
+ val remoteScriptExecutionService = MockRemoteScriptExecutionService()
+ val componentRemotePythonExecutor = ComponentRemotePythonExecutor(remoteScriptExecutionService)
+ val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("123456-1000")
every { bluePrintRuntime.setNodeTemplateAttributeValue(any(), any(), any()) } answers {}
val input = getMockedOutput(bluePrintRuntime)
- componentRemotePythonExecutor.bluePrintRuntimeService =
- bluePrintRuntime
+ componentRemotePythonExecutor.bluePrintRuntimeService = bluePrintRuntime
componentRemotePythonExecutor.applyNB(input)
}
}
* Mocked input information for remote python executor.
*/
fun getMockedOutput(svc: DefaultBluePrintRuntimeService):
- ExecutionServiceInput {
+ ExecutionServiceInput {
val stepMetaData: MutableMap<String, JsonNode> = 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()
val operationalInputs: MutableMap<String, JsonNode> = 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")
every {
svc.resolveNodeTemplateInterfaceOperationInputs(
"execute-remote-python",
- "ComponentRemotePythonExecutor", "process")
+ "ComponentRemotePythonExecutor", "process"
+ )
} returns operationalInputs
val stepInputData = StepData().apply {
val executionServiceInput = JacksonUtils
.readValueFromClassPathFile(
"payload/requests/sample-remote-python-request.json",
- ExecutionServiceInput::class.java)!!
+ ExecutionServiceInput::class.java
+ )!!
executionServiceInput.stepData = stepInputData
val operationOutputs = hashMapOf<String, JsonNode>()
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()
assertNotNull(prepareEnvInput.packages, "failed to get packages")
val remoteScriptExecutionOutput = mockk<RemoteScriptExecutionOutput>()
+ every { remoteScriptExecutionOutput.payload } returns "payload".asJsonPrimitive()
every { remoteScriptExecutionOutput.response } returns listOf("prepared successfully")
every { remoteScriptExecutionOutput.status } returns StatusType.SUCCESS
return remoteScriptExecutionOutput
assertEquals(remoteExecutionInput.requestId, "123456-1000", "failed to match request id")
val remoteScriptExecutionOutput = mockk<RemoteScriptExecutionOutput>()
+ 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() {
-
}
}