2 * Copyright © 2019 IBM.
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.capabilities
19 import com.fasterxml.jackson.databind.node.NullNode
20 import io.mockk.coEvery
23 import io.mockk.mockkObject
24 import kotlinx.coroutines.runBlocking
25 import org.junit.Before
26 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
27 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.CapabilityResourceResolutionProcessor
28 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
29 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resourceAssignments
30 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.resourceDefinitions
31 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
32 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
33 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
34 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
35 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
36 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
37 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
38 import org.onap.ccsdk.cds.controllerblueprints.core.logger
39 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
40 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
41 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
42 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResolutionSummary
43 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
44 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
45 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.BulkResourceSequencingUtils
46 import kotlin.test.Test
47 import kotlin.test.assertEquals
48 import kotlin.test.assertNotNull
49 import kotlin.test.assertTrue
55 class NamingResolutionCapabilityTest {
57 private val log = logger(NamingResolutionCapabilityTest::class)
62 mockkObject(BluePrintDependencyService)
64 val blueprintWebClientService = mockk<BlueprintWebClientService>()
65 // Create mock Response
66 val mockResponse = BlueprintWebClientService.WebClientResponse<String>(
68 "vf-module-name" : "dlsst001dbcx-adsf-Base-01",
69 "vnfc-name" : "dlsst001dbcx"
73 every { blueprintWebClientService.exchangeResource(any(), any(), any()) } returns mockResponse
75 val restLibPropertyService = mockk<BluePrintRestLibPropertyService>()
76 every { restLibPropertyService.blueprintWebClientService("naming-ms") } returns blueprintWebClientService
77 every { BluePrintDependencyService.applicationContext.getBean(any()) } returns restLibPropertyService
81 fun testNamingResolutionCapability() {
83 val componentFunctionScriptingService = mockk<ComponentFunctionScriptingService>()
85 componentFunctionScriptingService
86 .scriptInstance<ResourceAssignmentProcessor>(any(), any(), any())
87 } returns NamingResolutionCapability()
90 componentFunctionScriptingService.cleanupInstance(any(), any())
93 val raRuntimeService = mockk<ResourceAssignmentRuntimeService>()
94 every { raRuntimeService.bluePrintContext() } returns mockk<BluePrintContext>()
95 every { raRuntimeService.getInputValue("vf-module-name") } returns NullNode.getInstance()
96 every { raRuntimeService.getInputValue("vnfc-name") } returns NullNode.getInstance()
98 every { raRuntimeService.getResolutionStore("policy-instance-name") } returns "SDNC_Policy.Config_MS_1806SRIOV_VNATJson.4.xml".asJsonPrimitive()
99 every { raRuntimeService.getResolutionStore("naming-code") } returns "dbc".asJsonPrimitive()
100 every { raRuntimeService.getResolutionStore("vnf-name") } returns "vnf-123".asJsonPrimitive()
101 every { raRuntimeService.getResolutionStore("vf-module-label") } returns "adsf".asJsonPrimitive()
102 every { raRuntimeService.getResolutionStore("vf-module-type") } returns "base".asJsonPrimitive()
103 every { raRuntimeService.getResolutionStore("cloud-region-id") } returns "region-123".asJsonPrimitive()
105 every { raRuntimeService.putResolutionStore(any(), any()) } returns Unit
106 every { raRuntimeService.putDictionaryStore(any(), any()) } returns Unit
108 val capabilityResourceResolutionProcessor =
109 CapabilityResourceResolutionProcessor(componentFunctionScriptingService)
110 capabilityResourceResolutionProcessor.raRuntimeService = raRuntimeService
112 capabilityResourceResolutionProcessor.resourceDictionaries = resourceDefinitions()
113 // log.info("ResourceAssignments Definitions : ${ capabilityResourceResolutionProcessor.resourceDictionaries.asJsonString(true)} ")
114 val resourceAssignments = resourceAssignments()
115 val resourceAssignmentList = resourceAssignments.values.toMutableList()
116 // log.info("ResourceAssignments Assignments : ${resourceAssignmentList.asJsonString(true)} ")
117 capabilityResourceResolutionProcessor.resourceAssignments = resourceAssignmentList
120 BulkResourceSequencingUtils.process(capabilityResourceResolutionProcessor.resourceAssignments)
121 // log.info("Bulk Sequenced : ${bulkSequenced} ")
122 val resourceAssignment1 = resourceAssignments["vf-module-name"]
123 var status = capabilityResourceResolutionProcessor.applyNB(resourceAssignment1!!)
124 assertTrue(status, "failed to execute capability source")
126 "dlsst001dbcx-adsf-Base-01".asJsonPrimitive(), resourceAssignment1.property!!.value,
127 "assigned value miss match"
130 val resourceAssignment2 = resourceAssignments["vnfc-name"]
131 status = capabilityResourceResolutionProcessor.applyNB(resourceAssignment2!!)
132 assertTrue(status, "failed to execute capability source")
134 "dlsst001dbcx".asJsonPrimitive(), resourceAssignment2.property!!.value,
135 "assigned value miss match"
138 val resoulutionSummary =
139 ResourceAssignmentUtils.generateResolutionSummaryData(resourceAssignments.values.toList(),
140 capabilityResourceResolutionProcessor.resourceDictionaries)
141 log.info(resoulutionSummary.asJsonType().toPrettyString())
142 assertNotNull(resoulutionSummary.asJsonType().get("resolution-summary"))
144 val summaries = JacksonUtils.jsonNode(resoulutionSummary)["resolution-summary"]
145 val list = JacksonUtils.getListFromJsonNode(summaries, ResolutionSummary::class.java)
146 val vnfModuleName = list.filter { it.name == "vf-module-name" }
148 assertEquals(list.size, 9)
149 assertNotNull(vnfModuleName[0].keyIdentifiers)
150 assertNotNull(vnfModuleName[0].requestPayload)
154 /** Test dictionaries */
155 private fun resourceDefinitions(): MutableMap<String, ResourceDefinition> {
156 return BluePrintTypes.resourceDefinitions {
157 resourceDefinition("naming-code", "naming-code Resource Definition") {
159 updatedBy("brindasanth@onap.com")
160 property("string", true)
162 sourceInput("input", "") {}
165 resourceDefinition("naming-type", "naming-type Resource Definition") {
167 updatedBy("brindasanth@onap.com")
168 property("string", true)
170 sourceInput("input", "") {}
173 resourceDefinition("cloud-region-id", "cloud-region-id Resource Definition") {
174 tags("cloud-region-id")
175 updatedBy("brindasanth@onap.com")
176 property("string", true)
178 sourceInput("input", "") {}
181 resourceDefinition("policy-instance-name", "policy-instance-name Resource Definition") {
182 tags("policy-instance-name")
183 updatedBy("sp694w@att.com")
184 property("string", true)
186 sourceInput("input", "") {}
189 resourceDefinition("vnf-name", "vnf-name Resource Definition") {
191 updatedBy("sp694w@att.com")
192 property("string", true)
194 sourceInput("input", "") {}
197 resourceDefinition("vf-module-label", "vf-module-label Resource Definition") {
198 tags("vf-module-label")
199 updatedBy("sp694w@att.com")
200 property("string", true)
202 sourceInput("input", "") {}
205 resourceDefinition("vf-module-type", "vf-module-type Resource Definition") {
206 tags("vf-module-type")
207 updatedBy("sp694w@att.com")
208 property("string", true)
210 sourceInput("input", "") {}
213 resourceDefinition("vf-module-name", "vf-module-name Resource Definition") {
214 tags("vf-module-name")
215 updatedBy("brindasanth@onap.com")
216 property("string", true) {
217 metadata("naming-type", "VF-MODULE")
220 sourceCapability("naming-ms", "") {
223 scriptClassReference(NamingResolutionCapability::class)
226 "policy-instance-name",
237 resourceDefinition("vnfc-name", "vnfc-name Resource Definition") {
239 updatedBy("brindasanth@onap.com")
240 property("string", true) {
241 metadata("naming-type", "VNFC")
245 sourceCapability("naming-ms", "") {
248 scriptClassReference(NamingResolutionCapability::class)
250 arrayListOf("vf-module-name")
256 resourceDefinition("ra-dict-name-3", "ra-dict-name-3 Resource Definition") {
257 tags("ra-dict-name-3")
258 updatedBy("brindasanth@onap.com")
259 property("string", true)
261 sourceCapability("naming-ms", "") {
264 scriptClassReference(NamingResolutionCapability::class)
266 arrayListOf("vf-module-name")
275 private fun resourceAssignments(): MutableMap<String, ResourceAssignment> {
276 return BluePrintTypes.resourceAssignments {
278 name = "naming-code", dictionaryName = "naming-code",
279 dictionarySource = "input"
281 property("string", true, "")
282 dependencies(arrayListOf())
285 name = "naming-type", dictionaryName = "naming-type",
286 dictionarySource = "input"
288 property("string", true, "")
289 dependencies(arrayListOf())
292 name = "cloud-region-id", dictionaryName = " cloud-region-id",
293 dictionarySource = "input"
295 property("string", true, "")
296 dependencies(arrayListOf())
299 name = "policy-instance-name", dictionaryName = " policy-instance-name",
300 dictionarySource = "input"
302 property("string", true, "")
303 dependencies(arrayListOf())
306 name = "vnf-name", dictionaryName = " vnf-name",
307 dictionarySource = "input"
309 property("string", true, "")
310 dependencies(arrayListOf())
313 name = "vf-module-label", dictionaryName = " vf-module-label",
314 dictionarySource = "input"
316 property("string", true, "")
317 dependencies(arrayListOf())
320 name = "vf-module-type", dictionaryName = " vf-module-type",
321 dictionarySource = "input"
323 property("string", true, "")
324 dependencies(arrayListOf())
327 name = "vf-module-name", dictionaryName = "vf-module-name",
328 dictionarySource = "naming-ms"
330 property("string", true, "")
333 "policy-instance-name",
342 name = "vnfc-name", dictionaryName = "vnfc-name",
343 dictionarySource = "naming-ms"
345 property("string", true, "")