Support for defining attributes on a node_type
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / ImportUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.impl;
22
23 import com.google.common.collect.Lists;
24 import fj.data.Either;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.openecomp.sdc.be.components.impl.ImportUtils.ResultStatusEnum;
28 import org.openecomp.sdc.be.components.impl.ImportUtils.ToscaElementTypeEnum;
29 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
30 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
31 import org.openecomp.sdc.be.model.AttributeDefinition;
32 import org.openecomp.sdc.be.model.HeatParameterDefinition;
33 import org.openecomp.sdc.be.model.InputDefinition;
34 import org.openecomp.sdc.be.model.PropertyConstraint;
35 import org.openecomp.sdc.be.model.PropertyDefinition;
36 import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
37 import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
38 import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
39 import org.openecomp.sdc.be.utils.TypeUtils;
40 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
41 import org.yaml.snakeyaml.Yaml;
42
43 import java.io.IOException;
44 import java.nio.file.FileSystems;
45 import java.nio.file.Files;
46 import java.util.ArrayList;
47 import java.util.HashMap;
48 import java.util.Iterator;
49 import java.util.List;
50 import java.util.Map;
51 import java.util.Map.Entry;
52
53 import static org.junit.Assert.assertEquals;
54 import static org.junit.Assert.assertFalse;
55 import static org.junit.Assert.assertNotNull;
56 import static org.junit.Assert.assertTrue;
57
58 public class ImportUtilsTest {
59
60
61     @Test
62     public void testStringTypeFindToscaElements() throws IOException {
63         Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-string-list-test.yml"), "stringTestTag", ToscaElementTypeEnum.STRING, new ArrayList<>());
64         assertTrue(toscaElements.isLeft());
65         List<Object> list = toscaElements.left().value();
66         assertEquals(4, list.size());
67         int count = 1;
68         for (Object element : list) {
69             assertTrue(element instanceof String);
70             String value = (String) element;
71             assertEquals(value, "stringVal" + count);
72             count++;
73         }
74     }
75
76     @Test
77     public void testBooleanTypeFindToscaElements() throws IOException {
78         Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "required", ToscaElementTypeEnum.BOOLEAN, new ArrayList<>());
79         assertTrue(toscaElements.isLeft());
80         List<Object> list = toscaElements.left().value();
81         assertEquals(3, list.size());
82         int count = 1;
83         for (Object element : list) {
84             assertTrue(element instanceof Boolean);
85             Boolean value = (Boolean) element;
86             if (count == 1 || count == 3) {
87                 assertFalse(value);
88             } else if (count == 2) {
89                 assertTrue(value);
90             }
91
92             count++;
93         }
94     }
95
96     @Test
97     public void testListTypeFindToscaElements() throws IOException {
98         Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-string-list-test.yml"), "listTestTag", ToscaElementTypeEnum.LIST, new ArrayList<>());
99         assertTrue(toscaElements.isLeft());
100         List<Object> list = toscaElements.left().value();
101         assertEquals(3, list.size());
102         int count = 1;
103         for (Object element : list) {
104             assertTrue(element instanceof List);
105
106             if (count == 1) {
107                 verifyListElement1(element);
108             } else if (count == 2) {
109                 verifyListElement2(element);
110             }
111
112             else if (count == 3) {
113                 verifyListElement3(element);
114             }
115             count++;
116         }
117     }
118
119     @Test
120     public void testAllTypeFindToscaElements() throws IOException {
121         Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "allTestTag", ToscaElementTypeEnum.ALL, new ArrayList<>());
122         assertTrue(toscaElements.isLeft());
123         List<Object> list = toscaElements.left().value();
124         assertEquals(5, list.size());
125         int count = 1;
126         for (Object element : list) {
127             if (count == 1) {
128                 assertTrue(element instanceof String);
129                 assertEquals("tosca.nodes.Root", element);
130             } else if (count == 2) {
131                 assertTrue(element instanceof Map);
132                 Map<String, Object> mapElement = (Map<String, Object>) element;
133                 assertEquals(2, mapElement.size());
134                 Iterator<Entry<String, Object>> elementEntries = mapElement.entrySet().iterator();
135                 Entry<String, Object> elementEntry = elementEntries.next();
136                 assertEquals("mapTestTag", elementEntry.getKey());
137                 assertEquals("string", elementEntry.getValue());
138
139                 elementEntry = elementEntries.next();
140                 assertEquals("required", elementEntry.getKey());
141                 assertTrue(elementEntry.getValue() instanceof Boolean);
142                 assertTrue((Boolean) elementEntry.getValue());
143             }
144
145             else if (count == 3) {
146                 assertTrue(element instanceof String);
147                 assertEquals("1 MB", element);
148             }
149
150             else if (count == 4) {
151                 assertTrue(element instanceof List);
152                 List<Object> listElement = (List<Object>) element;
153                 assertEquals(2, listElement.size());
154
155                 assertTrue(listElement.get(0) instanceof Map);
156                 Map<String, Object> innerElement = (Map<String, Object>) listElement.get(0);
157                 assertEquals(1, innerElement.size());
158                 Entry<String, Object> innerEntry = innerElement.entrySet().iterator().next();
159                 assertEquals("greater_or_equal", innerEntry.getKey());
160                 assertEquals("1 MB", innerEntry.getValue());
161
162                 assertTrue(listElement.get(1) instanceof Map);
163                 innerElement = (Map<String, Object>) listElement.get(1);
164                 assertEquals(1, innerElement.size());
165                 innerEntry = innerElement.entrySet().iterator().next();
166                 assertEquals("stringTestTag", innerEntry.getKey());
167                 assertEquals("stringVal3", innerEntry.getValue());
168             } else if (count == 5) {
169                 assertTrue(element instanceof Boolean);
170                 assertFalse((Boolean) element);
171             }
172             count++;
173         }
174     }
175
176     @Test
177     public void testMapTypeFindToscaElements() throws IOException {
178         Either<List<Object>, ResultStatusEnum> toscaElements = ImportUtils.findToscaElements((Map<String, Object>) loadJsonFromFile("normative-types-all-map-test.yml"), "mapTestTag", ToscaElementTypeEnum.MAP, new ArrayList<>());
179         assertTrue(toscaElements.isLeft());
180         List<Object> list = toscaElements.left().value();
181         assertEquals(2, list.size());
182         int count = 1;
183         for (Object element : list) {
184             assertTrue(element instanceof Map);
185
186             if (count == 1) {
187                 Map<String, Object> mapElement = (Map<String, Object>) element;
188                 assertEquals(2, mapElement.size());
189                 Iterator<Entry<String, Object>> iterator = mapElement.entrySet().iterator();
190                 Entry<String, Object> inerElementEntry = iterator.next();
191                 assertEquals("stringTestTag", inerElementEntry.getKey());
192                 assertEquals("stringVal1", inerElementEntry.getValue());
193
194                 inerElementEntry = iterator.next();
195                 assertEquals("listTestTag", inerElementEntry.getKey());
196                 assertTrue(inerElementEntry.getValue() instanceof List);
197                 List<Object> innerValue = (List<Object>) inerElementEntry.getValue();
198
199                 assertEquals(3, innerValue.size());
200
201             } else if (count == 2) {
202                 Map<String, Object> mapElement = (Map<String, Object>) element;
203                 assertEquals(2, mapElement.size());
204                 Iterator<Entry<String, Object>> entryItr = mapElement.entrySet().iterator();
205                 Entry<String, Object> inerElementEntry = entryItr.next();
206                 assertEquals("type", inerElementEntry.getKey());
207                 assertEquals("tosca.capabilities.Attachment", inerElementEntry.getValue());
208                 inerElementEntry = entryItr.next();
209                 assertEquals("allTestTag", inerElementEntry.getKey());
210                 assertTrue(inerElementEntry.getValue() instanceof Boolean);
211             }
212
213             count++;
214         }
215     }
216
217     @Test
218     public void testCreateFullHeatParameterModuleWithString() {
219
220         testCreateFullHeatParameterModule("string", "default value");
221
222     }
223
224     @Test
225     public void testCreateFullHeatParameterModuleWithNumber() {
226
227         testCreateFullHeatParameterModule("number", "777");
228         testCreateFullHeatParameterModule("number", "777.23");
229
230     }
231
232     @Test
233     public void testCreateFullHeatParameterModuleWithBoolean() {
234
235         testCreateFullHeatParameterModule("boolean", "true");
236         testCreateFullHeatParameterModule("boolean", "on");
237         testCreateFullHeatParameterModule("boolean", "n");
238
239     }
240
241     @Test
242     public void testCreateFullHeatParameterModuleWithList() {
243
244         testCreateFullHeatParameterModule("comma_delimited_list", "[one, two]");
245
246     }
247
248     // @Test
249     // public void testCreateFullHeatParameterModuleWithInvalidType(){
250     //
251     // String name = "fullParameter";
252     // String description = "description_text";
253     //
254     // Map<String, Object> parametersMap = new HashMap<String, Object>();
255     // Map<String, Object> firstParam = createParameterMap("aaa", "aaa",
256     // name, description);
257     // parametersMap.put(ToscaTagNamesEnum.PARAMETERS.getElementName(),
258     // firstParam);
259     //
260     // Either<List<HeatParameterDefinition>,ResultStatusEnum> heatParameters =
261     // ImportUtils.getHeatParameters(parametersMap);
262     // assertTrue(heatParameters.isRight());
263     // assertEquals(ResultStatusEnum.INVALID_PROPERTY_TYPE,
264     // heatParameters.right().value());
265     //
266     // }
267
268     @Test
269     public void testCreateFullHeatParameterModuleWithMissingType() {
270
271         String name = "fullParameter";
272         String description = "description_text";
273
274         Map<String, Object> parametersMap = new HashMap<>();
275         Map<String, Object> firstParam = createParameterMap(null, "aaa", name, description);
276         parametersMap.put(TypeUtils.ToscaTagNamesEnum.PARAMETERS.getElementName(), firstParam);
277
278         Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap, ArtifactTypeEnum.HEAT.getType());
279         assertTrue(heatParameters.isRight());
280         assertEquals(ResultStatusEnum.INVALID_PROPERTY_TYPE, heatParameters.right().value());
281
282     }
283
284     @Test
285     public void testCreateFullHeatParameterModuleWithMissingFields() {
286
287         String name = "fullParameter";
288
289         Map<String, Object> parametersMap = new HashMap<>();
290         String type = "number";
291         String defValue = "defvalue";
292         // default value cannot be empty in heat in case tag exists
293         Map<String, Object> firstParam = createParameterMap(type, defValue, name, null);
294         parametersMap.put(TypeUtils.ToscaTagNamesEnum.PARAMETERS.getElementName(), firstParam);
295
296         Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap, ArtifactTypeEnum.HEAT.getType());
297         assertTrue(heatParameters.isLeft());
298         List<HeatParameterDefinition> parameterDefList = heatParameters.left().value();
299         assertFalse(parameterDefList.isEmpty());
300         HeatParameterDefinition parameterDefinition = parameterDefList.get(0);
301
302         assertParameter(parameterDefinition, name, type, null, defValue);
303
304     }
305
306     @Test
307     public void testGetAttributesFromYml() throws IOException {
308
309         Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("importToscaWithAttribute.yml");
310         Either<Map<String, AttributeDataDefinition>, ResultStatusEnum> actualAttributes = ImportUtils.getAttributes(toscaJson);
311         assertTrue(actualAttributes.isLeft());
312         Map<String, Map<String, Object>> expectedAttributes = getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.ATTRIBUTES);
313         compareAttributes(expectedAttributes, actualAttributes.left().value());
314
315     }
316
317     @Test
318     public void testGetPropertiesFromYml() throws IOException {
319
320         Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("importToscaProperties.yml");
321         Either<Map<String, PropertyDefinition>, ResultStatusEnum> actualProperties = ImportUtils.getProperties(toscaJson);
322         assertTrue(actualProperties.isLeft());
323         Map<String, Map<String, Object>> expectedProperties = getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.PROPERTIES);
324         compareProperties(expectedProperties, actualProperties.left().value());
325
326     }
327
328     @Test
329     public void testGetPropertiesWithConstraintsFromYml() throws IOException {
330
331         Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("propertyConstraintsTest.yml");
332         Either<Map<String, PropertyDefinition>, ResultStatusEnum> actualProperties = ImportUtils.getProperties(toscaJson);
333         assertTrue(actualProperties.isLeft());
334         Map<String, PropertyDefinition> properties = actualProperties.left().value();
335         assertTrue(properties.containsKey("service_type"));
336         PropertyDefinition property = properties.get("service_type");
337         assertTrue(property.getConstraints()!= null && property.getConstraints().size() == 1);
338         assertTrue(property.getConstraints().get(0) instanceof ValidValuesConstraint);
339         assertTrue(((ValidValuesConstraint) property.getConstraints().get(0)).getValidValues() != null);
340         List<String> validValues = ((ValidValuesConstraint) property.getConstraints().get(0)).getValidValues();
341         assertTrue(validValues.containsAll(Lists.newArrayList("firewall", "analyzer", "source-nat", "loadbalancer")));
342
343         assertTrue(properties.containsKey("service_interface_type_list"));
344         property = properties.get("service_interface_type_list");
345         assertTrue(property.getSchema()!= null && property.getSchema().getProperty() != null);
346         PropertyDefinition innerProperty = new PropertyDefinition(property.getSchema().getProperty());
347         List<PropertyConstraint> innerConstraints = innerProperty.getConstraints();
348         assertTrue(innerConstraints.get(0) instanceof ValidValuesConstraint);
349         assertTrue(((ValidValuesConstraint) innerConstraints.get(0)).getValidValues() != null);
350         validValues = ((ValidValuesConstraint) innerConstraints.get(0)).getValidValues();
351         assertTrue(validValues.containsAll(Lists.newArrayList("management", "left", "right", "other")));
352     }
353
354     @Test
355     public void testGetInputsFromYml() throws IOException {
356
357         Map<String, Object> toscaJson = (Map<String, Object>) loadJsonFromFile("importToscaInputs.yml");
358
359         AnnotationTypeOperations annotationTypeOperations= Mockito.mock(AnnotationTypeOperations.class);
360         Mockito.when(annotationTypeOperations.getLatestType(Mockito.anyString())).thenReturn(null);
361
362         Either<Map<String, InputDefinition>, ResultStatusEnum> actualInputs = ImportUtils.getInputs(toscaJson,annotationTypeOperations);
363         assertTrue(actualInputs.isLeft());
364         Map<String, Map<String, Object>> expectedProperties = getElements(toscaJson, TypeUtils.ToscaTagNamesEnum.INPUTS);
365         compareProperties(expectedProperties, actualInputs.left().value());
366
367     }
368
369     private void compareAttributes(Map<String, Map<String, Object>> expected, Map<String, AttributeDataDefinition> actual) {
370
371         Map<String, Object> singleExpectedAttribute;
372         AttributeDataDefinition actualAttribute, expectedAttributeModel;
373         // attributes of resource
374         for (Map.Entry<String, Map<String, Object>> expectedAttribute : expected.entrySet()) {
375
376             singleExpectedAttribute = expectedAttribute.getValue();
377             assertNotNull(singleExpectedAttribute);
378             actualAttribute = actual.get(expectedAttribute.getKey());
379             assertNotNull(actualAttribute);
380             actualAttribute.setName(expectedAttribute.getKey().toString());
381             expectedAttributeModel = ImportUtils.createModuleAttribute(singleExpectedAttribute);
382             expectedAttributeModel.setName(expectedAttribute.getKey().toString());
383
384             assertEquals(((AttributeDefinition)expectedAttributeModel).getDefaultValue(), ((AttributeDefinition)actualAttribute).getDefaultValue());
385             assertEquals(((AttributeDefinition)expectedAttributeModel).getDescription(), ((AttributeDefinition)actualAttribute).getDescription());
386             assertEquals(((AttributeDefinition)expectedAttributeModel).getName(), ((AttributeDefinition)actualAttribute).getName());
387             assertEquals(((AttributeDefinition)expectedAttributeModel).getStatus(), ((AttributeDefinition)actualAttribute).getStatus());
388             assertEquals(((AttributeDefinition)expectedAttributeModel).getType(), ((AttributeDefinition)actualAttribute).getType());
389
390             compareSchemas(expectedAttributeModel.getSchema(), actualAttribute.getSchema());
391
392         }
393
394     }
395
396     private  void compareProperties(Map<String, Map<String, Object>> expected, Map<String, ? extends PropertyDefinition > actual) {
397
398         Map<String, Object> singleExpectedProperty;
399         PropertyDefinition actualProperty, expectedPropertyModel;
400
401         for (Map.Entry<String, Map<String, Object>> expectedProperty : expected.entrySet()) {
402
403             singleExpectedProperty = expectedProperty.getValue();
404             assertNotNull(singleExpectedProperty);
405             actualProperty = actual.get(expectedProperty.getKey());
406             assertNotNull(actualProperty);
407             actualProperty.setName(expectedProperty.getKey().toString());
408             expectedPropertyModel = ImportUtils.createModuleProperty(singleExpectedProperty);
409             expectedPropertyModel.setName(expectedProperty.getKey().toString());
410
411             assertEquals(expectedPropertyModel.getDefaultValue(), actualProperty.getDefaultValue());
412             assertEquals(expectedPropertyModel.getDescription(), actualProperty.getDescription());
413             assertEquals(expectedPropertyModel.getName(), actualProperty.getName());
414             assertEquals(expectedPropertyModel.getStatus(), actualProperty.getStatus());
415             assertEquals(expectedPropertyModel.getType(), actualProperty.getType());
416
417             compareSchemas(expectedPropertyModel.getSchema(), actualProperty.getSchema());
418
419         }
420
421     }
422
423     private void compareSchemas(SchemaDefinition expected, SchemaDefinition actual) {
424
425         if (expected == null && actual == null) {
426             return;
427         }
428         PropertyDataDefinition actualPropertySchema = actual.getProperty();
429         PropertyDataDefinition expectedPropertySchema = expected.getProperty();
430         assertNotNull(actualPropertySchema);
431         assertNotNull(expectedPropertySchema);
432         assertEquals(expectedPropertySchema.getDescription(), actualPropertySchema.getDescription());
433         assertEquals(expectedPropertySchema.getType(), actualPropertySchema.getType());
434
435     }
436
437     private <T> Map<String, T> getElements(Map<String, Object> toscaJson, TypeUtils.ToscaTagNamesEnum elementType) {
438
439         Either<Map<String, T>, ResultStatusEnum> toscaExpectedElements = ImportUtils.findFirstToscaMapElement(toscaJson, elementType);
440         assertTrue(toscaExpectedElements.isLeft());
441
442         return toscaExpectedElements.left().value();
443
444     }
445
446     private void testCreateFullHeatParameterModule(String type, Object defaultVal) {
447
448         String name = "fullParameter";
449         String description = "description_text";
450
451         Map<String, Object> parametersMap = new HashMap<>();
452         Map<String, Object> firstParam = createParameterMap(type, defaultVal, name, description);
453         parametersMap.put(TypeUtils.ToscaTagNamesEnum.PARAMETERS.getElementName(), firstParam);
454
455         Either<List<HeatParameterDefinition>, ResultStatusEnum> heatParameters = ImportUtils.getHeatParameters(parametersMap, ArtifactTypeEnum.HEAT.getType());
456         assertTrue(heatParameters.isLeft());
457         List<HeatParameterDefinition> parameterDefList = heatParameters.left().value();
458         assertFalse(parameterDefList.isEmpty());
459         HeatParameterDefinition parameterDefinition = parameterDefList.get(0);
460
461         assertParameter(parameterDefinition, name, type, description, defaultVal);
462
463     }
464
465     private Map<String, Object> createParameterMap(String type, Object defaultVal, String name, String description) {
466         Map<String, Object> firstParam = new HashMap<>();
467         Map<String, Object> valuesMap = new HashMap<>();
468
469         valuesMap.put(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName(), type);
470         valuesMap.put(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName(), description);
471         valuesMap.put(TypeUtils.ToscaTagNamesEnum.DEFAULT_VALUE.getElementName(), defaultVal);
472
473         firstParam.put(name, valuesMap);
474         return firstParam;
475     }
476
477     private void assertParameter(HeatParameterDefinition parameterDefinition, String name, String type, String description, Object defaultVal) {
478         assertEquals(name, parameterDefinition.getName());
479         assertEquals(description, parameterDefinition.getDescription());
480         assertEquals(type, parameterDefinition.getType());
481         assertEquals(String.valueOf(defaultVal), parameterDefinition.getDefaultValue());
482         assertEquals(String.valueOf(defaultVal), parameterDefinition.getCurrentValue());
483     }
484
485     private void verifyListElement3(Object element) {
486         List<Object> listElement = (List<Object>) element;
487         assertEquals(2, listElement.size());
488
489         Map<String, String> innerElement = (Map<String, String>) listElement.get(0);
490         assertEquals(1, innerElement.size());
491         Entry<String, String> innerEntry = innerElement.entrySet().iterator().next();
492         assertEquals("testTag1", innerEntry.getKey());
493         assertEquals("1 MB", innerEntry.getValue());
494
495         innerElement = (Map<String, String>) listElement.get(1);
496         assertEquals(1, innerElement.size());
497         innerEntry = innerElement.entrySet().iterator().next();
498         assertEquals("type", innerEntry.getKey());
499         assertEquals("stringVal2", innerEntry.getValue());
500     }
501
502     private void verifyListElement2(Object element) {
503         List<Object> listElement = (List<Object>) element;
504         assertEquals(2, listElement.size());
505
506         Map<String, Object> innerElement = (Map<String, Object>) listElement.get(0);
507         assertEquals(1, innerElement.size());
508         Entry<String, Object> innerEntry = innerElement.entrySet().iterator().next();
509         assertEquals("testTag1", innerEntry.getKey());
510         assertEquals("1 MB", innerEntry.getValue());
511
512         assertTrue(listElement.get(1) instanceof Map);
513         innerElement = (Map<String, Object>) listElement.get(1);
514         assertEquals(1, innerElement.size());
515         innerEntry = innerElement.entrySet().iterator().next();
516         assertEquals("listTestTag", innerEntry.getKey());
517         assertTrue(innerEntry.getValue() instanceof List);
518     }
519
520     private void verifyListElement1(Object element) {
521         List<Object> listElement = (List<Object>) element;
522         assertEquals(3, listElement.size());
523
524         Map<String, String> innerElement = (Map<String, String>) listElement.get(0);
525         assertEquals(1, innerElement.size());
526         Entry<String, String> innerEntry = innerElement.entrySet().iterator().next();
527         assertEquals("listTestTag", innerEntry.getKey());
528         assertEquals("1 MB", innerEntry.getValue());
529
530         innerElement = (Map<String, String>) listElement.get(1);
531         assertEquals(1, innerElement.size());
532         innerEntry = innerElement.entrySet().iterator().next();
533         assertEquals("listTestTag", innerEntry.getKey());
534         assertEquals("2 MB", innerEntry.getValue());
535
536         innerElement = (Map<String, String>) listElement.get(2);
537         assertEquals(1, innerElement.size());
538         innerEntry = innerElement.entrySet().iterator().next();
539         assertEquals("stringTestTag", innerEntry.getKey());
540         assertEquals("stringVal2", innerEntry.getValue());
541     }
542
543     public static String loadFileNameToJsonString(String fileName) throws IOException {
544         String sourceDir = "src/test/resources/normativeTypes";
545         return loadFileNameToJsonString(sourceDir, fileName);
546     }
547     
548     public static String loadCustomTypeFileNameToJsonString(String fileName) throws IOException {
549         String sourceDir = "src/test/resources/customTypes";
550         return loadFileNameToJsonString(sourceDir, fileName);
551     }
552     
553     private static String loadFileNameToJsonString(String sourceDir, String fileName) throws IOException {
554         java.nio.file.Path filePath = FileSystems.getDefault().getPath(sourceDir, fileName);
555         byte[] fileContent = Files.readAllBytes(filePath);
556         return new String(fileContent);
557     }
558
559
560     private static Object loadJsonFromFile(String fileName) throws IOException {
561         String content = loadFileNameToJsonString(fileName);
562         return new Yaml().load(content);
563     }
564
565 }