7684b2b03d5e94951f0505c0f252d9d1831cc83c
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / python-executor / src / test / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / functions / python / executor / ComponentJythonExecutorTest.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor
18
19 import com.fasterxml.jackson.databind.JsonNode
20 import com.fasterxml.jackson.databind.node.JsonNodeFactory
21 import org.junit.Test
22 import org.junit.runner.RunWith
23 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers
24 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader
25 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
26 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
27 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
28 import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
29 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
30 import org.springframework.beans.factory.annotation.Autowired
31 import org.springframework.test.context.ContextConfiguration
32 import org.springframework.test.context.TestPropertySource
33 import org.springframework.test.context.junit4.SpringRunner
34
35 @RunWith(SpringRunner::class)
36 @ContextConfiguration(classes = [PythonExecutorConfiguration::class, PythonExecutorProperty::class])
37 @TestPropertySource(properties =
38 ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints",
39     "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"])
40 class ComponentJythonExecutorTest {
41
42     @Autowired
43     lateinit var componentJythonExecutor: ComponentJythonExecutor
44
45     @Test
46     fun testPythonComponentInjection() {
47         val executionServiceInput = ExecutionServiceInput()
48         executionServiceInput.payload = JsonNodeFactory.instance.objectNode()
49
50         val commonHeader = CommonHeader()
51         commonHeader.requestId = "1234"
52         executionServiceInput.commonHeader = commonHeader
53
54         val actionIdentifiers = ActionIdentifiers()
55         actionIdentifiers.blueprintName = "baseconfiguration"
56         actionIdentifiers.blueprintVersion = "1.0.0"
57         actionIdentifiers.actionName = "activate"
58         executionServiceInput.actionIdentifiers = actionIdentifiers
59
60
61         val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(commonHeader.requestId,
62                 "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration")
63
64         val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
65         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-jython")
66         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "JythonExecutorComponent")
67         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process")
68         bluePrintRuntimeService.put("activate-jython-step-inputs", stepMetaData.asJsonNode())
69
70         componentJythonExecutor.bluePrintRuntimeService = bluePrintRuntimeService
71         componentJythonExecutor.stepName = "activate-jython"
72
73
74         componentJythonExecutor.apply(executionServiceInput)
75
76     }
77 }