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>(
69 "vf-module-name" : "dlsst001dbcx-adsf-Base-01",
70 "vnfc-name" : "dlsst001dbcx"
74 every { blueprintWebClientService.exchangeResource(any(), any(), any()) } returns mockResponse
76 val restLibPropertyService = mockk<BluePrintRestLibPropertyService>()
77 every { restLibPropertyService.blueprintWebClientService("naming-ms") } returns blueprintWebClientService
78 every { BluePrintDependencyService.applicationContext.getBean(any()) } returns restLibPropertyService
82 fun testNamingResolutionCapability() {
84 val componentFunctionScriptingService = mockk<ComponentFunctionScriptingService>()
86 componentFunctionScriptingService
87 .scriptInstance<ResourceAssignmentProcessor>(any(), any(), any())
88 } returns NamingResolutionCapability()
91 componentFunctionScriptingService.cleanupInstance(any(), any())
94 val raRuntimeService = mockk<ResourceAssignmentRuntimeService>()
95 every { raRuntimeService.bluePrintContext() } returns mockk<BluePrintContext>()
96 every { raRuntimeService.getInputValue("vf-module-name") } returns NullNode.getInstance()
97 every { raRuntimeService.getInputValue("vnfc-name") } returns NullNode.getInstance()
99 every { raRuntimeService.getResolutionStore("policy-instance-name") } returns "SDNC_Policy.Config_MS_1806SRIOV_VNATJson.4.xml".asJsonPrimitive()
100 every { raRuntimeService.getResolutionStore("naming-code") } returns "dbc".asJsonPrimitive()
101 every { raRuntimeService.getResolutionStore("vnf-name") } returns "vnf-123".asJsonPrimitive()
102 every { raRuntimeService.getResolutionStore("vf-module-label") } returns "adsf".asJsonPrimitive()
103 every { raRuntimeService.getResolutionStore("vf-module-type") } returns "base".asJsonPrimitive()
104 every { raRuntimeService.getResolutionStore("cloud-region-id") } returns "region-123".asJsonPrimitive()
106 every { raRuntimeService.putResolutionStore(any(), any()) } returns Unit
107 every { raRuntimeService.putDictionaryStore(any(), any()) } returns Unit
109 val capabilityResourceResolutionProcessor =
110 CapabilityResourceResolutionProcessor(componentFunctionScriptingService)
111 capabilityResourceResolutionProcessor.raRuntimeService = raRuntimeService
113 capabilityResourceResolutionProcessor.resourceDictionaries = resourceDefinitions()
114 // log.info("ResourceAssignments Definitions : ${ capabilityResourceResolutionProcessor.resourceDictionaries.asJsonString(true)} ")
115 val resourceAssignments = resourceAssignments()
116 val resourceAssignmentList = resourceAssignments.values.toMutableList()
117 // log.info("ResourceAssignments Assignments : ${resourceAssignmentList.asJsonString(true)} ")
118 capabilityResourceResolutionProcessor.resourceAssignments = resourceAssignmentList
121 BulkResourceSequencingUtils.process(capabilityResourceResolutionProcessor.resourceAssignments)
122 // log.info("Bulk Sequenced : ${bulkSequenced} ")
123 val resourceAssignment1 = resourceAssignments["vf-module-name"]
124 var status = capabilityResourceResolutionProcessor.applyNB(resourceAssignment1!!)
125 assertTrue(status, "failed to execute capability source")
127 "dlsst001dbcx-adsf-Base-01".asJsonPrimitive(), resourceAssignment1.property!!.value,
128 "assigned value miss match"
131 val resourceAssignment2 = resourceAssignments["vnfc-name"]
132 status = capabilityResourceResolutionProcessor.applyNB(resourceAssignment2!!)
133 assertTrue(status, "failed to execute capability source")
135 "dlsst001dbcx".asJsonPrimitive(), resourceAssignment2.property!!.value,
136 "assigned value miss match"
139 val resoulutionSummary =
140 ResourceAssignmentUtils.generateResolutionSummaryData(
141 resourceAssignments.values.toList(),
142 capabilityResourceResolutionProcessor.resourceDictionaries
144 log.info(resoulutionSummary.asJsonType().toPrettyString())
145 assertNotNull(resoulutionSummary.asJsonType().get("resolution-summary"))
147 val summaries = JacksonUtils.jsonNode(resoulutionSummary)["resolution-summary"]
148 val list = JacksonUtils.getListFromJsonNode(summaries, ResolutionSummary::class.java)
149 val vnfModuleName = list.filter { it.name == "vf-module-name" }
151 assertEquals(list.size, 9)
152 assertNotNull(vnfModuleName[0].keyIdentifiers)
153 assertNotNull(vnfModuleName[0].requestPayload)
157 /** Test dictionaries */
158 private fun resourceDefinitions(): MutableMap<String, ResourceDefinition> {
159 return BluePrintTypes.resourceDefinitions {
160 resourceDefinition("naming-code", "naming-code Resource Definition") {
162 updatedBy("brindasanth@onap.com")
163 property("string", true)
165 sourceInput("input", "") {}
168 resourceDefinition("naming-type", "naming-type Resource Definition") {
170 updatedBy("brindasanth@onap.com")
171 property("string", true)
173 sourceInput("input", "") {}
176 resourceDefinition("cloud-region-id", "cloud-region-id Resource Definition") {
177 tags("cloud-region-id")
178 updatedBy("brindasanth@onap.com")
179 property("string", true)
181 sourceInput("input", "") {}
184 resourceDefinition("policy-instance-name", "policy-instance-name Resource Definition") {
185 tags("policy-instance-name")
186 updatedBy("sp694w@att.com")
187 property("string", true)
189 sourceInput("input", "") {}
192 resourceDefinition("vnf-name", "vnf-name Resource Definition") {
194 updatedBy("sp694w@att.com")
195 property("string", true)
197 sourceInput("input", "") {}
200 resourceDefinition("vf-module-label", "vf-module-label Resource Definition") {
201 tags("vf-module-label")
202 updatedBy("sp694w@att.com")
203 property("string", true)
205 sourceInput("input", "") {}
208 resourceDefinition("vf-module-type", "vf-module-type Resource Definition") {
209 tags("vf-module-type")
210 updatedBy("sp694w@att.com")
211 property("string", true)
213 sourceInput("input", "") {}
216 resourceDefinition("vf-module-name", "vf-module-name Resource Definition") {
217 tags("vf-module-name")
218 updatedBy("brindasanth@onap.com")
219 property("string", true) {
220 metadata("naming-type", "VF-MODULE")
223 sourceCapability("naming-ms", "") {
226 scriptClassReference(NamingResolutionCapability::class)
229 "policy-instance-name",
240 resourceDefinition("vnfc-name", "vnfc-name Resource Definition") {
242 updatedBy("brindasanth@onap.com")
243 property("string", true) {
244 metadata("naming-type", "VNFC")
248 sourceCapability("naming-ms", "") {
251 scriptClassReference(NamingResolutionCapability::class)
253 arrayListOf("vf-module-name")
259 resourceDefinition("ra-dict-name-3", "ra-dict-name-3 Resource Definition") {
260 tags("ra-dict-name-3")
261 updatedBy("brindasanth@onap.com")
262 property("string", true)
264 sourceCapability("naming-ms", "") {
267 scriptClassReference(NamingResolutionCapability::class)
269 arrayListOf("vf-module-name")
278 private fun resourceAssignments(): MutableMap<String, ResourceAssignment> {
279 return BluePrintTypes.resourceAssignments {
281 name = "naming-code", dictionaryName = "naming-code",
282 dictionarySource = "input"
284 property("string", true, "")
285 dependencies(arrayListOf())
288 name = "naming-type", dictionaryName = "naming-type",
289 dictionarySource = "input"
291 property("string", true, "")
292 dependencies(arrayListOf())
295 name = "cloud-region-id", dictionaryName = " cloud-region-id",
296 dictionarySource = "input"
298 property("string", true, "")
299 dependencies(arrayListOf())
302 name = "policy-instance-name", dictionaryName = " policy-instance-name",
303 dictionarySource = "input"
305 property("string", true, "")
306 dependencies(arrayListOf())
309 name = "vnf-name", dictionaryName = " vnf-name",
310 dictionarySource = "input"
312 property("string", true, "")
313 dependencies(arrayListOf())
316 name = "vf-module-label", dictionaryName = " vf-module-label",
317 dictionarySource = "input"
319 property("string", true, "")
320 dependencies(arrayListOf())
323 name = "vf-module-type", dictionaryName = " vf-module-type",
324 dictionarySource = "input"
326 property("string", true, "")
327 dependencies(arrayListOf())
330 name = "vf-module-name", dictionaryName = "vf-module-name",
331 dictionarySource = "naming-ms"
333 property("string", true, "")
336 "policy-instance-name",
345 name = "vnfc-name", dictionaryName = "vnfc-name",
346 dictionarySource = "naming-ms"
348 property("string", true, "")