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