2 * Copyright © 2019 IBM.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor
19 import com.fasterxml.jackson.databind.JsonNode
22 import kotlinx.coroutines.runBlocking
24 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.*
25 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.RemoteScriptExecutionService
26 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
27 import org.onap.ccsdk.cds.controllerblueprints.core.putJsonElement
28 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
30 import kotlin.test.assertEquals
31 import kotlin.test.assertNotNull
34 class ComponentRemotePythonExecutorTest {
37 fun testComponentRemotePythonExecutor() {
39 val remoteScriptExecutionService = MockRemoteScriptExecutionService()
41 val componentRemotePythonExecutor = ComponentRemotePythonExecutor(remoteScriptExecutionService)
43 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("payload/requests/sample-activate-request.json",
44 ExecutionServiceInput::class.java)!!
46 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("123456-1000",
47 "./../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts")
49 val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
50 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "execute-remote-python")
51 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentRemotePythonExecutor")
52 stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
53 componentRemotePythonExecutor.bluePrintRuntimeService = bluePrintRuntimeService
54 val stepInputData = StepData().apply {
55 name = "execute-remote-python"
56 properties = stepMetaData
58 executionServiceInput.stepData = stepInputData
59 componentRemotePythonExecutor.applyNB(executionServiceInput)
65 class MockRemoteScriptExecutionService : RemoteScriptExecutionService {
66 override suspend fun init(selector: String) {
69 override suspend fun prepareEnv(prepareEnvInput: PrepareRemoteEnvInput): RemoteScriptExecutionOutput {
70 assertEquals(prepareEnvInput.requestId, "123456-1000", "failed to match request id")
71 assertNotNull(prepareEnvInput.packages, "failed to get packages")
73 val remoteScriptExecutionOutput = mockk<RemoteScriptExecutionOutput>()
74 every { remoteScriptExecutionOutput.status } returns StatusType.SUCCESS
75 return remoteScriptExecutionOutput
78 override suspend fun executeCommand(remoteExecutionInput: RemoteScriptExecutionInput): RemoteScriptExecutionOutput {
79 assertEquals(remoteExecutionInput.requestId, "123456-1000", "failed to match request id")
81 val remoteScriptExecutionOutput = mockk<RemoteScriptExecutionOutput>()
82 every { remoteScriptExecutionOutput.status } returns StatusType.SUCCESS
83 return remoteScriptExecutionOutput
86 override suspend fun close() {