fix sonar null pointer 27/89627/2
authork.kazak <k.kazak@samsung.com>
Mon, 10 Jun 2019 07:21:44 +0000 (09:21 +0200)
committerOfir Sonsino <ofir.sonsino@intl.att.com>
Wed, 19 Jun 2019 07:13:33 +0000 (07:13 +0000)
NoveServerNamingConventionGuideLineValidator: potential null pointer fixed
Test for this use-case added

Change-Id: I3180bc6c159d1b690f0be0370abbd1fefe70045f
Issue-ID: SO-1811
Signed-off-by: k.kazak <k.kazak@samsung.com>
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidator.java
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidatorTest.java
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 with mode: 0644]
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 with mode: 0644]

index b2c25c2..4f640df 100644 (file)
@@ -154,6 +154,9 @@ public class NovaServerNamingConventionGuideLineValidator implements ResourceVal
                                                            Map<String, String> 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<String, String> validateImageAndFlavorFromNovaServer(String fileName,
                                                                    Map.Entry<String, Resource> resourceEntry,
                                                                    GlobalValidationContext globalContext) {
+      Map<String, String> imageAndFlavorLegalNames = new HashMap<>();
+
     if (MapUtils.isEmpty(resourceEntry.getValue().getProperties())) {
-      return null;
+      return imageAndFlavorLegalNames;
     }
 
     Pair<String, String> imagePair = new ImmutablePair<>("image", ".*_image_name");
     Pair<String, String> flavorPair = new ImmutablePair<>("flavor", ".*_flavor_name");
     List<Pair<String, String>> imageFlavorPairs = Arrays.asList(imagePair, flavorPair);
     Map<String, Object> propertiesMap = resourceEntry.getValue().getProperties();
-    Map<String, String> imageAndFlavorLegalNames = new HashMap<>();
 
     for (Pair<String, String> imageOrFlavor : imageFlavorPairs) {
       boolean isErrorInImageOrFlavor =
index 26aad3c..759b376 100644 (file)
@@ -73,8 +73,20 @@ public class NovaServerNamingConventionGuideLineValidatorTest {
   }
 
   @Test
-  public void testNovaImageAndFlavorNames() {
+  public void testNovaImageAndFlavorNamesEmptyProperties() {
     Map<String, MessageContainer> 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<String, MessageContainer> 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 (file)
index 0000000..d452552
--- /dev/null
@@ -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 (file)
index 0000000..19731db
--- /dev/null
@@ -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 }
+
+