summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/merge/property/PropertyDataValueMergeBusinessLogicTest.java
blob: 44824cb5784715b1061cfcba5635289ef6fe3ab3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.be.components.merge.property;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
import fj.data.Either;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;

import java.io.IOException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class PropertyDataValueMergeBusinessLogicTest {

    private ObjectMapper mapper = new ObjectMapper();
    
    private PropertyDataValueMergeBusinessLogic testInstance;

    @Mock
    private ApplicationDataTypeCache applicationDataTypeCache;

    @Before
    public void setUp() throws Exception {
        PropertyValueMerger propertyValueMerger = new PropertyValueMerger();
        
        testInstance = new PropertyDataValueMergeBusinessLogic(propertyValueMerger, applicationDataTypeCache);
    }

    @Test
    public void mergeProperties_emptyOldAndNewValues() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.STRING.getType(), null, null);
        PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.STRING.getType(), null, null);
        testMergeProps(oldProp, newProp, null);
    }

    @Test
    public void mergeProperties_emptyOldValue() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.STRING.getType(), null, null);
        PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.STRING.getType(), null, "newVal");
        testMergeProps(oldProp, newProp, "newVal");
    }

    @Test
    public void mergeSimpleStringType_copyOldValueIfNoNewValue() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.STRING.getType(), null, "val1");
        PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.STRING.getType(), null, null);
        testMergeProps(oldProp, newProp, "val1");
    }

    @Test
    public void mergeSimpleStringType_dontCopyOldValIfHasNewVal() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.STRING.getType(), null, "val1");
        PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.STRING.getType(), null, "newVal");
        testMergeProps(oldProp, newProp, "newVal");
    }

    @Test
    public void mergeSimpleIntType_copyOldValueIfNoNewValue() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.INTEGER.getType(), null, "44");
        PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.INTEGER.getType(), null, null);
        testMergeProps(oldProp, newProp, "44");
    }

    @Test
    public void mergeSimpleIntType_dontCopyOldValIfHasNewVal() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.INTEGER.getType(), null, "44");
        PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.INTEGER.getType(), null, "45");
        testMergeProps(oldProp, newProp, "45");
    }

    @Test
    public void mergeSimpleBooleanType_copyOldValueIfNoNewValue() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.BOOLEAN.getType(), null, "false");
        PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.BOOLEAN.getType(), null, null);
        testMergeProps(oldProp, newProp, "false");
    }

    @Test
    public void mergeSimpleBooleanType_dontCopyOldValIfHasNewVal() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.BOOLEAN.getType(), null, "false");
        PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.BOOLEAN.getType(), null, "true");
        testMergeProps(oldProp, newProp, "true");
    }

    @Test
    public void mergeSimpleListType_copyOldValuesByIndex() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "string", "[\"a\", \"b\"]");
        PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "string", "[\"x\", \"\"]");
        testMergeProps(oldProp, newProp, "[\"x\",\"b\"]");
    }
    
    @Test
    public void mergeSimpleListType_differentSize() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "string", "[\"a\", \"b\", \"c\"]");
        PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "string", "[\"x\", \"\"]");
        testMergeProps(oldProp, newProp, "[\"x\",\"\"]");
    }

    @Test
    public void mergeSimpleListType_jsonList() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "json", "[[\"a\", \"b\"], \"c\"]");
        PropertyDataDefinition newProp = createProp("prop1", ToscaPropertyType.LIST.getType(), "json", "[[\"a\"], \"d\"]");
        testMergeProps(oldProp, newProp, "[[\"a\"],\"d\"]");
    }

    /**                                   
     * Old property:                       New property:                           Expected:                           
     *   {                                  {                                       {                                 
     *     "mac_range_plan": "y",             "mac_range_plan": "",                   "mac_range_plan": "y",          
     *     "mac_count_required": {            "mac_count_required": {                 "mac_count_required": {         
     *       "is_required": true,               "is_required": false,                   "is_required": false,         
     *       "count": 44                        "mac_address": "myAddress"              "mac_address": "myAddress"    
     *     }                                  }                                       }                               
     *   }                                  }                                       }                                 
     *                                                                                                                
     */
    @Test
    public void mergeComplexType() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", "myType", null, "{\"mac_range_plan\":\"y\", \"mac_count_required\":{\"is_required\":true,\"count\":44}}");
        PropertyDataDefinition newProp = createProp("prop1", "myType", null, "{\"mac_range_plan\":\"\",  \"mac_count_required\":{\"is_required\":false, \"mac_address\":\"myAddress\"}}");
        
        DataTypeDefinition myType = new DataTypeDefinition();
        myType.setName("myType");
      
        PropertyDefinition mac_range_plan = new PropertyDefinition();
        mac_range_plan.setName("mac_range_plan");
        mac_range_plan.setType("string");

        PropertyDefinition mac_count_required = new PropertyDefinition();
        mac_count_required.setName("mac_count_required");
        mac_count_required.setType("map");
        
        myType.setProperties(Arrays.asList(mac_range_plan, mac_count_required));
        Map<String, DataTypeDefinition> dataTypes = Collections.singletonMap(myType.getName(), myType);

        when(applicationDataTypeCache.getAll()).thenReturn(Either.left(dataTypes));
        
        testInstance.mergePropertyValue(oldProp, newProp, Collections.emptyList());
        
        assertEquals("myType", "{\"mac_range_plan\":\"y\",\"mac_count_required\":{\"is_required\":false,\"mac_address\":\"myAddress\"}}", newProp.getValue());
    }
    
    
    
    
    /**                                                                                    Expected property:
     * Old property:                            New property:                                {
     *   {                                        {                                            "mac_range_plan": "n",
     *     "mac_range_plan": "y",   "               "mac_range_plan": "n",                     "mymap": {
     * 	   "mymap": {                           	"mymap": {                             	       "mac_count_required": {      
     * 		  "mac_count_required": {           		"mac_count_required": {            		      "is_required": false,
     * 		    "is_required": true,            		  "is_required": false                        "count": 44		  
     * 		    "count": 44                    		    },                                 		   },
     * 		  },                                		"host":"localhost",                		   "host":"localhost",
     * 		  "backup-mode":"daily",            		"ip":"127.0.0.1"                   		   "ip":"127.0.0.1"
     * 		  "ip":"0.0.0.0"                    	}                                      	   }                            
     * 	   }                                      }                                          }
     *   }                                                                                      
     *                                                                                       
     */
    @Test
    public void mergeComplexType_containingMapWithComplexType() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", "myType", null, "{\"mac_range_plan\":\"y\",\"mymap\": {\"mac_count_required\": {\"is_required\":true,\"count\":44},\"backup-mode\":\"daily\",\"ip\":\"0.0.0.0\"}}");
        PropertyDataDefinition newProp = createProp("prop1", "myType", null, "{\"mac_range_plan\":\"n\",\"mymap\": {\"mac_count_required\": {\"is_required\":false},\"host\":\"localhost\",\"ip\":\"127.0.0.1\"}}");
        
        DataTypeDefinition myType = new DataTypeDefinition();
        myType.setName("myType");
      
        PropertyDefinition mac_range_plan = new PropertyDefinition();
        mac_range_plan.setName("mac_range_plan");
        mac_range_plan.setType("string");
        
        PropertyDefinition mymap = new PropertyDefinition();
        mymap.setName("mymap");
        mymap.setType("map");

        PropertyDefinition mac_count_required = new PropertyDefinition();
        mac_count_required.setName("mac_count_required");
        mac_count_required.setType("MacType");
        
        SchemaDefinition entrySchema = new SchemaDefinition();
        entrySchema.setProperty(mac_count_required);
        mymap.setSchema(entrySchema);
        
        myType.setProperties(Arrays.asList(mac_range_plan, mymap, mac_count_required));
        Map<String, DataTypeDefinition> dataTypes = Collections.singletonMap(myType.getName(), myType);

        when(applicationDataTypeCache.getAll()).thenReturn(Either.left(dataTypes));
        
        testInstance.mergePropertyValue(oldProp, newProp, Collections.emptyList());
        
        assertEquals("myType", "{\"mac_range_plan\":\"n\",\"mymap\":{\"ip\":\"127.0.0.1\",\"mac_count_required\":{\"is_required\":false,\"count\":44},\"host\":\"localhost\"}}", newProp.getValue());
    }


    /*                                                               
     *  Old Property:                      New Property:                          Expected:          
     *  [                                  [                                      [                      
     *    {                                   {                                      {                   
     *      "prop1": "val1",                    "prop2": {                             "prop2": {        
     *      "prop2": {                            "prop3": false                         "prop3": false  
     *        "prop3": true,                    }                                      }                 
     *        "prop4": 44                     }                                      }                   
     *      }                              ]                                      ]                      
     *    },                                                         
     *    {
     *      "prop1": "val2",
     *      "prop2": {
     *        "prop3": true
     *      }
     *    }
     *  ]
     *  
     */
    @Test
    public void mergeListOfComplexType_differentSize() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", "list", "myType", "[{\"prop1\":\"val1\", \"prop2\":{\"prop3\":true,\"prop4\":44}}, " +
                                                                                       "{\"prop1\":\"val2\", \"prop2\":{\"prop3\":true}}]");
        PropertyDataDefinition newProp = createProp("prop1", "list", "myType", "[{\"prop2\":{\"prop3\":false}}]");

        Map<String, DataTypeDefinition> dataTypes = buildDataTypes();
        when(applicationDataTypeCache.getAll()).thenReturn(Either.left(dataTypes));
        testInstance.mergePropertyValue(oldProp, newProp, Collections.emptyList());
        assertEquals("myType", "[{\"prop2\":{\"prop3\":false}}]", newProp.getValue());
    }
    
    
    /*
     *  Old Property:                     New Property:                 Expected:
     *  [                                 [                             [
     *    {                                 {                            {
     *      "prop1": "val1",                  "prop1": "",                 "prop1": "val1",
     *      "prop2": {                        "prop2": {                   "prop2": {
     *        "prop3": true,                    "prop4": 45                  "prop3": true
     *        "prop4": 44                     }                              "prop4": 45
     *      }                               },                             }                       
     *    },                                {                            },                        
     *    {                                                              {                         
     *      "prop1": "val2",                  "prop2": {                   "prop1": "val2",                        
     *      "prop2": {                          "prop3": false             "prop2": {              
     *        "prop3": true                   }                              "prop3": false        
     *      }                               }                              }                       
     *    }                               ]                              }                         
     *  ]                                                              ]                           
     *                                                                                             
     */                                                                                            
    @Test
    public void mergeListOfComplexType() throws Exception {
        PropertyDataDefinition oldProp = createProp("lprop", "list", "myType", "[{\"prop1\":\"val1\", \"prop2\":{\"prop3\":true,\"prop4\":44}}, " +
                                                                                "{\"prop1\":\"val2\", \"prop2\":{\"prop3\":true}}]");
        PropertyDataDefinition newProp = createProp("lprop", "list", "myType", "[{\"prop1\":\"\", \"prop2\":{\"prop4\":45}}, {\"prop2\":{\"prop3\":false}}]");

        
        DataTypeDefinition myType = new DataTypeDefinition();
        myType.setName("myType");
        
        Map<String, DataTypeDefinition> dataTypes = buildDataTypes();
        when(applicationDataTypeCache.getAll()).thenReturn(Either.left(dataTypes));
        testInstance.mergePropertyValue(oldProp, newProp, Collections.emptyList());
        assertEquals("lprop",  "[{\"prop2\":{\"prop4\":45,\"prop3\":true},\"prop1\":\"val1\"},{\"prop2\":{\"prop3\":false},\"prop1\":\"val2\"}]", newProp.getValue());
    }
    
    
    
    /*
     * Old Property:                          New Property:                               Expected:                          
     * {                                      {                                           {
     *   "lprop": [                             "lprop": [                                  "lprop": [
     *     {                                      {                                           {
     *       "prop1": "val1",                       "prop2": [                                  "prop1": "val1",
     *       "prop2": [                               {                                         "prop2": [
     *         {                                        "prop3": true                             {
     *           "prop3": true,                       },                                            "prop3": true,
     *           "prop4": 44                  		  {                                             "prop4": 44
     *         },                             	 	    "prop4":69                                },
     *         {                              		  }                                   		  {
     *           "prop3": false,                    ]                                               "prop3": false,
     *           "prop4": 96                      },                                                "prop4": 69
     *         }                                  {                                               }
     *       ]                                      "prop1": "val1",                            ]
     *     },                                       "prop2": [                                },
     *     {                                          {                                       {
     *       "prop1": "val2",                           "prop3": false                          "prop1": "val1",
     *       "prop2": [                               }                                         "prop2": [
     *         {                                    ]                                             {
     *           "prop3": true                    }                                                 "prop3": false
     *         }                                ],                                                }
     *       ]                                  "prop5": "value05"                              ]
     *     }                                  }                                               }
     *   ],                                                                                 ],
     *   "prop5": "value5"                                                                  "prop5": "value05"
     * }                                                                                  }   
     *
     *
     */                                                                                            
    @Test
    public void mergeComplexType_containsListOfComplexType() throws Exception {
        PropertyDataDefinition oldProp = createProp("complexProp", "complexType", null, 
                "{\"lprop\":[{\"prop1\":\"val1\",\"prop2\":[{\"prop3\":true,\"prop4\":44},{\"prop3\":false,\"prop4\":96}]}," + 
                "{\"prop1\":\"val2\",\"prop2\":[{\"prop3\":true}]}],\"prop5\":\"value5\"} ");
        PropertyDataDefinition newProp = createProp("complexProp", "complexType", null,
                "{\"lprop\":[{\"prop2\":[{\"prop3\":true},{\"prop4\":69}]},{\"prop1\":\"val1\",\"prop2\":[{\"prop3\":false}]}],\"prop5\":\"value05\"}");

        DataTypeDefinition complexType = new DataTypeDefinition();
        complexType.setName("complexType");

        PropertyDefinition lprop = new PropertyDefinition(createProp("lprop", "list", "myType", null));

        PropertyDefinition prop5 = new PropertyDefinition();
        prop5.setName("prop5");
        prop5.setType("string");
        
        DataTypeDefinition complexProp = new DataTypeDefinition();
        complexProp.setName("complexType");
        complexType.setProperties(Arrays.asList(lprop, prop5));
        
        DataTypeDefinition myType = new DataTypeDefinition();
        myType.setName("myType");

        PropertyDefinition prop1 = new PropertyDefinition();
        prop1.setName("prop1");
        prop1.setType("string");
        
        DataTypeDefinition myInnerType = new DataTypeDefinition();
        myInnerType.setName("myInnerType");

        PropertyDefinition prop2 = new PropertyDefinition(createProp("prop2", "list", "myInnerType", null));

        PropertyDefinition prop3 = new PropertyDefinition();
        prop3.setName("prop3");
        prop3.setType("boolean");

        PropertyDefinition prop4 = new PropertyDefinition();
        prop4.setName("prop4");
        prop4.setType("integer");

        complexType.setProperties(Arrays.asList(lprop, prop5));
        myType.setProperties(Arrays.asList(prop1, prop2));
        myInnerType.setProperties(Arrays.asList(prop3, prop4));
        
        Map<String, DataTypeDefinition> dataTypes = Stream.of(complexType, myType, myInnerType)
                                                           .collect(Collectors.toMap(DataTypeDefinition::getName, Function.identity()));
        
        when(applicationDataTypeCache.getAll()).thenReturn(Either.left(dataTypes));
        
        testInstance.mergePropertyValue(oldProp, newProp, Collections.emptyList());
        
        assertEquals("complexProp", 
                "{\"lprop\":[{\"prop2\":[{\"prop4\":44,\"prop3\":true},{\"prop4\":69,\"prop3\":false}],\"prop1\":\"val1\"},{\"prop2\":[{\"prop3\":false}],\"prop1\":\"val1\"}],\"prop5\":\"value05\"}",
                newProp.getValue());
    }
    
    
    @Test
    public void mergeMapType_differentSize() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", "map", "string", "{\"prop1\":\"val1\", \"prop2\":\"val2\", \"prop3\":\"val3\"}");
        PropertyDataDefinition newProp = createProp("prop1", "map", "string", "{\"prop1\":\"valY\", \"prop2\":\"\"}");
        
        HashMap<String, String> expected = Maps.newHashMap();
        expected.put("prop1", "valY");
        expected.put("prop2", "val2");
        verifyMapMerge(getMergedMapProp(oldProp, newProp, Collections.emptyList()), expected);
    }
    
    
    @Test
    public void mergeMapType() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", "map", "string", "{\"prop1\":\"val1\", \"prop2\":\"val2\", \"prop3\":\"\", \"prop4\":\"val4\"}");
        PropertyDataDefinition newProp = createProp("prop1", "map", "string", "{\"prop1\":\"valY\", \"prop2\":\"\", \"prop3\":\"val3\", \"prop5\":\"val5\"}");
        
        
        HashMap<String, String> expected = Maps.newHashMap();
        expected.put("prop1", "valY");
        expected.put("prop2", "val2");
        expected.put("prop3", "val3");
        expected.put("prop5", "val5");
        verifyMapMerge(getMergedMapProp(oldProp, newProp, Collections.emptyList()), expected);
    }

    @Test
    public void mergeMapTypeWhenNewValueIsEmpty() throws Exception {
        PropertyDataDefinition oldProp = createProp("prop1", "map", "string", "{\"prop1\":\"val1\", \"prop2\":\"val2\", \"prop3\":\"val3\"}");
        PropertyDataDefinition newProp = createProp("prop1", "map", "string", null);
        HashMap<String, String> expected = Maps.newHashMap();
        expected.put("prop1", "val1");
        expected.put("prop2", "val2");
        expected.put("prop3", "val3");
        verifyMapMerge(getMergedMapProp(oldProp, newProp, Collections.singletonList("input1")), expected);
    }

    @Test
    public void mergeGetInputValue() throws Exception {
        PropertyDataDefinition oldProp = createGetInputProp("prop1", "string", null, "input1");
        PropertyDataDefinition newProp = createProp("prop1", "string", null, "");
        testMergeProps(oldProp, newProp, oldProp.getValue(), Collections.singletonList("input1"));
        assertEquals(oldProp.getGetInputValues(), newProp.getGetInputValues());
    }

    @Test
    public void mergeGetInputValue_valueIsNull_InNewProp() throws Exception {
        PropertyDataDefinition oldProp = createGetInputProp("prop1", "string", null, "input1");
        PropertyDataDefinition newProp = createProp("prop1", "string", null, null);
        testMergeProps(oldProp, newProp,"{\"get_input\":\"input1\"}", Collections.singletonList("input1"));
        assertGetInputValues(newProp, "input1");
    }

    /*
     * Old property:                      New property:                       Expected:              
     * [                                  [                                   [                          
     *   {                                  {                                   {                         
     *     "mac_range_plan": {                "mac_count_required": {           "mac_range_plan": {     
     *       "get_input": "input1"              "is_required": true               "get_input": "input1" 
     *     },                                 }                                 },                      
     *     "mac_count_required": {          }                                   "mac_count_required": {                                    
     *       "is_required": true,                                                 "is_required": true         
     *       "count": {                   inputs: intput1, input2               }                             
     *         "get_input": "input2"      ]                                   }                               
     *       }                                                                                                
     *     }                                                                  inputs: input2                    
     *   }                                                                  ]                                 
     *                                                                        
     *   inputs: intput1, input2                                                                            
     * ]                                                                                                    
     * 
     * 
     * 
     */
    @Test
    public void mergeComplexGetInputValue() throws Exception {
        PropertyDataDefinition oldProp = new PropertyDataDefinitionBuilder().addGetInputValue("input1").addGetInputValue("input2").setName("prop1").setType("myType").setValue("{\"mac_range_plan\":{\"get_input\": \"input1\"}, \"mac_count_required\":{\"is_required\":true,\"count\":{\"get_input\": \"input2\"}}}").build();
        PropertyDataDefinition newProp = new PropertyDataDefinitionBuilder().addGetInputValue("input2").setName("prop1").setType("myType").setValue("{\"mac_count_required\":{\"is_required\":true}}").build();
        testMergeProps(oldProp, newProp,"{\"mac_range_plan\":{},\"mac_count_required\":{\"is_required\":true}}", Collections.singletonList("input2"));
        assertGetInputValues(newProp, "input2");
    }

    @Test
    public void mergeListValueWithMultipleGetInputs() throws Exception {
        PropertyDataDefinition oldProp = new PropertyDataDefinitionBuilder()
                .addGetInputValue("input1").addGetInputValue("input2").addGetInputValue("input3")
                .setName("prop1")
                .setType("list").setSchemaType("string")
                .setValue("[{\"get_input\": \"input2\"},{\"get_input\": \"input3\"},{\"get_input\": \"input1\"}]")
                .build();

        PropertyDataDefinition newProp = new PropertyDataDefinitionBuilder()
                .addGetInputValue("input3")
                .addGetInputValue("input5")
                .setName("prop1")
                .setType("list").setSchemaType("string")
                .setValue("[{\"get_input\": \"input5\"}, {\"get_input\": \"input3\"}]")
                .build();

        testMergeProps(oldProp, newProp,"[{\"get_input\":\"input5\"},{\"get_input\":\"input3\"}]");
        assertGetInputValues(newProp, "input3", "input5");
    }

    private void assertGetInputValues(PropertyDataDefinition newProp, String ... expectedInputNames) {
        assertTrue(newProp.isGetInputProperty());
        assertEquals(newProp.getGetInputValues().size(), expectedInputNames.length);
        for (int i = 0; i < expectedInputNames.length; i++) {
            String expectedInputName = expectedInputNames[i];
            GetInputValueDataDefinition getInputValueDataDefinition = newProp.getGetInputValues().get(i);
            assertEquals(getInputValueDataDefinition.getInputName(), expectedInputName);
        }
    }
    
    private void testMergeProps(PropertyDataDefinition oldProp, PropertyDataDefinition newProp, String expectedValue) {
        testMergeProps(oldProp, newProp, expectedValue, Collections.emptyList());
    }

    private void testMergeProps(PropertyDataDefinition oldProp, PropertyDataDefinition newProp, String expectedValue,  List<String> getInputsToMerge) {
        when(applicationDataTypeCache.getAll()).thenReturn(Either.left(Collections.emptyMap()));
        testInstance.mergePropertyValue(oldProp, newProp, getInputsToMerge);
        assertEquals(expectedValue, newProp.getValue());
    }


    private String getMergedMapProp(PropertyDataDefinition oldProp, PropertyDataDefinition newProp, List<String> getInputsToMerge) {
        when(applicationDataTypeCache.getAll()).thenReturn(Either.left(Collections.emptyMap()));
        testInstance.mergePropertyValue(oldProp, newProp, getInputsToMerge);
        return newProp.getValue();
    }

    private void verifyMapMerge(String newValue, Map<String, String> expectedValues) {
        Map<String, String> values = convertJsonToMap(newValue);
        assertThat(values).isNotNull();
        assertThat(values).containsAllEntriesOf(expectedValues);
    }

    private PropertyDataDefinition createProp(String name, String type, String innerType, String val) {
        return new PropertyDataDefinitionBuilder()
                .setType(type)
                .setSchemaType(innerType)
                .setValue(val)
                .setName(name)
                .build();
    }

    private PropertyDataDefinition createGetInputProp(String name, String type, String innerType, String inputName) {
        String val = String.format("{\"get_input\":\"%s\"}", inputName);
        return new PropertyDataDefinitionBuilder()
                .setType(type)
                .setSchemaType(innerType)
                .setValue(val)
                .addGetInputValue(inputName)
                .setName(name)
                .build();

    }

    private Map<String, String> convertJsonToMap(String jsonString) {
        try {
            return mapper.readValue(jsonString, new TypeReference<Map<String, String>>(){});
        } catch (IOException e) {
            return null;
        }
    }

    private Map<String, DataTypeDefinition> buildDataTypes() {
        DataTypeDefinition myType = new DataTypeDefinition();
        myType.setName("myType");
        DataTypeDefinition myInnerType = new DataTypeDefinition();
        myInnerType.setName("myInnerType");

        PropertyDefinition prop1 = new PropertyDefinition();
        prop1.setName("prop1");
        prop1.setType("string");

        PropertyDefinition prop2 = new PropertyDefinition();
        prop2.setName("prop2");
        prop2.setType("myInnerType");

        PropertyDefinition prop3 = new PropertyDefinition();
        prop3.setName("prop3");

        PropertyDefinition prop4 = new PropertyDefinition();
        prop4.setName("prop4");

        myType.setProperties(Arrays.asList(prop1, prop2));
        myInnerType.setProperties(Arrays.asList(prop3, prop4));

        return Stream.of(myType, myInnerType).collect(Collectors.toMap(DataTypeDefinition::getName, Function.identity()));
    }


}