diff options
author | Bonkur, Venkat (vb8416) <vb8416@att.com> | 2019-08-07 13:47:54 -0400 |
---|---|---|
committer | Bonkur, Venkat (vb8416) <vb8416@att.com> | 2019-08-07 15:11:15 -0400 |
commit | 8155c85c8d342e68256e5b4da804f822a26a370a (patch) | |
tree | 274007d52b77ab425ca2ac0bcc18333639fea1c6 /bpmn/MSOCommonBPMN | |
parent | e468693695de298bf2282508fa00c3a21496524e (diff) |
Add SO Message instead of Exception when vmIds are empty
Add the conditions to log messages instead of null pointer exception
when vmIds or vserverIds are not present.
Issue-ID: SO-2186
Signed-off-by: Bonkur, Venkat (vb8416) <vb8416@att.com>
Change-Id: I27dd8a5480cf5e2d8588cc71ca3bfefaf0e138cc
Diffstat (limited to 'bpmn/MSOCommonBPMN')
2 files changed, 112 insertions, 0 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java index 9828d11186..c05557a317 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java @@ -78,8 +78,24 @@ public class ApplicationControllerAction { appCStatus = healthCheckAction(msoRequestId, vnfId, vnfName, vnfHostIpAddress, controllerType); break; case Snapshot: + if (vmIdList.isEmpty()) { + logger.warn("vmIdList is Empty in AppCClient"); + break; + } String vmIds = JsonUtils.getJsonValue(vmIdList, "vmIds"); + if (vmIds == null) { + logger.warn("vmIds null in AppCClient"); + break; + } + if (vserverIdList.isEmpty()) { + logger.warn("vserverIdList is empty in AppCClient"); + break; + } String vserverIds = JsonUtils.getJsonValue(vserverIdList, "vserverIds"); + if (vserverIds == null) { + logger.warn("vserverIds null in AppCClient"); + break; + } String vmId = ""; String vserverId = ""; ObjectMapper mapper = new ObjectMapper(); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java index 32db3a7bf6..48c6995715 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java @@ -481,4 +481,100 @@ public class ApplicationControllerActionTest extends BaseTest { assertEquals(expectedErrorCode, appCAction.getErrorCode()); } + @Test + public void runAppCCommand_Snapshot_vmIdList_Empty_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat("", "identityUrl"); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } + + @Test + public void runAppCCommand_Snapshot_vmId_null_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + + JSONObject vmIdListJson = new JSONObject(); + payloadInfo.put("vmIdList", vmIdListJson.toString()); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat("", payloadInfo.get("identityUrl")); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } + + @Test + public void runAppCCommand_Snapshot_vserverIdList_Empty_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + ArrayList<String> vmIdList = new ArrayList<String>(); + String vmId = "testlink:testVmId"; + vmIdList.add(vmId); + JSONObject vmIdListJson = new JSONObject(); + vmIdListJson.put("vmIds", vmIdList); + payloadInfo.put("vmIdList", vmIdListJson.toString()); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat(vmId, payloadInfo.get("identityUrl")); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } + + @Test + public void runAppCCommand_Snapshot_vserverId_null_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + ArrayList<String> vmIdList = new ArrayList<String>(); + String vmId = "testlink:testVmId1"; + vmIdList.add(vmId); + JSONObject vmIdListJson = new JSONObject(); + vmIdListJson.put("vmIds", vmIdList); + payloadInfo.put("vmIdList", vmIdListJson.toString()); + JSONObject vserverIdListJson = new JSONObject(); + payloadInfo.put("vserverIdList", vserverIdListJson.toString()); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat(vmId, payloadInfo.get("identityUrl")); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } } |