From 2a74ec311f9fc3b430a3d768195156c7b20c5e93 Mon Sep 17 00:00:00 2001 From: "k.kazak" Date: Mon, 10 Jun 2019 09:21:44 +0200 Subject: fix sonar null pointer NoveServerNamingConventionGuideLineValidator: potential null pointer fixed Test for this use-case added Change-Id: I3180bc6c159d1b690f0be0370abbd1fefe70045f Issue-ID: SO-1811 Signed-off-by: k.kazak --- ...vaServerNamingConventionGuideLineValidator.java | 8 ++++-- ...rverNamingConventionGuideLineValidatorTest.java | 14 +++++++++- .../negativeEmptyProperties/MANIFEST.json | 14 ++++++++++ .../negativeEmptyProperties/first.yaml | 30 ++++++++++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerImageAndFlavor/negativeEmptyProperties/MANIFEST.json create mode 100644 openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerImageAndFlavor/negativeEmptyProperties/first.yaml (limited to 'openecomp-be/lib') diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidator.java index b2c25c2d5f..4f640dff29 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidator.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidator.java @@ -154,6 +154,9 @@ public class NovaServerNamingConventionGuideLineValidator implements ResourceVal Map uniqueResourcePortNetworkRole, HeatOrchestrationTemplate heatOrchestrationTemplate, GlobalValidationContext globalValidationContext) { + if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources().get(resourceId).getProperties())) { + return; + } Object propertyNetworkValue = heatOrchestrationTemplate.getResources().get(resourceId).getProperties().get("networks"); if (propertyNetworkValue != null && propertyNetworkValue instanceof List) { @@ -320,15 +323,16 @@ public class NovaServerNamingConventionGuideLineValidator implements ResourceVal private Map validateImageAndFlavorFromNovaServer(String fileName, Map.Entry resourceEntry, GlobalValidationContext globalContext) { + Map imageAndFlavorLegalNames = new HashMap<>(); + if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) { - return null; + return imageAndFlavorLegalNames; } Pair imagePair = new ImmutablePair<>("image", ".*_image_name"); Pair flavorPair = new ImmutablePair<>("flavor", ".*_flavor_name"); List> imageFlavorPairs = Arrays.asList(imagePair, flavorPair); Map propertiesMap = resourceEntry.getValue().getProperties(); - Map imageAndFlavorLegalNames = new HashMap<>(); for (Pair imageOrFlavor : imageFlavorPairs) { boolean isErrorInImageOrFlavor = diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidatorTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidatorTest.java index 26aad3cdf8..759b376b97 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidatorTest.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidatorTest.java @@ -73,8 +73,20 @@ public class NovaServerNamingConventionGuideLineValidatorTest { } @Test - public void testNovaImageAndFlavorNames() { + public void testNovaImageAndFlavorNamesEmptyProperties() { Map messages = ValidationTestUtil.testValidator(baseValidator, + resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(), + PATH + "heatNovaServerImageAndFlavor/negativeEmptyProperties"); + Assert.assertNotNull(messages); + Assert.assertEquals(1, messages.size()); + Assert.assertEquals(1, messages.get("first.yaml").getErrorMessageList().size()); + Assert.assertEquals(messages.get("first.yaml").getErrorMessageList().get(0).getMessage(), + "WARNING: [NNS13]: Server 'image' Parameter Name not aligned with Guidelines, Parameter Name [fsb2-image], Resource ID [FSB3]. As a result, VF/VFC Profile may miss this information"); + } + + @Test + public void testNovaImageAndFlavorNames() { + Map messages = ValidationTestUtil.testValidator(baseValidator, resourceValidator, HeatResourcesTypes.NOVA_SERVER_RESOURCE_TYPE.getHeatResource(), PATH + "heatNovaServerImageAndFlavor/positive"); Assert.assertNotNull(messages); diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerImageAndFlavor/negativeEmptyProperties/MANIFEST.json b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerImageAndFlavor/negativeEmptyProperties/MANIFEST.json new file mode 100644 index 0000000000..d4525527bd --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerImageAndFlavor/negativeEmptyProperties/MANIFEST.json @@ -0,0 +1,14 @@ +{ + "name": "validTest", + "description": "Valid Test", + "version": "1610", + "data": [ + { + "file": "first.yaml", + "type": "HEAT", + "isBase": true, + "data": [ + ] + } + ] +} diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerImageAndFlavor/negativeEmptyProperties/first.yaml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerImageAndFlavor/negativeEmptyProperties/first.yaml new file mode 100644 index 0000000000..19731db73d --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/resources/org/openecomp/validation/validators/guideLineValidator/novaserverValidation/heatNovaServerImageAndFlavor/negativeEmptyProperties/first.yaml @@ -0,0 +1,30 @@ +heat_template_version: 2013-05-23 + +description: heat expose volume resource + +resources: + FSB2: + type: OS::Nova::Server + properties: + + FSB3: + type: OS::Nova::Server + properties: + name: { get_param: fsb2_name_2 } + block_device_mapping: [{device_name: "vda", volume_id : {get_param: VMME_FSB2_boot_volume }, delete_on_termination: "false" }] + image: { get_param: fsb2-image } + availability_zone: { get_param: availability_zone_0 } + metadata: + VNF_id: { get_param: vnfvfVF_id } + vf_module_id: { get_param: vf_module_id } + networks: + - port: { get_resource: FSB2_Internal1 } + - port: { get_resource: FSB2_Internal2 } + - port: { get_resource: FSB2_OAM } + +outputs: + expose_resource_nove_output: + description: the pcrf_server + value: { get_resource: FSB2 } + + -- cgit 1.2.3-korg