From 1c2207093f959202f69e3978289c3dbf321053c7 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Tue, 7 Apr 2020 18:33:23 +0200 Subject: add junit coverage Issue-ID: SO-1576 Signed-off-by: Lukasz Muszkieta Change-Id: Idbe2e35eecb16706d4ddf5447e4cc1efc0aa78fd --- .../network/tasks/NetworkAdapterRestV1Test.java | 44 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'bpmn') diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java index 9adae88a5a..67ce6bfbe9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java @@ -41,6 +41,7 @@ import org.onap.so.adapters.nwrest.CreateNetworkRequest; import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.DeleteNetworkRequest; import org.onap.so.adapters.nwrest.DeleteNetworkResponse; +import org.onap.so.adapters.nwrest.NetworkRequestCommon; import org.onap.so.adapters.nwrest.UpdateNetworkError; import org.onap.so.adapters.nwrest.UpdateNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; @@ -224,7 +225,7 @@ public class NetworkAdapterRestV1Test { deleteNetworkRequest.setMessageId(messageId); delegateExecution.setVariable("networkAdapterRequest", deleteNetworkRequest); Status status = Status.OK; - String responseEntity = "createNetworkResponse"; + String responseEntity = "deleteNetworkResponse"; Optional response = Optional.of(createResponse(status, responseEntity)); when(networkAdapterResources.deleteNetworkAsync(deleteNetworkRequest)).thenReturn(response); // when @@ -233,6 +234,47 @@ public class NetworkAdapterRestV1Test { verifyExecutionContent(status, responseEntity, messageId); } + @Test + public void callNetworkAdapter_UpdateNetworkRequestSuccess() throws Exception { + // given + String messageId = "UpdateNetReqMessageId"; + UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest(); + updateNetworkRequest.setMessageId(messageId); + delegateExecution.setVariable("networkAdapterRequest", updateNetworkRequest); + Status status = Status.OK; + String responseEntity = "updateNetworkResponse"; + Optional response = Optional.of(createResponse(status, responseEntity)); + when(networkAdapterResources.updateNetworkAsync(updateNetworkRequest)).thenReturn(response); + // when + networkAdapterRestV1Tasks.callNetworkAdapter(delegateExecution); + // then + verifyExecutionContent(status, responseEntity, messageId); + } + + @Test + public void callNetworkAdapterError_networkAdapterRequestIsNull() { + // when + networkAdapterRestV1Tasks.callNetworkAdapter(delegateExecution); + // then + verify(exceptionBuilder, times(1)).buildAndThrowWorkflowException(any(DelegateExecution.class), eq(7000), + any(Exception.class), eq(ONAPComponents.SO)); + } + + @Test + public void callNetworkAdapterError_noResponse() throws Exception { + // given + String messageId = "UpdateNetReqMessageId"; + UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest(); + updateNetworkRequest.setMessageId(messageId); + delegateExecution.setVariable("networkAdapterRequest", updateNetworkRequest); + when(networkAdapterResources.updateNetworkAsync(updateNetworkRequest)).thenReturn(Optional.empty()); + // when + networkAdapterRestV1Tasks.callNetworkAdapter(delegateExecution); + // then + verify(exceptionBuilder, times(1)).buildAndThrowWorkflowException(any(DelegateExecution.class), eq(7000), + any(Exception.class), eq(ONAPComponents.SO)); + } + private void verifyExecutionContent(Status status, String responseEntity, String messageId) { assertEquals(delegateExecution.getVariable("NETWORKREST_networkAdapterStatusCode"), Integer.toString(status.getStatusCode())); -- cgit 1.2.3-korg