diff options
author | Lukasz Muszkieta <lukasz.muszkieta@nokia.com> | 2019-08-16 10:04:05 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-08-16 10:04:05 +0000 |
commit | 0e57a09647ea8ab7736cbbc322e876c84cbcb346 (patch) | |
tree | fb5cb1200a341d7aa8123b2d49d3da634b2e8acc | |
parent | dfbc8abd0f1c151e34d07defbe0a5ff363fcf1f0 (diff) | |
parent | c1436f09badded98f86da7add6c73b108e0d8c24 (diff) |
Merge "Added check for empty processInstanceList"
2 files changed, 26 insertions, 13 deletions
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<HistoricProcessInstanceEntity> 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<HistoricActivityInstanceEntity> 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<HistoricActivityInstanceEntity> 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<HistoricActivityInstanceEntity> 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<List<HistoricProcessInstanceEntity>> 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<HistoricProcessInstanceEntity> 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<List<HistoricProcessInstanceEntity>> 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"; |