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