re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / verificator / ToscaValidation.java
1 package org.openecomp.sdc.ci.tests.verificator;
2
3 import com.aventstack.extentreports.Status;
4 import fj.data.Either;
5 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
6 import org.onap.sdc.toscaparser.api.Group;
7 import org.onap.sdc.toscaparser.api.Property;
8 import org.onap.sdc.toscaparser.api.elements.Metadata;
9 import org.onap.sdc.toscaparser.api.parameters.Input;
10 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
11 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
12 import org.openecomp.sdc.ci.tests.tosca.datatypes.*;
13
14 import java.lang.reflect.Field;
15 import java.util.HashMap;
16 import java.util.LinkedHashMap;
17 import java.util.List;
18 import java.util.Map;
19
20 public class ToscaValidation {
21
22         
23         /**
24          * @param expectedToscaDefinition - expected toscaDefinition object
25          * @param actualToscaDefinition - actual toscaDefinition object
26          * @return true if all validation success else return error map
27          */
28         public static Either<Boolean, Map<String, Object>> resourceToscaMetadataValidator(ToscaDefinition expectedToscaDefinition, ToscaDefinition actualToscaDefinition){
29                 
30                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate resource TOSCA metadata...");
31                 Map<String, String> expectedMetadata = expectedToscaDefinition.getMetadata();
32                 Map<String, String> actualMetadata = actualToscaDefinition.getMetadata();
33                 Either<Boolean, Map<String, Object>> resourceToscaMetadataValidator = compareStringMapData(expectedMetadata, actualMetadata);
34                 if(resourceToscaMetadataValidator.isLeft()){
35                         SetupCDTest.getExtendTest().log(Status.INFO, "Resource TOSCA metadata verification success");
36                 }else{
37                         SetupCDTest.getExtendTest().log(Status.ERROR, "Resource TOSCA metadata verification failed" + resourceToscaMetadataValidator.right().value());
38                 }
39                 return resourceToscaMetadataValidator;
40         }
41
42         public static Boolean resourceToscaNodeTemplateMetadataValidator(Map<String, Map<String, String>> expectedMetadata, ToscaDefinition actualToscaDefinition){
43                 boolean isTestFailed = true;
44                 for(String nodeTemplateName : expectedMetadata.keySet()){
45                         Either<Boolean,Map<String,Object>> serviceToscaMetadataValidator = componentToscaNodeTemplateMetadataValidator(expectedMetadata.get(nodeTemplateName), actualToscaDefinition, nodeTemplateName, ComponentTypeEnum.RESOURCE, nodeTemplateName);
46                         if(!serviceToscaMetadataValidator.left().value()){
47                                 isTestFailed = false;
48                         }
49                 }
50                 return isTestFailed;
51         }
52         
53         public static Either<Boolean, Map<String, Object>> vfModuleJsonFileValidator(Map<String, VfModuleDefinition> expectedVfModulesDefinitionObject, Map<String, VfModuleDefinition> actualVfModulesDefinitionObject){
54                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate vf module json file...");
55                 Either<Boolean,Map<String,Object>> vfModuleFileValidator = compareObjectMapData(expectedVfModulesDefinitionObject, actualVfModulesDefinitionObject);
56                 if(vfModuleFileValidator.isLeft()){
57                         SetupCDTest.getExtendTest().log(Status.INFO, "Vf module json file verification success");
58                 }else{
59                         SetupCDTest.getExtendTest().log(Status.ERROR, "Vf module json file verification failed" + vfModuleFileValidator.right().value().toString());
60                 }
61                 return vfModuleFileValidator;
62         }
63
64         public static Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator(Map<String, String> expectedMetadata, ToscaDefinition actualToscaDefinition){
65
66                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA metadata...");
67                 Map<String, String> actualMetadata = actualToscaDefinition.getMetadata();
68                 Either<Boolean,Map<String,Object>> serviceToscaMetadataValidator = compareStringMapData(expectedMetadata, actualMetadata);
69                 if(serviceToscaMetadataValidator.isLeft()){
70                         SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA metadata verification success");
71                 }else{
72                         SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA metadata verification failed" + serviceToscaMetadataValidator.right().value().toString());
73                 }
74                 return serviceToscaMetadataValidator;
75         }
76
77         public static Either<Boolean, Map<String, Object>> serviceToscaGroupMetadataValidator(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, ToscaDefinition actualToscaDefinition){
78
79                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA group metadata...");
80                 Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups = actualToscaDefinition.getTopology_template().getGroups();
81                 Either<Boolean,Map<String,Object>> serviceToscaGroupMetadataValidator = compareServiceGroupMetadata(expectedServiceGroup, actualServiceGroups);
82                 if(serviceToscaGroupMetadataValidator.isLeft()){
83                         SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA group metadata verification success");
84                 }else{
85                         SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group metadata verification failed" + serviceToscaGroupMetadataValidator.right().value().toString());
86                 }
87                 return serviceToscaGroupMetadataValidator;
88         }
89
90     public static Either<Boolean,Map<String,Object>> compareServiceGroupMetadata(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups) {
91
92         Map<String, Object> errorMap = new HashMap<>();
93         for (String groupName : expectedServiceGroup.keySet()){
94             if (actualServiceGroups.get(groupName) == null ){
95                 errorMap.put("group/module [" + groupName + "]", " does not exist in TOSCA main yaml");
96             }else{
97                 compareServiceGroupData(expectedServiceGroup.get(groupName), actualServiceGroups.get(groupName), groupName, errorMap);
98             }
99         }
100         if(!errorMap.isEmpty()){
101             return Either.right(errorMap);
102         }
103         return Either.left(true);
104     }
105
106     public static Either<Boolean, Map<String, Object>> compareServiceGroupData(ToscaServiceGroupsMetadataDefinition expectedServiceGroupMetadata, ToscaServiceGroupsMetadataDefinition actualServiceGroupMetadata, String groupName, Map<String, Object> errorMap) {
107
108         Field[] declaredFields = expectedServiceGroupMetadata.getClass().getSuperclass().getFields();
109         for (Field field : declaredFields){
110                 if(!field.getName().equals("serialVersionUID")) {
111                                 try {
112                                         String expectedValue = (String) field.get(expectedServiceGroupMetadata);
113                                         String actualValue = (String) field.get(actualServiceGroupMetadata);
114                                         comparingServiceGroupMetadata(groupName, errorMap, field, expectedValue, actualValue);
115                                 } catch (IllegalAccessException e) {
116                                         e.printStackTrace();
117                                 }
118                         }
119         }
120
121         if(!errorMap.isEmpty()){
122             return Either.right(errorMap);
123         }
124         return Either.left(true);
125     }
126
127
128 //    ###########################UsingParser############################
129 public static Either<Boolean, Map<String, Object>> serviceToscaGroupMetadataValidatorUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups){
130
131         SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA group metadata...");
132         Either<Boolean,Map<String,Object>> serviceToscaGroupMetadataValidator = compareServiceGroupMetadataUsingParser(expectedServiceGroup, actualServiceGroups);
133         if(serviceToscaGroupMetadataValidator.isLeft()){
134                 SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA group metadata verification vs. tosca parser success");
135         }else{
136                 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group metadata verification vs. tosca parser failed" + serviceToscaGroupMetadataValidator.right().value().toString());
137         }
138         return serviceToscaGroupMetadataValidator;
139 }
140
141         public static Either<Boolean,Map<String,Object>> compareServiceGroupMetadataUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups) {
142
143                 Map<String, Object> errorMap = new HashMap<>();
144                 for (String groupName : expectedServiceGroup.keySet()){
145                         Group actualGroup = getServiceToscaParserGroupFromObject(groupName, actualServiceGroups);
146                         if (actualGroup == null ){
147                                 errorMap.put("group/module [" + groupName + "]", " does not exist in TOSCA main yaml");
148                         }else{
149                                 compareServiceGroupDataUsingParser(expectedServiceGroup.get(groupName), actualGroup.getMetadata(), groupName, errorMap);
150                         }
151                 }
152                 if(!errorMap.isEmpty()){
153                         return Either.right(errorMap);
154                 }
155                 return Either.left(true);
156         }
157
158         private static Group getServiceToscaParserGroupFromObject(String groupName, List<Group> actualServiceGroups) {
159                 for(Group group : actualServiceGroups){
160                         if(group.getName().equals(groupName)){
161                                 return group;
162                         }
163                 }
164                 return null;
165         }
166
167         public static Either<Boolean, Map<String, Object>> compareServiceGroupDataUsingParser(ToscaServiceGroupsMetadataDefinition expectedServiceGroupMetadata, Metadata actualServiceGroupMetadata, String groupName, Map<String, Object> errorMap) {
168
169                 Field[] declaredFields = expectedServiceGroupMetadata.getClass().getSuperclass().getFields();
170                 for (Field field : declaredFields){
171                         if(!field.getName().equals("serialVersionUID")) {
172                                 try {
173                                         String expectedValue = (String) field.get(expectedServiceGroupMetadata);
174                                         String actualValue = actualServiceGroupMetadata.getValue(field.getName());
175                                         comparingServiceGroupMetadata(groupName, errorMap, field, expectedValue, actualValue);
176                                 } catch (IllegalAccessException e) {
177                                         e.printStackTrace();
178                                 }
179                         }
180                 }
181
182                 if(!errorMap.isEmpty()){
183                         return Either.right(errorMap);
184                 }
185                 return Either.left(true);
186         }
187
188         private static void comparingServiceGroupMetadata(String groupName, Map<String, Object> errorMap, Field field, String expectedValue, String actualValue) {
189                 if (expectedValue != null && !expectedValue.trim().equals("")) {
190             if (actualValue != null) {
191                 Boolean result = compareStringValue(expectedValue, actualValue);
192                 if (!result) {
193                     errorMap.put("Data field [" + field.getName() + "] in group service metadata [" + groupName + "]", "expected: " + expectedValue + ", actual: " + actualValue);
194                 }
195             } else {
196                 errorMap.put("Data field [" + field.getName() + "] in group service metadata [" + groupName + "]", " does not exist in actual object");
197                 System.out.println("Data field [" + field.getName() + "] in group service metadata [" + groupName + "] does not exist in actual object");
198             }
199         }
200         }
201
202 //      ############################################################################################
203
204
205
206         //    ###########################Property UsingParser############################
207         public static Either<Boolean, Map<String, Object>> serviceToscaGroupPropertyValidatorUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups){
208
209                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA group property...");
210                 Either<Boolean,Map<String,Object>> serviceToscaGroupMetadataValidator = compareServiceGroupPropertyUsingParser(expectedServiceGroup, actualServiceGroups);
211                 if(serviceToscaGroupMetadataValidator.isLeft()){
212                         SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA group property verification vs. tosca parser success");
213                 }else{
214                         SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group property verification vs. tosca parser failed" + serviceToscaGroupMetadataValidator.right().value().toString());
215                 }
216                 return serviceToscaGroupMetadataValidator;
217         }
218
219         public static Either<Boolean,Map<String,Object>> compareServiceGroupPropertyUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups) {
220
221                 Map<String, Object> errorMap = new HashMap<>();
222                 for (String groupName : expectedServiceGroup.keySet()){
223                         Group actualGroup = getServiceToscaParserGroupFromObject(groupName, actualServiceGroups);
224                         if (actualGroup == null ){
225                                 errorMap.put("group/module [" + groupName + "]", " does not exist in TOSCA main yaml");
226                         }else{
227                                 compareServiceGroupPropertyUsingParser(expectedServiceGroup.get(groupName).getProperties(), actualGroup.getProperties(), groupName, errorMap);
228                         }
229                 }
230                 if(!errorMap.isEmpty()){
231                         return Either.right(errorMap);
232                 }
233                 return Either.left(true);
234         }
235
236         public static Either<Boolean, Map<String, Object>> compareServiceGroupPropertyUsingParser(ToscaGroupPropertyDefinition expectedServiceGroupProperty, LinkedHashMap<String, Property> actualServiceGroupProperty, String groupName, Map<String, Object> errorMap) {
237
238                 Field[] declaredFields = expectedServiceGroupProperty.getClass().getDeclaredFields();
239                 for (Field field : declaredFields){
240                         if(!field.getName().equals("serialVersionUID")) {
241                                 try {
242                                         String expectedValue = null;
243                                         String actualValue = null;
244                                         if (field.get(expectedServiceGroupProperty) != null) {
245                                                 expectedValue = field.get(expectedServiceGroupProperty).toString();
246                                         }
247                                         if (actualServiceGroupProperty.get(field.getName()) != null && actualServiceGroupProperty.get(field.getName()).getValue() != null) {
248                                                 actualValue = actualServiceGroupProperty.get(field.getName()).getValue().toString();
249                                         }
250                                         comparingServiceGroupProperty(groupName, errorMap, field, expectedValue, actualValue);
251                                 } catch (IllegalAccessException e) {
252                                         e.printStackTrace();
253                                 }
254                         }
255                 }
256
257                 if(!errorMap.isEmpty()){
258                         return Either.right(errorMap);
259                 }
260                 return Either.left(true);
261         }
262
263 //      ############################################################################################
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281 //?-------
282         public static Either<Boolean, Map<String, Object>> serviceToscaGroupPropertyValidator(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, ToscaDefinition actualToscaDefinition){
283
284                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA group property...");
285                 Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups = actualToscaDefinition.getTopology_template().getGroups();
286                 Either<Boolean,Map<String,Object>> serviceToscaGroupPropertyValidator = compareServiceGroupProperty(expectedServiceGroup, actualServiceGroups);
287                 if(serviceToscaGroupPropertyValidator.isLeft()){
288                         SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA group property verification success");
289                 }else{
290                         SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group property verification failed" + serviceToscaGroupPropertyValidator.right().value().toString());
291                 }
292                 return serviceToscaGroupPropertyValidator;
293         }
294
295         public static Either<Boolean,Map<String,Object>> compareServiceGroupProperty(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups) {
296
297                 Map<String, Object> errorMap = new HashMap<>();
298                 for (String groupName : expectedServiceGroup.keySet()){
299                         if (actualServiceGroups.get(groupName) == null ){
300                                 errorMap.put("group/module [" + groupName + "]", " does not exist in TOSCA main yaml");
301                         }else{
302                                 compareServiceGroupProperty(expectedServiceGroup.get(groupName).getProperties(), actualServiceGroups.get(groupName).getProperties(), groupName, errorMap);
303                         }
304                 }
305                 if(!errorMap.isEmpty()){
306                         return Either.right(errorMap);
307                 }
308                 return Either.left(true);
309         }
310
311         public static Either<Boolean, Map<String, Object>> compareServiceGroupProperty(ToscaGroupPropertyDefinition expectedServiceGroupProperty, ToscaGroupPropertyDefinition actualServiceGroupProperty, String groupName, Map<String, Object> errorMap) {
312
313                 Field[] declaredFields = expectedServiceGroupProperty.getClass().getDeclaredFields();
314                 for (Field field : declaredFields){
315                         if(!field.getName().equals("serialVersionUID")) {
316                                 try {
317                                         String expectedValue = null;
318                                         String actualValue = null;
319                                         if(field.get(expectedServiceGroupProperty) != null) {
320                                                 expectedValue = field.get(expectedServiceGroupProperty).toString();
321                                         }
322                                         if(field.get(actualServiceGroupProperty) != null) {
323                                                 actualValue = field.get(actualServiceGroupProperty).toString();
324                                         }
325                                         comparingServiceGroupProperty(groupName, errorMap, field, expectedValue, actualValue);
326                                 } catch (IllegalAccessException e) {
327                                         e.printStackTrace();
328                                 }
329                         }
330                 }
331
332                 if(!errorMap.isEmpty()){
333                         return Either.right(errorMap);
334                 }
335                 return Either.left(true);
336         }
337
338         private static void comparingServiceGroupProperty(String groupName, Map<String, Object> errorMap, Field field, String expectedValue, String actualValue) {
339                 if (expectedValue != null && !expectedValue.trim().equals("")) {
340             if (actualValue != null) {
341                 Boolean result = compareStringValue(expectedValue, actualValue);
342                 if (!result) {
343                     errorMap.put("Data field [" + field.getName() + "] in group service property [" + groupName + "]", "expected: " + expectedValue + ", actual: " + actualValue);
344                 }
345             } else {
346                 errorMap.put("Data field [" + field.getName() + "] in group service property [" + groupName + "]", " does not exist in actual object");
347                 System.out.println("Data field [" + field.getName() + "] in group service property [" + groupName + "] does not exist in actual object");
348             }
349         }
350         }
351
352
353         //    ----------------------------------
354         public static Either<Boolean, Map<String, Object>> componentToscaNodeTemplateMetadataValidator(Map<String, String> expectedMetadata, ToscaDefinition actualToscaDefinition, String nodeTemplateName, ComponentTypeEnum componentType, String componentName){
355                 
356                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate "+ componentName + " " + componentType.getValue() + " node template TOSCA metadata...");
357                 Map<String, String> actualMetadata = actualToscaDefinition.getTopology_template().getNode_templates().get(nodeTemplateName).getMetadata();
358                 Either<Boolean,Map<String,Object>> componentToscaMetadataValidator = compareStringMapData(expectedMetadata, actualMetadata);
359                 if(componentToscaMetadataValidator.isLeft()){
360                         SetupCDTest.getExtendTest().log(Status.INFO, " " + componentName + " " + componentType.getValue() + "TOSCA node template metadata verification success");
361                 }else{
362                         SetupCDTest.getExtendTest().log(Status.ERROR, " " +componentName + " " + componentType.getValue() + "TOSCA node template metadata verification failed" + componentToscaMetadataValidator.right().value().toString());
363                 }
364                 return componentToscaMetadataValidator;
365         }
366         
367         public static Either<Boolean, Map<String, Object>> serviceToscaMetadataValidatorAgainstParser(Map<String, String> expectedMetadata, Metadata actualMetadata){
368                 
369                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA metadata...");
370
371                 Either<Boolean,Map<String,Object>> serviceToscaMetadataValidator = compareMetadataUsingToscaParser(expectedMetadata, actualMetadata);
372                 if(serviceToscaMetadataValidator.isLeft()){
373                         SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA metadata verification vs. tosca parser success");
374                 }else{
375                         SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA metadata verification vs. tosca parser failed" + serviceToscaMetadataValidator.right().value().toString());
376                 }
377                 return serviceToscaMetadataValidator;
378         }
379
380         
381         public static Either<Boolean, Map<String, Object>> compareStringMapData(Map<String, String> expectedMetadata, Map<String, String> actualMetadata) {
382                 Either.left(false);
383                 Map<String, Object> errorMap = new HashMap<>();
384                 for(String key : expectedMetadata.keySet()){
385                         boolean isError = compareStringValue(expectedMetadata.get(key), actualMetadata.get(key));
386                         if(!isError){
387                                 errorMap.put("Data key["+key+"]", "expected: " + expectedMetadata.get(key) + ", actual: " + actualMetadata.get(key));
388                         }
389                 }
390                 if(!errorMap.isEmpty()){
391                         return Either.right(errorMap);
392                 }
393                 return Either.left(true);
394         }
395
396
397         public static Either<Boolean, Map<String, Object>> compareObjectMapData(Map<String, VfModuleDefinition> expectedObject, Map<String, VfModuleDefinition> actualObject) {
398                 Map<String, Object> errorMap = new HashMap<>();
399                 for(String key : expectedObject.keySet()){
400                         boolean isError = compareObjectValue(expectedObject.get(key), actualObject.get(key));
401                         if(!isError){
402                                 errorMap.put("Data key["+key+"]", "expected: " + expectedObject.get(key) + ", actual: " + actualObject.get(key));
403                         }
404                 }
405                 if(!errorMap.isEmpty()){
406                         return Either.right(errorMap);
407                 }
408                 return Either.left(true);
409         }
410
411         private static boolean compareObjectValue(VfModuleDefinition expected, VfModuleDefinition actual) {
412                 return expected.equals(actual);
413         }
414
415         public static Either<Boolean, Map<String, Object>> compareMetadataUsingToscaParser(Map<String, String> expectedMetadata, Metadata actualMetadata) {
416                 Map<String, Object> errorMap = new HashMap<>();
417                 for(String key : expectedMetadata.keySet()){
418                         boolean isError = compareStringValue(expectedMetadata.get(key), actualMetadata.getValue(key));
419                         if(!isError){
420                                 errorMap.put("Data key["+key+"]", "expected: " + expectedMetadata.get(key) + ", actual: " + actualMetadata.getValue(key));
421                         }
422                 }
423                 if(!errorMap.isEmpty()){
424                         return Either.right(errorMap);
425                 }
426                 return Either.left(true);
427         }
428         
429         private static boolean compareStringValue(String expected, String actual) {
430                 return expected.equals(actual);
431         }
432         
433         public static Either<Boolean, Map<String, Object>> toscaInputsValidator(Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputs, Map<String, ToscaInputsTopologyTemplateDefinition> actualInputs){
434                 
435                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate TOSCA inputs...");
436                 Either<Boolean,Map<String,Object>> toscaInputsValidator = compareInputs(expectedInputs, actualInputs);
437                 if(toscaInputsValidator.isLeft()){
438                         SetupCDTest.getExtendTest().log(Status.INFO, "TOSCA inputs verification success");
439                 }else{
440                         SetupCDTest.getExtendTest().log(Status.ERROR, "TOSCA inputs verification failed" + toscaInputsValidator.right().value().toString());
441                 }
442                 
443                 if(toscaInputsValidator.right() != null && ! toscaInputsValidator.right().equals("")){
444                         return toscaInputsValidator;
445                 }
446                 return Either.left(true);
447         }
448         
449         public static Either<Boolean,Map<String,Object>> compareInputs(Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputs, Map<String, ToscaInputsTopologyTemplateDefinition> actualInputs) {
450                 
451                 Map<String, Object> errorMap = new HashMap<>();
452                 
453                 for (String inputName : expectedInputs.keySet()){
454                         if (actualInputs.get(inputName) == null ){
455                                 errorMap.put("input [" + inputName + "]", " does not exist in TOSCA main yaml");
456                         }else{
457                                 compareInputData(expectedInputs.get(inputName), actualInputs.get(inputName), errorMap);
458                         }
459                 }
460                 if(!errorMap.isEmpty()){
461                         return Either.right(errorMap);
462                 }
463                 return Either.left(true);
464         }
465
466         public static Either<Boolean, Map<String, Object>> compareInputData(ToscaInputsTopologyTemplateDefinition expectedInputDefinition, ToscaInputsTopologyTemplateDefinition actualInputDefinition, Map<String, Object> errorMap) {
467
468                 Field[] declaredFields = expectedInputDefinition.getClass().getDeclaredFields();
469                 for (Field field : declaredFields){
470                         try {
471                                 Object expectedValue = field.get(expectedInputDefinition);
472                                 Object actualValue = field.get(actualInputDefinition);
473 //                              verification exclude fields as (immutable, hidden, constraints, entry_schema) according Renana
474                                 if(expectedValue != null && !expectedValue.toString().trim().equals("") && field.getName() != "name" && field.getName() != "immutable" && field.getName() != "hidden" && field.getName() != "constraints" && field.getName() != "entry_schema" && field.getName() != "required") {
475                                         if (actualValue != null) {
476                                                 compareInputValue(expectedInputDefinition, errorMap, field, expectedValue, actualValue);
477                                         } else {
478                                                 errorMap.put("Data field [" + field.getName() + "] in input [" + expectedInputDefinition.getName() + "]", " does not exist in actual object");
479                                                 System.out.println("Data field [" + field.getName() + "] in input [" + expectedInputDefinition.getName() + "] does not exist in actual object");
480                                         }
481                                 }
482                         }catch (IllegalAccessException e) {
483                                 e.printStackTrace();
484                         }
485                 }
486                 
487                 if(!errorMap.isEmpty()){
488                         return Either.right(errorMap);
489                 }
490                 return Either.left(true);
491         }
492
493         public static void compareInputValue(ToscaInputsTopologyTemplateDefinition expectedInputDefinition, Map<String, Object> errorMap, Field field, Object expectedValue, Object actualValue) {
494                 if(field.getName().equals("value") || field.getName().equals("Default")){
495                         switch (expectedInputDefinition.getType()) {
496                         case "string":
497                                 if(! expectedValue.toString().replace("\n"," ").replaceAll("( +)", " ").equals(actualValue.toString().replace("\n"," ").replaceAll("( +)", " "))){
498                                         errorMap.put("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]",  "expected: " + expectedValue + ", actual: " + actualValue);
499                                         System.out.println("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]: expected: " + expectedValue + ", actual: " + actualValue);
500                                 }
501                                 break;
502                         case "float":
503                                         float newExpectedValue = convertObjectToFloat(expectedValue);
504                                         float newActualValue = convertObjectToFloat(actualValue);
505                                         if(newExpectedValue != newActualValue){
506                                                 errorMap.put("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]",  "expected: " + newExpectedValue + ", actual: " + newActualValue);
507                                                 System.out.println("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]: expected: " + newExpectedValue + ", actual: " + newActualValue);
508                                         }
509                                 break;
510                         case "boolean":
511                                 if(! expectedValue.toString().equalsIgnoreCase(actualValue.toString())){
512                                         errorMap.put("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]",  "expected: " + expectedValue + ", actual: " + actualValue);
513                                         System.out.println("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]: expected: " + expectedValue + ", actual: " + actualValue);
514                                 }
515                                 break;
516                         case "list":
517                                 expectedInputDefinition.getEntry_schema().get("type");
518                                 break;
519                         case "map":
520
521                                 break;
522                         default:
523                                 break;
524                         }
525
526
527                 }else{
528                         if(! expectedValue.equals(actualValue)){
529                                 errorMap.put("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]",  "expected: " + expectedValue + ", actual: " + actualValue);
530                                 System.out.println("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]: expected: " + expectedValue + ", actual: " + actualValue);
531                         }
532                 }
533                 
534         }
535         
536         
537         public static float convertObjectToFloat(Object object){
538                 
539                 float floatValue = 0;
540                 
541                 if(object instanceof Integer){
542                         floatValue = ((Integer)object).floatValue();
543                 }
544                 if(object instanceof Double){
545                         floatValue = ((Double)object).floatValue();
546                 }
547                 if(object instanceof Float){
548                         floatValue = ((Float) object).floatValue();
549                 }
550                 if(object instanceof String){
551                         floatValue = Float.parseFloat(object.toString());
552                 }
553                 
554                 if(object instanceof Long){
555                         floatValue = ((Long) object).floatValue();
556                 }
557                 return floatValue;
558         }
559
560         public static Either<Boolean, Map<String, Object>> toscaInputsValidatorAgainstParser(Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputsMap, ISdcCsarHelper fdntCsarHelper) {
561                 SetupCDTest.getExtendTest().log(Status.INFO, "Going to convert tosca parser inputs output to ToscaInputsTopologyTemplateDefinition object...");
562                 if(!fdntCsarHelper.getServiceInputs().isEmpty()){
563                         if(expectedInputsMap != null && ! expectedInputsMap.isEmpty()){
564                                 return Either.left(true);
565                         }else{
566                                 Map<String, Object> errorMap = new HashMap<>();
567                                 errorMap.put("Inputs", " do not exist on actual service");
568                                 SetupCDTest.getExtendTest().log(Status.INFO, "Inputs do not exist on actual service csar");
569                                 return Either.right(errorMap);
570                         }
571                 }
572                 Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = convertInputsParserOutputToMap(fdntCsarHelper);
573                 return toscaInputsValidator(expectedInputsMap, actualInputsMap);
574         }
575
576         /**
577          * @param fdntCsarHelper convert list of inputs return from tosca parser to map of ToscaInputsTopologyTemplateDefinition
578          * @return field.get(actualServiceGroupProperty)
579          */
580         public static Map<String, ToscaInputsTopologyTemplateDefinition> convertInputsParserOutputToMap(ISdcCsarHelper fdntCsarHelper) {
581                 Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = new HashMap<>();
582                 List<Input> serviceInputs = fdntCsarHelper.getServiceInputs();
583                 for (Input input : serviceInputs){
584                         ToscaInputsTopologyTemplateDefinition actualInputDefinition = new ToscaInputsTopologyTemplateDefinition();
585                         actualInputDefinition.setDefault(input.getDefault());
586                         actualInputDefinition.setType(input.getType());
587                         actualInputDefinition.setDescription(input.getDescription());
588                         actualInputsMap.put(input.getName(), actualInputDefinition);
589                 }
590                 return actualInputsMap;
591         }
592         
593 }