From 5650c6a9b50287d572e8e040085d0ce2100a82a1 Mon Sep 17 00:00:00 2001 From: mojahidi Date: Wed, 22 Nov 2017 18:02:49 +0530 Subject: Heat Validator This task is about updating error messages with error codes for HeatValidator Change-Id: I80d918e4ae0541c194634e744545d705907d8e15 Issue-ID: SDC-572 Signed-off-by: mojahidi --- .../impl/util/HeatValidationService.java | 184 +--------------- .../validation/impl/validators/HeatValidator.java | 233 ++++++++++++++++++--- .../impl/validators/HeatValidatorTest.java | 114 ++++++---- .../invalidHeatContent/MANIFEST.json | 21 ++ .../invalidHeatContent/mount_iso_script.sh | 0 .../heat_validator/invalidHeatContent/single.env | 11 + .../heat_validator/invalidHeatContent/single.yaml | 53 +++++ .../missingManifestContent/MANIFEST.json | 17 ++ .../missingManifestContent/single.env | 11 + .../missingManifestContent/single.yaml | 52 +++++ .../wrongFileExtension/MANIFEST.json | 17 ++ .../heat_validator/wrongFileExtension/single.aad | 11 + .../heat_validator/wrongFileExtension/single.ya | 60 ++++++ 13 files changed, 549 insertions(+), 235 deletions(-) create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/MANIFEST.json create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/mount_iso_script.sh create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/single.env create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/single.yaml create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/MANIFEST.json create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/single.env create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/single.yaml create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/MANIFEST.json create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/single.aad create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/single.ya (limited to 'openecomp-be') diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java index 39362c7e10..d59d0a8def 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/util/HeatValidationService.java @@ -21,7 +21,6 @@ package org.openecomp.sdc.validation.impl.util; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; import org.openecomp.sdc.tosca.services.YamlUtil; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; import org.openecomp.core.validation.types.GlobalValidationContext; @@ -30,11 +29,8 @@ import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.heat.datatypes.DefinedHeatParameterTypes; import org.openecomp.sdc.heat.datatypes.model.Environment; import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate; -import org.openecomp.sdc.heat.datatypes.model.Output; import org.openecomp.sdc.heat.datatypes.model.Parameter; import org.openecomp.sdc.heat.datatypes.model.Resource; -import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions; -import org.openecomp.sdc.heat.services.HeatStructureUtil; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; @@ -57,6 +53,7 @@ import java.util.Set; public class HeatValidationService { private static final Logger logger = (Logger) LoggerFactory.getLogger(HeatValidator.class); + private static final String NESTED_FILE = "nested file"; private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); /** @@ -77,94 +74,15 @@ public class HeatValidationService { .forEach(artifactName -> { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.MISSING_ARTIFACT.getErrorMessage(), - artifactName), LoggerTragetServiceName.VALIDATE_ARTIFACTS_EXISTENCE, + .getErrorWithParameters(globalContext.getMessageCode(),Messages.MISSING_ARTIFACT.getErrorMessage() + ,artifactName), + LoggerTragetServiceName.VALIDATE_ARTIFACTS_EXISTENCE, LoggerErrorDescription.MISSING_FILE); }); mdcDataDebugMessage.debugExitMessage("file", fileName); } - /** - * Check resource existence from resources map. - * - * @param fileName the file name - * @param resourcesNames the resources names - * @param valuesToSearchIn the values to search in - * @param globalContext the global context - */ - public static void checkResourceExistenceFromResourcesMap(String fileName, - Set resourcesNames, - Collection valuesToSearchIn, - GlobalValidationContext globalContext) { - - - mdcDataDebugMessage.debugEntryMessage("file", fileName); - - if (CollectionUtils.isNotEmpty(valuesToSearchIn)) { - for (Object value : valuesToSearchIn) { - if (value instanceof Resource) { - Resource resource = (Resource) value; - - Collection resourcePropertiesValues = - resource.getProperties() == null ? null : resource.getProperties().values(); - if (CollectionUtils.isNotEmpty(resourcePropertiesValues)) { - for (Object propertyValue : resourcePropertiesValues) { - handleReferencedResources(fileName, propertyValue, resourcesNames, globalContext); - } - } - } else if (value instanceof Output) { - Output output = (Output) value; - Object outputsValue = output.getValue(); - handleReferencedResources(fileName, outputsValue, resourcesNames, globalContext); - } - } - } - - mdcDataDebugMessage.debugExitMessage("file", fileName); - } - - private static void handleReferencedResources(String fileName, Object valueToSearchReferencesIn, - Set resourcesNames, - GlobalValidationContext globalContext) { - - - mdcDataDebugMessage.debugEntryMessage("file", fileName); - - Set referencedResourcesNames = HeatStructureUtil - .getReferencedValuesByFunctionName(fileName, - ResourceReferenceFunctions.GET_RESOURCE.getFunction(), valueToSearchReferencesIn, - globalContext); - if (CollectionUtils.isNotEmpty(referencedResourcesNames)) { - checkIfResourceReferenceExist(fileName, resourcesNames, referencedResourcesNames, - globalContext); - } - - mdcDataDebugMessage.debugExitMessage("file", fileName); - } - - private static void checkIfResourceReferenceExist(String fileName, - Set referencedResourcesNames, - Set referencedResources, - GlobalValidationContext globalContext) { - - - mdcDataDebugMessage.debugEntryMessage("file", fileName); - - referencedResources.stream() - .filter(referencedResource -> !referencedResourcesNames.contains(referencedResource)) - .forEach(referencedResource -> { - globalContext.addMessage(fileName, - ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.REFERENCED_RESOURCE_NOT_FOUND.getErrorMessage(), - referencedResource), - LoggerTragetServiceName.VALIDATE_RESOURCE_REFERENCE_EXISTENCE, - LoggerErrorDescription.RESOURCE_NOT_FOUND); - }); - - mdcDataDebugMessage.debugExitMessage("file", fileName); - } - /** * Draw files loop string. * @@ -267,7 +185,7 @@ public class HeatValidationService { Set nestedParametersNames, GlobalValidationContext globalContext) { - mdcDataDebugMessage.debugEntryMessage("nested file", nestedFileName); + mdcDataDebugMessage.debugEntryMessage(NESTED_FILE, nestedFileName); if (CollectionUtils.isNotEmpty(nestedParametersNames)) { resourceFileProperties @@ -282,7 +200,7 @@ public class HeatValidationService { LoggerErrorDescription.MISSING_PARAMETER_IN_NESTED)); } - mdcDataDebugMessage.debugExitMessage("nested file", nestedFileName); + mdcDataDebugMessage.debugExitMessage(NESTED_FILE, nestedFileName); } @@ -295,7 +213,7 @@ public class HeatValidationService { GlobalValidationContext globalContext) { - mdcDataDebugMessage.debugEntryMessage("nested file", nestedFileName); + mdcDataDebugMessage.debugEntryMessage(NESTED_FILE, nestedFileName); Map properties = resource.getProperties(); for (Map.Entry propertyEntry : properties.entrySet()) { @@ -314,7 +232,7 @@ public class HeatValidationService { } } - mdcDataDebugMessage.debugExitMessage("nested file", nestedFileName); + mdcDataDebugMessage.debugExitMessage(NESTED_FILE, nestedFileName); } private static void validateStaticValueForNestedInputParameter(String parentFileName, @@ -327,7 +245,7 @@ public class HeatValidationService { globalContext) { - mdcDataDebugMessage.debugEntryMessage("nested file", nestedFileName); + mdcDataDebugMessage.debugEntryMessage(NESTED_FILE, nestedFileName); if (parameterInNested == null) { return; @@ -342,7 +260,7 @@ public class HeatValidationService { LoggerErrorDescription.WRONG_VALUE_ASSIGNED_NESTED_PARAMETER); } - mdcDataDebugMessage.debugExitMessage("nested file", nestedFileName); + mdcDataDebugMessage.debugExitMessage(NESTED_FILE, nestedFileName); } @@ -403,92 +321,10 @@ public class HeatValidationService { return false; } - - /** - * Loop over output map and validate get attr from nested. - * - * @param fileName the file name - * @param outputMap the output map - * @param heatOrchestrationTemplate the heat orchestration template - * @param globalContext the global context - */ - @SuppressWarnings("unchecked") - public static void loopOverOutputMapAndValidateGetAttrFromNested(String fileName, - Map outputMap, - HeatOrchestrationTemplate - heatOrchestrationTemplate, - GlobalValidationContext - globalContext) { - for (Output output : outputMap.values()) { - Object outputValue = output.getValue(); - if (outputValue != null && outputValue instanceof Map) { - Map outputValueMap = (Map) outputValue; - List getAttrValue = - (List) outputValueMap.get(ResourceReferenceFunctions.GET_ATTR.getFunction()); - if (!CollectionUtils.isEmpty(getAttrValue)) { - String resourceName = getAttrValue.get(0); - Object attNameObject = getAttrValue.get(1); - if (!(attNameObject instanceof String)) { - return; - } - String attName = getAttrValue.get(1); - String resourceType = - getResourceTypeFromResourcesMap(resourceName, heatOrchestrationTemplate); - - if (Objects.nonNull(resourceType) - && isNestedResource(resourceType)) { - handleGetAttrNestedResource(fileName, globalContext, resourceName, attName, - resourceType); - } - } - } - } - } - - private static void handleGetAttrNestedResource(String fileName, - GlobalValidationContext globalContext, - String resourceName, String attName, - String resourceType) { - Map nestedOutputMap; - HeatOrchestrationTemplate nestedHeatOrchestrationTemplate; - try { - Optional fileContent = globalContext.getFileContent(resourceType); - if (fileContent.isPresent()) { - nestedHeatOrchestrationTemplate = - new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class); - } else { - MdcDataErrorMessage - .createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, - LoggerTragetServiceName.VALIDATE_GET_ATTR_FROM_NESTED, - ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), - LoggerErrorDescription.EMPTY_FILE); - throw new Exception("The file '" + resourceType + "' has no content"); - } - } catch (Exception exception) { - logger.debug("",exception); - return; - } - nestedOutputMap = nestedHeatOrchestrationTemplate.getOutputs(); - - if (MapUtils.isEmpty(nestedOutputMap) || !nestedOutputMap.containsKey(attName)) { - globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.GET_ATTR_NOT_FOUND.getErrorMessage(), - attName, resourceName), - LoggerTragetServiceName.VALIDATE_GET_ATTR_FROM_NESTED, - LoggerErrorDescription.GET_ATTR_NOT_FOUND); - } - } - public static boolean isNestedResource(String resourceType) { return resourceType.contains(".yaml") || resourceType.contains(".yml"); } - private static String getResourceTypeFromResourcesMap(String resourceName, - HeatOrchestrationTemplate - heatOrchestrationTemplate) { - return heatOrchestrationTemplate.getResources().get(resourceName).getType(); - } - /** * Validate env content environment. * diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java index 5297453369..da87a13eb4 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/HeatValidator.java @@ -22,6 +22,11 @@ package org.openecomp.sdc.validation.impl.validators; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.validation.ErrorMessageCode; +import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage; +import org.openecomp.sdc.logging.types.LoggerConstants; +import org.openecomp.sdc.logging.types.LoggerErrorCode; +import org.openecomp.sdc.tosca.services.YamlUtil; import org.openecomp.sdc.validation.Validator; import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder; import org.openecomp.core.validation.types.GlobalValidationContext; @@ -48,15 +53,29 @@ import org.openecomp.sdc.logging.types.LoggerTragetServiceName; import org.openecomp.sdc.validation.impl.util.HeatValidationService; import org.openecomp.sdc.validation.util.ValidationUtil; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; -import java.util.Set; +import java.io.InputStream; +import java.util.*; public class HeatValidator implements Validator { public static final MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); protected static Logger logger = (Logger) LoggerFactory.getLogger(HeatValidator.class); + private static final ErrorMessageCode ERROR_CODE_HOT_1 = new ErrorMessageCode("HOT1"); + private static final ErrorMessageCode ERROR_CODE_HOT_2 = new ErrorMessageCode("HOT2"); + private static final ErrorMessageCode ERROR_CODE_HOT_3 = new ErrorMessageCode("HOT3"); + private static final ErrorMessageCode ERROR_CODE_HOT_4 = new ErrorMessageCode("HOT4"); + private static final ErrorMessageCode ERROR_CODE_HOT_5 = new ErrorMessageCode("HOT5"); + private static final ErrorMessageCode ERROR_CODE_HOT_6 = new ErrorMessageCode("HOT6"); + private static final ErrorMessageCode ERROR_CODE_HOT_7 = new ErrorMessageCode("HOT7"); + private static final ErrorMessageCode ERROR_CODE_HOT_8 = new ErrorMessageCode("HOT8"); + private static final ErrorMessageCode ERROR_CODE_HOT_9 = new ErrorMessageCode("HOT9"); + private static final ErrorMessageCode ERROR_CODE_HOT_10 = new ErrorMessageCode("HOT10"); + private static final ErrorMessageCode ERROR_CODE_HOT_11 = new ErrorMessageCode("HOT11"); + private static final ErrorMessageCode ERROR_CODE_HOT_12 = new ErrorMessageCode("HOT12"); + private static final ErrorMessageCode ERROR_CODE_HOT_13 = new ErrorMessageCode("HOT13"); + private static final ErrorMessageCode ERROR_CODE_HOT_14 = new ErrorMessageCode("HOT14"); + private static final ErrorMessageCode ERROR_CODE_HOT_15 = new ErrorMessageCode("HOT15"); + private static final ErrorMessageCode ERROR_CODE_HOT_16 = new ErrorMessageCode("HOT16"); + private static final ErrorMessageCode ERROR_CODE_HOT_17 = new ErrorMessageCode("HOT17"); private static void validateAllRequiredArtifactsExist(String fileName, HeatOrchestrationTemplate @@ -76,10 +95,12 @@ public class HeatValidator implements Validator { if (CollectionUtils.isNotEmpty(properties)) { for (Object property : properties) { if (property instanceof Map) { + globalContext.setMessageCode(ERROR_CODE_HOT_14); Set artifactNames = HeatStructureUtil .getReferencedValuesByFunctionName(fileName, ResourceReferenceFunctions.GET_FILE.getFunction(), property, globalContext); artifacts.addAll(artifactNames); + globalContext.setMessageCode(ERROR_CODE_HOT_15); HeatValidationService.checkArtifactsExistence(fileName, artifactNames, globalContext); } } @@ -105,18 +126,92 @@ public class HeatValidator implements Validator { : heatOrchestrationTemplate.getResources().values(); Collection outputsValues = heatOrchestrationTemplate.getOutputs() == null ? null : heatOrchestrationTemplate.getOutputs().values(); - - HeatValidationService - .checkResourceExistenceFromResourcesMap(fileName, resourcesNames, resourcesValues, + checkResourceExistenceFromResourcesMap(fileName, resourcesNames, resourcesValues, globalContext); - HeatValidationService - .checkResourceExistenceFromResourcesMap(fileName, resourcesNames, outputsValues, + checkResourceExistenceFromResourcesMap(fileName, resourcesNames, outputsValues, globalContext); mdcDataDebugMessage.debugExitMessage("file", fileName); } + private static void checkResourceExistenceFromResourcesMap(String fileName, + Set resourcesNames, + Collection valuesToSearchIn, + GlobalValidationContext globalContext) { + + mdcDataDebugMessage.debugEntryMessage("file", fileName); + + if (CollectionUtils.isNotEmpty(valuesToSearchIn)) { + for (Object value : valuesToSearchIn) { + if (value instanceof Resource) { + extractResourceProperty(fileName, resourcesNames, globalContext, (Resource) value); + } else if (value instanceof Output) { + Output output = (Output) value; + Object outputsValue = output.getValue(); + handleReferencedResources(fileName, outputsValue, resourcesNames, + globalContext); + } + } + } + } + + private static void extractResourceProperty(String fileName, Set resourcesNames, + GlobalValidationContext globalContext, + Resource value) { + Resource resource = value; + Collection resourcePropertiesValues = + resource.getProperties() == null ? null : resource.getProperties() + .values(); + if (CollectionUtils.isNotEmpty(resourcePropertiesValues)) { + for (Object propertyValue : resourcePropertiesValues) { + handleReferencedResources(fileName, propertyValue, resourcesNames, + globalContext); + } + } + } + + private static void handleReferencedResources(String fileName, Object valueToSearchReferencesIn, + Set resourcesNames, + GlobalValidationContext globalContext) { + + + mdcDataDebugMessage.debugEntryMessage("file", fileName); + globalContext.setMessageCode(ERROR_CODE_HOT_13); + Set referencedResourcesNames = HeatStructureUtil + .getReferencedValuesByFunctionName(fileName, + ResourceReferenceFunctions.GET_RESOURCE.getFunction(), + valueToSearchReferencesIn, globalContext); + if (CollectionUtils.isNotEmpty(referencedResourcesNames)) { + checkIfResourceReferenceExist(fileName, resourcesNames, referencedResourcesNames, + globalContext); + } + + mdcDataDebugMessage.debugExitMessage("file", fileName); + } + + private static void checkIfResourceReferenceExist(String fileName, + Set referencedResourcesNames, + Set referencedResources, + GlobalValidationContext globalContext) { + + + mdcDataDebugMessage.debugEntryMessage("file", fileName); + + referencedResources.stream() + .filter(referencedResource -> !referencedResourcesNames.contains(referencedResource)) + .forEach(referencedResource -> { + globalContext.addMessage(fileName, + ErrorLevel.ERROR, ErrorMessagesFormatBuilder + .getErrorWithParameters(ERROR_CODE_HOT_16,Messages + .REFERENCED_RESOURCE_NOT_FOUND.getErrorMessage(), referencedResource), + LoggerTragetServiceName.VALIDATE_RESOURCE_REFERENCE_EXISTENCE, + LoggerErrorDescription.RESOURCE_NOT_FOUND); + }); + + mdcDataDebugMessage.debugExitMessage("file", fileName); + } + /* validation 16 */ private static void validateGetParamPointToParameter(String fileName, @@ -153,7 +248,6 @@ public class HeatValidator implements Validator { mdcDataDebugMessage.debugExitMessage("file", fileName); } - private static void validateReferenceParams(String fileName, String resourceName, Set parametersNamesFromFile, Set referencedParametersNames, @@ -166,7 +260,8 @@ public class HeatValidator implements Validator { if (!isHeatPseudoParameter(parameterName) && !parametersNamesFromFile.contains(parameterName)) { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.REFERENCED_PARAMETER_NOT_FOUND.getErrorMessage(), + .getErrorWithParameters(ERROR_CODE_HOT_1,Messages. + REFERENCED_PARAMETER_NOT_FOUND.getErrorMessage(), parameterName, resourceName), LoggerTragetServiceName.VALIDATE_PARAMETER_REFERENCE_EXITENCE, LoggerErrorDescription.PARAMETER_NOT_FOUND); @@ -192,13 +287,87 @@ public class HeatValidator implements Validator { outputMap = heatOrchestrationTemplate.getOutputs(); if (MapUtils.isNotEmpty(outputMap)) { - HeatValidationService.loopOverOutputMapAndValidateGetAttrFromNested(fileName, outputMap, + loopOverOutputMapAndValidateGetAttrFromNested(fileName, outputMap, heatOrchestrationTemplate, globalContext); } mdcDataDebugMessage.debugExitMessage("file", fileName); } + private static void loopOverOutputMapAndValidateGetAttrFromNested(String fileName, + Map outputMap, + HeatOrchestrationTemplate + heatOrchestrationTemplate, + GlobalValidationContext + globalContext) { + for (Output output : outputMap.values()) { + Object outputValue = output.getValue(); + if (outputValue != null && outputValue instanceof Map) { + Map outputValueMap = (Map) outputValue; + List getAttrValue = + (List) outputValueMap.get( + ResourceReferenceFunctions.GET_ATTR.getFunction()); + if (!CollectionUtils.isEmpty(getAttrValue)) { + String resourceName = getAttrValue.get(0); + Object attNameObject = getAttrValue.get(1); + if (!(attNameObject instanceof String)) { + return; + } + String attName = getAttrValue.get(1); + String resourceType = + getResourceTypeFromResourcesMap(resourceName, heatOrchestrationTemplate); + + if (Objects.nonNull(resourceType) + && HeatValidationService.isNestedResource(resourceType)) { + handleGetAttrNestedResource(fileName, globalContext, resourceName, attName, + resourceType); + } + } + } + } + } + + private static void handleGetAttrNestedResource(String fileName, + GlobalValidationContext globalContext, + String resourceName, String attName, + String resourceType) { + Map nestedOutputMap; + HeatOrchestrationTemplate nestedHeatOrchestrationTemplate; + try { + Optional fileContent = globalContext.getFileContent(resourceType); + if (fileContent.isPresent()) { + nestedHeatOrchestrationTemplate = + new YamlUtil().yamlToObject(fileContent.get(), HeatOrchestrationTemplate.class); + } else { + MdcDataErrorMessage + .createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, + LoggerTragetServiceName.VALIDATE_GET_ATTR_FROM_NESTED, + ErrorLevel.ERROR.name(), LoggerErrorCode.DATA_ERROR.getErrorCode(), + LoggerErrorDescription.EMPTY_FILE); + throw new Exception("The file '" + resourceType + "' has no content"); + } + } catch (Exception exception) { + logger.debug("",exception); + return; + } + nestedOutputMap = nestedHeatOrchestrationTemplate.getOutputs(); + + if (MapUtils.isEmpty(nestedOutputMap) || !nestedOutputMap.containsKey(attName)) { + globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder + .getErrorWithParameters(ERROR_CODE_HOT_17,Messages. + GET_ATTR_NOT_FOUND.getErrorMessage(), + attName, resourceName), + LoggerTragetServiceName.VALIDATE_GET_ATTR_FROM_NESTED, + LoggerErrorDescription.GET_ATTR_NOT_FOUND); + } + } + + private static String getResourceTypeFromResourcesMap(String resourceName, + HeatOrchestrationTemplate + heatOrchestrationTemplate) { + return heatOrchestrationTemplate.getResources().get(resourceName).getType(); + } + /* validation 17 + */ private static void validateEnvFile(String fileName, String envFileName, HeatOrchestrationTemplate heatOrchestrationTemplate, @@ -211,7 +380,7 @@ public class HeatValidator implements Validator { if (!envFileName.contains(".env")) { globalContext.addMessage(envFileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages + .getErrorWithParameters(ERROR_CODE_HOT_2,Messages .WRONG_ENV_FILE_EXTENSION.getErrorMessage(), envFileName), LoggerTragetServiceName.VALIDATE_ENV_FILE, LoggerErrorDescription.WRONG_FILE_EXTENSION); } @@ -247,7 +416,8 @@ public class HeatValidator implements Validator { if (parametersNames != null && !parametersNames.contains(envParameter)) { globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder .getErrorWithParameters( - Messages.ENV_INCLUDES_PARAMETER_NOT_IN_HEAT.getErrorMessage(), envFile, + ERROR_CODE_HOT_3,Messages. + ENV_INCLUDES_PARAMETER_NOT_IN_HEAT.getErrorMessage(), envFile, envParameter), LoggerTragetServiceName.VALIDATE_ENV_FILE, LoggerErrorDescription.ENV_PARAMETER_NOT_IN_HEAT); } @@ -255,7 +425,7 @@ public class HeatValidator implements Validator { } else { for (Map.Entry envEntry : envContent.getParameters().entrySet()) { globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages + .getErrorWithParameters(ERROR_CODE_HOT_3,Messages .ENV_INCLUDES_PARAMETER_NOT_IN_HEAT.getErrorMessage(), envFile, envEntry.getKey()), LoggerTragetServiceName.VALIDATE_ENV_FILE, LoggerErrorDescription.ENV_PARAMETER_NOT_IN_HEAT); @@ -289,7 +459,8 @@ public class HeatValidator implements Validator { if (!isValueMatchDefault) { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder .getErrorWithParameters( - Messages.PARAMETER_DEFAULT_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(), + ERROR_CODE_HOT_4,Messages. + PARAMETER_DEFAULT_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(), parameterEntry.getKey(), parameterType), LoggerTragetServiceName.VALIDATE_PARAMTER_DEFAULT_MATCH_TYPE, LoggerErrorDescription.PARAMETER_DEFAULT_VALUE_NOT_ALIGNED_WITH_TYPE); @@ -324,7 +495,8 @@ public class HeatValidator implements Validator { .isValueIsFromGivenType(parameterEnvValue, parameterType)) { globalContext.addMessage(envFile, ErrorLevel.ERROR, ErrorMessagesFormatBuilder .getErrorWithParameters( - Messages.PARAMETER_ENV_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(), + ERROR_CODE_HOT_5,Messages. + PARAMETER_ENV_VALUE_NOT_ALIGN_WITH_TYPE.getErrorMessage(), parameterName), LoggerTragetServiceName.VALIDATE_ENV_PARAMETER_MATCH_TYPE, LoggerErrorDescription.PARAMETER_DEFAULT_VALUE_NOT_ALIGNED_WITH_TYPE); } @@ -374,7 +546,9 @@ public class HeatValidator implements Validator { .filter(fileName -> isManifestArtifact(manifestArtifacts, fileName) && isNotArtifact(artifacts, fileName)) .forEach(fileName -> globalContext.addMessage(fileName, ErrorLevel.WARNING, - Messages.ARTIFACT_FILE_NOT_REFERENCED.getErrorMessage(), + ErrorMessagesFormatBuilder + .getErrorWithParameters(ERROR_CODE_HOT_11, + Messages.ARTIFACT_FILE_NOT_REFERENCED.getErrorMessage()), LoggerTragetServiceName.CHECK_FOR_ORPHAN_ARTIFACTS, LoggerErrorDescription.ARTIFACT_NOT_REFERENCED)); @@ -393,14 +567,16 @@ public class HeatValidator implements Validator { private void validate(String fileName, String envFileName, String baseFileName, Set artifacts, Set securityGroupsNamesFromBaseFileOutputs, GlobalValidationContext globalContext) { + globalContext.setMessageCode(ERROR_CODE_HOT_12); HeatOrchestrationTemplate - heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext); + heatOrchestrationTemplate = ValidationUtil.checkHeatOrchestrationPreCondition( + fileName, globalContext); if (heatOrchestrationTemplate != null) { if (!(fileName.contains(".yaml") || fileName.contains(".yml"))) { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages + .getErrorWithParameters(ERROR_CODE_HOT_6,Messages .WRONG_HEAT_FILE_EXTENSION.getErrorMessage(), fileName), LoggerTragetServiceName.CHECK_FOR_VALID_FILE_EXTENTION, LoggerErrorDescription.WRONG_FILE_EXTENSION); @@ -432,7 +608,8 @@ public class HeatValidator implements Validator { Set resourcesNames = resourcesMap.keySet(); resourcesMap.entrySet().stream() - .forEach(entry -> checkResourceDependsOn(fileName, entry.getValue(), resourcesNames, globalContext)); + .forEach(entry -> checkResourceDependsOn(fileName, entry.getValue(), + resourcesNames, globalContext)); } @SuppressWarnings("unchecked") @@ -450,13 +627,15 @@ public class HeatValidator implements Validator { .filter(resource_id -> !resourcesNames.contains(resource_id)) .forEach(resource_id -> globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(), + .getErrorWithParameters(ERROR_CODE_HOT_7,Messages. + MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(), (String) resource_id), LoggerTragetServiceName.CHECK_RESOURCE_DEPENDS_ON, LoggerErrorDescription.MISSING_RESOURCE_DEPENDS_ON)); } else if (dependencies instanceof String) { if (!resourcesNames.contains(dependencies)) { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(), + .getErrorWithParameters(ERROR_CODE_HOT_8,Messages. + MISSING_RESOURCE_IN_DEPENDS_ON.getErrorMessage(), (String) dependencies), LoggerTragetServiceName.CHECK_RESOURCE_DEPENDS_ON, LoggerErrorDescription.MISSING_RESOURCE_DEPENDS_ON); } @@ -475,14 +654,16 @@ public class HeatValidator implements Validator { if (heatOrchestrationTemplate.getHeat_template_version() == null) { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage(), + .getErrorWithParameters(ERROR_CODE_HOT_9,Messages. + INVALID_HEAT_FORMAT_REASON.getErrorMessage(), "missing template version"), LoggerTragetServiceName.VALIDATE_HEAT_FORMAT, LoggerErrorDescription.INVALID_HEAT_FORMAT); } if (heatOrchestrationTemplate.getResources() == null || heatOrchestrationTemplate.getResources().size() == 0) { globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder - .getErrorWithParameters(Messages.INVALID_HEAT_FORMAT_REASON.getErrorMessage(), + .getErrorWithParameters(ERROR_CODE_HOT_10,Messages. + INVALID_HEAT_FORMAT_REASON.getErrorMessage(), "The heat file does not contain any resources"), LoggerTragetServiceName.VALIDATE_HEAT_FORMAT, LoggerErrorDescription.INVALID_HEAT_FORMAT); } diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/HeatValidatorTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/HeatValidatorTest.java index 471ed7df10..a523627081 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/HeatValidatorTest.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/HeatValidatorTest.java @@ -34,12 +34,13 @@ import java.util.Map; public class HeatValidatorTest { + private static final String RESOURCE_PATH = "/org/openecomp/validation/validators/heat_validator"; private Validator validator = new HeatValidator(); @Test public void testInvalidHeatFormat() { Map messages = ValidationTestUtil.testValidator(validator, - "/org/openecomp/validation/validators/heat_validator/invalid_heat_format/negative_test/input"); + RESOURCE_PATH + "/invalid_heat_format/negative_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); @@ -47,21 +48,19 @@ public class HeatValidatorTest { Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1); Assert.assertEquals( messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), - "ERROR: Invalid HEAT format problem - [Cannot create property=kuku for JavaBean=Resource{type='null', properties=null, metadata=null, depends_on=null, update_policy='null', deletion_policy='null'}\n" + - " in 'reader', line 25, column 5:\n" + - " kuku: kuku\n" + - " ^\n" + - "Unable to find property 'kuku' on class: org.openecomp.sdc.heat.datatypes.model.Resource\n" + - " in 'reader', line 25, column 11:\n" + - " kuku: kuku\n" + - " ^\n" + - "]"); + "ERROR: [HOT12]: Invalid HEAT format problem - [Cannot create property=kuku for " + + "JavaBean=Resource{type='null', properties=null, metadata=null, depends_on=null, " + + "update_policy='null', deletion_policy='null'}\n" + " in 'reader', line 25, column 5:\n" + + " kuku: kuku\n" + " ^\n" + + "Unable to find property 'kuku' on class: org.openecomp.sdc.heat.datatypes.model." + + "Resource\n" + " in 'reader', line 25, column 11:\n" + " kuku: kuku\n" + + " ^\n" + "]"); } @Test public void testDependsOn() { Map messages = ValidationTestUtil.testValidator(validator, - "/org/openecomp/validation/validators/heat_validator/depends_on_points_to_existing_resource/input"); + RESOURCE_PATH + "/depends_on_points_to_existing_resource/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); @@ -69,17 +68,17 @@ public class HeatValidatorTest { Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2); Assert.assertEquals( messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), - "ERROR: a Missing resource in depend On, Missing Resource ID [resource_not_exist]"); + "ERROR: [HOT8]: a Missing resource in depend On, Missing Resource ID [resource_not_exist]"); Assert.assertEquals( messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), - "ERROR: a Missing resource in depend On, Missing Resource ID [resource_3]"); + "ERROR: [HOT7]: a Missing resource in depend On, Missing Resource ID [resource_3]"); } @Test public void testResourcesReferencesExistInHeat() throws IOException { Map messages = ValidationTestUtil.testValidator(new HeatValidator(), - "/org/openecomp/validation/validators/heat_validator/resource_references_exist_in_heat/negative_test/input"); + RESOURCE_PATH + "/resource_references_exist_in_heat/negative_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); @@ -87,17 +86,18 @@ public class HeatValidatorTest { Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 2); Assert.assertEquals( messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), - "ERROR: Referenced resource - not_existing_resource not found"); + "ERROR: [HOT16]: Referenced resource - not_existing_resource not found"); Assert.assertEquals( messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), - "ERROR: invalid get_resource syntax is in use - null , get_resource function should get the resource id of the referenced resource"); + "ERROR: [HOT13]: invalid get_resource syntax is in use - null , get_resource " + + "function should get the resource id of the referenced resource"); } @Test public void testGetResourceValueIsValid() { Map messages = ValidationTestUtil.testValidator(new HeatValidator(), - "/org/openecomp/validation/validators/heat_validator/get_resource_value_valid/negative_test/input"); + RESOURCE_PATH + "/get_resource_value_valid/negative_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); @@ -105,27 +105,67 @@ public class HeatValidatorTest { Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 3); Assert.assertEquals( messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), - "ERROR: invalid get_resource syntax is in use - [param_1, param_2] , get_resource function should get the resource id of the referenced resource"); + "ERROR: [HOT13]: invalid get_resource syntax is in use - [param_1, param_2] , " + + "get_resource function should get the resource id of the referenced resource"); Assert.assertEquals( messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(1).getMessage(), - "ERROR: invalid get_resource syntax is in use - {get_param=param_1} , get_resource function should get the resource id of the referenced resource"); + "ERROR: [HOT13]: invalid get_resource syntax is in use - {get_param=param_1} , " + + "get_resource function should get the resource id of the referenced resource"); Assert.assertEquals( messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(2).getMessage(), - "ERROR: invalid get_resource syntax is in use - null , get_resource function should get the resource id of the referenced resource"); + "ERROR: [HOT13]: invalid get_resource syntax is in use - null , get_resource " + + "function should get the resource id of the referenced resource"); } @Test public void testTwoResourcesDoesNotHoldSameId() throws IOException { Map messages = ValidationTestUtil.testValidator(new HeatValidator(), - "/org/openecomp/validation/validators/heat_validator/two_resources_does_not_hold_same_id/positive_test/input"); + RESOURCE_PATH + "/two_resources_does_not_hold_same_id/positive_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 0); } + @Test + public void testWithWrongFileExtension(){ + Map messages = ValidationTestUtil.testValidator(new HeatValidator(), + RESOURCE_PATH + "/wrongFileExtension"); + Assert.assertNotNull(messages); + Assert.assertEquals(messages.get("single.aad").getErrorMessageList().get(0).getMessage(), + "ERROR: [HOT2]: Wrong ENV file extension - single.aad"); + Assert.assertEquals(messages.get("single.ya").getErrorMessageList().get(0).getMessage(), + "ERROR: [HOT6]: Wrong HEAT file extension - single.ya"); + } + + @Test + public void testWithMissingManifestContent(){ + Map messages = ValidationTestUtil.testValidator(new HeatValidator(), + RESOURCE_PATH + "/missingManifestContent"); + Assert.assertNotNull(messages); + Assert.assertEquals(messages.get("single.yaml").getErrorMessageList().get(0).getMessage(), + "ERROR: [HOT9]: Invalid HEAT format problem - [missing template version]"); + Assert.assertEquals(messages.get("single.yaml").getErrorMessageList().get(1).getMessage(), + "WARNING: [HOT10]: Invalid HEAT format problem - " + + "[The heat file does not contain any resources]"); + } + + @Test + public void testWithInvalidHeatContent(){ + Map messages = ValidationTestUtil.testValidator(new HeatValidator(), + RESOURCE_PATH + "/invalidHeatContent"); + Assert.assertNotNull(messages); + Assert.assertEquals(messages.get("single.yaml").getErrorMessageList().get(0).getMessage(), + "ERROR: [HOT9]: Invalid HEAT format problem - [missing template version]"); + Assert.assertEquals(messages.get("single.yaml").getErrorMessageList().get(1).getMessage(), + "WARNING: [HOT10]: Invalid HEAT format problem - " + + "[The heat file does not contain any resources]"); + Assert.assertEquals(messages.get("mount_iso_script.sh").getErrorMessageList().get(0). + getMessage(),"WARNING: [HOT11]: Artifact file is not referenced."); + } + @Test public void negativeTestGetParamPointToExistingParameter() throws IOException { Map messages = ValidationTestUtil.testValidator(new HeatValidator(), - "/org/openecomp/validation/validators/heat_validator/get_param_points_to_existing_parameter/negative_test/input"); + RESOURCE_PATH + "/get_param_points_to_existing_parameter/negative_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); @@ -133,13 +173,14 @@ public class HeatValidatorTest { Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1); Assert.assertEquals( messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), - "ERROR: Referenced parameter - not_existing_param_1 - not found, used in resource [server_pcrf_psm_001]"); + "ERROR: [HOT1]: Referenced parameter - not_existing_param_1 - not found, used in " + + "resource [server_pcrf_psm_001]"); } @Test public void testGetAttrFromNested() throws IOException { Map messages =ValidationTestUtil.testValidator(new HeatValidator(), - "/org/openecomp/validation/validators/heat_validator/get_attr_from_nested/negative_test/input"); + RESOURCE_PATH + "/get_attr_from_nested/negative_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); @@ -147,13 +188,14 @@ public class HeatValidatorTest { Assert.assertEquals(messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().size(), 1); Assert.assertEquals( messages.get("hot-nimbus-psm_v1.0.yaml").getErrorMessageList().get(0).getMessage(), - "ERROR: get_attr attribute not found, Attribute name [nested_output], Resource ID [server_pcrf_psm_001]"); + "ERROR: [HOT17]: get_attr attribute not found, Attribute name [nested_output], " + + "Resource ID [server_pcrf_psm_001]"); } @Test public void testDefaultValueAlignWithType() throws IOException { Map messages =ValidationTestUtil.testValidator(new HeatValidator(), - "/org/openecomp/validation/validators/heat_validator/default_value_align_with_type/negative_test/input"); + RESOURCE_PATH + "/default_value_align_with_type/negative_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); @@ -161,14 +203,15 @@ public class HeatValidatorTest { Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1); Assert.assertEquals( messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), - "ERROR: Parameter - pcrf_pps_image_name_1 default value not align with type number"); + "ERROR: [HOT4]: Parameter - pcrf_pps_image_name_1 default value not align with " + + "type number"); } @Test public void testEnvParametersMatchDefinedHeatParameterTypes() throws IOException { Map messages =ValidationTestUtil.testValidator(new HeatValidator(), - "/org/openecomp/validation/validators/heat_validator/env_parameters_match_defined_types/negative_test/input"); + RESOURCE_PATH + "/env_parameters_match_defined_types/negative_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); @@ -176,14 +219,14 @@ public class HeatValidatorTest { Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().size(), 1); Assert.assertEquals( messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().get(0).getMessage(), - "ERROR: Parameter env value pcrf_pps_flavor_name not align with type"); + "ERROR: [HOT5]: Parameter env value pcrf_pps_flavor_name not align with type"); } @Test public void testReferencedArtifactsExist() throws IOException { Map messages =ValidationTestUtil.testValidator(new HeatValidator(), - "/org/openecomp/validation/validators/heat_validator/referenced_artifacts_exist/negative_test/input"); + RESOURCE_PATH + "/referenced_artifacts_exist/negative_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); @@ -191,14 +234,14 @@ public class HeatValidatorTest { Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().size(), 1); Assert.assertEquals( messages.get("hot-nimbus-pps_v1.0.yaml").getErrorMessageList().get(0).getMessage(), - "ERROR: Missing artifact - nimbus-ethernet"); + "ERROR: [HOT15]: Missing artifact - nimbus-ethernet"); } @Test public void testEnvContentIsSubSetOfHeatParameters() throws IOException { Map messages =ValidationTestUtil.testValidator(validator, - "/org/openecomp/validation/validators/heat_validator/env_content_is_subset_of_heat/negative_test/input"); + RESOURCE_PATH + "/env_content_is_subset_of_heat/negative_test/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 1); @@ -206,13 +249,14 @@ public class HeatValidatorTest { Assert.assertEquals(messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().size(), 1); Assert.assertEquals( messages.get("hot-nimbus-pps_v1.0.env").getErrorMessageList().get(0).getMessage(), - "ERROR: Env file hot-nimbus-pps_v1.0.env includes a parameter not in HEAT - mock_param"); + "ERROR: [HOT3]: Env file hot-nimbus-pps_v1.0.env includes a parameter not in " + + "HEAT - mock_param"); } @Test public void testGetParamPseudoParameters() { Map messages =ValidationTestUtil.testValidator(new HeatValidator(), - "/org/openecomp/validation/validators/heat_validator/pseudo_parameters/input"); + RESOURCE_PATH + "/pseudo_parameters/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 0); @@ -221,7 +265,7 @@ public class HeatValidatorTest { @Test public void testNoErrorWhenEmptyValueForParameterInEnv() { Map messages = ValidationTestUtil.testValidator(validator, - "/org/openecomp/validation/validators/heat_validator/env_empty_value/input"); + RESOURCE_PATH + "/env_empty_value/input"); Assert.assertNotNull(messages); Assert.assertEquals(messages.size(), 0); diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/MANIFEST.json new file mode 100644 index 0000000000..3e995864c9 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/MANIFEST.json @@ -0,0 +1,21 @@ +{ + "name": "validTest", + "description": "Valid Test", + "version": "1610", + "data": [ + { + "file": "single.yaml", + "type": "HEAT", + "data": [ + { + "file": "single.env", + "type": "HEAT_ENV" + } + ] + }, + { + "file": "mount_iso_script.sh", + "type": "SHELL" + } + ] +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/mount_iso_script.sh b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/mount_iso_script.sh new file mode 100644 index 0000000000..e69de29bb2 diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/single.env b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/single.env new file mode 100644 index 0000000000..8ae6fc021a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/single.env @@ -0,0 +1,11 @@ +parameters: + pcrf_pps_server_names: ZRDM1PCRF01PPS001,ZRDM1PCRF01PPS002,ZRDM1PCRF01PPS003,ZRDM1PCRF01PPS004,ZRDM1PCRF01PPS005,ZRDM1PCRF01PPS006 + pcrf_pps_image_name_1: 14 + pcrf_pps_flavor_name: lc.3xlarge + availabilityzone_name: nova + pcrf_cps_net_name: Mobisupport-25193-I-INT1_int_pcrf_net_0 + pcrf_cps_net_ips: 172.26.16.7,172.26.16.8,172.26.16.9,172.26.16.10,172.26.16.11,172.26.16.12 + pcrf_cps_net_mask: 255.255.255.0 + pcrf_security_group_name: nimbus_security_group + pcrf_vnf_id: 730797234b4a40aa99335157b02871cd + diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/single.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/single.yaml new file mode 100644 index 0000000000..64151b1317 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/invalidHeatContent/single.yaml @@ -0,0 +1,53 @@ +heat_template_version: + +description: heat template that creates PCRF Policy Server stack + +parameters: + pcrf_pps_server_names: + type: comma_delimited_list + label: PCRF PS server names + description: PCRF PS server names + pcrf_pps_image_name_1: + type: number + default: True + label: PCRF PS image name + description: PCRF PS image name + pcrf_pps_image_name_2: + type: + default: True + label: PCRF PS image name + description: PCRF PS image name + pcrf_pps_image_name_3: + type: number + default: + label: PCRF PS image name + description: PCRF PS image name + pcrf_pps_flavor_name: + type: string + label: PCRF PS flavor name + description: flavor name of PCRF PS instance + availabilityzone_name: + type: string + label: availabilityzone name + description: availabilityzone name + pcrf_cps_net_name: + type: string + label: CPS network name + description: CPS network name + pcrf_cps_net_ips: + type: comma_delimited_list + label: CPS network ips + description: CPS network ips + pcrf_cps_net_mask: + type: string + label: CPS network mask + description: CPS network mask + pcrf_security_group_name: + type: string + label: security group name + description: the name of security group + pcrf_vnf_id: + type: string + label: PCRF VNF Id + description: PCRF VNF Id + diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/MANIFEST.json new file mode 100644 index 0000000000..943bef200d --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/MANIFEST.json @@ -0,0 +1,17 @@ +{ + "name": "validTest", + "description": "Valid Test", + "version": "1610", + "data": [ + { + "file": "single.yaml", + "type": "HEAT", + "data": [ + { + "file": "single.env", + "type": "HEAT_ENV" + } + ] + } + ] +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/single.env b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/single.env new file mode 100644 index 0000000000..8ae6fc021a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/single.env @@ -0,0 +1,11 @@ +parameters: + pcrf_pps_server_names: ZRDM1PCRF01PPS001,ZRDM1PCRF01PPS002,ZRDM1PCRF01PPS003,ZRDM1PCRF01PPS004,ZRDM1PCRF01PPS005,ZRDM1PCRF01PPS006 + pcrf_pps_image_name_1: 14 + pcrf_pps_flavor_name: lc.3xlarge + availabilityzone_name: nova + pcrf_cps_net_name: Mobisupport-25193-I-INT1_int_pcrf_net_0 + pcrf_cps_net_ips: 172.26.16.7,172.26.16.8,172.26.16.9,172.26.16.10,172.26.16.11,172.26.16.12 + pcrf_cps_net_mask: 255.255.255.0 + pcrf_security_group_name: nimbus_security_group + pcrf_vnf_id: 730797234b4a40aa99335157b02871cd + diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/single.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/single.yaml new file mode 100644 index 0000000000..1a35c29ba3 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/missingManifestContent/single.yaml @@ -0,0 +1,52 @@ +heat_template_version: + +description: heat template that creates PCRF Policy Server stack + +parameters: + pcrf_pps_server_names: + type: comma_delimited_list + label: PCRF PS server names + description: PCRF PS server names + pcrf_pps_image_name_1: + type: number + default: True + label: PCRF PS image name + description: PCRF PS image name + pcrf_pps_image_name_2: + type: + default: True + label: PCRF PS image name + description: PCRF PS image name + pcrf_pps_image_name_3: + type: number + default: + label: PCRF PS image name + description: PCRF PS image name + pcrf_pps_flavor_name: + type: string + label: PCRF PS flavor name + description: flavor name of PCRF PS instance + availabilityzone_name: + type: string + label: availabilityzone name + description: availabilityzone name + pcrf_cps_net_name: + type: string + label: CPS network name + description: CPS network name + pcrf_cps_net_ips: + type: comma_delimited_list + label: CPS network ips + description: CPS network ips + pcrf_cps_net_mask: + type: string + label: CPS network mask + description: CPS network mask + pcrf_security_group_name: + type: string + label: security group name + description: the name of security group + pcrf_vnf_id: + type: string + label: PCRF VNF Id + description: PCRF VNF Id diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/MANIFEST.json new file mode 100644 index 0000000000..b722f1ac76 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/MANIFEST.json @@ -0,0 +1,17 @@ +{ + "name": "validTest", + "description": "Valid Test", + "version": "1610", + "data": [ + { + "file": "single.ya", + "type": "HEAT", + "data": [ + { + "file": "single.aad", + "type": "HEAT_ENV" + } + ] + } + ] +} \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/single.aad b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/single.aad new file mode 100644 index 0000000000..8ae6fc021a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/single.aad @@ -0,0 +1,11 @@ +parameters: + pcrf_pps_server_names: ZRDM1PCRF01PPS001,ZRDM1PCRF01PPS002,ZRDM1PCRF01PPS003,ZRDM1PCRF01PPS004,ZRDM1PCRF01PPS005,ZRDM1PCRF01PPS006 + pcrf_pps_image_name_1: 14 + pcrf_pps_flavor_name: lc.3xlarge + availabilityzone_name: nova + pcrf_cps_net_name: Mobisupport-25193-I-INT1_int_pcrf_net_0 + pcrf_cps_net_ips: 172.26.16.7,172.26.16.8,172.26.16.9,172.26.16.10,172.26.16.11,172.26.16.12 + pcrf_cps_net_mask: 255.255.255.0 + pcrf_security_group_name: nimbus_security_group + pcrf_vnf_id: 730797234b4a40aa99335157b02871cd + diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/single.ya b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/single.ya new file mode 100644 index 0000000000..555f6ae852 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/heat_validator/wrongFileExtension/single.ya @@ -0,0 +1,60 @@ +heat_template_version: 2013-05-23 + +description: heat template that creates PCRF Policy Server stack + +parameters: + pcrf_pps_server_names: + type: comma_delimited_list + label: PCRF PS server names + description: PCRF PS server names + pcrf_pps_image_name_1: + type: number + default: True + label: PCRF PS image name + description: PCRF PS image name + pcrf_pps_image_name_2: + type: + default: True + label: PCRF PS image name + description: PCRF PS image name + pcrf_pps_image_name_3: + type: number + default: + label: PCRF PS image name + description: PCRF PS image name + pcrf_pps_flavor_name: + type: string + label: PCRF PS flavor name + description: flavor name of PCRF PS instance + availabilityzone_name: + type: string + label: availabilityzone name + description: availabilityzone name + pcrf_cps_net_name: + type: string + label: CPS network name + description: CPS network name + pcrf_cps_net_ips: + type: comma_delimited_list + label: CPS network ips + description: CPS network ips + pcrf_cps_net_mask: + type: string + label: CPS network mask + description: CPS network mask + pcrf_security_group_name: + type: string + label: security group name + description: the name of security group + pcrf_vnf_id: + type: string + label: PCRF VNF Id + description: PCRF VNF Id + +resources: + server_pcrf_pps_001: + type: OS::Heat::CloudConfig + properties: + pcrf_pps_server_name: { get_param: [pcrf_pps_server_names, 0] } + + -- cgit 1.2.3-korg