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