package org.openecomp.sdc.validation.impl.validators.namingconvention;
import org.apache.commons.collections4.MapUtils;
+import org.openecomp.core.validation.ErrorMessageCode;
import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
import org.openecomp.core.validation.types.GlobalValidationContext;
import org.openecomp.sdc.common.errors.Messages;
*/
public class NeutronPortNamingConventionValidator implements ResourceValidator {
private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
+ private static final ErrorMessageCode ERROR_CODE_NNP1 = new ErrorMessageCode("NNP1");
+ private static final ErrorMessageCode ERROR_CODE_NNP2 = new ErrorMessageCode("NNP2");
+ private static final ErrorMessageCode ERROR_CODE_NNP3 = new ErrorMessageCode("NNP3");
@Override
public void validate(String fileName, Map.Entry<String, Resource> resourceEntry,
GlobalValidationContext globalContext, ValidationContext validationContext) {
NamingConventionValidationContext namingConventionValidationContext =
- (NamingConventionValidationContext)validationContext;
+ (NamingConventionValidationContext)validationContext;
validatePortNetworkNamingConvention(fileName, namingConventionValidationContext.getHeatOrchestrationTemplate(), globalContext);
validateFixedIpsNamingConvention(fileName, namingConventionValidationContext.getHeatOrchestrationTemplate(), globalContext);
}
String[] regexList = new String[]{".*_net_id", ".*_net_name", ".*_net_fqdn"};
heatOrchestrationTemplate
- .getResources()
- .entrySet()
- .stream()
- .filter(entry -> entry.getValue().getType()
- .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource()))
- .forEach(entry -> entry.getValue()
- .getProperties()
+ .getResources()
.entrySet()
.stream()
- .filter(propertyEntry ->
- propertyEntry.getKey().toLowerCase().equals("network".toLowerCase())
- || propertyEntry.getKey().equals("network_id"))
- .forEach(propertyEntry -> validateParamNamingConvention(fileName, entry.getKey(),
- propertyEntry.getValue(), "Port", "Network", regexList,
- Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES, globalContext)));
+ .filter(entry -> entry.getValue().getType()
+ .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource()))
+ .forEach(entry -> entry.getValue()
+ .getProperties()
+ .entrySet()
+ .stream()
+ .filter(propertyEntry ->
+ propertyEntry.getKey().toLowerCase().equals("network".toLowerCase())
+ || propertyEntry.getKey().equals("network_id"))
+ .forEach(propertyEntry -> validateParamNamingConvention(fileName, entry.getKey(),
+ propertyEntry.getValue(), "Port", "Network", regexList,
+ Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES, globalContext)));
mdcDataDebugMessage.debugExitMessage("file", fileName);
}
}
heatOrchestrationTemplate.getResources()
- .entrySet()
- .stream()
- .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType()) != null)
- .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType())
- .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE))
- .forEach(entry -> checkNeutronPortFixedIpsName(fileName, entry, globalContext));
+ .entrySet()
+ .stream()
+ .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType()) != null)
+ .filter(entry -> HeatResourcesTypes.findByHeatResource(entry.getValue().getType())
+ .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE))
+ .forEach(entry -> checkNeutronPortFixedIpsName(fileName, entry, globalContext));
mdcDataDebugMessage.debugExitMessage("file", fileName);
}
Map.Entry<String, Resource> resourceEntry,
GlobalValidationContext globalContext) {
String[] regexList =
- new String[]{"[^_]+_[^_]+_ips", "[^_]+_[^_]+_v6_ips", "[^_]+_[^_]+_ip_(\\d+)",
- "[^_]+_[^_]+_v6_ip_(\\d+)"};
+ new String[]{"[^_]+_[^_]+_ips", "[^_]+_[^_]+_v6_ips", "[^_]+_[^_]+_ip_(\\d+)",
+ "[^_]+_[^_]+_v6_ip_(\\d+)"};
if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
return;
List<Object> fixedIpsList = (List<Object>) fixedIps;
for (Object fixedIpsObject : fixedIpsList) {
Map.Entry<String, Object> fixedIpsEntry =
- ((Map<String, Object>) fixedIpsObject).entrySet().iterator().next();
+ ((Map<String, Object>) fixedIpsObject).entrySet().iterator().next();
if (nonNull(fixedIpsEntry)) {
if (fixedIpsEntry.getValue() instanceof Map) {
String fixedIpsName = ValidationUtil.getWantedNameFromPropertyValueGetParam
- (fixedIpsEntry
- .getValue());
+ (fixedIpsEntry
+ .getValue());
if (nonNull(fixedIpsName)) {
if (!ValidationUtil.evalPattern(fixedIpsName, regexList)) {
globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters(
- Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
- "Port", "Fixed_IPS", fixedIpsName, resourceEntry.getKey()),
- LoggerTragetServiceName.VALIDATE_FIXED_IPS_NAME,
- LoggerErrorDescription.NAME_NOT_ALIGNED_WITH_GUIDELINES);
+ fileName,
+ ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters(
+ ERROR_CODE_NNP1,
+ Messages.PARAMETER_NAME_NOT_ALIGNED_WITH_GUIDELINES.getErrorMessage(),
+ "Port", "Fixed_IPS", fixedIpsName, resourceEntry.getKey()),
+ LoggerTragetServiceName.VALIDATE_FIXED_IPS_NAME,
+ LoggerErrorDescription.NAME_NOT_ALIGNED_WITH_GUIDELINES);
}
}
} else {
globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.MISSING_GET_PARAM.getErrorMessage(),
- "fixed_ips", resourceEntry.getKey()),
- LoggerTragetServiceName.VALIDATE_FIXED_IPS_NAME,
- LoggerErrorDescription.MISSING_GET_PARAM);
+ fileName,
+ ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(
+ ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(),
+ "fixed_ips", resourceEntry.getKey()),
+ LoggerTragetServiceName.VALIDATE_FIXED_IPS_NAME,
+ LoggerErrorDescription.MISSING_GET_PARAM);
}
}
}
if (paramName instanceof String) {
if (!ValidationUtil.evalPattern((String) paramName, regexList)) {
globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING, ErrorMessagesFormatBuilder
- .getErrorWithParameters(message.getErrorMessage(), resourceType,
- wrongPropertyFormat, (String) paramName, resourceId),
- LoggerTragetServiceName.VALIDATE_PORT_NETWORK_NAME,
- LoggerErrorDescription.NAME_NOT_ALIGNED_WITH_GUIDELINES);
+ fileName,
+ ErrorLevel.WARNING, ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_NNP3, message.getErrorMessage(), resourceType,
+ wrongPropertyFormat, (String) paramName, resourceId),
+ LoggerTragetServiceName.VALIDATE_PORT_NETWORK_NAME,
+ LoggerErrorDescription.NAME_NOT_ALIGNED_WITH_GUIDELINES);
}
}
} else {
globalContext.addMessage(
- fileName,
- ErrorLevel.WARNING,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(Messages.MISSING_GET_PARAM.getErrorMessage(),
- "network or network_id", resourceId),
- LoggerTragetServiceName.VALIDATE_PORT_NETWORK_NAME,
- LoggerErrorDescription.MISSING_GET_PARAM);
+ fileName,
+ ErrorLevel.WARNING,
+ ErrorMessagesFormatBuilder
+ .getErrorWithParameters(
+ ERROR_CODE_NNP2, Messages.MISSING_GET_PARAM.getErrorMessage(),
+ "network or network_id", resourceId),
+ LoggerTragetServiceName.VALIDATE_PORT_NETWORK_NAME,
+ LoggerErrorDescription.MISSING_GET_PARAM);
}
mdcDataDebugMessage.debugExitMessage("file", fileName);
NamingConventionGuideLineValidator baseValidator = new NamingConventionGuideLineValidator();
NeutronPortNamingConventionValidator resourceValidator = new
NeutronPortNamingConventionValidator();
-
+ private static final String PATH = "/org/openecomp/validation/validators/guideLineValidator/heatPortNetworkNamingConvention/";
@Test
public void testHeatPortNetworkNamingConvention() {
Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
- "/org/openecomp/validation/validators/guideLineValidator/heatPortNetworkNamingConvention/positive/");
+ resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
+ PATH + "positive/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
- "/org/openecomp/validation/validators/guideLineValidator/heatPortNetworkNamingConvention/negative/");
+ resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
+ PATH + "negative/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 3);
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
- "WARNING: Port 'Network' Parameter Name not aligned with Guidelines, Parameter Name [not_valid_network_name], Resource ID [port_resource]. As a result, VF/VFC Profile may miss this information");
+ "WARNING: [NNP3]: Port 'Network' Parameter Name not aligned with Guidelines, Parameter Name [not_valid_network_name], Resource ID [port_resource]. As a result, VF/VFC Profile may miss this information");
}
@Test
public void testNeutronFixedIpName() {
Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
- "/org/openecomp/validation/validators/guideLineValidator/heatPortFixedIpNamingConvention/positive");
+ resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
+ PATH + "positiveFixedIP");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 0);
messages = ValidationTestUtil.testValidator(baseValidator,
- resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
- "/org/openecomp/validation/validators/guideLineValidator/heatPortFixedIpNamingConvention/negative/");
+ resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
+ PATH + "negativeFixedIP/");
Assert.assertNotNull(messages);
Assert.assertEquals(messages.size(), 1);
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 4);
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
- "WARNING: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [pcrf_net_v6_ip_a], Resource ID [port_resource_0]. As a result, VF/VFC Profile may miss this information");
+ "WARNING: [NNP1]: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [pcrf_net_v6_ip_a], Resource ID [port_resource_0]. As a result, VF/VFC Profile may miss this information");
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(1).getMessage(),
- "WARNING: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [indx], Resource ID [port_resource_1]. As a result, VF/VFC Profile may miss this information");
+ "WARNING: [NNP1]: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [indx], Resource ID [port_resource_1]. As a result, VF/VFC Profile may miss this information");
+
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(2).getMessage(),
- "WARNING: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [pcrf_net_ipz], Resource ID [port_resource_2]. As a result, VF/VFC Profile may miss this information");
+ "WARNING: [NNP1]: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [pcrf_net_ipz], Resource ID [port_resource_2]. As a result, VF/VFC Profile may miss this information");
+
Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(3).getMessage(),
- "WARNING: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [pcrf_net_v0_ip_3], Resource ID [port_resource_2]. As a result, VF/VFC Profile may miss this information");
+ "WARNING: [NNP1]: Port 'Fixed_IPS' Parameter Name not aligned with Guidelines, Parameter Name [pcrf_net_v0_ip_3], Resource ID [port_resource_2]. As a result, VF/VFC Profile may miss this information");
+ }
+
+ @Test
+ public void testMissingParam() {
+ Map<String, MessageContainer> messages = ValidationTestUtil.testValidator(baseValidator,
+ resourceValidator, HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(),
+ PATH + "missingparam/");
+ Assert.assertNotNull(messages);
+ Assert.assertEquals(messages.size(), 1);
+ Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().size(), 1);
+ Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(),
+ "WARNING: [NNP2]: Missing get_param in network or network_id, Resource Id [port_resource_2]");
}
}