1c0f33fcdace33ceef1085ea431c065a1c98a691
[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(classes = [MockRestResourceResolutionProcessor::class, MockBluePrintRestLibPropertyService::class,
40     BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, RestClientProperties::class])
41 @TestPropertySource(locations = ["classpath:application-test.properties"])
42 class RestResourceResolutionProcessorTest {
43     @Autowired
44     lateinit var bluePrintRestLibPropertyService: MockBluePrintRestLibPropertyService
45
46     private lateinit var restResourceResolutionProcessor: MockRestResourceResolutionProcessor
47
48     @BeforeTest
49     fun init(){
50         restResourceResolutionProcessor = MockRestResourceResolutionProcessor(bluePrintRestLibPropertyService)
51     }
52
53     @Test
54     fun `test rest resource resolution`() {
55         runBlocking {
56             val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
57                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
58
59             val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
60
61             restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
62             restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils
63                     .resourceDefinitions(bluePrintContext.rootPath)
64
65             val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
66             scriptPropertyInstances["mock-service1"] = MockCapabilityService()
67             scriptPropertyInstances["mock-service2"] = MockCapabilityService()
68
69             restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances
70
71             val resourceAssignment = ResourceAssignment().apply {
72                 name = "rr-name"
73                 dictionaryName = "vnf_name"
74                 dictionarySource = "sdnc"
75                 property = PropertyDefinition().apply {
76                     type = "string"
77                 }
78             }
79
80             val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment)
81             assertNotNull(processorName, "couldn't get Rest resource assignment processor name")
82             println(processorName)
83         }
84     }
85
86     @Test
87     fun `test rest aai get resource resolution`() {
88         runBlocking {
89             val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
90                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
91
92             val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
93
94             restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
95             restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils
96                     .resourceDefinitions(bluePrintContext.rootPath)
97
98             val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
99             scriptPropertyInstances["mock-service1"] = MockCapabilityService()
100             scriptPropertyInstances["mock-service2"] = MockCapabilityService()
101
102             restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances
103
104             val resourceAssignment = ResourceAssignment().apply {
105                 name = "rr-aai"
106                 dictionaryName = "aai-get-resource"
107                 dictionarySource = "aai-data"
108                 property = PropertyDefinition().apply {
109                     type = "string"
110                 }
111             }
112
113             val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment)
114             assertNotNull(processorName, "couldn't get AAI Rest resource assignment processor name")
115             println(processorName)
116         }
117     }
118
119     @Test
120     fun `test rest aai put resource resolution`() {
121         runBlocking {
122             val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
123                     "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
124
125             val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
126
127             restResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
128             restResourceResolutionProcessor.resourceDictionaries = ResourceAssignmentUtils
129                     .resourceDefinitions(bluePrintContext.rootPath)
130
131             val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
132             scriptPropertyInstances["mock-service1"] = MockCapabilityService()
133             scriptPropertyInstances["mock-service2"] = MockCapabilityService()
134
135             restResourceResolutionProcessor.scriptPropertyInstances = scriptPropertyInstances
136
137             val resourceAssignment = ResourceAssignment().apply {
138                 name = "rr-aai"
139                 dictionaryName = "aai-put-resource"
140                 dictionarySource = "aai-data"
141                 property = PropertyDefinition().apply {
142                     type = "string"
143                 }
144             }
145
146             val processorName = restResourceResolutionProcessor.applyNB(resourceAssignment)
147             assertNotNull(processorName, "couldn't get AAI Rest resource assignment processor name")
148             println(processorName)
149         }
150     }
151 }