2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Modifications Copyright © 2019 IBM, Bell Canada.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
22 import org.junit.runner.RunWith
23 import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
24 import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
25 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
26 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
27 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
28 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
29 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
30 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition
31 import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl
32 import org.springframework.beans.factory.annotation.Autowired
33 import org.springframework.test.context.ContextConfiguration
34 import org.springframework.test.context.TestPropertySource
35 import org.springframework.test.context.junit4.SpringRunner
36 import kotlin.test.assertNotNull
38 @RunWith(SpringRunner::class)
39 @ContextConfiguration(classes = [CapabilityResourceAssignmentProcessor::class, BluePrintScriptsServiceImpl::class,
40 BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::class])
41 @TestPropertySource(properties =
42 ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints",
43 "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"])
44 class CapabilityResourceAssignmentProcessorTest {
47 lateinit var capabilityResourceAssignmentProcessor: CapabilityResourceAssignmentProcessor
50 fun `test kotlin capability`() {
52 val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
53 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
55 val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
57 capabilityResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
58 capabilityResourceAssignmentProcessor.resourceDictionaries = hashMapOf()
61 val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
62 scriptPropertyInstances["mock-service1"] = MockCapabilityService()
63 scriptPropertyInstances["mock-service2"] = MockCapabilityService()
65 val resourceAssignmentProcessor = capabilityResourceAssignmentProcessor
66 .getKotlinResourceAssignmentProcessorInstance(
67 "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", scriptPropertyInstances)
69 assertNotNull(resourceAssignmentProcessor, "couldn't get kotlin script resource assignment processor")
71 val resourceAssignment = ResourceAssignment().apply {
73 dictionaryName = "ra-dict-name"
74 dictionarySource = "capability"
75 property = PropertyDefinition().apply {
80 val processorName = resourceAssignmentProcessor.apply(resourceAssignment)
81 assertNotNull(processorName, "couldn't get kotlin script resource assignment processor name")
82 println(processorName)
86 fun `test jython capability`() {
88 val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
89 "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python")
91 val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
93 capabilityResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
95 val resourceDefinition = JacksonUtils
96 .readValueFromClassPathFile("mapping/capability/jython-resource-definitions.json",
97 ResourceDefinition::class.java)!!
98 val resourceDefinitions: MutableMap<String, ResourceDefinition> = mutableMapOf()
99 resourceDefinitions[resourceDefinition.name] = resourceDefinition
100 capabilityResourceAssignmentProcessor.resourceDictionaries = resourceDefinitions
102 val resourceAssignment = ResourceAssignment().apply {
103 name = "service-instance-id"
104 dictionaryName = "service-instance-id"
105 dictionarySource = "capability"
106 property = PropertyDefinition().apply {
111 val processorName = capabilityResourceAssignmentProcessor.apply(resourceAssignment)
112 assertNotNull(processorName, "couldn't get Jython script resource assignment processor name")
118 open class MockCapabilityService {