summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN
diff options
context:
space:
mode:
authorr.bogacki <r.bogacki@samsung.com>2019-02-12 11:41:29 +0100
committerRobert Bogacki <r.bogacki@samsung.com>2019-02-13 07:33:52 +0000
commit8bfcb5ca8fbd30ecfde7c9ee2d52a5f8b03f5c90 (patch)
tree79f85ea37e9b9178266c06fb8655cc3751ebe837 /bpmn/MSOCommonBPMN
parent1ffa4a397fb51acb09273e2b04b47281f7eb4840 (diff)
Fixed possible NPE in ResourceRequestBuilder
According to Sonar current implementation could cause NullPointerException. Added JUnit test. Change-Id: I840c018bed346d85e2042c7308bdd27197f50b46 Issue-ID: SO-1498 Signed-off-by: Robert Bogacki <r.bogacki@samsung.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java4
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java30
2 files changed, 32 insertions, 2 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java
index 025b533dc0..750f25532c 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -154,7 +156,7 @@ public class ResourceRequestBuilder {
}
}
- if (resourceInputStr != null || !resourceInputStr.equals("")) {
+ if (resourceInputStr != null && !resourceInputStr.isEmpty()) {
return getResourceInput(resourceInputStr, serviceInputs);
}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java
index e5e13268b2..ddca319708 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilderTest.java
@@ -405,4 +405,32 @@ public class ResourceRequestBuilderTest extends BaseTest {
assertEquals(resourceSequence.get(0), "res1");
assertEquals(resourceSequence.get(1), "res2");
}
-} \ No newline at end of file
+
+ @Test
+ public void getResourceInputWithEmptyServiceResourcesTest() throws Exception {
+
+ stubFor(get(urlEqualTo("/ecomp/mso/catalog/v2/serviceResources?serviceModelUuid=c3954379-4efe-431c-8258-f84905b158e5"))
+ .willReturn(ok("{ \"serviceResources\" : {\n" +
+ "\t\"modelInfo\" : {\n" +
+ "\t\t\"modelName\" : \"demoVFWCL\",\n" +
+ "\t\t\"modelUuid\" : \"c3954379-4efe-431c-8258-f84905b158e5\",\n" +
+ "\t\t\"modelInvariantUuid\" : \"0cbff61e-3b0a-4eed-97ce-b1b4faa03493\",\n" +
+ "\t\t\"modelVersion\" : \"1.0\"\n" +
+ "\t},\n" +
+ "\t\"serviceType\" : \"\",\n" +
+ "\t\"serviceRole\" : \"\",\n" +
+ "\t\"environmentContext\" : null,\n" +
+ "\t\"workloadContext\" : \"Production\",\n" +
+ "\t\"serviceVnfs\": [], \n" +
+ "\t\"serviceNetworks\": [],\n" +
+ "\t\"serviceAllottedResources\": []\n" +
+ "\t}}")));
+
+ HashMap serviceInput = new HashMap();
+ serviceInput.put("key1", "value");
+ Map<String, Object> stringObjectMap = ResourceRequestBuilder.buildResouceRequest("c3954379-4efe-431c-8258-f84905b158e5",
+ "e776449e-2b10-45c5-9217-2775c88ca1a0", serviceInput);
+ assertEquals(0, stringObjectMap.size());
+ }
+
+}