summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-08-05 10:56:25 +0300
committerEylon Malin <eylon.malin@intl.att.com>2019-08-05 10:56:25 +0300
commitce4838cf3836facbe397b25440922320b421141a (patch)
tree4f359fb17e03dee9d786e6ed068dd4987be6c98f
parentc459c7efeafd556333c46c65fc4fe2616d3ef532 (diff)
change management return 400 handling NPE
return 400 internal status when exception is thrown during extracting serviceInstanceId Issue-ID: VID-378 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com> Change-Id: I97f740de0a700f503d115033980f8e8366e806e7
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java14
-rw-r--r--vid-automation/src/test/java/org/onap/vid/api/ChangeManagementApiTest.java13
2 files changed, 16 insertions, 11 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java
index 814959020..214eec79d 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/ChangeManagementServiceImpl.java
@@ -162,13 +162,19 @@ public class ChangeManagementServiceImpl implements ChangeManagementService {
protected String extractServiceInstanceId(RequestDetails currentRequestDetails,
String requestType) {
- String serviceInstanceId = currentRequestDetails.getRelatedInstList().get(0)
- .getRelatedInstance().getInstanceId();
- if (serviceInstanceId == null) {
+ try {
+ String serviceInstanceId = currentRequestDetails.getRelatedInstList().get(0)
+ .getRelatedInstance().getInstanceId();
+ if (serviceInstanceId == null) {
+ logger.error("Failed to extract serviceInstanceId");
+ throw new BadRequestException("No instanceId in request " + requestType);
+ }
+ return serviceInstanceId;
+ }
+ catch (Exception e) {
logger.error("Failed to extract serviceInstanceId");
throw new BadRequestException("No instanceId in request " + requestType);
}
- return serviceInstanceId;
}
@Override
diff --git a/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementApiTest.java
index 999b66cee..7490c0610 100644
--- a/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementApiTest.java
+++ b/vid-automation/src/test/java/org/onap/vid/api/ChangeManagementApiTest.java
@@ -64,11 +64,10 @@ public class ChangeManagementApiTest extends BaseApiTest {
@DataProvider
public static Object[][] requestWithoutServiceInstanceId(Method test) {
return new Object[][]{
- {(Consumer<ChangeManagementRequest>) changeManagementRequest -> changeManagementRequest.getRequestDetails().get(0).setRelatedInstList(null)},
- {(Consumer<ChangeManagementRequest>) changeManagementRequest -> changeManagementRequest.getRequestDetails().get(0).setRelatedInstList(new ArrayList<>())},
- {(Consumer<ChangeManagementRequest>) changeManagementRequest -> changeManagementRequest.getRequestDetails().get(0).getRelatedInstList().get(0).setRelatedInstance(null)},
- {(Consumer<ChangeManagementRequest>) changeManagementRequest -> changeManagementRequest.getRequestDetails().get(0).getRelatedInstList().get(0).getRelatedInstance().setInstanceId(null)}
-
+ {"RelatedInstList null", (Consumer<ChangeManagementRequest>) changeManagementRequest -> changeManagementRequest.getRequestDetails().get(0).setRelatedInstList(null)},
+ {"Empty list", (Consumer<ChangeManagementRequest>) changeManagementRequest -> changeManagementRequest.getRequestDetails().get(0).setRelatedInstList(new ArrayList<>())},
+ {"Related instance null", (Consumer<ChangeManagementRequest>) changeManagementRequest -> changeManagementRequest.getRequestDetails().get(0).getRelatedInstList().get(0).setRelatedInstance(null)},
+ {"instanceId null", (Consumer<ChangeManagementRequest>) changeManagementRequest -> changeManagementRequest.getRequestDetails().get(0).getRelatedInstList().get(0).getRelatedInstance().setInstanceId(null)}
};
}
@@ -178,7 +177,7 @@ public class ChangeManagementApiTest extends BaseApiTest {
}
@Test(dataProvider = "requestWithoutServiceInstanceId")
- public void testInPlaceSoftwareUpdateWithoutServiceInstanceId(Consumer<ChangeManagementRequest> dropInstanceIdMethod) throws IOException {
+ public void testInPlaceSoftwareUpdateWithoutServiceInstanceId(String desc, Consumer<ChangeManagementRequest> dropInstanceIdMethod) throws IOException {
testChangeManagementServiceInstanceId(dropInstanceIdMethod, ChangeManagementRequest.VNF_IN_PLACE_SOFTWARE_UPDATE);
}
@@ -289,7 +288,7 @@ public class ChangeManagementApiTest extends BaseApiTest {
}
@Test(dataProvider = "requestWithoutServiceInstanceId")
- public void testConfigUpdateWithoutServiceInstanceId(Consumer<ChangeManagementRequest> dropInstanceIdMethod) throws IOException {
+ public void testConfigUpdateWithoutServiceInstanceId(String desc, Consumer<ChangeManagementRequest> dropInstanceIdMethod) throws IOException {
testChangeManagementServiceInstanceId(dropInstanceIdMethod, ChangeManagementRequest.CONFIG_UPDATE);
}