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.BluePrintError
36 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
37 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
38 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
39 import org.onap.ccsdk.cds.controllerblueprints.core.logger
40 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
41 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
42 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
43 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResolutionSummary
44 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
45 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
46 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.BulkResourceSequencingUtils
47 import kotlin.test.Test
48 import kotlin.test.assertEquals
49 import kotlin.test.assertNotNull
50 import kotlin.test.assertTrue
56 class NamingResolutionCapabilityTest {
58 private val log = logger(NamingResolutionCapabilityTest::class)
63 mockkObject(BluePrintDependencyService)
65 val blueprintWebClientService = mockk<BlueprintWebClientService>()
66 // Create mock Response
67 val mockResponse = BlueprintWebClientService.WebClientResponse<String>(
70 "vf-module-name" : "dlsst001dbcx-adsf-Base-01",
71 "vnfc-name" : "dlsst001dbcx"
75 every { blueprintWebClientService.exchangeResource(any(), any(), any()) } returns mockResponse
77 val restLibPropertyService = mockk<BluePrintRestLibPropertyService>()
78 every { restLibPropertyService.blueprintWebClientService("naming-ms") } returns blueprintWebClientService
79 every { BluePrintDependencyService.applicationContext.getBean(any()) } returns restLibPropertyService
83 fun testNamingResolutionCapability() {
85 val componentFunctionScriptingService = mockk<ComponentFunctionScriptingService>()
87 componentFunctionScriptingService
88 .scriptInstance<ResourceAssignmentProcessor>(any(), any(), any())
89 } returns NamingResolutionCapability()
91 val raRuntimeService = mockk<ResourceAssignmentRuntimeService>()
92 every { raRuntimeService.getBluePrintError() } returns BluePrintError()
93 every { raRuntimeService.bluePrintContext() } returns mockk<BluePrintContext>()
94 every { raRuntimeService.getInputValue("vf-module-name") } returns NullNode.getInstance()
95 every { raRuntimeService.getInputValue("vnfc-name") } returns NullNode.getInstance()
97 every { raRuntimeService.getResolutionStore("policy-instance-name") } returns "SDNC_Policy.Config_MS_1806SRIOV_VNATJson.4.xml".asJsonPrimitive()
98 every { raRuntimeService.getResolutionStore("naming-code") } returns "dbc".asJsonPrimitive()
99 every { raRuntimeService.getResolutionStore("vnf-name") } returns "vnf-123".asJsonPrimitive()
100 every { raRuntimeService.getResolutionStore("vf-module-label") } returns "adsf".asJsonPrimitive()
101 every { raRuntimeService.getResolutionStore("vf-module-type") } returns "base".asJsonPrimitive()
102 every { raRuntimeService.getResolutionStore("cloud-region-id") } returns "region-123".asJsonPrimitive()
104 every { raRuntimeService.putResolutionStore(any(), any()) } returns Unit
105 every { raRuntimeService.putDictionaryStore(any(), any()) } returns Unit
107 val capabilityResourceResolutionProcessor =
108 CapabilityResourceResolutionProcessor(componentFunctionScriptingService)
109 capabilityResourceResolutionProcessor.raRuntimeService = raRuntimeService
111 capabilityResourceResolutionProcessor.resourceDictionaries = resourceDefinitions()
112 // log.info("ResourceAssignments Definitions : ${ capabilityResourceResolutionProcessor.resourceDictionaries.asJsonString(true)} ")
113 val resourceAssignments = resourceAssignments()
114 val resourceAssignmentList = resourceAssignments.values.toMutableList()
115 // log.info("ResourceAssignments Assignments : ${resourceAssignmentList.asJsonString(true)} ")
116 capabilityResourceResolutionProcessor.resourceAssignments = resourceAssignmentList
119 BulkResourceSequencingUtils.process(capabilityResourceResolutionProcessor.resourceAssignments)
120 // log.info("Bulk Sequenced : ${bulkSequenced} ")
121 val resourceAssignment1 = resourceAssignments["vf-module-name"]
122 var status = capabilityResourceResolutionProcessor.applyNB(resourceAssignment1!!)
123 assertTrue(status, "failed to execute capability source")
125 "dlsst001dbcx-adsf-Base-01".asJsonPrimitive(), resourceAssignment1.property!!.value,
126 "assigned value miss match"
129 val resourceAssignment2 = resourceAssignments["vnfc-name"]
130 status = capabilityResourceResolutionProcessor.applyNB(resourceAssignment2!!)
131 assertTrue(status, "failed to execute capability source")
133 "dlsst001dbcx".asJsonPrimitive(), resourceAssignment2.property!!.value,
134 "assigned value miss match"
137 val resoulutionSummary =
138 ResourceAssignmentUtils.generateResolutionSummaryData(
139 resourceAssignments.values.toList(),
140 capabilityResourceResolutionProcessor.resourceDictionaries
142 log.info(resoulutionSummary.asJsonType().toPrettyString())
143 assertNotNull(resoulutionSummary.asJsonType().get("resolution-summary"))
145 val summaries = JacksonUtils.jsonNode(resoulutionSummary)["resolution-summary"]
146 val list = JacksonUtils.getListFromJsonNode(summaries, ResolutionSummary::class.java)
147 val vnfModuleName = list.filter { it.name == "vf-module-name" }
149 assertEquals(list.size, 9)
150 assertNotNull(vnfModuleName[0].keyIdentifiers)
151 assertNotNull(vnfModuleName[0].requestPayload)
155 /** Test dictionaries */
156 private fun resourceDefinitions(): MutableMap<String, ResourceDefinition> {
157 return BluePrintTypes.resourceDefinitions {
158 resourceDefinition("naming-code", "naming-code Resource Definition") {
160 updatedBy("brindasanth@onap.com")
161 property("string", true)
163 sourceInput("input", "") {}
166 resourceDefinition("naming-type", "naming-type Resource Definition") {
168 updatedBy("brindasanth@onap.com")
169 property("string", true)
171 sourceInput("input", "") {}
174 resourceDefinition("cloud-region-id", "cloud-region-id Resource Definition") {
175 tags("cloud-region-id")
176 updatedBy("brindasanth@onap.com")
177 property("string", true)
179 sourceInput("input", "") {}
182 resourceDefinition("policy-instance-name", "policy-instance-name Resource Definition") {
183 tags("policy-instance-name")
184 updatedBy("sp694w@att.com")
185 property("string", true)
187 sourceInput("input", "") {}
190 resourceDefinition("vnf-name", "vnf-name Resource Definition") {
192 updatedBy("sp694w@att.com")
193 property("string", true)
195 sourceInput("input", "") {}
198 resourceDefinition("vf-module-label", "vf-module-label Resource Definition") {
199 tags("vf-module-label")
200 updatedBy("sp694w@att.com")
201 property("string", true)
203 sourceInput("input", "") {}
206 resourceDefinition("vf-module-type", "vf-module-type Resource Definition") {
207 tags("vf-module-type")
208 updatedBy("sp694w@att.com")
209 property("string", true)
211 sourceInput("input", "") {}
214 resourceDefinition("vf-module-name", "vf-module-name Resource Definition") {
215 tags("vf-module-name")
216 updatedBy("brindasanth@onap.com")
217 property("string", true) {
218 metadata("naming-type", "VF-MODULE")
221 sourceCapability("naming-ms", "") {
224 scriptClassReference(NamingResolutionCapability::class)
227 "policy-instance-name",
238 resourceDefinition("vnfc-name", "vnfc-name Resource Definition") {
240 updatedBy("brindasanth@onap.com")
241 property("string", true) {
242 metadata("naming-type", "VNFC")
246 sourceCapability("naming-ms", "") {
249 scriptClassReference(NamingResolutionCapability::class)
251 arrayListOf("vf-module-name")
257 resourceDefinition("ra-dict-name-3", "ra-dict-name-3 Resource Definition") {
258 tags("ra-dict-name-3")
259 updatedBy("brindasanth@onap.com")
260 property("string", true)
262 sourceCapability("naming-ms", "") {
265 scriptClassReference(NamingResolutionCapability::class)
267 arrayListOf("vf-module-name")
276 private fun resourceAssignments(): MutableMap<String, ResourceAssignment> {
277 return BluePrintTypes.resourceAssignments {
279 name = "naming-code", dictionaryName = "naming-code",
280 dictionarySource = "input"
282 property("string", true, "")
283 dependencies(arrayListOf())
286 name = "naming-type", dictionaryName = "naming-type",
287 dictionarySource = "input"
289 property("string", true, "")
290 dependencies(arrayListOf())
293 name = "cloud-region-id", dictionaryName = " cloud-region-id",
294 dictionarySource = "input"
296 property("string", true, "")
297 dependencies(arrayListOf())
300 name = "policy-instance-name", dictionaryName = " policy-instance-name",
301 dictionarySource = "input"
303 property("string", true, "")
304 dependencies(arrayListOf())
307 name = "vnf-name", dictionaryName = " vnf-name",
308 dictionarySource = "input"
310 property("string", true, "")
311 dependencies(arrayListOf())
314 name = "vf-module-label", dictionaryName = " vf-module-label",
315 dictionarySource = "input"
317 property("string", true, "")
318 dependencies(arrayListOf())
321 name = "vf-module-type", dictionaryName = " vf-module-type",
322 dictionarySource = "input"
324 property("string", true, "")
325 dependencies(arrayListOf())
328 name = "vf-module-name", dictionaryName = "vf-module-name",
329 dictionarySource = "naming-ms"
331 property("string", true, "")
334 "policy-instance-name",
343 name = "vnfc-name", dictionaryName = "vnfc-name",
344 dictionarySource = "naming-ms"
346 property("string", true, "")