2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.ci.tests.verificator;
23 import com.aventstack.extentreports.Status;
24 import fj.data.Either;
25 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
26 import org.onap.sdc.toscaparser.api.Group;
27 import org.onap.sdc.toscaparser.api.Property;
28 import org.onap.sdc.toscaparser.api.elements.Metadata;
29 import org.onap.sdc.toscaparser.api.parameters.Input;
30 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
31 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
32 import org.openecomp.sdc.ci.tests.tosca.datatypes.*;
34 import java.lang.reflect.Field;
35 import java.util.HashMap;
36 import java.util.LinkedHashMap;
37 import java.util.List;
40 public class ToscaValidation {
44 * @param expectedToscaDefinition - expected toscaDefinition object
45 * @param actualToscaDefinition - actual toscaDefinition object
46 * @return true if all validation success else return error map
48 public static Either<Boolean, Map<String, Object>> resourceToscaMetadataValidator(ToscaDefinition expectedToscaDefinition, ToscaDefinition actualToscaDefinition){
50 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate resource TOSCA metadata...");
51 Map<String, String> expectedMetadata = expectedToscaDefinition.getMetadata();
52 Map<String, String> actualMetadata = actualToscaDefinition.getMetadata();
53 Either<Boolean, Map<String, Object>> resourceToscaMetadataValidator = compareStringMapData(expectedMetadata, actualMetadata);
54 if(resourceToscaMetadataValidator.isLeft()){
55 SetupCDTest.getExtendTest().log(Status.INFO, "Resource TOSCA metadata verification success");
57 SetupCDTest.getExtendTest().log(Status.ERROR, "Resource TOSCA metadata verification failed" + resourceToscaMetadataValidator.right().value());
59 return resourceToscaMetadataValidator;
62 public static Boolean resourceToscaNodeTemplateMetadataValidator(Map<String, Map<String, String>> expectedMetadata, ToscaDefinition actualToscaDefinition){
63 boolean isTestFailed = true;
64 for(String nodeTemplateName : expectedMetadata.keySet()){
65 Either<Boolean,Map<String,Object>> serviceToscaMetadataValidator = componentToscaNodeTemplateMetadataValidator(expectedMetadata.get(nodeTemplateName), actualToscaDefinition, nodeTemplateName, ComponentTypeEnum.RESOURCE, nodeTemplateName);
66 if(!serviceToscaMetadataValidator.left().value()){
73 public static Either<Boolean, Map<String, Object>> vfModuleJsonFileValidator(Map<String, VfModuleDefinition> expectedVfModulesDefinitionObject, Map<String, VfModuleDefinition> actualVfModulesDefinitionObject){
74 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate vf module json file...");
75 Either<Boolean,Map<String,Object>> vfModuleFileValidator = compareObjectMapData(expectedVfModulesDefinitionObject, actualVfModulesDefinitionObject);
76 if(vfModuleFileValidator.isLeft()){
77 SetupCDTest.getExtendTest().log(Status.INFO, "Vf module json file verification success");
79 SetupCDTest.getExtendTest().log(Status.ERROR, "Vf module json file verification failed" + vfModuleFileValidator.right().value().toString());
81 return vfModuleFileValidator;
84 public static Either<Boolean, Map<String, Object>> serviceToscaMetadataValidator(Map<String, String> expectedMetadata, ToscaDefinition actualToscaDefinition){
86 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA metadata...");
87 Map<String, String> actualMetadata = actualToscaDefinition.getMetadata();
88 Either<Boolean,Map<String,Object>> serviceToscaMetadataValidator = compareStringMapData(expectedMetadata, actualMetadata);
89 if(serviceToscaMetadataValidator.isLeft()){
90 SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA metadata verification success");
92 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA metadata verification failed" + serviceToscaMetadataValidator.right().value().toString());
94 return serviceToscaMetadataValidator;
97 public static Either<Boolean, Map<String, Object>> serviceToscaGroupMetadataValidator(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, ToscaDefinition actualToscaDefinition){
99 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA group metadata...");
100 Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups = actualToscaDefinition.getTopology_template().getGroups();
101 Either<Boolean,Map<String,Object>> serviceToscaGroupMetadataValidator = compareServiceGroupMetadata(expectedServiceGroup, actualServiceGroups);
102 if(serviceToscaGroupMetadataValidator.isLeft()){
103 SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA group metadata verification success");
105 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group metadata verification failed" + serviceToscaGroupMetadataValidator.right().value().toString());
107 return serviceToscaGroupMetadataValidator;
110 public static Either<Boolean,Map<String,Object>> compareServiceGroupMetadata(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups) {
112 Map<String, Object> errorMap = new HashMap<>();
113 for (String groupName : expectedServiceGroup.keySet()){
114 if (actualServiceGroups.get(groupName) == null ){
115 errorMap.put("group/module [" + groupName + "]", " does not exist in TOSCA main yaml");
117 compareServiceGroupData(expectedServiceGroup.get(groupName), actualServiceGroups.get(groupName), groupName, errorMap);
120 if(!errorMap.isEmpty()){
121 return Either.right(errorMap);
123 return Either.left(true);
126 public static Either<Boolean, Map<String, Object>> compareServiceGroupData(ToscaServiceGroupsMetadataDefinition expectedServiceGroupMetadata, ToscaServiceGroupsMetadataDefinition actualServiceGroupMetadata, String groupName, Map<String, Object> errorMap) {
128 Field[] declaredFields = expectedServiceGroupMetadata.getClass().getSuperclass().getFields();
129 for (Field field : declaredFields){
130 if(!field.getName().equals("serialVersionUID")) {
132 String expectedValue = (String) field.get(expectedServiceGroupMetadata);
133 String actualValue = (String) field.get(actualServiceGroupMetadata);
134 comparingServiceGroupMetadata(groupName, errorMap, field, expectedValue, actualValue);
135 } catch (IllegalAccessException e) {
141 if(!errorMap.isEmpty()){
142 return Either.right(errorMap);
144 return Either.left(true);
148 // ###########################UsingParser############################
149 public static Either<Boolean, Map<String, Object>> serviceToscaGroupMetadataValidatorUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups){
151 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA group metadata...");
152 Either<Boolean,Map<String,Object>> serviceToscaGroupMetadataValidator = compareServiceGroupMetadataUsingParser(expectedServiceGroup, actualServiceGroups);
153 if(serviceToscaGroupMetadataValidator.isLeft()){
154 SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA group metadata verification vs. tosca parser success");
156 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group metadata verification vs. tosca parser failed" + serviceToscaGroupMetadataValidator.right().value().toString());
158 return serviceToscaGroupMetadataValidator;
161 public static Either<Boolean,Map<String,Object>> compareServiceGroupMetadataUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups) {
163 Map<String, Object> errorMap = new HashMap<>();
164 for (String groupName : expectedServiceGroup.keySet()){
165 Group actualGroup = getServiceToscaParserGroupFromObject(groupName, actualServiceGroups);
166 if (actualGroup == null ){
167 errorMap.put("group/module [" + groupName + "]", " does not exist in TOSCA main yaml");
169 compareServiceGroupDataUsingParser(expectedServiceGroup.get(groupName), actualGroup.getMetadata(), groupName, errorMap);
172 if(!errorMap.isEmpty()){
173 return Either.right(errorMap);
175 return Either.left(true);
178 private static Group getServiceToscaParserGroupFromObject(String groupName, List<Group> actualServiceGroups) {
179 for(Group group : actualServiceGroups){
180 if(group.getName().equals(groupName)){
187 public static Either<Boolean, Map<String, Object>> compareServiceGroupDataUsingParser(ToscaServiceGroupsMetadataDefinition expectedServiceGroupMetadata, Metadata actualServiceGroupMetadata, String groupName, Map<String, Object> errorMap) {
189 Field[] declaredFields = expectedServiceGroupMetadata.getClass().getSuperclass().getFields();
190 for (Field field : declaredFields){
191 if(!field.getName().equals("serialVersionUID")) {
193 String expectedValue = (String) field.get(expectedServiceGroupMetadata);
194 String actualValue = actualServiceGroupMetadata.getValue(field.getName());
195 comparingServiceGroupMetadata(groupName, errorMap, field, expectedValue, actualValue);
196 } catch (IllegalAccessException e) {
202 if(!errorMap.isEmpty()){
203 return Either.right(errorMap);
205 return Either.left(true);
208 private static void comparingServiceGroupMetadata(String groupName, Map<String, Object> errorMap, Field field, String expectedValue, String actualValue) {
209 if (expectedValue != null && !expectedValue.trim().equals("")) {
210 if (actualValue != null) {
211 Boolean result = compareStringValue(expectedValue, actualValue);
213 errorMap.put("Data field [" + field.getName() + "] in group service metadata [" + groupName + "]", "expected: " + expectedValue + ", actual: " + actualValue);
216 errorMap.put("Data field [" + field.getName() + "] in group service metadata [" + groupName + "]", " does not exist in actual object");
217 System.out.println("Data field [" + field.getName() + "] in group service metadata [" + groupName + "] does not exist in actual object");
222 // ############################################################################################
226 // ###########################Property UsingParser############################
227 public static Either<Boolean, Map<String, Object>> serviceToscaGroupPropertyValidatorUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups){
229 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA group property...");
230 Either<Boolean,Map<String,Object>> serviceToscaGroupMetadataValidator = compareServiceGroupPropertyUsingParser(expectedServiceGroup, actualServiceGroups);
231 if(serviceToscaGroupMetadataValidator.isLeft()){
232 SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA group property verification vs. tosca parser success");
234 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group property verification vs. tosca parser failed" + serviceToscaGroupMetadataValidator.right().value().toString());
236 return serviceToscaGroupMetadataValidator;
239 public static Either<Boolean,Map<String,Object>> compareServiceGroupPropertyUsingParser(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, List<Group> actualServiceGroups) {
241 Map<String, Object> errorMap = new HashMap<>();
242 for (String groupName : expectedServiceGroup.keySet()){
243 Group actualGroup = getServiceToscaParserGroupFromObject(groupName, actualServiceGroups);
244 if (actualGroup == null ){
245 errorMap.put("group/module [" + groupName + "]", " does not exist in TOSCA main yaml");
247 compareServiceGroupPropertyUsingParser(expectedServiceGroup.get(groupName).getProperties(), actualGroup.getProperties(), groupName, errorMap);
250 if(!errorMap.isEmpty()){
251 return Either.right(errorMap);
253 return Either.left(true);
256 public static Either<Boolean, Map<String, Object>> compareServiceGroupPropertyUsingParser(ToscaGroupPropertyDefinition expectedServiceGroupProperty, LinkedHashMap<String, Property> actualServiceGroupProperty, String groupName, Map<String, Object> errorMap) {
258 Field[] declaredFields = expectedServiceGroupProperty.getClass().getDeclaredFields();
259 for (Field field : declaredFields){
260 if(!field.getName().equals("serialVersionUID")) {
262 String expectedValue = null;
263 String actualValue = null;
264 if (field.get(expectedServiceGroupProperty) != null) {
265 expectedValue = field.get(expectedServiceGroupProperty).toString();
267 if (actualServiceGroupProperty.get(field.getName()) != null && actualServiceGroupProperty.get(field.getName()).getValue() != null) {
268 actualValue = actualServiceGroupProperty.get(field.getName()).getValue().toString();
270 comparingServiceGroupProperty(groupName, errorMap, field, expectedValue, actualValue);
271 } catch (IllegalAccessException e) {
277 if(!errorMap.isEmpty()){
278 return Either.right(errorMap);
280 return Either.left(true);
283 // ############################################################################################
302 public static Either<Boolean, Map<String, Object>> serviceToscaGroupPropertyValidator(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, ToscaDefinition actualToscaDefinition){
304 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA group property...");
305 Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups = actualToscaDefinition.getTopology_template().getGroups();
306 Either<Boolean,Map<String,Object>> serviceToscaGroupPropertyValidator = compareServiceGroupProperty(expectedServiceGroup, actualServiceGroups);
307 if(serviceToscaGroupPropertyValidator.isLeft()){
308 SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA group property verification success");
310 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA group property verification failed" + serviceToscaGroupPropertyValidator.right().value().toString());
312 return serviceToscaGroupPropertyValidator;
315 public static Either<Boolean,Map<String,Object>> compareServiceGroupProperty(Map<String, ToscaGroupsTopologyTemplateDefinition> expectedServiceGroup, Map<String, ToscaGroupsTopologyTemplateDefinition> actualServiceGroups) {
317 Map<String, Object> errorMap = new HashMap<>();
318 for (String groupName : expectedServiceGroup.keySet()){
319 if (actualServiceGroups.get(groupName) == null ){
320 errorMap.put("group/module [" + groupName + "]", " does not exist in TOSCA main yaml");
322 compareServiceGroupProperty(expectedServiceGroup.get(groupName).getProperties(), actualServiceGroups.get(groupName).getProperties(), groupName, errorMap);
325 if(!errorMap.isEmpty()){
326 return Either.right(errorMap);
328 return Either.left(true);
331 public static Either<Boolean, Map<String, Object>> compareServiceGroupProperty(ToscaGroupPropertyDefinition expectedServiceGroupProperty, ToscaGroupPropertyDefinition actualServiceGroupProperty, String groupName, Map<String, Object> errorMap) {
333 Field[] declaredFields = expectedServiceGroupProperty.getClass().getDeclaredFields();
334 for (Field field : declaredFields){
335 if(!field.getName().equals("serialVersionUID")) {
337 String expectedValue = null;
338 String actualValue = null;
339 if(field.get(expectedServiceGroupProperty) != null) {
340 expectedValue = field.get(expectedServiceGroupProperty).toString();
342 if(field.get(actualServiceGroupProperty) != null) {
343 actualValue = field.get(actualServiceGroupProperty).toString();
345 comparingServiceGroupProperty(groupName, errorMap, field, expectedValue, actualValue);
346 } catch (IllegalAccessException e) {
352 if(!errorMap.isEmpty()){
353 return Either.right(errorMap);
355 return Either.left(true);
358 private static void comparingServiceGroupProperty(String groupName, Map<String, Object> errorMap, Field field, String expectedValue, String actualValue) {
359 if (expectedValue != null && !expectedValue.trim().equals("")) {
360 if (actualValue != null) {
361 Boolean result = compareStringValue(expectedValue, actualValue);
363 errorMap.put("Data field [" + field.getName() + "] in group service property [" + groupName + "]", "expected: " + expectedValue + ", actual: " + actualValue);
366 errorMap.put("Data field [" + field.getName() + "] in group service property [" + groupName + "]", " does not exist in actual object");
367 System.out.println("Data field [" + field.getName() + "] in group service property [" + groupName + "] does not exist in actual object");
373 // ----------------------------------
374 public static Either<Boolean, Map<String, Object>> componentToscaNodeTemplateMetadataValidator(Map<String, String> expectedMetadata, ToscaDefinition actualToscaDefinition, String nodeTemplateName, ComponentTypeEnum componentType, String componentName){
376 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate "+ componentName + " " + componentType.getValue() + " node template TOSCA metadata...");
377 Map<String, String> actualMetadata = actualToscaDefinition.getTopology_template().getNode_templates().get(nodeTemplateName).getMetadata();
378 Either<Boolean,Map<String,Object>> componentToscaMetadataValidator = compareStringMapData(expectedMetadata, actualMetadata);
379 if(componentToscaMetadataValidator.isLeft()){
380 SetupCDTest.getExtendTest().log(Status.INFO, " " + componentName + " " + componentType.getValue() + "TOSCA node template metadata verification success");
382 SetupCDTest.getExtendTest().log(Status.ERROR, " " +componentName + " " + componentType.getValue() + "TOSCA node template metadata verification failed" + componentToscaMetadataValidator.right().value().toString());
384 return componentToscaMetadataValidator;
387 public static Either<Boolean, Map<String, Object>> serviceToscaMetadataValidatorAgainstParser(Map<String, String> expectedMetadata, Metadata actualMetadata){
389 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate service TOSCA metadata...");
391 Either<Boolean,Map<String,Object>> serviceToscaMetadataValidator = compareMetadataUsingToscaParser(expectedMetadata, actualMetadata);
392 if(serviceToscaMetadataValidator.isLeft()){
393 SetupCDTest.getExtendTest().log(Status.INFO, "Service TOSCA metadata verification vs. tosca parser success");
395 SetupCDTest.getExtendTest().log(Status.ERROR, "Service TOSCA metadata verification vs. tosca parser failed" + serviceToscaMetadataValidator.right().value().toString());
397 return serviceToscaMetadataValidator;
401 public static Either<Boolean, Map<String, Object>> compareStringMapData(Map<String, String> expectedMetadata, Map<String, String> actualMetadata) {
403 Map<String, Object> errorMap = new HashMap<>();
404 for(String key : expectedMetadata.keySet()){
405 boolean isError = compareStringValue(expectedMetadata.get(key), actualMetadata.get(key));
407 errorMap.put("Data key["+key+"]", "expected: " + expectedMetadata.get(key) + ", actual: " + actualMetadata.get(key));
410 if(!errorMap.isEmpty()){
411 return Either.right(errorMap);
413 return Either.left(true);
417 public static Either<Boolean, Map<String, Object>> compareObjectMapData(Map<String, VfModuleDefinition> expectedObject, Map<String, VfModuleDefinition> actualObject) {
418 Map<String, Object> errorMap = new HashMap<>();
419 for(String key : expectedObject.keySet()){
420 boolean isError = compareObjectValue(expectedObject.get(key), actualObject.get(key));
422 errorMap.put("Data key["+key+"]", "expected: " + expectedObject.get(key) + ", actual: " + actualObject.get(key));
425 if(!errorMap.isEmpty()){
426 return Either.right(errorMap);
428 return Either.left(true);
431 private static boolean compareObjectValue(VfModuleDefinition expected, VfModuleDefinition actual) {
432 return expected.equals(actual);
435 public static Either<Boolean, Map<String, Object>> compareMetadataUsingToscaParser(Map<String, String> expectedMetadata, Metadata actualMetadata) {
436 Map<String, Object> errorMap = new HashMap<>();
437 for(String key : expectedMetadata.keySet()){
438 boolean isError = compareStringValue(expectedMetadata.get(key), actualMetadata.getValue(key));
440 errorMap.put("Data key["+key+"]", "expected: " + expectedMetadata.get(key) + ", actual: " + actualMetadata.getValue(key));
443 if(!errorMap.isEmpty()){
444 return Either.right(errorMap);
446 return Either.left(true);
449 private static boolean compareStringValue(String expected, String actual) {
450 return expected.equals(actual);
453 public static Either<Boolean, Map<String, Object>> toscaInputsValidator(Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputs, Map<String, ToscaInputsTopologyTemplateDefinition> actualInputs){
455 SetupCDTest.getExtendTest().log(Status.INFO, "Going to validate TOSCA inputs...");
456 Either<Boolean,Map<String,Object>> toscaInputsValidator = compareInputs(expectedInputs, actualInputs);
457 if(toscaInputsValidator.isLeft()){
458 SetupCDTest.getExtendTest().log(Status.INFO, "TOSCA inputs verification success");
460 SetupCDTest.getExtendTest().log(Status.ERROR, "TOSCA inputs verification failed" + toscaInputsValidator.right().value().toString());
463 if(toscaInputsValidator.right() != null && ! toscaInputsValidator.right().equals("")){
464 return toscaInputsValidator;
466 return Either.left(true);
469 public static Either<Boolean,Map<String,Object>> compareInputs(Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputs, Map<String, ToscaInputsTopologyTemplateDefinition> actualInputs) {
471 Map<String, Object> errorMap = new HashMap<>();
473 for (String inputName : expectedInputs.keySet()){
474 if (actualInputs.get(inputName) == null ){
475 errorMap.put("input [" + inputName + "]", " does not exist in TOSCA main yaml");
477 compareInputData(expectedInputs.get(inputName), actualInputs.get(inputName), errorMap);
480 if(!errorMap.isEmpty()){
481 return Either.right(errorMap);
483 return Either.left(true);
486 public static Either<Boolean, Map<String, Object>> compareInputData(ToscaInputsTopologyTemplateDefinition expectedInputDefinition, ToscaInputsTopologyTemplateDefinition actualInputDefinition, Map<String, Object> errorMap) {
488 Field[] declaredFields = expectedInputDefinition.getClass().getDeclaredFields();
489 for (Field field : declaredFields){
491 Object expectedValue = field.get(expectedInputDefinition);
492 Object actualValue = field.get(actualInputDefinition);
493 // verification exclude fields as (immutable, hidden, constraints, entry_schema) according Renana
494 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") {
495 if (actualValue != null) {
496 compareInputValue(expectedInputDefinition, errorMap, field, expectedValue, actualValue);
498 errorMap.put("Data field [" + field.getName() + "] in input [" + expectedInputDefinition.getName() + "]", " does not exist in actual object");
499 System.out.println("Data field [" + field.getName() + "] in input [" + expectedInputDefinition.getName() + "] does not exist in actual object");
502 }catch (IllegalAccessException e) {
507 if(!errorMap.isEmpty()){
508 return Either.right(errorMap);
510 return Either.left(true);
513 public static void compareInputValue(ToscaInputsTopologyTemplateDefinition expectedInputDefinition, Map<String, Object> errorMap, Field field, Object expectedValue, Object actualValue) {
514 if(field.getName().equals("value") || field.getName().equals("Default")){
515 switch (expectedInputDefinition.getType()) {
517 if(! expectedValue.toString().replace("\n"," ").replaceAll("( +)", " ").equals(actualValue.toString().replace("\n"," ").replaceAll("( +)", " "))){
518 errorMap.put("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]", "expected: " + expectedValue + ", actual: " + actualValue);
519 System.out.println("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]: expected: " + expectedValue + ", actual: " + actualValue);
523 float newExpectedValue = convertObjectToFloat(expectedValue);
524 float newActualValue = convertObjectToFloat(actualValue);
525 if(newExpectedValue != newActualValue){
526 errorMap.put("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]", "expected: " + newExpectedValue + ", actual: " + newActualValue);
527 System.out.println("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]: expected: " + newExpectedValue + ", actual: " + newActualValue);
531 if(! expectedValue.toString().equalsIgnoreCase(actualValue.toString())){
532 errorMap.put("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]", "expected: " + expectedValue + ", actual: " + actualValue);
533 System.out.println("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]: expected: " + expectedValue + ", actual: " + actualValue);
537 expectedInputDefinition.getEntry_schema().get("type");
548 if(! expectedValue.equals(actualValue)){
549 errorMap.put("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]", "expected: " + expectedValue + ", actual: " + actualValue);
550 System.out.println("Data field [" + field.getName()+"] in input [" + expectedInputDefinition.getName() + "]: expected: " + expectedValue + ", actual: " + actualValue);
557 public static float convertObjectToFloat(Object object){
559 float floatValue = 0;
561 if(object instanceof Integer){
562 floatValue = ((Integer)object).floatValue();
564 if(object instanceof Double){
565 floatValue = ((Double)object).floatValue();
567 if(object instanceof Float){
568 floatValue = ((Float) object).floatValue();
570 if(object instanceof String){
571 floatValue = Float.parseFloat(object.toString());
574 if(object instanceof Long){
575 floatValue = ((Long) object).floatValue();
580 public static Either<Boolean, Map<String, Object>> toscaInputsValidatorAgainstParser(Map<String, ToscaInputsTopologyTemplateDefinition> expectedInputsMap, ISdcCsarHelper fdntCsarHelper) {
581 SetupCDTest.getExtendTest().log(Status.INFO, "Going to convert tosca parser inputs output to ToscaInputsTopologyTemplateDefinition object...");
582 if(!fdntCsarHelper.getServiceInputs().isEmpty()){
583 if(expectedInputsMap != null && ! expectedInputsMap.isEmpty()){
584 return Either.left(true);
586 Map<String, Object> errorMap = new HashMap<>();
587 errorMap.put("Inputs", " do not exist on actual service");
588 SetupCDTest.getExtendTest().log(Status.INFO, "Inputs do not exist on actual service csar");
589 return Either.right(errorMap);
592 Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = convertInputsParserOutputToMap(fdntCsarHelper);
593 return toscaInputsValidator(expectedInputsMap, actualInputsMap);
597 * @param fdntCsarHelper convert list of inputs return from tosca parser to map of ToscaInputsTopologyTemplateDefinition
598 * @return field.get(actualServiceGroupProperty)
600 public static Map<String, ToscaInputsTopologyTemplateDefinition> convertInputsParserOutputToMap(ISdcCsarHelper fdntCsarHelper) {
601 Map<String, ToscaInputsTopologyTemplateDefinition> actualInputsMap = new HashMap<>();
602 List<Input> serviceInputs = fdntCsarHelper.getServiceInputs();
603 for (Input input : serviceInputs){
604 ToscaInputsTopologyTemplateDefinition actualInputDefinition = new ToscaInputsTopologyTemplateDefinition();
605 actualInputDefinition.setDefault(input.getDefault());
606 actualInputDefinition.setType(input.getType());
607 actualInputDefinition.setDescription(input.getDescription());
608 actualInputsMap.put(input.getName(), actualInputDefinition);
610 return actualInputsMap;