aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2019-12-18 21:01:12 +0000
committerGerrit Code Review <gerrit@onap.org>2019-12-18 21:01:12 +0000
commit64549b75d77bca0ab25f7096540c3e8aeec076b1 (patch)
tree1b72b52be09b56b49459c778b4a6dbb20481e474 /bpmn
parentef21117befdbb9b0158d94789fb303d976584a8e (diff)
parente740c7e59345ee32ee3a15c63e60053fbc5cc9e0 (diff)
Merge "add junit coverage"
Diffstat (limited to 'bpmn')
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java92
1 files 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 =
"<?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 =
@@ -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<String, String> subnetMap = new HashMap<String, String>();
+ Map<String, String> 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 "<?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 + ">";
+ }
+
}