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