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