1 package org.openecomp.sdc.ci.tests.verificator;
3 import com.aventstack.extentreports.Status;
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.*;
14 import java.lang.reflect.Field;
15 import java.util.HashMap;
16 import java.util.LinkedHashMap;
17 import java.util.List;
20 public class ToscaValidation {
24 * @param expectedToscaDefinition - expected toscaDefinition object
25 * @param actualToscaDefinition - actual toscaDefinition object
26 * @return true if all validation success else return error map
28 public static Either<Boolean, Map<String, Object>> resourceToscaMetadataValidator(ToscaDefinition expectedToscaDefinition, ToscaDefinition actualToscaDefinition){
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");
37 SetupCDTest.getExtendTest().log(Status.ERROR, "Resource TOSCA metadata verification failed" + resourceToscaMetadataValidator.right().value());
39 return resourceToscaMetadataValidator;
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()){
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");
59 SetupCDTest.getExtendTest().log(Status.ERROR, "Vf module json file verification failed" + vfModuleFileValidator.right().value().toString());
61 return vfModuleFileValidator;
64 public static Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator(Map<String, String> expectedMetadata, ToscaDefinition actualToscaDefinition){
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");
72 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA metadata verification failed" + serviceToscaMetadataValidator.right().value().toString());
74 return serviceToscaMetadataValidator;
77 public static Either<Boolean, Map<String, Object>> serviceToscaGroupMetadataValidator(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, ToscaDefinition actualToscaDefinition){
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");
85 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group metadata verification failed" + serviceToscaGroupMetadataValidator.right().value().toString());
87 return serviceToscaGroupMetadataValidator;
90 public static Either<Boolean,Map<String,Object>> compareServiceGroupMetadata(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups) {
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");
97 compareServiceGroupData(expectedServiceGroup.get(groupName), actualServiceGroups.get(groupName), groupName, errorMap);
100 if(!errorMap.isEmpty()){
101 return Either.right(errorMap);
103 return Either.left(true);
106 public static Either<Boolean, Map<String, Object>> compareServiceGroupData(ToscaServiceGroupsMetadataDefinition expectedServiceGroupMetadata, ToscaServiceGroupsMetadataDefinition actualServiceGroupMetadata, String groupName, Map<String, Object> errorMap) {
108 Field[] declaredFields = expectedServiceGroupMetadata.getClass().getSuperclass().getFields();
109 for (Field field : declaredFields){
110 if(!field.getName().equals("serialVersionUID")) {
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) {
121 if(!errorMap.isEmpty()){
122 return Either.right(errorMap);
124 return Either.left(true);
128 // ###########################UsingParser############################
129 public static Either<Boolean, Map<String, Object>> serviceToscaGroupMetadataValidatorUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups){
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");
136 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group metadata verification vs. tosca parser failed" + serviceToscaGroupMetadataValidator.right().value().toString());
138 return serviceToscaGroupMetadataValidator;
141 public static Either<Boolean,Map<String,Object>> compareServiceGroupMetadataUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups) {
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");
149 compareServiceGroupDataUsingParser(expectedServiceGroup.get(groupName), actualGroup.getMetadata(), groupName, errorMap);
152 if(!errorMap.isEmpty()){
153 return Either.right(errorMap);
155 return Either.left(true);
158 private static Group getServiceToscaParserGroupFromObject(String groupName, List<Group> actualServiceGroups) {
159 for(Group group : actualServiceGroups){
160 if(group.getName().equals(groupName)){
167 public static Either<Boolean, Map<String, Object>> compareServiceGroupDataUsingParser(ToscaServiceGroupsMetadataDefinition expectedServiceGroupMetadata, Metadata actualServiceGroupMetadata, String groupName, Map<String, Object> errorMap) {
169 Field[] declaredFields = expectedServiceGroupMetadata.getClass().getSuperclass().getFields();
170 for (Field field : declaredFields){
171 if(!field.getName().equals("serialVersionUID")) {
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) {
182 if(!errorMap.isEmpty()){
183 return Either.right(errorMap);
185 return Either.left(true);
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);
193 errorMap.put("Data field [" + field.getName() + "] in group service metadata [" + groupName + "]", "expected: " + expectedValue + ", actual: " + actualValue);
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");
202 // ############################################################################################
206 // ###########################Property UsingParser############################
207 public static Either<Boolean, Map<String, Object>> serviceToscaGroupPropertyValidatorUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups){
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");
214 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group property verification vs. tosca parser failed" + serviceToscaGroupMetadataValidator.right().value().toString());
216 return serviceToscaGroupMetadataValidator;
219 public static Either<Boolean,Map<String,Object>> compareServiceGroupPropertyUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups) {
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");
227 compareServiceGroupPropertyUsingParser(expectedServiceGroup.get(groupName).getProperties(), actualGroup.getProperties(), groupName, errorMap);
230 if(!errorMap.isEmpty()){
231 return Either.right(errorMap);
233 return Either.left(true);
236 public static Either<Boolean, Map<String, Object>> compareServiceGroupPropertyUsingParser(ToscaGroupPropertyDefinition expectedServiceGroupProperty, LinkedHashMap<String, Property> actualServiceGroupProperty, String groupName, Map<String, Object> errorMap) {
238 Field[] declaredFields = expectedServiceGroupProperty.getClass().getDeclaredFields();
239 for (Field field : declaredFields){
240 if(!field.getName().equals("serialVersionUID")) {
242 String expectedValue = null;
243 String actualValue = null;
244 if (field.get(expectedServiceGroupProperty) != null) {
245 expectedValue = field.get(expectedServiceGroupProperty).toString();
247 if (actualServiceGroupProperty.get(field.getName()) != null && actualServiceGroupProperty.get(field.getName()).getValue() != null) {
248 actualValue = actualServiceGroupProperty.get(field.getName()).getValue().toString();
250 comparingServiceGroupProperty(groupName, errorMap, field, expectedValue, actualValue);
251 } catch (IllegalAccessException e) {
257 if(!errorMap.isEmpty()){
258 return Either.right(errorMap);
260 return Either.left(true);
263 // ############################################################################################
282 public static Either<Boolean, Map<String, Object>> serviceToscaGroupPropertyValidator(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, ToscaDefinition actualToscaDefinition){
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");
290 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group property verification failed" + serviceToscaGroupPropertyValidator.right().value().toString());
292 return serviceToscaGroupPropertyValidator;
295 public static Either<Boolean,Map<String,Object>> compareServiceGroupProperty(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups) {
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");
302 compareServiceGroupProperty(expectedServiceGroup.get(groupName).getProperties(), actualServiceGroups.get(groupName).getProperties(), groupName, errorMap);
305 if(!errorMap.isEmpty()){
306 return Either.right(errorMap);
308 return Either.left(true);
311 public static Either<Boolean, Map<String, Object>> compareServiceGroupProperty(ToscaGroupPropertyDefinition expectedServiceGroupProperty, ToscaGroupPropertyDefinition actualServiceGroupProperty, String groupName, Map<String, Object> errorMap) {
313 Field[] declaredFields = expectedServiceGroupProperty.getClass().getDeclaredFields();
314 for (Field field : declaredFields){
315 if(!field.getName().equals("serialVersionUID")) {
317 String expectedValue = null;
318 String actualValue = null;
319 if(field.get(expectedServiceGroupProperty) != null) {
320 expectedValue = field.get(expectedServiceGroupProperty).toString();
322 if(field.get(actualServiceGroupProperty) != null) {
323 actualValue = field.get(actualServiceGroupProperty).toString();
325 comparingServiceGroupProperty(groupName, errorMap, field, expectedValue, actualValue);
326 } catch (IllegalAccessException e) {
332 if(!errorMap.isEmpty()){
333 return Either.right(errorMap);
335 return Either.left(true);
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);
343 errorMap.put("Data field [" + field.getName() + "] in group service property [" + groupName + "]", "expected: " + expectedValue + ", actual: " + actualValue);
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");
353 // ----------------------------------
354 public static Either<Boolean, Map<String, Object>> componentToscaNodeTemplateMetadataValidator(Map<String, String> expectedMetadata, ToscaDefinition actualToscaDefinition, String nodeTemplateName, ComponentTypeEnum componentType, String componentName){
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");
362 SetupCDTest.getExtendTest().log(Status.ERROR, " " +componentName + " " + componentType.getValue() + "TOSCA node template metadata verification failed" + componentToscaMetadataValidator.right().value().toString());
364 return componentToscaMetadataValidator;
367 public static Either<Boolean, Map<String, Object>> serviceToscaMetadataValidatorAgainstParser(Map<String, String> expectedMetadata, Metadata actualMetadata){
369 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA metadata...");
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");
375 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA metadata verification vs. tosca parser failed" + serviceToscaMetadataValidator.right().value().toString());
377 return serviceToscaMetadataValidator;
381 public static Either<Boolean, Map<String, Object>> compareStringMapData(Map<String, String> expectedMetadata, Map<String, String> actualMetadata) {
383 Map<String, Object> errorMap = new HashMap<>();
384 for(String key : expectedMetadata.keySet()){
385 boolean isError = compareStringValue(expectedMetadata.get(key), actualMetadata.get(key));
387 errorMap.put("Data key["+key+"]", "expected: " + expectedMetadata.get(key) + ", actual: " + actualMetadata.get(key));
390 if(!errorMap.isEmpty()){
391 return Either.right(errorMap);
393 return Either.left(true);
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));
402 errorMap.put("Data key["+key+"]", "expected: " + expectedObject.get(key) + ", actual: " + actualObject.get(key));
405 if(!errorMap.isEmpty()){
406 return Either.right(errorMap);
408 return Either.left(true);
411 private static boolean compareObjectValue(VfModuleDefinition expected, VfModuleDefinition actual) {
412 return expected.equals(actual);
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));
420 errorMap.put("Data key["+key+"]", "expected: " + expectedMetadata.get(key) + ", actual: " + actualMetadata.getValue(key));
423 if(!errorMap.isEmpty()){
424 return Either.right(errorMap);
426 return Either.left(true);
429 private static boolean compareStringValue(String expected, String actual) {
430 return expected.equals(actual);
433 public static Either<Boolean, Map<String, Object>> toscaInputsValidator(Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputs, Map<String, ToscaInputsTopologyTemplateDefinition> actualInputs){
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");
440 SetupCDTest.getExtendTest().log(Status.ERROR, "TOSCA inputs verification failed" + toscaInputsValidator.right().value().toString());
443 if(toscaInputsValidator.right() != null && ! toscaInputsValidator.right().equals("")){
444 return toscaInputsValidator;
446 return Either.left(true);
449 public static Either<Boolean,Map<String,Object>> compareInputs(Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputs, Map<String, ToscaInputsTopologyTemplateDefinition> actualInputs) {
451 Map<String, Object> errorMap = new HashMap<>();
453 for (String inputName : expectedInputs.keySet()){
454 if (actualInputs.get(inputName) == null ){
455 errorMap.put("input [" + inputName + "]", " does not exist in TOSCA main yaml");
457 compareInputData(expectedInputs.get(inputName), actualInputs.get(inputName), errorMap);
460 if(!errorMap.isEmpty()){
461 return Either.right(errorMap);
463 return Either.left(true);
466 public static Either<Boolean, Map<String, Object>> compareInputData(ToscaInputsTopologyTemplateDefinition expectedInputDefinition, ToscaInputsTopologyTemplateDefinition actualInputDefinition, Map<String, Object> errorMap) {
468 Field[] declaredFields = expectedInputDefinition.getClass().getDeclaredFields();
469 for (Field field : declaredFields){
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);
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");
482 }catch (IllegalAccessException e) {
487 if(!errorMap.isEmpty()){
488 return Either.right(errorMap);
490 return Either.left(true);
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()) {
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);
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);
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);
517 expectedInputDefinition.getEntry_schema().get("type");
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);
537 public static float convertObjectToFloat(Object object){
539 float floatValue = 0;
541 if(object instanceof Integer){
542 floatValue = ((Integer)object).floatValue();
544 if(object instanceof Double){
545 floatValue = ((Double)object).floatValue();
547 if(object instanceof Float){
548 floatValue = ((Float) object).floatValue();
550 if(object instanceof String){
551 floatValue = Float.parseFloat(object.toString());
554 if(object instanceof Long){
555 floatValue = ((Long) object).floatValue();
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);
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);
572 Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = convertInputsParserOutputToMap(fdntCsarHelper);
573 return toscaInputsValidator(expectedInputsMap, actualInputsMap);
577 * @param fdntCsarHelper convert list of inputs return from tosca parser to map of ToscaInputsTopologyTemplateDefinition
578 * @return field.get(actualServiceGroupProperty)
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);
590 return actualInputsMap;