From c1436f09badded98f86da7add6c73b108e0d8c24 Mon Sep 17 00:00:00 2001 From: "Plummer, Brittany" Date: Tue, 13 Aug 2019 19:12:07 -0400 Subject: Added check for empty processInstanceList Added check for empty processInstanceList Issue-ID: SO-2225 Signed-off-by: Benjamin, Max (mb388a) Change-Id: If4569d94dbda794c9a347e6dc73102acf7664558 --- .../so/apihandlerinfra/CamundaRequestHandler.java | 2 +- .../apihandlerinfra/CamundaRequestHandlerTest.java | 37 +++++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) (limited to 'mso-api-handlers/mso-api-handler-infra/src') diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java index 451fa64585..e56eb422d8 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java @@ -115,7 +115,7 @@ public class CamundaRequestHandler { List historicProcessInstanceList = response.getBody(); - if (historicProcessInstanceList != null) { + if (historicProcessInstanceList != null && !historicProcessInstanceList.isEmpty()) { Collections.reverse(historicProcessInstanceList); processInstanceId = historicProcessInstanceList.get(0).getId(); } else { diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/CamundaRequestHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/CamundaRequestHandlerTest.java index e6b5163f59..830f38f98b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/CamundaRequestHandlerTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/CamundaRequestHandlerTest.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.camunda.bpm.engine.impl.persistence.entity.HistoricActivityInstanceEntity; import org.camunda.bpm.engine.impl.persistence.entity.HistoricProcessInstanceEntity; @@ -119,7 +120,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getActivityNameTest() throws IOException { + public void getActivityNameTest() { String expectedActivityName = "Last task executed: BB to Execute"; String actualActivityName = camundaRequestHandler.getActivityName(activityInstanceList); @@ -127,7 +128,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getActivityNameNullActivityNameTest() throws IOException { + public void getActivityNameNullActivityNameTest() { String expectedActivityName = "Task name is null."; HistoricActivityInstanceEntity activityInstance = new HistoricActivityInstanceEntity(); List activityInstanceList = new ArrayList<>(); @@ -139,7 +140,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getActivityNameNullListTest() throws IOException { + public void getActivityNameNullListTest() { String expectedActivityName = "No results returned on activityInstance history lookup."; List activityInstanceList = null; String actualActivityName = camundaRequestHandler.getActivityName(activityInstanceList); @@ -148,7 +149,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getActivityNameEmptyListTest() throws IOException { + public void getActivityNameEmptyListTest() { String expectedActivityName = "No results returned on activityInstance history lookup."; List activityInstanceList = new ArrayList<>(); String actualActivityName = camundaRequestHandler.getActivityName(activityInstanceList); @@ -157,7 +158,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getTaskNameTest() throws IOException, ContactCamundaException { + public void getTaskNameTest() throws ContactCamundaException { doReturn(processInstanceResponse).when(camundaRequestHandler).getCamundaProcessInstanceHistory(REQUEST_ID); doReturn(activityInstanceResponse).when(camundaRequestHandler) .getCamundaActivityHistory("c4c6b647-a26e-11e9-b144-0242ac14000b", REQUEST_ID); @@ -170,7 +171,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getTaskNameNullProcessInstanceListTest() throws IOException, ContactCamundaException { + public void getTaskNameNullProcessInstanceListTest() throws ContactCamundaException { ResponseEntity> response = new ResponseEntity<>(null, HttpStatus.OK); doReturn(response).when(camundaRequestHandler).getCamundaProcessInstanceHistory(REQUEST_ID); String expected = "No processInstances returned for requestId: " + REQUEST_ID; @@ -181,7 +182,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getTaskNameNullProcessInstanceIdTest() throws IOException, ContactCamundaException { + public void getTaskNameNullProcessInstanceIdTest() throws ContactCamundaException { HistoricProcessInstanceEntity processInstance = new HistoricProcessInstanceEntity(); List processInstanceList = new ArrayList<>(); processInstanceList.add(processInstance); @@ -196,7 +197,19 @@ public class CamundaRequestHandlerTest { } @Test - public void getTaskNameProcessInstanceLookupFailureTest() throws IOException, ContactCamundaException { + public void getTaskNameEmptyProcessInstanceListTest() throws ContactCamundaException { + ResponseEntity> response = + new ResponseEntity<>(Collections.emptyList(), HttpStatus.OK); + doReturn(response).when(camundaRequestHandler).getCamundaProcessInstanceHistory(REQUEST_ID); + String expected = "No processInstances returned for requestId: " + REQUEST_ID; + + String actual = camundaRequestHandler.getTaskName(REQUEST_ID); + + assertEquals(expected, actual); + } + + @Test + public void getTaskNameProcessInstanceLookupFailureTest() throws ContactCamundaException { doThrow(HttpClientErrorException.class).when(camundaRequestHandler) .getCamundaProcessInstanceHistory(REQUEST_ID); @@ -205,7 +218,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getCamundaActivityHistoryTest() throws IOException, ContactCamundaException { + public void getCamundaActivityHistoryTest() throws ContactCamundaException { HttpHeaders headers = setHeaders(); HttpEntity requestEntity = new HttpEntity<>(headers); String targetUrl = "http://localhost:8089/sobpmnengine/history/activity-instance?processInstanceId=" @@ -239,7 +252,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getCamundaProccesInstanceHistoryTest() throws IOException, ContactCamundaException { + public void getCamundaProccesInstanceHistoryTest() { HttpHeaders headers = setHeaders(); HttpEntity requestEntity = new HttpEntity<>(headers); String targetUrl = @@ -292,7 +305,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getCamundaProccesInstanceHistoryFailThenSuccessTest() throws IOException, ContactCamundaException { + public void getCamundaProccesInstanceHistoryFailThenSuccessTest() { HttpHeaders headers = setHeaders(); HttpEntity requestEntity = new HttpEntity<>(headers); String targetUrl = @@ -310,7 +323,7 @@ public class CamundaRequestHandlerTest { } @Test - public void setCamundaHeadersTest() throws ContactCamundaException, RequestDbFailureException { + public void setCamundaHeadersTest() { String encryptedAuth = "015E7ACF706C6BBF85F2079378BDD2896E226E09D13DC2784BA309E27D59AB9FAD3A5E039DF0BB8408"; // user:password String key = "07a7159d3bf51a0e53be7a8f89699be7"; -- cgit 1.2.3-korg