Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / processor / RestResourceResolutionProcessorTest.kt
1 /*
2  * Copyright © 2019 IBM, Bell Canada.
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 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
17
18 import kotlinx.coroutines.runBlocking
19 import org.junit.Test
20 import org.junit.runner.RunWith
21 import org.onap.ccsdk.cds.blueprintsprocessor.core.BlueprintPropertiesService
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
37
38 @RunWith(SpringRunner::class)
39 @ContextConfiguration(
40     classes = [
41         MockRestResourceResolutionProcessor::class, MockBlueprintRestLibPropertyService::class,
42         BlueprintPropertyConfiguration::class, BlueprintPropertiesService::class, RestClientProperties::class
43     ]
44 )
45 @TestPropertySource(locations = ["classpath:application-test.properties"])
46 class RestResourceResolutionProcessorTest {
47
48     @Autowired
49     lateinit var bluePrintRestLibPropertyService: MockBlueprintRestLibPropertyService
50
51     private lateinit var restResourceResolutionProcessor: MockRestResourceResolutionProcessor
52
53     @BeforeTest
54     fun init() {
55         restResourceResolutionProcessor = MockRestResourceResolutionProcessor(bluePrintRestLibPropertyService)
56     }
57
58     @Test
59     fun `test rest resource resolution`() {
60         runBlocking {
61             val bluePrintContext = BlueprintMetadataUtils.getBlueprintContext(
62                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
63             )
64
65             val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
66
67             restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
68             restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils
69                 .resourceDefinitions(bluePrintContext.rootPath)
70
71             val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
72             scriptPropertyInstances["mock-service1"] = MockCapabilityService()
73             scriptPropertyInstances["mock-service2"] = MockCapabilityService()
74
75             restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances
76
77             val resourceAssignment = ResourceAssignment().apply {
78                 name = "rr-name"
79                 dictionaryName = "vnf_name"
80                 dictionarySource = "sdnc"
81                 property = PropertyDefinition().apply {
82                     type = "string"
83                 }
84             }
85
86             val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment)
87             assertNotNull(processorName, "couldn't get Rest resource assignment processor name")
88             println(processorName)
89         }
90     }
91
92     @Test
93     fun `test rest aai get resource resolution`() {
94         runBlocking {
95             val bluePrintContext = BlueprintMetadataUtils.getBlueprintContext(
96                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
97             )
98
99             val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
100
101             restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
102             restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils
103                 .resourceDefinitions(bluePrintContext.rootPath)
104
105             val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
106             scriptPropertyInstances["mock-service1"] = MockCapabilityService()
107             scriptPropertyInstances["mock-service2"] = MockCapabilityService()
108
109             restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances
110
111             val resourceAssignment = ResourceAssignment().apply {
112                 name = "rr-aai"
113                 dictionaryName = "aai-get-resource"
114                 dictionarySource = "aai-data"
115                 property = PropertyDefinition().apply {
116                     type = "string"
117                 }
118             }
119
120             val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment)
121             assertNotNull(processorName, "couldn't get AAI Rest resource assignment processor name")
122             println(processorName)
123         }
124     }
125
126     @Test
127     fun `test rest aai put resource resolution`() {
128         runBlocking {
129             val bluePrintContext = BlueprintMetadataUtils.getBlueprintContext(
130                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
131             )
132
133             val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
134
135             restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
136             restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils
137                 .resourceDefinitions(bluePrintContext.rootPath)
138
139             val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
140             scriptPropertyInstances["mock-service1"] = MockCapabilityService()
141             scriptPropertyInstances["mock-service2"] = MockCapabilityService()
142
143             restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances
144
145             val resourceAssignment = ResourceAssignment().apply {
146                 name = "rr-aai"
147                 dictionaryName = "aai-put-resource"
148                 dictionarySource = "aai-data"
149                 property = PropertyDefinition().apply {
150                     type = "string"
151                 }
152             }
153
154             val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment)
155             assertNotNull(processorName, "couldn't get AAI Rest resource assignment processor name")
156             println(processorName)
157         }
158     }
159 }