6da3fd71ef0d9a3b43204224a093a970200223ae
[ccsdk/apps.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Modifications Copyright © 2019 IBM, Bell Canada.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
20
21 import org.junit.Test
22 import org.junit.runner.RunWith
23 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
24 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
25 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
26 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty
27 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
28 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
29 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
30 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
31 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
32 import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl
33 import org.springframework.beans.factory.annotation.Autowired
34 import org.springframework.test.context.ContextConfiguration
35 import org.springframework.test.context.TestPropertySource
36 import org.springframework.test.context.junit4.SpringRunner
37 import kotlin.test.assertNotNull
38
39 @RunWith(SpringRunner::class)
40 @ContextConfiguration(classes = [CapabilityResourceResolutionProcessor::class, ComponentFunctionScriptingService::class,
41     BluePrintScriptsServiceImpl::class,
42     BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::class])
43 @TestPropertySource(properties =
44 ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints",
45     "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"])
46 class CapabilityResourceResolutionProcessorTest {
47
48     @Autowired
49     lateinit var capabilityResourceResolutionProcessor: CapabilityResourceResolutionProcessor
50
51     @Test
52     fun `test kotlin capability`() {
53
54         val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
55                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
56
57         val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
58
59         capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
60         capabilityResourceResolutionProcessor.resourceDictionaries = hashMapOf()
61
62
63         val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
64         scriptPropertyInstances["mock-service1"] = MockCapabilityService()
65         scriptPropertyInstances["mock-service2"] = MockCapabilityService()
66
67         val instanceDependencies: List<String> = listOf()
68
69         val resourceAssignmentProcessor = capabilityResourceResolutionProcessor
70                 .scriptInstance("kotlin",
71                         "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", instanceDependencies)
72
73         assertNotNull(resourceAssignmentProcessor, "couldn't get kotlin script resource assignment processor")
74
75         val resourceAssignment = ResourceAssignment().apply {
76             name = "ra-name"
77             dictionaryName = "ra-dict-name"
78             dictionarySource = "capability"
79             property = PropertyDefinition().apply {
80                 type = "string"
81             }
82         }
83
84         val processorName = resourceAssignmentProcessor.apply(resourceAssignment)
85         assertNotNull(processorName, "couldn't get kotlin script resource assignment processor name")
86         println(processorName)
87     }
88
89     @Test
90     fun `test jython capability`() {
91
92         val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
93                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python")
94
95         val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
96
97         capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
98
99         val resourceDefinition = JacksonUtils
100                 .readValueFromClassPathFile("mapping/capability/jython-resource-definitions.json",
101                         ResourceDefinition::class.java)!!
102         val resourceDefinitions: MutableMap<String, ResourceDefinition> = mutableMapOf()
103         resourceDefinitions[resourceDefinition.name] = resourceDefinition
104         capabilityResourceResolutionProcessor.resourceDictionaries = resourceDefinitions
105
106         val resourceAssignment = ResourceAssignment().apply {
107             name = "service-instance-id"
108             dictionaryName = "service-instance-id"
109             dictionarySource = "capability"
110             property = PropertyDefinition().apply {
111                 type = "string"
112             }
113         }
114
115         val processorName = capabilityResourceResolutionProcessor.apply(resourceAssignment)
116         assertNotNull(processorName, "couldn't get Jython script resource assignment processor name")
117
118     }
119
120 }
121
122 open class MockCapabilityService {
123
124 }