88405f00790d9955be4bcee834390818df83b408
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / resource-resolution / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / resource / resolution / utils / ResourceAssignmentUtilsTest.kt
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  * Modifications Copyright (c) 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  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils
23
24 import com.fasterxml.jackson.databind.JsonNode
25 import com.fasterxml.jackson.databind.node.TextNode
26 import io.mockk.every
27 import io.mockk.spyk
28 import kotlinx.coroutines.runBlocking
29 import org.junit.Before
30 import org.junit.Test
31 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
32 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.METADATA_TRANSFORM_TEMPLATE
33 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
34 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
35 import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType
36 import org.onap.ccsdk.cds.controllerblueprints.core.data.EntrySchema
37 import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate
38 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
39 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
40 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
41 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
42 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
43 import java.util.concurrent.atomic.AtomicBoolean
44 import kotlin.concurrent.thread
45 import kotlin.test.assertEquals
46
47 data class IpAddress(val port: String, val ip: String)
48 data class Host(val name: String, val ipAddress: IpAddress)
49 data class ExpectedResponseIp(val ip: String)
50 data class ExpectedResponseIpAddress(val ipAddress: IpAddress)
51
52 class ResourceAssignmentUtilsTest {
53
54     private lateinit var resourceAssignmentRuntimeService: ResourceAssignmentRuntimeService
55     private lateinit var resourceAssignment: ResourceAssignment
56
57     private lateinit var inputMapToTestPrimitiveTypeWithValue: JsonNode
58     private lateinit var inputMapToTestPrimitiveTypeWithKeyValue: JsonNode
59     private lateinit var inputMapToTestCollectionOfPrimitiveType: JsonNode
60     private lateinit var inputMapToTestCollectionOfComplexTypeWithOneOutputKeyMapping: JsonNode
61     private lateinit var inputMapToTestCollectionOfComplexTypeWithAllOutputKeyMapping: JsonNode
62     private lateinit var inputMapToTestComplexTypeWithOneOutputKeyMapping: JsonNode
63     private lateinit var inputMapToTestComplexTypeWithAllOutputKeyMapping: JsonNode
64     private lateinit var expectedValueToTestPrimitiveType: JsonNode
65     private lateinit var expectedValueToTesCollectionOfPrimitiveType: JsonNode
66     private lateinit var expectedValueToTestCollectionOfComplexTypeWithOneOutputKeyMapping: JsonNode
67     private lateinit var expectedValueToTestComplexTypeWithOneOutputKeyMapping: JsonNode
68     private lateinit var expectedValueToTestComplexTypeWithAllOutputKeyMapping: JsonNode
69     private lateinit var expectedValueToTestCollectionOfComplexTypeWithAllOutputKeyMapping: JsonNode
70
71     @Before
72     fun setup() {
73
74         val bluePrintContext = runBlocking {
75             BluePrintMetadataUtils.getBluePrintContext(
76                 "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
77             )
78         }
79
80         resourceAssignmentRuntimeService = spyk(ResourceAssignmentRuntimeService("1234", bluePrintContext))
81
82         // Init input map and expected values for tests
83         initInputMapAndExpectedValuesForPrimitiveType()
84         initInputMapAndExpectedValuesForCollection()
85         initInputMapAndExpectedValuesForComplexType()
86
87         val propertiesDefinition1 = PropertyDefinition().apply {
88             type = "string"
89             id = "port"
90         }
91
92         val propertiesDefinition2 = PropertyDefinition().apply {
93             type = "string"
94             id = "ip"
95         }
96
97         val propertiesDefinition3 = PropertyDefinition().apply {
98             type = "string"
99             id = "name"
100         }
101
102         val propertiesDefinition4 = PropertyDefinition().apply {
103             type = "ip-address"
104             id = "ipAddress"
105         }
106
107         val mapOfPropertiesIpAddress = mutableMapOf<String, PropertyDefinition>()
108         mapOfPropertiesIpAddress["port"] = propertiesDefinition1
109         mapOfPropertiesIpAddress["ip"] = propertiesDefinition2
110
111         val mapOfPropertiesHost = mutableMapOf<String, PropertyDefinition>()
112         mapOfPropertiesHost["name"] = propertiesDefinition3
113         mapOfPropertiesHost["ipAddress"] = propertiesDefinition4
114
115         val myDataTypeIpaddress = DataType().apply {
116             id = "ip-address"
117             properties = mapOfPropertiesIpAddress
118         }
119
120         val myDataTypeHost = DataType().apply {
121             id = "host"
122             properties = mapOfPropertiesHost
123         }
124
125         every {
126             resourceAssignmentRuntimeService.bluePrintContext().dataTypeByName("ip-address")
127         } returns myDataTypeIpaddress
128
129         every { resourceAssignmentRuntimeService.bluePrintContext().dataTypeByName("host") } returns myDataTypeHost
130
131         every { resourceAssignmentRuntimeService.setNodeTemplateAttributeValue(any(), any(), any()) } returns Unit
132     }
133
134     @Test
135     fun `generateResourceDataForAssignments - positive test`() {
136         // given a valid resource assignment
137         val validResourceAssignment1 = createResourceAssignmentForTest("valid_value", "pnf-id")
138         val validResourceAssignment2 = createResourceAssignmentForTest("also_valid", "a1")
139
140         // and a list containing that resource assignment
141         val resourceAssignmentList = listOf<ResourceAssignment>(validResourceAssignment1, validResourceAssignment2)
142
143         // when the values of the resources are evaluated
144         val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList)
145
146         // then the assignment should produce a valid result
147         val expected = """
148             {
149               "a1" : "also_valid",
150               "pnf-id" : "valid_value"
151             }
152         """.trimIndent()
153         assertEquals(expected, outcome.trimIndent(), "unexpected outcome generated")
154     }
155
156     @Test
157     fun `generateResourceDataForAssignments - resource without value is not resolved as null`() {
158         // given a valid resource assignment
159         val resourceAssignmentWithNullValue = createResourceAssignmentForTest(null)
160
161         // and a list containing that resource assignment
162         val resourceAssignmentList = listOf<ResourceAssignment>(resourceAssignmentWithNullValue)
163
164         // when the values of the resources are evaluated
165         val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList)
166
167         // then the assignment should produce a valid result
168         val expected = "{\n" + "  \"pnf-id\" : \"\${pnf-id}\"\n" + "}"
169         assertEquals(expected, outcome.replace("\r\n", "\n"), "unexpected outcome generated")
170     }
171
172     @Test
173     fun generateResolutionSummaryDataTest() {
174         val resourceAssignment = createResourceAssignmentForTest(null)
175         val resourceDefinition = ResourceDefinition()
176         val nodeTemplate = NodeTemplate().apply {
177             properties = mutableMapOf("resolved-payload" to JacksonUtils.jsonNode("{\"mock\": true}"))
178         }
179         resourceDefinition.sources = mutableMapOf("input" to nodeTemplate)
180         resourceDefinition.property = PropertyDefinition().apply {
181             this.description = "pnf-id"
182             this.metadata = mutableMapOf("aai-path" to "//path/in/aai")
183         }
184
185         val result = ResourceAssignmentUtils.generateResolutionSummaryData(
186             listOf(resourceAssignment), mapOf("pnf-id" to resourceDefinition)
187         )
188
189         assertEquals(
190             """
191             {
192                 "resolution-summary":[
193                     {
194                         "name":"pnf-id",
195                         "value":"",
196                         "required":false,
197                         "type":"string",
198                         "key-identifiers":[],
199                         "dictionary-description":"pnf-id",
200                         "dictionary-metadata":[
201                             {"name":"aai-path","value":"//path/in/aai"}
202                         ],
203                         "dictionary-name":"pnf-id",
204                         "dictionary-source":"input",
205                         "request-payload":{"mock":true},
206                         "status":"",
207                         "message":""
208                     }
209                 ]
210             }
211         """.replace("\n|\\s".toRegex(), ""),
212             result
213         )
214     }
215
216     private fun createResourceAssignmentForTest(resourceValue: String?, resourceName: String = "pnf-id"): ResourceAssignment {
217         val valueForTest = if (resourceValue == null) null else TextNode(resourceValue)
218         val resourceAssignmentForTest = ResourceAssignment().apply {
219             name = resourceName
220             dictionaryName = "pnf-id"
221             dictionarySource = "input"
222             property = PropertyDefinition().apply {
223                 type = "string"
224                 value = valueForTest
225             }
226         }
227         return resourceAssignmentForTest
228     }
229
230     @Test
231     fun parseResponseNodeTestForPrimitivesTypes() {
232         var outcome = prepareResponseNodeForTest(
233             "sample-value", "string", "",
234             inputMapToTestPrimitiveTypeWithValue
235         )
236         assertEquals(
237             expectedValueToTestPrimitiveType,
238             outcome,
239             "Unexpected outcome returned for primitive type of simple String"
240         )
241         assertEquals(0, resourceAssignment.keyIdentifiers.size)
242
243         outcome = prepareResponseNodeForTest(
244             "sample-key-value", "string", "",
245             inputMapToTestPrimitiveTypeWithKeyValue
246         )
247         assertEquals(
248             expectedValueToTestPrimitiveType,
249             outcome,
250             "Unexpected outcome returned for primitive type of key-value String"
251         )
252         assertEquals(
253             expectedValueToTestPrimitiveType,
254             resourceAssignment.keyIdentifiers[0].value
255         )
256     }
257
258     @Test
259     fun parseResponseNodeTestForCollectionsOfString() {
260         var outcome = prepareResponseNodeForTest(
261             "listOfString", "list",
262             "string", inputMapToTestCollectionOfPrimitiveType
263         )
264         assertEquals(
265             expectedValueToTesCollectionOfPrimitiveType,
266             outcome,
267             "unexpected outcome returned for list of String"
268         )
269
270         val expectedKeyIdentifierValue = JacksonUtils.getJsonNode(outcome.map { it["ip"] })
271         assertEquals(
272             expectedKeyIdentifierValue,
273             resourceAssignment.keyIdentifiers[0].value
274         )
275
276         // FIXME("Map is not collection type, It is known complex type")
277         // outcome = prepareResponseNodeForTest(
278         //     "mapOfString", "map", "string",
279         //     inputMapToTestCollectionOfPrimitiveType
280         // )
281         // assertEquals(
282         //     expectedValueToTesCollectionOfPrimitiveType,
283         //     outcome,
284         //     "unexpected outcome returned for map of String"
285         // )
286     }
287
288     @Test
289     fun parseResponseNodeTestForCollectionsOfComplexType() {
290         var outcome = prepareResponseNodeForTest(
291             "listOfMyDataTypeWithOneOutputKeyMapping", "list",
292             "ip-address", inputMapToTestCollectionOfComplexTypeWithOneOutputKeyMapping
293         )
294         assertEquals(
295             expectedValueToTestCollectionOfComplexTypeWithOneOutputKeyMapping,
296             outcome,
297             "unexpected outcome returned for list of String"
298         )
299
300         outcome = prepareResponseNodeForTest(
301             "listOfMyDataTypeWithAllOutputKeyMapping", "list",
302             "ip-address", inputMapToTestCollectionOfComplexTypeWithAllOutputKeyMapping
303         )
304         assertEquals(
305             expectedValueToTestCollectionOfComplexTypeWithAllOutputKeyMapping,
306             outcome,
307             "unexpected outcome returned for list of String"
308         )
309     }
310
311     @Test
312     fun `parseResponseNodeTestForComplexType find one output key mapping`() {
313         val outcome = prepareResponseNodeForTest(
314             "complexTypeOneKeys", "host",
315             "", inputMapToTestComplexTypeWithOneOutputKeyMapping
316         )
317         assertEquals(
318             expectedValueToTestComplexTypeWithOneOutputKeyMapping,
319             outcome,
320             "Unexpected outcome returned for complex type"
321         )
322         assertEquals(
323             expectedValueToTestComplexTypeWithOneOutputKeyMapping["host"],
324             resourceAssignment.keyIdentifiers[0].value
325         )
326     }
327
328     @Test
329     fun `parseResponseNodeTestForComplexType find all output key mapping`() {
330         val outcome = prepareResponseNodeForTest(
331             "complexTypeAllKeys", "host",
332             "", inputMapToTestComplexTypeWithAllOutputKeyMapping
333         )
334         assertEquals(
335             expectedValueToTestComplexTypeWithAllOutputKeyMapping,
336             outcome,
337             "Unexpected outcome returned for complex type"
338         )
339         assertEquals(2, resourceAssignment.keyIdentifiers.size)
340         assertEquals(
341             expectedValueToTestComplexTypeWithAllOutputKeyMapping["name"],
342             resourceAssignment.keyIdentifiers[0].value
343         )
344
345         assertEquals(
346             expectedValueToTestComplexTypeWithAllOutputKeyMapping["ipAddress"],
347             resourceAssignment.keyIdentifiers[1].value
348         )
349     }
350
351     @Test
352     fun `transform resolved value with inline template`() {
353         resourceAssignmentRuntimeService.putResolutionStore("vnf_name", "abc-vnf".asJsonType())
354         resourceAssignment = ResourceAssignment()
355         resourceAssignment.name = "int_pktgen_private_net_id"
356         resourceAssignment.property = PropertyDefinition()
357         resourceAssignment.property!!.type = "string"
358         val value = "".asJsonType()
359
360         // Enable transform template
361         resourceAssignment.property!!.metadata =
362             mutableMapOf(METADATA_TRANSFORM_TEMPLATE to "\${vnf_name}_private2")
363
364         ResourceAssignmentUtils
365             .setResourceDataValue(resourceAssignment, resourceAssignmentRuntimeService, value)
366
367         val valueJson = "{\"config\":{\"parameter\":\"address\",\"value\":\"0.0.0.0\"}}"
368         resourceAssignmentRuntimeService.putResolutionStore("vnf_config", JacksonUtils.objectMapper.readTree(valueJson))
369         val resourceAssignmentJson = ResourceAssignment()
370         resourceAssignmentJson.name = "vendor_vnf_configuration"
371         resourceAssignmentJson.property = PropertyDefinition()
372         resourceAssignmentJson.property!!.type = "json"
373
374         // Enable transform template
375         resourceAssignmentJson.property!!.metadata =
376             mutableMapOf(METADATA_TRANSFORM_TEMPLATE to "\${vnf_config}")
377
378         ResourceAssignmentUtils
379             .setResourceDataValue(resourceAssignmentJson, resourceAssignmentRuntimeService, JacksonUtils.objectMapper.createObjectNode())
380
381         assertEquals(
382             "abc-vnf_private2",
383             resourceAssignment.property!!.value!!.asText()
384         )
385
386         assertEquals(
387             valueJson,
388             resourceAssignmentJson.property!!.value!!.toString()
389         )
390     }
391
392     @Test
393     fun `resource resolution issue of resourceStore HashMap during resource resolution`() {
394         var uncaughtExceptionOccured = AtomicBoolean(false)
395         for (i in 1..1000) {
396             thread {
397                 resourceAssignmentRuntimeService.putResolutionStore("key_$i", "value_$i".asJsonType())
398             }
399             val t = thread(false) {
400                 resourceAssignmentRuntimeService.getResolutionStore()
401                 // often ConcurrentModificationException occurs here
402             }
403             t.uncaughtExceptionHandler =
404                 Thread.UncaughtExceptionHandler { t, e -> uncaughtExceptionOccured = AtomicBoolean(true) }
405             t.start()
406         }
407         assertEquals(uncaughtExceptionOccured.get(), false)
408     }
409
410     private fun initInputMapAndExpectedValuesForPrimitiveType() {
411         inputMapToTestPrimitiveTypeWithValue = "1.2.3.1".asJsonType()
412         val keyValue = mutableMapOf<String, String>()
413         keyValue["value"] = "1.2.3.1"
414         inputMapToTestPrimitiveTypeWithKeyValue = keyValue.asJsonType()
415         expectedValueToTestPrimitiveType = TextNode("1.2.3.1")
416     }
417
418     private fun initInputMapAndExpectedValuesForCollection() {
419         val listOfIps = arrayListOf("1.2.3.1", "1.2.3.2", "1.2.3.3")
420         val arrayNodeForList1 = JacksonUtils.objectMapper.createArrayNode()
421         listOfIps.forEach {
422             val arrayChildNode = JacksonUtils.objectMapper.createObjectNode()
423             arrayChildNode.set<JsonNode>("value", it.asJsonPrimitive())
424             arrayNodeForList1.add(arrayChildNode)
425         }
426         inputMapToTestCollectionOfPrimitiveType = arrayNodeForList1
427
428         expectedValueToTesCollectionOfPrimitiveType = arrayListOf(
429             ExpectedResponseIp("1.2.3.1"),
430             ExpectedResponseIp("1.2.3.2"), ExpectedResponseIp("1.2.3.3")
431         ).asJsonType()
432
433         val listOfIpAddresses = arrayListOf(
434             IpAddress("1111", "1.2.3.1").asJsonType(),
435             IpAddress("2222", "1.2.3.2").asJsonType(), IpAddress("3333", "1.2.3.3").asJsonType()
436         )
437         val arrayNodeForList2 = JacksonUtils.objectMapper.createArrayNode()
438         listOfIpAddresses.forEach {
439             val arrayChildNode = JacksonUtils.objectMapper.createObjectNode()
440             arrayChildNode.set<JsonNode>("value", it.asJsonType())
441             arrayNodeForList2.add(arrayChildNode)
442         }
443         inputMapToTestCollectionOfComplexTypeWithOneOutputKeyMapping = arrayNodeForList2
444
445         val arrayNodeForList3 = JacksonUtils.objectMapper.createArrayNode()
446         var childNode = JacksonUtils.objectMapper.createObjectNode()
447         childNode.set<JsonNode>("port", "1111".asJsonPrimitive())
448         childNode.set<JsonNode>("ip", "1.2.3.1".asJsonPrimitive())
449         arrayNodeForList3.add(childNode)
450         childNode = JacksonUtils.objectMapper.createObjectNode()
451         childNode.set<JsonNode>("port", "2222".asJsonPrimitive())
452         childNode.set<JsonNode>("ip", "1.2.3.2".asJsonPrimitive())
453         arrayNodeForList3.add(childNode)
454         childNode = JacksonUtils.objectMapper.createObjectNode()
455         childNode.set<JsonNode>("port", "3333".asJsonPrimitive())
456         childNode.set<JsonNode>("ip", "1.2.3.3".asJsonPrimitive())
457         arrayNodeForList3.add(childNode)
458         inputMapToTestCollectionOfComplexTypeWithAllOutputKeyMapping = arrayNodeForList3
459
460         expectedValueToTestCollectionOfComplexTypeWithOneOutputKeyMapping = arrayListOf(
461             ExpectedResponseIpAddress(IpAddress("1111", "1.2.3.1")),
462             ExpectedResponseIpAddress(IpAddress("2222", "1.2.3.2")),
463             ExpectedResponseIpAddress(
464                 IpAddress("3333", "1.2.3.3")
465             )
466         ).asJsonType()
467         expectedValueToTestCollectionOfComplexTypeWithAllOutputKeyMapping = arrayListOf(
468             IpAddress("1111", "1.2.3.1"),
469             IpAddress("2222", "1.2.3.2"),
470             IpAddress("3333", "1.2.3.3")
471         ).asJsonType()
472     }
473
474     private fun initInputMapAndExpectedValuesForComplexType() {
475         val mapOfComplexType = mutableMapOf<String, JsonNode>()
476         mapOfComplexType["value"] = Host("my-ipAddress", IpAddress("1111", "1.2.3.1")).asJsonType()
477         mapOfComplexType["port"] = "8888".asJsonType()
478         mapOfComplexType["something"] = "1.2.3.2".asJsonType()
479         inputMapToTestComplexTypeWithOneOutputKeyMapping = mapOfComplexType.asJsonType()
480
481         val objectNode = JacksonUtils.objectMapper.createObjectNode()
482         expectedValueToTestComplexTypeWithOneOutputKeyMapping =
483             objectNode.set("host", Host("my-ipAddress", IpAddress("1111", "1.2.3.1")).asJsonType())
484
485         val childNode1 = JacksonUtils.objectMapper.createObjectNode()
486         childNode1.set<JsonNode>("name", "my-ipAddress".asJsonPrimitive())
487         childNode1.set<JsonNode>("ipAddress", IpAddress("1111", "1.2.3.1").asJsonType())
488         childNode1.set<JsonNode>("port", "8888".asJsonType())
489         childNode1.set<JsonNode>("something", IpAddress("2222", "1.2.3.1").asJsonType())
490         inputMapToTestComplexTypeWithAllOutputKeyMapping = childNode1
491
492         val childNode2 = JacksonUtils.objectMapper.createObjectNode()
493         childNode2.set<JsonNode>("name", "my-ipAddress".asJsonPrimitive())
494         childNode2.set<JsonNode>("ipAddress", IpAddress("1111", "1.2.3.1").asJsonType())
495         expectedValueToTestComplexTypeWithAllOutputKeyMapping = childNode2
496     }
497
498     private fun prepareResponseNodeForTest(
499         dictionary_source: String,
500         sourceType: String,
501         entrySchema: String,
502         response: Any
503     ): JsonNode {
504
505         resourceAssignment = when (sourceType) {
506             "list" -> {
507                 prepareRAResourceDictionaryCollection(dictionary_source, sourceType, entrySchema)
508             }
509             "string" -> {
510                 prepareRAResourceDictionaryOfPrimaryType(dictionary_source)
511             }
512             else -> {
513                 prepareRAResourceDictionaryComplexType(dictionary_source, sourceType, entrySchema)
514             }
515         }
516
517         val responseNode = checkNotNull(JacksonUtils.getJsonNode(response)) {
518             "Failed to get database query result into Json node."
519         }
520
521         val outputKeyMapping = prepareOutputKeyMapping(dictionary_source)
522
523         return ResourceAssignmentUtils.parseResponseNode(
524             responseNode,
525             resourceAssignment,
526             resourceAssignmentRuntimeService,
527             outputKeyMapping
528         )
529     }
530
531     private fun prepareRAResourceDictionaryOfPrimaryType(dictionary_source: String): ResourceAssignment {
532         return ResourceAssignment().apply {
533             name = "ipAddress"
534             dictionaryName = "sample-ip"
535             dictionarySource = "$dictionary_source"
536             property = PropertyDefinition().apply {
537                 type = "string"
538             }
539         }
540     }
541
542     private fun prepareRAResourceDictionaryCollection(
543         dictionary_source: String,
544         sourceType: String,
545         schema: String
546     ): ResourceAssignment {
547         return ResourceAssignment().apply {
548             name = "ipAddress-list"
549             dictionaryName = "sample-licenses"
550             dictionarySource = "$dictionary_source"
551             property = PropertyDefinition().apply {
552                 type = "$sourceType"
553                 entrySchema = EntrySchema().apply {
554                     type = "$schema"
555                 }
556             }
557         }
558     }
559
560     private fun prepareRAResourceDictionaryComplexType(
561         dictionary_source: String,
562         sourceType: String,
563         schema: String
564     ): ResourceAssignment {
565         return ResourceAssignment().apply {
566             name = "ipAddress-complexType"
567             dictionaryName = "sample-licenses"
568             dictionarySource = "$dictionary_source"
569             property = PropertyDefinition().apply {
570                 type = "$sourceType"
571             }
572         }
573     }
574
575     private fun prepareOutputKeyMapping(dictionary_source: String): MutableMap<String, String> {
576         val outputMapping = mutableMapOf<String, String>()
577
578         when (dictionary_source) {
579             "sample-key-value", "sample-value" -> {
580                 // Primary Type
581                 if (dictionary_source == "sample-key-value")
582                     outputMapping["sample-ip"] = "value"
583             }
584             "listOfString", "mapOfString" -> {
585                 // List of string
586                 outputMapping["ip"] = "value"
587             }
588             "listOfMyDataTypeWithOneOutputKeyMapping", "listOfMyDataTypeWithAllOutputKeyMapping" -> {
589                 // List or map of complex Type
590                 if (dictionary_source == "listOfMyDataTypeWithOneOutputKeyMapping")
591                     outputMapping["ipAddress"] = "value"
592                 else {
593                     outputMapping["port"] = "port"
594                     outputMapping["ip"] = "ip"
595                 }
596             }
597             else -> {
598                 // Complex Type
599                 if (dictionary_source == "complexTypeOneKeys")
600                     outputMapping["host"] = "value"
601                 else {
602                     outputMapping["name"] = "name"
603                     outputMapping["ipAddress"] = "ipAddress"
604                 }
605             }
606         }
607         return outputMapping
608     }
609 }