summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/test/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/test/java/org/onap')
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java75
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java19
2 files changed, 88 insertions, 6 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 516c9480ad..c11dc822b4 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
@@ -20,21 +20,52 @@
package org.onap.so.bpmn.infrastructure.adapter.network.tasks;
-import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
-import static org.junit.Assert.assertThat;
-
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
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.junit.Before;
import org.junit.Test;
+
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
import org.onap.so.adapters.nwrest.CreateNetworkResponse;
+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 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;
-public class NetworkAdapterRestV1Test {
+public class NetworkAdapterRestV1Test extends BaseTaskTest {
+
+ @InjectMocks
+ NetworkAdapterRestV1 networkAdapterRestV1Tasks = new NetworkAdapterRestV1();
+ @Mock
+ ExceptionBuilder exceptionBuilder = new ExceptionBuilder();
+ @Before
+ public void setup(){
+ delegateExecution = new DelegateExecutionFake();
+ }
+
@Test
public void testUnmarshalXml() throws IOException, 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>";
@@ -42,7 +73,7 @@ public class NetworkAdapterRestV1Test {
String returnedXml = response.toXmlString();
System.out.println(returnedXml);
}
-
+
@Test
public void testUnmarshalXmlUpdate() throws IOException, JAXBException {
UpdateNetworkResponse expectedResponse = new UpdateNetworkResponse();
@@ -55,4 +86,38 @@ public class NetworkAdapterRestV1Test {
UpdateNetworkResponse response = (UpdateNetworkResponse) new NetworkAdapterRestV1().unmarshalXml(xml, UpdateNetworkResponse.class);
assertThat(expectedResponse, sameBeanAs(response));
}
+
+ @Test
+ public void processCallbackTest() throws MapperException, BadResponseException, IOException{
+ 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() throws MapperException, BadResponseException, IOException{
+ 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));
+ 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"));
+ }
}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java
index a2880ce07f..1bcc464fa0 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java
@@ -28,7 +28,8 @@ import static com.github.tomakehurst.wiremock.client.WireMock.put;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static org.junit.Assert.assertEquals;
-
+import static org.junit.Assert.assertNotNull;
+import javax.ws.rs.core.Response;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.so.BaseIntegrationTest;
@@ -210,6 +211,22 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{
UpdateNetworkResponse response = client.updateNetwork(AAI_NETWORK_ID, request);
assertEquals("Testing UpdateVfModule response", "test1", response.getNetworkId());
}
+
+ @Test
+ public void updateNetworkTestAsync() throws NetworkAdapterClientException, JsonProcessingException {
+ UpdateNetworkRequest request = new UpdateNetworkRequest();
+ request.setCloudSiteId(TESTING_ID);
+ request.setNetworkId("test1");
+
+ UpdateNetworkResponse mockResponse = new UpdateNetworkResponse();
+ mockResponse.setNetworkId("test1");
+ stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID))
+ .willReturn(aResponse().withHeader("Content-Type", "application/json")
+ .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200)));
+
+ Response response = client.updateNetworkAsync(AAI_NETWORK_ID, request);
+ assertNotNull(response.getEntity());
+ }
@Test(expected = NetworkAdapterClientException.class)
public void updateNetworkTestThrowException() throws NetworkAdapterClientException, JsonProcessingException {