aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks
diff options
context:
space:
mode:
authorBoslet, Cory <cory.boslet@att.com>2020-04-16 10:43:38 -0400
committerBenjamin, Max (mb388a) <mb388a@att.com>2020-04-16 10:43:44 -0400
commitfa9a707c87654330dfb5788a6029b8199c6cdf17 (patch)
treeebd981e12166281957b47353a45b6b3c9b3ee490 /bpmn/so-bpmn-tasks
parentb0f5ac59c297f81b7f17c1f367e64257ef7be2d2 (diff)
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) <mb388a@att.com> Change-Id: I4c25892012cc86659ab122448ed1aca5cab91671
Diffstat (limited to 'bpmn/so-bpmn-tasks')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java5
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasks.java2
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImpl.java103
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java166
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasks.java2
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java2
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImplTest.java30
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java303
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java2
9 files changed, 140 insertions, 475 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java
index 0ec28d901c..fb5c81a52e 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java
@@ -63,7 +63,7 @@ public class NetworkAdapterCreateTasks {
gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance,
l3Network, userInput, cloudRegionPo, gBBInput.getCustomer());
- execution.setVariable("networkAdapterRequest", createNetworkRequest);
+ execution.setVariable("networkAdapterRequest", createNetworkRequest.toXmlString());
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
@@ -81,13 +81,14 @@ public class NetworkAdapterCreateTasks {
execution.setVariable("networkAdapterCreateRollback", true);
}
} else {
- throw new Exception("No response was sent back from NetworkAdapterRestV1 subflow.");
+ throw new Exception("No response was sent back from NetworkAdapter subflow.");
}
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
}
+ // TODO is this even used anywhere?
public void rollbackCreateNetwork(BuildingBlockExecution execution) {
try {
GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasks.java
index 7a7d681762..df5e7d2b34 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasks.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasks.java
@@ -53,7 +53,7 @@ public class NetworkAdapterDeleteTasks {
DeleteNetworkRequest deleteNetworkRequest = networkAdapterObjectMapper.deleteNetworkRequestMapper(
gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, l3Network);
- execution.setVariable("networkAdapterRequest", deleteNetworkRequest);
+ execution.setVariable("networkAdapterRequest", deleteNetworkRequest.toXmlString());
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImpl.java
new file mode 100644
index 0000000000..5a84910a29
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImpl.java
@@ -0,0 +1,103 @@
+package org.onap.so.bpmn.infrastructure.adapter.network.tasks;
+
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
+import java.util.Optional;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.onap.so.adapters.nwrest.CreateNetworkError;
+import org.onap.so.adapters.nwrest.CreateNetworkRequest;
+import org.onap.so.adapters.nwrest.CreateNetworkResponse;
+import org.onap.so.adapters.nwrest.DeleteNetworkError;
+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.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.utils.Components;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class NetworkAdapterImpl {
+
+ private static final Logger logger = LoggerFactory.getLogger(NetworkAdapterImpl.class);
+
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+
+ public void preProcessNetworkAdapter(BuildingBlockExecution execution) {
+ try {
+ GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
+ ServiceInstance serviceInstance =
+ extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
+ execution.setVariable("mso-request-id", gBBInput.getRequestContext().getMsoRequestId());
+ execution.setVariable("mso-service-instance-id", serviceInstance.getServiceInstanceId());
+ } catch (Exception ex) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
+ }
+ }
+
+ public void postProcessNetworkAdapter(BuildingBlockExecution execution) {
+ try {
+ String workflowResponse = (String) execution.getVariable("WorkflowResponse");
+ if (workflowResponse != null) {
+ Optional<String> responseType = findResponseType(workflowResponse);
+ if ("createNetworkResponse".equals(responseType.get())) {
+ CreateNetworkResponse createNetworkResponse =
+ (CreateNetworkResponse) unmarshalXml(workflowResponse, CreateNetworkResponse.class);
+ execution.setVariable("createNetworkResponse", createNetworkResponse);
+ } else if ("deleteNetworkResponse".equals(responseType.get())) {
+ DeleteNetworkResponse deleteNetworkResponse =
+ (DeleteNetworkResponse) unmarshalXml(workflowResponse, DeleteNetworkResponse.class);
+ execution.setVariable("deleteNetworkResponse", deleteNetworkResponse);
+ } else if ("updateNetworkResponse".equals(responseType.get())) {
+ UpdateNetworkResponse updateNetworkResponse =
+ (UpdateNetworkResponse) unmarshalXml(workflowResponse, UpdateNetworkResponse.class);
+ execution.setVariable("updateNetworkResponse", updateNetworkResponse);
+ } else {
+ logger.warn("Unable to determine network response type");
+ }
+ }
+ } catch (Exception e) {
+ logger.error("Error Network Adapter post process", e);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e.getMessage(), Components.OPENSTACK);
+ }
+ }
+
+ protected <T> Object unmarshalXml(String xmlString, Class<T> resultClass) throws JAXBException {
+ StringReader reader = new StringReader(xmlString);
+ JAXBContext context = JAXBContext.newInstance(resultClass);
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ return unmarshaller.unmarshal(reader);
+ }
+
+ protected Optional<String> findResponseType(String xmlString) {
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ org.w3c.dom.Document doc;
+ doc = builder.parse(new ByteArrayInputStream(xmlString.getBytes("UTF-8")));
+ return Optional.of(doc.getDocumentElement().getNodeName());
+ } catch (Exception e) {
+ logger.error("Error Finding Response Type", e);
+ return Optional.empty();
+ }
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java
deleted file mode 100644
index 2705d00d6b..0000000000
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.io.StringReader;
-import java.util.Optional;
-import javax.ws.rs.core.Response;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-import org.camunda.bpm.engine.delegate.DelegateExecution;
-import org.onap.so.adapters.nwrest.CreateNetworkError;
-import org.onap.so.adapters.nwrest.CreateNetworkRequest;
-import org.onap.so.adapters.nwrest.CreateNetworkResponse;
-import org.onap.so.adapters.nwrest.DeleteNetworkError;
-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.client.exception.ExceptionBuilder;
-import org.onap.so.client.orchestration.NetworkAdapterResources;
-import org.onap.logging.filter.base.ONAPComponents;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import org.onap.so.utils.Components;
-
-@Component
-public class NetworkAdapterRestV1 {
-
- private static final Logger logger = LoggerFactory.getLogger(NetworkAdapterRestV1.class);
-
- private static final String NETWORK_REQUEST = "networkAdapterRequest";
- private static final String NETWORK_MESSAGE = "NetworkAResponse_MESSAGE";
- private static final String NETWORK_SYNC_CODE = "NETWORKREST_networkAdapterStatusCode";
- private static final String NETWORK_SYNC_RESPONSE = "NETWORKREST_networkAdapterResponse";
- private static final String NETWORK_CORRELATOR = "NetworkAResponse_CORRELATOR";
-
- @Autowired
- private ExceptionBuilder exceptionBuilder;
-
- @Autowired
- private NetworkAdapterResources networkAdapterResources;
-
- public void callNetworkAdapter(DelegateExecution execution) {
- try {
- Object networkAdapterRequest = execution.getVariable(NETWORK_REQUEST);
- if (networkAdapterRequest != null) {
- Optional<Response> response = Optional.empty();
- if (networkAdapterRequest instanceof CreateNetworkRequest) {
- CreateNetworkRequest createNetworkRequest = (CreateNetworkRequest) networkAdapterRequest;
- execution.setVariable(NETWORK_CORRELATOR, createNetworkRequest.getMessageId());
- response = networkAdapterResources.createNetworkAsync(createNetworkRequest);
- } else if (networkAdapterRequest instanceof DeleteNetworkRequest) {
- DeleteNetworkRequest deleteNetworkRequest = (DeleteNetworkRequest) networkAdapterRequest;
- execution.setVariable(NETWORK_CORRELATOR, deleteNetworkRequest.getMessageId());
- response = networkAdapterResources.deleteNetworkAsync(deleteNetworkRequest);
- } else if (networkAdapterRequest instanceof UpdateNetworkRequest) {
- UpdateNetworkRequest updateNetworkRequest = (UpdateNetworkRequest) networkAdapterRequest;
- execution.setVariable(NETWORK_CORRELATOR, updateNetworkRequest.getMessageId());
- response = networkAdapterResources.updateNetworkAsync(updateNetworkRequest);
- }
- if (response.isPresent()) {
- String statusCode = Integer.toString(response.get().getStatus());
- String responseString = "";
- if (response.get().getEntity() != null) {
- responseString = (String) response.get().getEntity();
- }
- execution.setVariable(NETWORK_SYNC_CODE, statusCode);
- execution.setVariable(NETWORK_SYNC_RESPONSE, responseString);
- } else {
- throw new Exception("No Ack response from Openstack Adapter");
- }
- } else {
- throw new Exception("No Network Request was created. networkAdapterRequest was null.");
- }
- } catch (Exception ex) {
- exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex, ONAPComponents.SO);
- }
- }
-
- public void processCallback(DelegateExecution execution) {
- try {
- Object networkAdapterRequest = execution.getVariable(NETWORK_REQUEST);
- String callback = (String) execution.getVariable(NETWORK_MESSAGE);
- String logCallbackMessage = "Callback from OpenstackAdapter: " + callback;
- logger.debug(logCallbackMessage);
- if (networkAdapterRequest != null) {
- if (networkAdapterRequest instanceof CreateNetworkRequest) {
- if (callback.contains("createNetworkError")) {
- CreateNetworkError createNetworkError =
- (CreateNetworkError) unmarshalXml(callback, CreateNetworkError.class);
- throw new Exception(createNetworkError.getMessage());
- } else {
- CreateNetworkResponse createNetworkResponse =
- (CreateNetworkResponse) unmarshalXml(callback, CreateNetworkResponse.class);
- execution.setVariable("createNetworkResponse", createNetworkResponse);
- }
- } else if (networkAdapterRequest instanceof DeleteNetworkRequest) {
- if (callback.contains("deleteNetworkError")) {
- DeleteNetworkError deleteNetworkError =
- (DeleteNetworkError) unmarshalXml(callback, DeleteNetworkError.class);
- throw new Exception(deleteNetworkError.getMessage());
- } else {
- DeleteNetworkResponse deleteNetworkResponse =
- (DeleteNetworkResponse) unmarshalXml(callback, DeleteNetworkResponse.class);
- execution.setVariable("deleteNetworkResponse", deleteNetworkResponse);
- }
- } else if (networkAdapterRequest instanceof UpdateNetworkRequest) {
- if (callback.contains("updateNetworkError")) {
- UpdateNetworkError updateNetworkError =
- (UpdateNetworkError) unmarshalXml(callback, UpdateNetworkError.class);
- throw new Exception(updateNetworkError.getMessage());
- } else {
- UpdateNetworkResponse updateNetworkResponse =
- (UpdateNetworkResponse) unmarshalXml(callback, UpdateNetworkResponse.class);
- execution.setVariable("updateNetworkResponse", updateNetworkResponse);
- }
- }
- }
- } catch (Exception e) {
- logger.error("Error in Openstack Adapter callback", e);
- exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage(), Components.OPENSTACK);
- }
- }
-
- protected <T> Object unmarshalXml(String xmlString, Class<T> resultClass) throws JAXBException {
- StringReader reader = new StringReader(xmlString);
- JAXBContext context = JAXBContext.newInstance(resultClass);
- Unmarshaller unmarshaller = context.createUnmarshaller();
- return unmarshaller.unmarshal(reader);
- }
-
- public void handleTimeOutException(DelegateExecution execution) {
- exceptionBuilder.buildAndThrowWorkflowException(execution, 7000,
- "Error timed out waiting on Openstack Async-Response", ONAPComponents.SO);
- }
-
- public void handleSyncError(DelegateExecution execution) {
- String statusCode = (String) execution.getVariable(NETWORK_SYNC_CODE);
- String responseString = (String) execution.getVariable(NETWORK_SYNC_RESPONSE);
- String errorMessage = "Error with Openstack Adapter Sync Request: StatusCode = " + statusCode + " Response = "
- + responseString;
- exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, errorMessage, Components.OPENSTACK);
- }
-}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasks.java
index e238a4fdd3..c64491f71a 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasks.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasks.java
@@ -55,7 +55,7 @@ public class NetworkAdapterUpdateTasks {
UpdateNetworkRequest updateNetworkRequest = networkAdapterObjectMapper.createNetworkUpdateRequestMapper(
gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance,
l3Network, gBBInput.getUserInput(), gBBInput.getCustomer());
- execution.setVariable("networkAdapterRequest", updateNetworkRequest);
+ execution.setVariable("networkAdapterRequest", updateNetworkRequest.toXmlString());
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
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 =
- "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><createNetworkResponse><messageId>ec37c121-e3ec-4697-8adf-2d7dca7044fc</messageId><networkCreated>true</networkCreated><networkFqdn>someNetworkFqdn</networkFqdn><networkId>991ec7bf-c9c4-4ac1-bb9c-4b61645bddb3</networkId><networkStackId>someStackId</networkStackId><neutronNetworkId>9c47521a-2916-4018-b2bc-71ab767497e3</neutronNetworkId><rollback><cloudId>someCloudId</cloudId><modelCustomizationUuid>b7171cdd-8b05-459b-80ef-2093150e8983</modelCustomizationUuid><msoRequest><requestId>90b32315-176e-4dab-bcf1-80eb97a1c4f4</requestId><serviceInstanceId>71e7db22-7907-4d78-8fcc-8d89d28e90be</serviceInstanceId></msoRequest><networkCreated>true</networkCreated><networkStackId>someStackId</networkStackId><networkType>SomeNetworkType</networkType><neutronNetworkId>9c47521a-2916-4018-b2bc-71ab767497e3</neutronNetworkId><tenantId>b60da4f71c1d4b35b8113d4eca6deaa1</tenantId></rollback><subnetMap><entry><key>6b381fa9-48ce-4e16-9978-d75309565bb6</key><value>bc1d5537-860b-4894-8eba-6faff41e648c</value></entry></subnetMap></createNetworkResponse>";
- 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<String, String> subnetMap = new HashMap<>();
- subnetMap.put("95cd8437-25f1-4238-8720-cbfe7fa81476", "d8d16606-5d01-4822-b160-9a0d257303e0");
- expectedResponse.setSubnetMap(subnetMap);
- String xml =
- "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><updateNetworkResponse><messageId>ec100bcc-2659-4aa4-b4d8-3255715c2a51</messageId><networkId>80de31e3-cc78-4111-a9d3-5b92bf0a39eb</networkId><subnetMap><entry><key>95cd8437-25f1-4238-8720-cbfe7fa81476</key><value>d8d16606-5d01-4822-b160-9a0d257303e0</value></entry></subnetMap></updateNetworkResponse>";
- 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> 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> 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> 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 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><" + networkResponseType + "><networkId>"
- + networkId + "</networkId></" + networkResponseType + ">";
- }
-
- private String createNetworkError(String networkErrorType, String message) {
-
- return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><" + networkErrorType + "><message>"
- + message + "</message></" + networkErrorType + ">";
- }
-
-}
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"));
}