From e740c7e59345ee32ee3a15c63e60053fbc5cc9e0 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Tue, 17 Dec 2019 17:06:03 +0100 Subject: add junit coverage Issue-ID: SO-1576 Signed-off-by: Lukasz Muszkieta Change-Id: I2ca18a7154ff07801defa17d2f4a19ea9dba7962 --- .../network/tasks/NetworkAdapterRestV1Test.java | 92 +++++++++++++++++++--- 1 file changed, 83 insertions(+), 9 deletions(-) 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 3994208d23..5bd4df74bb 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 @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2018 Nokia. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,7 +22,6 @@ package org.onap.so.bpmn.infrastructure.adapter.network.tasks; -import java.io.IOException; import java.util.HashMap; import java.util.Map; import javax.xml.bind.JAXBException; @@ -31,23 +32,24 @@ import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; +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.UpdateNetworkError; import org.onap.so.adapters.nwrest.UpdateNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; import org.onap.so.bpmn.BaseTaskTest; -import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.so.client.exception.MapperException; import org.onap.so.utils.Components; import org.onap.logging.filter.base.ONAPComponents; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -60,13 +62,22 @@ public class NetworkAdapterRestV1Test extends BaseTaskTest { @Mock ExceptionBuilder exceptionBuilder = new ExceptionBuilder(); + private static final String CREATE_NETWORK_RESPONSE = "createNetworkResponse"; + private static final String DELETE_NETWORK_RESPONSE = "deleteNetworkResponse"; + private static final String CREATE_NETWORK_ERROR = "createNetworkError"; + private static final String DELETE_NETWORK_ERROR = "deleteNetworkError"; + private static final String NET_ID_FOR_CREATE_NETWORK_RESPONSE = "netIdForCreateNetworkResponse"; + private static final String NET_ID_FOR_DELETE_NETWORK_RESPONSE = "netIdForDeleteNetworkResponse"; + private static final String CREATE_NETWORK_ERROR_MESSAGE = "createNetErrorMessage"; + private static final String DELETE_NETWORK_ERROR_MESSAGE = "deleteNetErrorMessage"; + @Before public void setup() { delegateExecution = new DelegateExecutionFake(); } @Test - public void testUnmarshalXml() throws IOException, JAXBException { + public void testUnmarshalXml() throws JAXBException { String xml = "ec37c121-e3ec-4697-8adf-2d7dca7044fctruesomeNetworkFqdn991ec7bf-c9c4-4ac1-bb9c-4b61645bddb3someStackId9c47521a-2916-4018-b2bc-71ab767497e3someCloudIdb7171cdd-8b05-459b-80ef-2093150e898390b32315-176e-4dab-bcf1-80eb97a1c4f471e7db22-7907-4d78-8fcc-8d89d28e90betruesomeStackIdSomeNetworkType9c47521a-2916-4018-b2bc-71ab767497e3b60da4f71c1d4b35b8113d4eca6deaa16b381fa9-48ce-4e16-9978-d75309565bb6bc1d5537-860b-4894-8eba-6faff41e648c"; CreateNetworkResponse response = @@ -76,11 +87,11 @@ public class NetworkAdapterRestV1Test extends BaseTaskTest { } @Test - public void testUnmarshalXmlUpdate() throws IOException, JAXBException { + public void testUnmarshalXmlUpdate() throws JAXBException { UpdateNetworkResponse expectedResponse = new UpdateNetworkResponse(); expectedResponse.setMessageId("ec100bcc-2659-4aa4-b4d8-3255715c2a51"); expectedResponse.setNetworkId("80de31e3-cc78-4111-a9d3-5b92bf0a39eb"); - Map subnetMap = new HashMap(); + Map subnetMap = new HashMap<>(); subnetMap.put("95cd8437-25f1-4238-8720-cbfe7fa81476", "d8d16606-5d01-4822-b160-9a0d257303e0"); expectedResponse.setSubnetMap(subnetMap); String xml = @@ -91,7 +102,7 @@ public class NetworkAdapterRestV1Test extends BaseTaskTest { } @Test - public void processCallbackTest() throws MapperException, BadResponseException, IOException { + public void processCallbackTest() { UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest(); UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse(); updateNetworkResponse.setMessageId("messageId"); @@ -105,7 +116,7 @@ public class NetworkAdapterRestV1Test extends BaseTaskTest { } @Test - public void processCallbackErrorTest() throws MapperException, BadResponseException, IOException { + public void processCallbackErrorTest() { UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest(); UpdateNetworkError updateNetworkResponse = new UpdateNetworkError(); updateNetworkResponse.setMessageId("messageId"); @@ -125,4 +136,67 @@ public class NetworkAdapterRestV1Test extends BaseTaskTest { verify(exceptionBuilder, times(1)).buildAndThrowWorkflowException(any(DelegateExecution.class), eq(7000), eq("test error message"), eq(Components.OPENSTACK)); } + + @Test + public void processCallback_createNetworkResponse() { + delegateExecution.setVariable("networkAdapterRequest", new CreateNetworkRequest()); + delegateExecution.setVariable("NetworkAResponse_MESSAGE", + createNetworkResponse(CREATE_NETWORK_RESPONSE, NET_ID_FOR_CREATE_NETWORK_RESPONSE)); + networkAdapterRestV1Tasks.processCallback(delegateExecution); + + Object result = delegateExecution.getVariable("createNetworkResponse"); + assertTrue(result instanceof CreateNetworkResponse); + CreateNetworkResponse createNetworkResponse = (CreateNetworkResponse) result; + assertEquals(createNetworkResponse.getNetworkId(), NET_ID_FOR_CREATE_NETWORK_RESPONSE); + } + + @Test + public void processCallback_deleteNetworkResponse() { + delegateExecution.setVariable("networkAdapterRequest", new DeleteNetworkRequest()); + delegateExecution.setVariable("NetworkAResponse_MESSAGE", + createNetworkResponse(DELETE_NETWORK_RESPONSE, NET_ID_FOR_DELETE_NETWORK_RESPONSE)); + networkAdapterRestV1Tasks.processCallback(delegateExecution); + + Object result = delegateExecution.getVariable("deleteNetworkResponse"); + assertTrue(result instanceof DeleteNetworkResponse); + DeleteNetworkResponse deleteNetworkResponse = (DeleteNetworkResponse) result; + assertEquals(deleteNetworkResponse.getNetworkId(), NET_ID_FOR_DELETE_NETWORK_RESPONSE); + } + + @Test + public void processCallback_createNetworkError() { + try { + delegateExecution.setVariable("networkAdapterRequest", new CreateNetworkRequest()); + delegateExecution.setVariable("NetworkAResponse_MESSAGE", + createNetworkError(CREATE_NETWORK_ERROR, CREATE_NETWORK_ERROR_MESSAGE)); + networkAdapterRestV1Tasks.processCallback(delegateExecution); + } catch (Exception e) { + assertEquals(e.getMessage(), CREATE_NETWORK_ERROR_MESSAGE); + } + } + + @Test + public void processCallback_deleteNetworkError() { + try { + delegateExecution.setVariable("networkAdapterRequest", new DeleteNetworkRequest()); + delegateExecution.setVariable("NetworkAResponse_MESSAGE", + createNetworkError(DELETE_NETWORK_ERROR, DELETE_NETWORK_ERROR_MESSAGE)); + networkAdapterRestV1Tasks.processCallback(delegateExecution); + } catch (Exception e) { + assertEquals(e.getMessage(), DELETE_NETWORK_ERROR_MESSAGE); + } + } + + private String createNetworkResponse(String networkResponseType, String networkId) { + + return "<" + networkResponseType + ">" + + networkId + ""; + } + + private String createNetworkError(String networkErrorType, String message) { + + return "<" + networkErrorType + ">" + + message + ""; + } + } -- cgit 1.2.3-korg