From fa9a707c87654330dfb5788a6029b8199c6cdf17 Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Thu, 16 Apr 2020 10:43:38 -0400 Subject: move network adapter to an external client task Began impelenting new network external task. Made the vnfAdapterTask subflow an openstack subflow, refactored infra flows and BB to call it for network functions. Fixed bugs discovered through a robot dry run, added unit test, added support for rollback network request Updated junit test files for comparison due to not polling for response Removed the no longer used network adapter rest task from bpmn tasks Removed the unused network adapter async and its beans Removed network async client package from open pojo scan Issue-ID: SO-2813 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I4c25892012cc86659ab122448ed1aca5cab91671 --- .../tasks/NetworkAdapterCreateTasksTest.java | 2 +- .../network/tasks/NetworkAdapterImplTest.java | 30 ++ .../network/tasks/NetworkAdapterRestV1Test.java | 303 --------------------- .../tasks/NetworkAdapterUpdateTasksTest.java | 2 +- 4 files changed, 32 insertions(+), 305 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImplTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java (limited to 'bpmn/so-bpmn-tasks/src/test/java') diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java index 00dfd4e236..60bed17447 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java @@ -89,7 +89,7 @@ public class NetworkAdapterCreateTasksTest extends BaseTaskTest { networkAdapterCreateTasks.createNetwork(execution); verify(networkAdapterObjectMapper, times(1)).createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer); - assertEquals(createNetworkRequest, execution.getVariable("networkAdapterRequest")); + assertEquals(createNetworkRequest.toXmlString(), execution.getVariable("networkAdapterRequest")); } @Test diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImplTest.java new file mode 100644 index 0000000000..10cc09cdcc --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImplTest.java @@ -0,0 +1,30 @@ +package org.onap.so.bpmn.infrastructure.adapter.network.tasks; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertNotNull; +import javax.xml.bind.JAXBException; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.onap.so.FileUtil; +import org.onap.so.adapters.nwrest.CreateNetworkResponse; +import org.onap.so.bpmn.BaseTaskTest; + +public class NetworkAdapterImplTest extends BaseTaskTest { + + @InjectMocks + private NetworkAdapterImpl networkAdapterImpl = new NetworkAdapterImpl(); + + private static final String RESPONSE = + FileUtil.readResourceFile("__files/BuildingBlocks/Network/createNetworkResponse.xml"); + + @Test + public void postProcessNetworkAdapter() throws JAXBException { + execution.setVariable("WorkflowResponse", RESPONSE); + networkAdapterImpl.postProcessNetworkAdapter(execution); + assertNotNull(execution.getVariable("createNetworkResponse")); + assertThat(networkAdapterImpl.unmarshalXml(RESPONSE, CreateNetworkResponse.class), + sameBeanAs(execution.getVariable("createNetworkResponse"))); + } + +} 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 deleted file mode 100644 index 67ce6bfbe9..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java +++ /dev/null @@ -1,303 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.infrastructure.adapter.network.tasks; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.xml.bind.JAXBException; -import org.camunda.bpm.engine.delegate.BpmnError; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; -import org.glassfish.jersey.message.internal.OutboundJaxrsResponse; -import org.glassfish.jersey.message.internal.OutboundMessageContext; -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.NetworkRequestCommon; -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.client.exception.ExceptionBuilder; -import org.onap.so.client.orchestration.NetworkAdapterResources; -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.doThrow; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -public class NetworkAdapterRestV1Test { - - @Mock - private ExceptionBuilder exceptionBuilder; - @Mock - private NetworkAdapterResources networkAdapterResources; - @InjectMocks - private NetworkAdapterRestV1 networkAdapterRestV1Tasks; - - private DelegateExecution delegateExecution; - - 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() { - initMocks(this); - delegateExecution = new DelegateExecutionFake(); - } - - @Test - 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 = - (CreateNetworkResponse) new NetworkAdapterRestV1().unmarshalXml(xml, CreateNetworkResponse.class); - String returnedXml = response.toXmlString(); - System.out.println(returnedXml); - } - - @Test - 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<>(); - subnetMap.put("95cd8437-25f1-4238-8720-cbfe7fa81476", "d8d16606-5d01-4822-b160-9a0d257303e0"); - expectedResponse.setSubnetMap(subnetMap); - String xml = - "ec100bcc-2659-4aa4-b4d8-3255715c2a5180de31e3-cc78-4111-a9d3-5b92bf0a39eb95cd8437-25f1-4238-8720-cbfe7fa81476d8d16606-5d01-4822-b160-9a0d257303e0"; - UpdateNetworkResponse response = - (UpdateNetworkResponse) new NetworkAdapterRestV1().unmarshalXml(xml, UpdateNetworkResponse.class); - assertThat(expectedResponse, sameBeanAs(response)); - } - - @Test - public void processCallbackTest() { - UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest(); - UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse(); - updateNetworkResponse.setMessageId("messageId"); - updateNetworkResponse.setNetworkId("networkId"); - delegateExecution.setVariable("networkAdapterRequest", updateNetworkRequest); - delegateExecution.setVariable("NetworkAResponse_MESSAGE", updateNetworkResponse.toXmlString()); - - networkAdapterRestV1Tasks.processCallback(delegateExecution); - - assertThat(updateNetworkResponse, sameBeanAs(delegateExecution.getVariable("updateNetworkResponse"))); - } - - @Test - public void processCallbackErrorTest() { - UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest(); - UpdateNetworkError updateNetworkResponse = new UpdateNetworkError(); - updateNetworkResponse.setMessageId("messageId"); - updateNetworkResponse.setMessage("test error message"); - delegateExecution.setVariable("networkAdapterRequest", updateNetworkRequest); - delegateExecution.setVariable("NetworkAResponse_MESSAGE", updateNetworkResponse.toXmlString()); - - doThrow(new BpmnError("MSOWorkflowException")).when(exceptionBuilder).buildAndThrowWorkflowException( - any(DelegateExecution.class), anyInt(), any(String.class), any(ONAPComponents.class)); - - try { - networkAdapterRestV1Tasks.processCallback(delegateExecution); - } catch (BpmnError be) { - assertEquals("MSOWorkflowException", be.getErrorCode()); - } - assertNull(delegateExecution.getVariable("updateNetworkResponse")); - 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); - } - } - - @Test - public void callNetworkAdapter_CreateNetworkRequestSuccess() throws Exception { - // given - String messageId = "createNetReqMessageId"; - CreateNetworkRequest createNetworkRequest = new CreateNetworkRequest(); - createNetworkRequest.setMessageId(messageId); - delegateExecution.setVariable("networkAdapterRequest", createNetworkRequest); - Status status = Status.OK; - String responseEntity = "createNetworkResponse"; - Optional response = Optional.of(createResponse(status, responseEntity)); - when(networkAdapterResources.createNetworkAsync(createNetworkRequest)).thenReturn(response); - // when - networkAdapterRestV1Tasks.callNetworkAdapter(delegateExecution); - // then - verifyExecutionContent(status, responseEntity, messageId); - } - - @Test - public void callNetworkAdapter_DeleteNetworkRequestSuccess() throws Exception { - // given - String messageId = "DeleteNetReqMessageId"; - DeleteNetworkRequest deleteNetworkRequest = new DeleteNetworkRequest(); - deleteNetworkRequest.setMessageId(messageId); - delegateExecution.setVariable("networkAdapterRequest", deleteNetworkRequest); - Status status = Status.OK; - String responseEntity = "deleteNetworkResponse"; - Optional response = Optional.of(createResponse(status, responseEntity)); - when(networkAdapterResources.deleteNetworkAsync(deleteNetworkRequest)).thenReturn(response); - // when - networkAdapterRestV1Tasks.callNetworkAdapter(delegateExecution); - // then - 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())); - assertEquals(delegateExecution.getVariable("NETWORKREST_networkAdapterResponse"), responseEntity); - assertEquals(delegateExecution.getVariable("NetworkAResponse_CORRELATOR"), messageId); - } - - private Response createResponse(Status status, String responseEntity) { - OutboundMessageContext outboundMessageContext = new OutboundMessageContext(); - outboundMessageContext.setEntity(responseEntity); - return new OutboundJaxrsResponse(status, outboundMessageContext); - } - - private String createNetworkResponse(String networkResponseType, String networkId) { - - return "<" + networkResponseType + ">" - + networkId + ""; - } - - private String createNetworkError(String networkErrorType, String message) { - - return "<" + networkErrorType + ">" - + message + ""; - } - -} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java index af97c3d038..64a315ad4d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java @@ -95,7 +95,7 @@ public class NetworkAdapterUpdateTasksTest extends BaseTaskTest { networkAdapterUpdateTasks.updateNetwork(execution); verify(networkAdapterObjectMapper, times(1)).createNetworkUpdateRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer); - assertEquals(updateNetworkRequest, execution.getVariable("networkAdapterRequest")); + assertEquals(updateNetworkRequest.toXmlString(), execution.getVariable("networkAdapterRequest")); } -- cgit 1.2.3-korg