2 * Copyright © 2019 IBM, Bell Canada.
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.
16 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
18 import kotlinx.coroutines.runBlocking
20 import org.junit.runner.RunWith
21 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintProperties
22 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertyConfiguration
23 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
24 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock.MockBluePrintRestLibPropertyService
25 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.mock.MockRestResourceResolutionProcessor
26 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
27 import org.onap.ccsdk.cds.blueprintsprocessor.rest.RestClientProperties
28 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
30 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
31 import org.springframework.beans.factory.annotation.Autowired
32 import org.springframework.test.context.ContextConfiguration
33 import org.springframework.test.context.TestPropertySource
34 import org.springframework.test.context.junit4.SpringRunner
35 import kotlin.test.BeforeTest
36 import kotlin.test.assertNotNull
38 @RunWith(SpringRunner::class)
39 @ContextConfiguration(classes = [MockRestResourceResolutionProcessor::class, MockBluePrintRestLibPropertyService::class,
40 BlueprintPropertyConfiguration::class, BluePrintProperties::class, RestClientProperties::class])
41 @TestPropertySource(locations = ["classpath:application-test.properties"])
42 class RestResourceResolutionProcessorTest {
44 lateinit var bluePrintRestLibPropertyService: MockBluePrintRestLibPropertyService
46 private lateinit var restResourceResolutionProcessor: MockRestResourceResolutionProcessor
50 restResourceResolutionProcessor = MockRestResourceResolutionProcessor(bluePrintRestLibPropertyService)
54 fun `test rest resource resolution`() {
56 val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
57 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
59 val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
61 restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
62 restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils
63 .resourceDefinitions(bluePrintContext.rootPath)
65 val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
66 scriptPropertyInstances["mock-service1"] = MockCapabilityService()
67 scriptPropertyInstances["mock-service2"] = MockCapabilityService()
69 restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances
71 val resourceAssignment = ResourceAssignment().apply {
73 dictionaryName = "vnf_name"
74 dictionarySource = "sdnc"
75 property = PropertyDefinition().apply {
80 val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment)
81 assertNotNull(processorName, "couldn't get Rest resource assignment processor name")
82 println(processorName)
87 fun `test rest aai get resource resolution`() {
89 val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
90 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
92 val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
94 restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
95 restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils
96 .resourceDefinitions(bluePrintContext.rootPath)
98 val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
99 scriptPropertyInstances["mock-service1"] = MockCapabilityService()
100 scriptPropertyInstances["mock-service2"] = MockCapabilityService()
102 restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances
104 val resourceAssignment = ResourceAssignment().apply {
106 dictionaryName = "aai-get-resource"
107 dictionarySource = "aai-data"
108 property = PropertyDefinition().apply {
113 val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment)
114 assertNotNull(processorName, "couldn't get AAI Rest resource assignment processor name")
115 println(processorName)
120 fun `test rest aai put resource resolution`() {
122 val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
123 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
125 val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
127 restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
128 restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils
129 .resourceDefinitions(bluePrintContext.rootPath)
131 val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
132 scriptPropertyInstances["mock-service1"] = MockCapabilityService()
133 scriptPropertyInstances["mock-service2"] = MockCapabilityService()
135 restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances
137 val resourceAssignment = ResourceAssignment().apply {
139 dictionaryName = "aai-put-resource"
140 dictionarySource = "aai-data"
141 property = PropertyDefinition().apply {
146 val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment)
147 assertNotNull(processorName, "couldn't get AAI Rest resource assignment processor name")
148 println(processorName)