Fixed possible NPE in WorkflowAction 05/78805/4
authorr.bogacki <r.bogacki@samsung.com>
Tue, 19 Feb 2019 14:03:41 +0000 (15:03 +0100)
committerRobert Bogacki <r.bogacki@samsung.com>
Wed, 20 Feb 2019 14:00:20 +0000 (14:00 +0000)
NullPointerException could be thrown
in case when resource == null.

Change-Id: I1f78e4733187f3086ac1915d2bfb098fb8c4aabd
Issue-ID: SO-1530
Signed-off-by: Robert Bogacki <r.bogacki@samsung.com>
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java

index 99bda80..8a3a778 100644 (file)
@@ -1050,9 +1050,11 @@ public class WorkflowAction {
                executeBuildingBlock.setRequestDetails(requestDetails);
                if(isConfiguration){
                        ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
-                       configurationResourceKeys.setCvnfcCustomizationUUID(resource.getCvnfModuleCustomizationId());
-                       configurationResourceKeys.setVfModuleCustomizationUUID(resource.getVfModuleCustomizationId());
-                       configurationResourceKeys.setVnfResourceCustomizationUUID(resource.getVnfCustomizationId());
+                       if (resource != null){
+                               configurationResourceKeys.setCvnfcCustomizationUUID(resource.getCvnfModuleCustomizationId());
+                               configurationResourceKeys.setVfModuleCustomizationUUID(resource.getVfModuleCustomizationId());
+                               configurationResourceKeys.setVnfResourceCustomizationUUID(resource.getVnfCustomizationId());
+                       }
                        executeBuildingBlock.setConfigurationResourceKeys(configurationResourceKeys);
                }
                return executeBuildingBlock;
index c74f590..93d4b41 100644 (file)
@@ -24,10 +24,7 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks;
 
 import static org.hamcrest.CoreMatchers.containsString;
 import static org.hamcrest.CoreMatchers.equalTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assert.*;
 import static org.mockito.ArgumentMatchers.anyObject;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Matchers.isA;
@@ -1329,6 +1326,19 @@ public class WorkflowActionTest extends BaseTaskTest {
             execution.getVariable("WorkflowActionErrorMessage"));
     }
 
+    @Test
+    public void verifyLackOfNullPointerExceptionForNullResource(){
+      ExecuteBuildingBlock result = null;
+      try {
+        result = workflowAction
+        .buildExecuteBuildingBlock(new OrchestrationFlow(), null, null, null, null, null, false,
+        null, null, null, false, null, true);
+      }catch (NullPointerException e){
+      fail("NullPointerException should not be thrown when 'resource' is null");
+      }
+      assertNotNull(result);
+    }
+
        private List<OrchestrationFlow> createFlowList (String... flowNames){
                List<OrchestrationFlow> result = new ArrayList<>();
                for(String flowName : flowNames){