CDS max-occurrence feature
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / ResourceResolutionServiceTest.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Modifications Copyright © 2018 - 2019 IBM, Bell Canada.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
20
21 import io.mockk.every
22 import io.mockk.mockk
23 import kotlinx.coroutines.runBlocking
24 import org.junit.Assert
25 import org.junit.Before
26 import org.junit.Test
27 import org.junit.runner.RunWith
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
29 import org.onap.ccsdk.cds.blueprintsprocessor.core.utils.PayloadUtils
30 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.MockCapabilityScriptRA
31 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
32 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
33 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
34 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintError
35 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
36 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
37 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
38 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
39 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResolutionSummary
40 import org.slf4j.LoggerFactory
41 import org.springframework.beans.factory.annotation.Autowired
42 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
43 import org.springframework.context.ApplicationContext
44 import org.springframework.context.annotation.ComponentScan
45 import org.springframework.test.context.ContextConfiguration
46 import org.springframework.test.context.TestPropertySource
47 import org.springframework.test.context.junit4.SpringRunner
48 import kotlin.test.assertEquals
49 import kotlin.test.assertNotNull
50 import kotlin.test.assertTrue
51
52 /**
53  * ResourceResolutionServiceTest
54  *
55  * @author Brinda Santh DATE : 8/15/2018
56  */
57 @RunWith(SpringRunner::class)
58 @ContextConfiguration(
59     classes = [TestDatabaseConfiguration::class]
60 )
61 @TestPropertySource(locations = ["classpath:application-test.properties"])
62 @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
63 @EnableAutoConfiguration
64 class ResourceResolutionServiceTest {
65
66     private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java)
67
68     @Autowired
69     lateinit var resourceResolutionService: ResourceResolutionService
70
71     private val props = hashMapOf<String, Any>()
72     private val resolutionKey = "resolutionKey"
73     private val resourceId = "1"
74     private val resourceType = "ServiceInstance"
75     private val occurrence = 0
76
77     @Before
78     fun setup() {
79         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = true
80         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey
81         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
82         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
83         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
84         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY] = false
85     }
86
87     @Test
88     fun testRegisteredSource() {
89         val sources = resourceResolutionService.registeredResourceSources()
90         assertNotNull(sources, "failed to get registered sources")
91         assertTrue(
92             sources.containsAll(
93                 arrayListOf(
94                     "source-input", "source-default", "source-db",
95                     "source-rest", "source-capability"
96                 )
97             ),
98             "failed to get registered sources : $sources"
99         )
100     }
101
102     @Test
103     @Throws(Exception::class)
104     fun testResolveResource() {
105         runBlocking {
106
107             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
108
109             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
110                 "1234",
111                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
112             )
113
114             val executionServiceInput =
115                 JacksonUtils.readValueFromClassPathFile(
116                     "payload/requests/sample-resourceresolution-request.json",
117                     ExecutionServiceInput::class.java
118                 )!!
119
120             val resourceAssignmentRuntimeService =
121                 ResourceAssignmentUtils.transformToRARuntimeService(
122                     bluePrintRuntimeService,
123                     "testResolveResource"
124                 )
125
126             // Prepare Inputs
127             PayloadUtils.prepareInputsFromWorkflowPayload(
128                 bluePrintRuntimeService,
129                 executionServiceInput.payload,
130                 "resource-assignment"
131             )
132
133             resourceResolutionService.resolveResources(
134                 resourceAssignmentRuntimeService,
135                 "resource-assignment",
136                 "baseconfig",
137                 props
138             )
139         }.let { (templateMap, assignmentList) ->
140             assertEquals("This is Sample Velocity Template", templateMap)
141
142             val expectedAssignmentList = mutableListOf(
143                 "service-instance-id" to "siid_1234",
144                 "vnf-id" to "vnf_1234",
145                 "vnf_name" to "temp_vnf"
146             )
147             assertEquals(expectedAssignmentList.size, assignmentList.size)
148
149             val areEqual = expectedAssignmentList.zip(assignmentList).all { (it1, it2) ->
150                 it1.first == it2.name && it1.second == it2.property?.value?.asText() ?: null
151             }
152             assertEquals(true, areEqual)
153         }
154     }
155
156     /**
157      * Always perform new resolution even if resolution exists in the database.
158      */
159     @Test
160     @Throws(Exception::class)
161     fun testResolveResourceAlwaysPerformNewResolution() {
162         runBlocking {
163             // Occurrence <= 0 indicates to perform new resolution even if resolution exists in the database.
164             props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = -1
165             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
166
167             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
168                 "1234",
169                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
170             )
171
172             // Request#1
173             val executionServiceInput =
174                 JacksonUtils.readValueFromClassPathFile(
175                     "payload/requests/sample-resourceresolution-request.json",
176                     ExecutionServiceInput::class.java
177                 )!!
178
179             val resourceAssignmentRuntimeService =
180                 ResourceAssignmentUtils.transformToRARuntimeService(
181                     bluePrintRuntimeService,
182                     "testResolveResource"
183                 )
184
185             // Prepare inputs from Request#1
186             PayloadUtils.prepareInputsFromWorkflowPayload(
187                 bluePrintRuntimeService,
188                 executionServiceInput.payload,
189                 "resource-assignment"
190             )
191
192             // Resolve resources as per Request#1
193             resourceResolutionService.resolveResources(
194                 resourceAssignmentRuntimeService,
195                 "resource-assignment",
196                 "baseconfig",
197                 props
198             )
199
200             // Request#2
201             val executionServiceInput2 =
202                 JacksonUtils.readValueFromClassPathFile(
203                     "payload/requests/sample-resourceresolution-request2.json",
204                     ExecutionServiceInput::class.java
205                 )!!
206
207             // Prepare inputs from Request#2
208             PayloadUtils.prepareInputsFromWorkflowPayload(
209                 bluePrintRuntimeService,
210                 executionServiceInput2.payload,
211                 "resource-assignment"
212             )
213
214             // Resolve resources as per Request#2
215             resourceResolutionService.resolveResources(
216                 resourceAssignmentRuntimeService,
217                 "resource-assignment",
218                 "baseconfig",
219                 props
220             )
221         }.let { (templateMap, assignmentList) ->
222             assertEquals("This is Sample Velocity Template", templateMap)
223
224             val assignmentListForRequest1 = mutableListOf(
225                 "service-instance-id" to "siid_1234",
226                 "vnf-id" to "vnf_1234",
227                 "vnf_name" to "temp_vnf"
228             )
229             val assignmentListForRequest2 = mutableListOf(
230                 "service-instance-id" to "siid_new_resolution",
231                 "vnf-id" to "vnf_new_resolution",
232                 "vnf_name" to "temp_vnf_new_resolution"
233             )
234             assertEquals(assignmentListForRequest1.size, assignmentList.size)
235             assertEquals(assignmentListForRequest2.size, assignmentList.size)
236
237             // AlwaysPerformNewResolution use case - resolution request #2 should returns the resolution as per
238             // assignmentListForRequest2 since new resolution is performed.
239             var areEqual = assignmentListForRequest1.zip(assignmentList).all { (it1, it2) ->
240                 it1.first == it2.name && it1.second == it2.property?.value?.asText() ?: null
241             }
242             assertEquals(false, areEqual)
243
244             areEqual = assignmentListForRequest2.zip(assignmentList).all { (it1, it2) ->
245                 it1.first == it2.name && it1.second == it2.property?.value?.asText() ?: null
246             }
247             assertEquals(true, areEqual)
248         }
249     }
250
251     /**
252      * Always perform new resolution even if resolution exists in the database.
253      */
254     @Test
255     @Throws(Exception::class)
256     fun testResolveResourcesForMaxOccurrence() {
257         runBlocking {
258             // Occurrence <= 0 indicates to perform new resolution even if resolution exists in the database.
259             props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = -1
260             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
261
262             // Run time for Request#1
263             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
264                 "1234",
265                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
266             )
267
268             // Request#1
269             val executionServiceInput =
270                 JacksonUtils.readValueFromClassPathFile(
271                     "payload/requests/sample-resourceresolution-request.json",
272                     ExecutionServiceInput::class.java
273                 )!!
274
275             // Prepare inputs from Request#1
276             PayloadUtils.prepareInputsFromWorkflowPayload(
277                 bluePrintRuntimeService,
278                 executionServiceInput.payload,
279                 "resource-assignment"
280             )
281
282             val resourceAssignmentRuntimeService =
283                 ResourceAssignmentUtils.transformToRARuntimeService(
284                     bluePrintRuntimeService,
285                     "testResolveResource"
286                 )
287
288             // Resolve resources as per Request#1
289             resourceResolutionService.resolveResources(
290                 resourceAssignmentRuntimeService,
291                 "resource-assignment",
292                 "maxoccurrence",
293                 props
294             )
295
296             // Run time for Request#2
297             val bluePrintRuntimeService2 = BluePrintMetadataUtils.getBluePrintRuntime(
298                 "1234",
299                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
300             )
301
302             // Request#2
303             val executionServiceInput2 =
304                 JacksonUtils.readValueFromClassPathFile(
305                     "payload/requests/sample-resourceresolution-request2.json",
306                     ExecutionServiceInput::class.java
307                 )!!
308
309             val resourceAssignmentRuntimeService2 =
310                 ResourceAssignmentUtils.transformToRARuntimeService(
311                     bluePrintRuntimeService2,
312                     "testResolveResource"
313                 )
314
315             // Prepare inputs from Request#2
316             PayloadUtils.prepareInputsFromWorkflowPayload(
317                 bluePrintRuntimeService2,
318                 executionServiceInput2.payload,
319                 "resource-assignment"
320             )
321
322             // Resolve resources as per Request#2
323             resourceResolutionService.resolveResources(
324                 resourceAssignmentRuntimeService2,
325                 "resource-assignment",
326                 "maxoccurrence",
327                 props
328             )
329         }.let { (template, assignmentList) ->
330             assertEquals("This is maxoccurrence Velocity Template", template)
331
332             val assignmentListForRequest1 = mutableListOf(
333                 "firmware-version" to "firmware-version-0",
334                 "ip-address" to "192.0.0.1"
335             )
336             val assignmentListForRequest2 = mutableListOf(
337                 "firmware-version" to "firmware-version-1",
338                 "ip-address" to "192.0.0.1"
339             )
340             assertEquals(assignmentListForRequest1.size, assignmentList.size)
341             assertEquals(assignmentListForRequest2.size, assignmentList.size)
342
343             // firmware-version has max-occurrence = 0 means perform new resolution all the time.
344             // ip-address has max-occurrence = 1 so its resolution should only be done once.
345             //
346             // AlwaysPerformNewResolution + max-occurrence feature use case - resolution request #2 should returns
347             // the resolution as per assignmentListForRequest2 since new resolution is only performed for
348             // firmware-version and not for ip-address.
349             var areEqual = assignmentListForRequest1.zip(assignmentList).all { (it1, it2) ->
350                 it1.first == it2.name && it1.second == it2.property?.value?.asText() ?: null
351             }
352             assertEquals(false, areEqual)
353
354             areEqual = assignmentListForRequest2.zip(assignmentList).all { (it1, it2) ->
355                 it1.first == it2.name && it1.second == it2.property?.value?.asText() ?: null
356             }
357             assertEquals(true, areEqual)
358         }
359     }
360
361     /**
362      * Don't perform new resolution in case resolution already exists in the database.
363      */
364     @Test
365     @Throws(Exception::class)
366     fun testResolveResourceNoNewResolution() {
367         runBlocking {
368             // Occurrence > 0 indicates to not perform new resolution if resolution exists in the database.
369             props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = 1
370             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
371
372             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
373                 "1234",
374                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
375             )
376
377             // Request#1
378             val executionServiceInput =
379                 JacksonUtils.readValueFromClassPathFile(
380                     "payload/requests/sample-resourceresolution-request.json",
381                     ExecutionServiceInput::class.java
382                 )!!
383
384             val resourceAssignmentRuntimeService =
385                 ResourceAssignmentUtils.transformToRARuntimeService(
386                     bluePrintRuntimeService,
387                     "testResolveResource"
388                 )
389
390             // Prepare inputs from Request#1
391             PayloadUtils.prepareInputsFromWorkflowPayload(
392                 bluePrintRuntimeService,
393                 executionServiceInput.payload,
394                 "resource-assignment"
395             )
396             // Resolve resources as per Request#1
397             resourceResolutionService.resolveResources(
398                 resourceAssignmentRuntimeService,
399                 "resource-assignment",
400                 "baseconfig",
401                 props
402             )
403
404             // Request#2
405             val executionServiceInput2 =
406                 JacksonUtils.readValueFromClassPathFile(
407                     "payload/requests/sample-resourceresolution-request2.json",
408                     ExecutionServiceInput::class.java
409                 )!!
410
411             // Prepare inputs from Request#2
412             PayloadUtils.prepareInputsFromWorkflowPayload(
413                 bluePrintRuntimeService,
414                 executionServiceInput2.payload,
415                 "resource-assignment"
416             )
417
418             // Resolve resources as per Request#2
419             resourceResolutionService.resolveResources(
420                 resourceAssignmentRuntimeService,
421                 "resource-assignment",
422                 "baseconfig",
423                 props
424             )
425         }.let { (templateMap, assignmentList) ->
426             assertEquals("This is Sample Velocity Template", templateMap)
427
428             val assignmentListForRequest1 = mutableListOf(
429                 "service-instance-id" to "siid_1234",
430                 "vnf-id" to "vnf_1234",
431                 "vnf_name" to "temp_vnf"
432             )
433             val assignmentListForRequest2 = mutableListOf(
434                 "service-instance-id" to "siid_new_resolution",
435                 "vnf-id" to "vnf_new_resolution",
436                 "vnf_name" to "temp_vnf_new_resolution"
437             )
438             assertEquals(assignmentListForRequest1.size, assignmentList.size)
439             assertEquals(assignmentListForRequest2.size, assignmentList.size)
440
441             //  NoNewResolution use case - resolution for request #2 returns the same resolution  as
442             //  assignmentListForRequest1 since no new resolution is/was actually performed.
443             var areEqual = assignmentListForRequest1.zip(assignmentList).all { (it1, it2) ->
444                 it1.first == it2.name && it1.second == it2.property?.value?.asText() ?: null
445             }
446             assertEquals(true, areEqual)
447
448             areEqual = assignmentListForRequest2.zip(assignmentList).all { (it1, it2) ->
449                 it1.first == it2.name && it1.second == it2.property?.value?.asText() ?: null
450             }
451             assertEquals(false, areEqual)
452         }
453     }
454
455     @Test
456     @Throws(Exception::class)
457     fun testResolveResources() {
458         val artifactNames = listOf("baseconfig", "another")
459         runBlocking {
460             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
461
462             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
463                 "1234",
464                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
465             )
466
467             val executionServiceInput =
468                 JacksonUtils.readValueFromClassPathFile(
469                     "payload/requests/sample-resourceresolution-request.json",
470                     ExecutionServiceInput::class.java
471                 )!!
472
473             // Prepare Inputs
474             PayloadUtils.prepareInputsFromWorkflowPayload(
475                 bluePrintRuntimeService,
476                 executionServiceInput.payload,
477                 "resource-assignment"
478             )
479
480             resourceResolutionService.resolveResources(
481                 bluePrintRuntimeService,
482                 "resource-assignment",
483                 artifactNames,
484                 props,
485                 "mockStep"
486             )
487         }.let {
488             assertEquals(artifactNames.toSet(), it.templateMap.keys)
489             assertEquals(artifactNames.toSet(), it.assignmentMap.keys)
490
491             assertEquals("This is Sample Velocity Template", it.templateMap["another"])
492             assertEquals("vnf_1234", it.assignmentMap["another"]!!["vnf-id"]!!.asText())
493         }
494     }
495
496     @Test
497     @Throws(Exception::class)
498     fun testResolveResourcesWithMappingAndTemplate() {
499         runBlocking {
500             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
501
502             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
503                 "1234",
504                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
505             )
506
507             val executionServiceInput =
508                 JacksonUtils.readValueFromClassPathFile(
509                     "payload/requests/sample-resourceresolution-request.json",
510                     ExecutionServiceInput::class.java
511                 )!!
512
513             val resourceAssignmentRuntimeService =
514                 ResourceAssignmentUtils.transformToRARuntimeService(
515                     bluePrintRuntimeService,
516                     "testResolveResourcesWithMappingAndTemplate"
517                 )
518
519             val artifactPrefix = "another"
520
521             // Prepare Inputs
522             PayloadUtils.prepareInputsFromWorkflowPayload(
523                 bluePrintRuntimeService,
524                 executionServiceInput.payload,
525                 "resource-assignment"
526             )
527
528             assertNotNull(
529                 resourceResolutionService.resolveResources(
530                     resourceAssignmentRuntimeService,
531                     "resource-assignment",
532                     artifactPrefix,
533                     props
534                 ),
535                 "Couldn't Resolve Resources for artifact $artifactPrefix"
536             )
537         }
538     }
539
540     @Test
541     @Throws(Exception::class)
542     fun testResolveResourcesResolutionSummary() {
543         runBlocking {
544             props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY] = true
545             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
546
547             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
548                 "1234",
549                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
550             )
551
552             val executionServiceInput =
553                 JacksonUtils.readValueFromClassPathFile(
554                     "payload/requests/sample-resourceresolution-request.json",
555                     ExecutionServiceInput::class.java
556                 )!!
557
558             val resourceAssignmentRuntimeService =
559                 ResourceAssignmentUtils.transformToRARuntimeService(
560                     bluePrintRuntimeService,
561                     "testResolveResourcesWithMappingAndTemplate"
562                 )
563
564             val artifactPrefix = "notemplate"
565
566             // Prepare Inputs
567             PayloadUtils.prepareInputsFromWorkflowPayload(
568                 bluePrintRuntimeService,
569                 executionServiceInput.payload,
570                 "resource-assignment"
571             )
572
573             resourceResolutionService.resolveResources(
574                 resourceAssignmentRuntimeService,
575                 "resource-assignment",
576                 artifactPrefix,
577                 props
578             )
579         }.let {
580             val summaries = JacksonUtils.jsonNode(it.first)["resolution-summary"]
581             val list = JacksonUtils.getListFromJsonNode(summaries, ResolutionSummary::class.java)
582             assertEquals(list.size, 3)
583         }
584     }
585
586     @Test
587     @Throws(Exception::class)
588     fun testResolveResourcesWithoutTemplate() {
589         val artifactPrefix = "notemplate"
590         runBlocking {
591             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
592
593             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
594                 "1234",
595                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
596             )
597
598             val executionServiceInput =
599                 JacksonUtils.readValueFromClassPathFile(
600                     "payload/requests/sample-resourceresolution-request.json",
601                     ExecutionServiceInput::class.java
602                 )!!
603
604             val resourceAssignmentRuntimeService =
605                 ResourceAssignmentUtils.transformToRARuntimeService(
606                     bluePrintRuntimeService,
607                     "testResolveResourcesWithMappingAndTemplate"
608                 )
609
610             // Prepare Inputs
611             PayloadUtils.prepareInputsFromWorkflowPayload(
612                 bluePrintRuntimeService,
613                 executionServiceInput.payload,
614                 "resource-assignment"
615             )
616
617             resourceResolutionService.resolveResources(
618                 resourceAssignmentRuntimeService,
619                 "resource-assignment",
620                 artifactPrefix,
621                 props
622             )
623         }.let {
624             assertEquals(
625                 """
626                 {
627                   "service-instance-id" : "siid_1234",
628                   "vnf-id" : "vnf_1234",
629                   "vnf_name" : "temp_vnf"
630                 }
631                 """.trimIndent(),
632                 it.first
633             )
634             val areEqual = it.second.first().name == "service-instance-id" &&
635                 "siid_1234" == it.second.first().property?.value?.asText() ?: null
636             assertEquals(true, areEqual)
637         }
638     }
639
640     @Test
641     fun testResolveResourcesWithResourceIdAndResourceType() {
642         props[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = ""
643         runBlocking {
644             Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService)
645
646             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(
647                 "1234",
648                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
649             )
650
651             val executionServiceInput =
652                 JacksonUtils.readValueFromClassPathFile(
653                     "payload/requests/sample-resourceresolution-request.json",
654                     ExecutionServiceInput::class.java
655                 )!!
656
657             val resourceAssignmentRuntimeService =
658                 ResourceAssignmentUtils.transformToRARuntimeService(
659                     bluePrintRuntimeService,
660                     "testResolveResourcesWithMappingAndTemplate"
661                 )
662
663             val artifactPrefix = "another"
664
665             // Prepare Inputs
666             PayloadUtils.prepareInputsFromWorkflowPayload(
667                 bluePrintRuntimeService,
668                 executionServiceInput.payload,
669                 "resource-assignment"
670             )
671
672             assertNotNull(
673                 resourceResolutionService.resolveResources(
674                     resourceAssignmentRuntimeService,
675                     "resource-assignment",
676                     artifactPrefix,
677                     props
678                 ),
679                 "Couldn't Resolve Resources for artifact $artifactPrefix"
680             )
681         }
682     }
683
684     @Test
685     fun testResourceResolutionForDefinition() {
686         val resourceDefinitions = BluePrintTypes.resourceDefinitions {
687             resourceDefinition(name = "port-speed", description = "Port Speed") {
688                 property(type = "string", required = true)
689                 sources {
690                     sourceCapability(id = "sdno", description = "SDNO Source") {
691                         definedProperties {
692                             type(BluePrintConstants.SCRIPT_KOTLIN)
693                             scriptClassReference(MockCapabilityScriptRA::class.qualifiedName!!)
694                             keyDependencies(arrayListOf("device-id"))
695                         }
696                     }
697                     sourceDb(id = "sdnc", description = "SDNC Controller") {
698                         definedProperties {
699                             endpointSelector("processor-db")
700                             query("SELECT PORT_SPEED FROM XXXX WHERE DEVICE_ID = :device_id")
701                             inputKeyMapping {
702                                 map("device_id", "\$device-id")
703                             }
704                             keyDependencies(arrayListOf("device-id"))
705                         }
706                     }
707                 }
708             }
709             resourceDefinition(name = "device-id", description = "Device Id") {
710                 property(type = "string", required = true) {
711                     sources {
712                         sourceInput(id = "input", description = "Dependency Source") {}
713                     }
714                 }
715             }
716         }
717         runBlocking {
718             val raRuntimeService = mockk<ResourceAssignmentRuntimeService>()
719             every { raRuntimeService.bluePrintContext() } returns mockk<BluePrintContext>()
720             every { raRuntimeService.getBluePrintError() } returns BluePrintError()
721             every { raRuntimeService.setBluePrintError(any()) } returns Unit
722             every { raRuntimeService.getInputValue("device-id") } returns "123456".asJsonPrimitive()
723             every { raRuntimeService.putResolutionStore(any(), any()) } returns Unit
724
725             val applicationContext = mockk<ApplicationContext>()
726             every { applicationContext.getBean("rr-processor-source-capability") } returns MockCapabilityScriptRA()
727             every { applicationContext.getBean("rr-processor-source-db") } returns MockCapabilityScriptRA()
728             every { applicationContext.getBean("rr-processor-source-input") } returns MockCapabilityScriptRA()
729
730             val sources = arrayListOf<String>("sdno", "sdnc")
731
732             val resourceResolutionService = ResourceResolutionServiceImpl(applicationContext, mockk(), mockk(), mockk())
733             val resolvedResources = resourceResolutionService.resolveResourceDefinition(
734                 raRuntimeService,
735                 resourceDefinitions, "port-speed", sources
736             )
737             assertNotNull(resolvedResources, "failed to resolve the resources")
738         }
739     }
740 }