1 package org.openecomp.sdc.ci.tests.verificator;
3 import com.aventstack.extentreports.Status;
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;
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() == false){
53 public static Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator(Map<String, String> expectedMetadata, ToscaDefinition actualToscaDefinition){
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");
61 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA metadata verification failed" + serviceToscaMetadataValidator.right().value().toString());
63 return serviceToscaMetadataValidator;
66 public static Either<Boolean, Map<String, Object>> serviceToscaGroupMetadataValidator(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, ToscaDefinition actualToscaDefinition){
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");
74 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group metadata verification failed" + serviceToscaGroupMetadataValidator.right().value().toString());
76 return serviceToscaGroupMetadataValidator;
79 public static Either<Boolean,Map<String,Object>> compareServiceGroupMetadata(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups) {
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");
86 compareServiceGroupData(expectedServiceGroup.get(groupName).getMetadata(), actualServiceGroups.get(groupName).getMetadata(), groupName, errorMap);
89 if(errorMap != null && !errorMap.isEmpty()){
90 return Either.right(errorMap);
92 return Either.left(true);
95 public static Either<Boolean, Map<String, Object>> compareServiceGroupData(ToscaServiceGroupsMetadataDefinition expectedServiceGroupMetadata, ToscaServiceGroupsMetadataDefinition actualServiceGroupMetadata, String groupName, Map<String, Object> errorMap) {
97 Field[] declaredFields = expectedServiceGroupMetadata.getClass().getDeclaredFields();
98 for (Field field : declaredFields){
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);
106 errorMap.put("Data field [" + field.getName()+"] in group service metadata [" + groupName + "]", "expected: " + expectedValue + ", actual: " + actualValue);
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");
113 }catch (IllegalAccessException e) {
118 if(errorMap != null && !errorMap.isEmpty()){
119 return Either.right(errorMap);
121 return Either.left(true);
125 // ###########################UsingParser############################
126 public static Either<Boolean, Map<String, Object>> serviceToscaGroupMetadataValidatorUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups){
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");
133 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group metadata verification vs. tosca parser failed" + serviceToscaGroupMetadataValidator.right().value().toString());
135 return serviceToscaGroupMetadataValidator;
138 public static Either<Boolean,Map<String,Object>> compareServiceGroupMetadataUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups) {
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");
146 compareServiceGroupDataUsingParser(expectedServiceGroup.get(groupName).getMetadata(), actualGroup.getMetadata(), groupName, errorMap);
149 if(errorMap != null && !errorMap.isEmpty()){
150 return Either.right(errorMap);
152 return Either.left(true);
155 private static Group getServiceToscaParserGroupFromObject(String groupName, List<Group> actualServiceGroups) {
156 for(Group group : actualServiceGroups){
157 if(group.getName().equals(groupName)){
164 public static Either<Boolean, Map<String, Object>> compareServiceGroupDataUsingParser(ToscaServiceGroupsMetadataDefinition expectedServiceGroupMetadata, Metadata actualServiceGroupMetadata, String groupName, Map<String, Object> errorMap) {
166 Field[] declaredFields = expectedServiceGroupMetadata.getClass().getDeclaredFields();
167 for (Field field : declaredFields){
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);
175 errorMap.put("Data field [" + field.getName()+"] in group service metadata [" + groupName + "]", "expected: " + expectedValue + ", actual: " + actualValue);
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");
182 }catch (IllegalAccessException e) {
187 if(errorMap != null && !errorMap.isEmpty()){
188 return Either.right(errorMap);
190 return Either.left(true);
193 // ############################################################################################
197 // ###########################Property UsingParser############################
198 public static Either<Boolean, Map<String, Object>> serviceToscaGroupPropertyValidatorUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups){
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");
205 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group property verification vs. tosca parser failed" + serviceToscaGroupMetadataValidator.right().value().toString());
207 return serviceToscaGroupMetadataValidator;
210 public static Either<Boolean,Map<String,Object>> compareServiceGroupPropertyUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups) {
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");
218 compareServiceGroupPropertyUsingParser(expectedServiceGroup.get(groupName).getProperties(), actualGroup.getProperties(), groupName, errorMap);
221 if(errorMap != null && !errorMap.isEmpty()){
222 return Either.right(errorMap);
224 return Either.left(true);
227 public static Either<Boolean, Map<String, Object>> compareServiceGroupPropertyUsingParser(ToscaGroupPropertyDefinition expectedServiceGroupProperty, LinkedHashMap<String, Property> actualServiceGroupProperty, String groupName, Map<String, Object> errorMap) {
229 Field[] declaredFields = expectedServiceGroupProperty.getClass().getDeclaredFields();
230 for (Field field : declaredFields){
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();
237 if(expectedValue != null && !expectedValue.toString().trim().equals("")) {
238 if (actualValue != null) {
239 Boolean result = compareValue(expectedValue, actualValue);
241 errorMap.put("Data field [" + field.getName()+"] in group service property [" + groupName + "]", "expected: " + expectedValue + ", actual: " + actualValue);
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");
248 }catch (IllegalAccessException e) {
253 if(errorMap != null && !errorMap.isEmpty()){
254 return Either.right(errorMap);
256 return Either.left(true);
259 // ############################################################################################
278 public static Either<Boolean, Map<String, Object>> serviceToscaGroupPropertyValidator(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, ToscaDefinition actualToscaDefinition){
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");
286 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group property verification failed" + serviceToscaGroupPropertyValidator.right().value().toString());
288 return serviceToscaGroupPropertyValidator;
291 public static Either<Boolean,Map<String,Object>> compareServiceGroupProperty(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups) {
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");
298 compareServiceGroupProperty(expectedServiceGroup.get(groupName).getProperties(), actualServiceGroups.get(groupName).getProperties(), groupName, errorMap);
301 if(errorMap != null && !errorMap.isEmpty()){
302 return Either.right(errorMap);
304 return Either.left(true);
307 public static Either<Boolean, Map<String, Object>> compareServiceGroupProperty(ToscaGroupPropertyDefinition expectedServiceGroupProperty, ToscaGroupPropertyDefinition actualServiceGroupProperty, String groupName, Map<String, Object> errorMap) {
309 Field[] declaredFields = expectedServiceGroupProperty.getClass().getDeclaredFields();
310 for (Field field : declaredFields){
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);
318 errorMap.put("Data field [" + field.getName()+"] in group service property [" + groupName + "]", "expected: " + expectedValue + ", actual: " + actualValue);
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");
325 }catch (IllegalAccessException e) {
330 if(errorMap != null && !errorMap.isEmpty()){
331 return Either.right(errorMap);
333 return Either.left(true);
337 // ----------------------------------
338 public static Either<Boolean, Map<String, Object>> componentToscaNodeTemplateMetadataValidator(Map<String, String> expectedMetadata, ToscaDefinition actualToscaDefinition, String nodeTemplateName, ComponentTypeEnum componentType, String componentName){
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");
346 SetupCDTest.getExtendTest().log(Status.ERROR, " " +componentName + " " + componentType.getValue() + "TOSCA node template metadata verification failed" + componentToscaMetadataValidator.right().value().toString());
348 return componentToscaMetadataValidator;
351 public static Either<Boolean, Map<String, Object>> serviceToscaMetadataValidatorAgainstParser(Map<String, String> expectedMetadata, Metadata actualMetadata){
353 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA metadata...");
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");
359 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA metadata verification vs. tosca parser failed" + serviceToscaMetadataValidator.right().value().toString());
361 return serviceToscaMetadataValidator;
365 public static Either<Boolean, Map<String, Object>> compareStringMapData(Map<String, String> expectedMetadata, Map<String, String> actualMetadata) {
367 Map<String, Object> errorMap = new HashMap<>();
368 for(String key : expectedMetadata.keySet()){
369 boolean isError = compareValue(expectedMetadata.get(key), actualMetadata.get(key));
371 errorMap.put("Data key["+key+"]", "expected: " + expectedMetadata.get(key) + ", actual: " + actualMetadata.get(key));
374 if(!errorMap.isEmpty()){
375 return Either.right(errorMap);
377 return Either.left(true);
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));
385 errorMap.put("Data key["+key+"]", "expected: " + expectedMetadata.get(key) + ", actual: " + actualMetadata.getValue(key));
388 if(!errorMap.isEmpty()){
389 return Either.right(errorMap);
391 return Either.left(true);
394 private static boolean compareValue(String expected, String actual) {
396 return expected.equals(actual);
400 public static Either<Boolean, Map<String, Object>> toscaInputsValidator(Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputs, Map<String, ToscaInputsTopologyTemplateDefinition> actualInputs){
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");
407 SetupCDTest.getExtendTest().log(Status.ERROR, "TOSCA inputs verification failed" + toscaInputsValidator.right().value().toString());
410 if(toscaInputsValidator.right() != null && ! toscaInputsValidator.right().equals("")){
411 return toscaInputsValidator;
413 return Either.left(true);
416 public static Either<Boolean,Map<String,Object>> compareInputs(Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputs, Map<String, ToscaInputsTopologyTemplateDefinition> actualInputs) {
418 Map<String, Object> errorMap = new HashMap<>();
420 for (String inputName : expectedInputs.keySet()){
421 if (actualInputs.get(inputName) == null ){
422 errorMap.put("input [" + inputName + "]", " does not exist in TOSCA main yaml");
424 compareInputData(expectedInputs.get(inputName), actualInputs.get(inputName), errorMap);
427 if(errorMap != null && !errorMap.isEmpty()){
428 return Either.right(errorMap);
430 return Either.left(true);
433 public static Either<Boolean, Map<String, Object>> compareInputData(ToscaInputsTopologyTemplateDefinition expectedInputDefinition, ToscaInputsTopologyTemplateDefinition actualInputDefinition, Map<String, Object> errorMap) {
435 Field[] declaredFields = expectedInputDefinition.getClass().getDeclaredFields();
436 for (Field field : declaredFields){
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);
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");
449 }catch (IllegalAccessException e) {
454 if(errorMap != null && !errorMap.isEmpty()){
455 return Either.right(errorMap);
457 return Either.left(true);
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()) {
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);
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);
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);
484 expectedInputDefinition.getEntry_schema().get("type");
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);
504 public static float convertObjectToFloat(Object object){
506 float floatValue = 0;
508 if(object instanceof Integer){
509 floatValue = ((Integer)object).floatValue();
511 if(object instanceof Double){
512 floatValue = ((Double)object).floatValue();
514 if(object instanceof Float){
515 floatValue = ((Float) object).floatValue();
517 if(object instanceof String){
518 floatValue = Float.parseFloat(object.toString());
521 if(object instanceof Long){
522 floatValue = ((Long) object).floatValue();
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);
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);
539 Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = convertInputsParserOutputToMap(fdntCsarHelper);
540 return toscaInputsValidator(expectedInputsMap, actualInputsMap);
544 * @param fdntCsarHelper convert list of inputs return from tosca parser to map of ToscaInputsTopologyTemplateDefinition
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);
557 return actualInputsMap;