summaryrefslogtreecommitdiffstats
path: root/adapters/mso-sdnc-adapter/src/test
diff options
context:
space:
mode:
authorMax Benjamin <max.benjamin@att.com>2021-03-12 15:39:45 +0000
committerGerrit Code Review <gerrit@onap.org>2021-03-12 15:39:45 +0000
commit2c5eeb355acf8bcafa7baeb00f6c6442e0ffcf77 (patch)
treeffffa7242855d5315c5c3a2110ddb187bb025e78 /adapters/mso-sdnc-adapter/src/test
parentb79e10d10d2c750d3f96d850c0b8b60f8d7781c4 (diff)
parent39761146b77f58973612f8fdee3de9f987278edf (diff)
Merge "add new sdnc interaction"1.8.1
Diffstat (limited to 'adapters/mso-sdnc-adapter/src/test')
-rw-r--r--adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/tasks/SDNCServiceTest.java72
-rw-r--r--adapters/mso-sdnc-adapter/src/test/resources/sdncRequest.json12
2 files changed, 84 insertions, 0 deletions
diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/tasks/SDNCServiceTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/tasks/SDNCServiceTest.java
new file mode 100644
index 0000000000..386d83f87d
--- /dev/null
+++ b/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/tasks/SDNCServiceTest.java
@@ -0,0 +1,72 @@
+package org.onap.so.adapters.sdnc.tasks;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.security.GeneralSecurityException;
+import java.util.HashMap;
+import org.camunda.bpm.client.task.ExternalTask;
+import org.camunda.bpm.client.task.ExternalTaskService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.logging.tasks.AuditMDCSetup;
+import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+@RunWith(MockitoJUnitRunner.class)
+public class SDNCServiceTest {
+
+ private String RESOURCE_PATH = "src/test/resources";
+
+ @Mock
+ private ExternalTask mockExternalTask;
+
+ @Mock
+ private ExternalTaskService mockExternalTaskService;
+
+ @Mock
+ private AuditMDCSetup mdcSetup;
+
+ @Mock
+ private RestTemplate restTemplate;
+
+ @Mock
+ private ResponseEntity<Object> response;
+
+ @Mock
+ private Environment env;
+
+ @Spy
+ @InjectMocks
+ private SDNCService sdncService;
+
+ @Test
+ public void testExecutePostTask() throws IOException, GeneralSecurityException {
+ String payload = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "/sdncRequest.json")));
+
+ Mockito.when(env.getProperty("org.onap.so.adapters.sdnc.sdncHost")).thenReturn("sdncHost");
+ Mockito.when(mockExternalTask.getVariable("sdncRequest")).thenReturn(payload);
+ Mockito.when(mockExternalTask.getVariable("sdncUri")).thenReturn("/sdnc/action");
+ Mockito.doReturn("Basic 123").when(sdncService).getAuth();
+ Mockito.when(restTemplate.exchange(Mockito.any(URI.class), Mockito.eq(HttpMethod.POST),
+ Mockito.any(HttpEntity.class), Mockito.eq(Object.class))).thenReturn(response);
+ Mockito.when(response.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
+ Mockito.doNothing().when(mockExternalTaskService).complete(Mockito.any(), Mockito.any());
+
+ sdncService.executePostTask(mockExternalTask, mockExternalTaskService);
+
+ Mockito.verify(mockExternalTaskService).complete(Mockito.eq(mockExternalTask), Mockito.eq(new HashMap<>()));
+
+ }
+
+}
diff --git a/adapters/mso-sdnc-adapter/src/test/resources/sdncRequest.json b/adapters/mso-sdnc-adapter/src/test/resources/sdncRequest.json
new file mode 100644
index 0000000000..879b9b3765
--- /dev/null
+++ b/adapters/mso-sdnc-adapter/src/test/resources/sdncRequest.json
@@ -0,0 +1,12 @@
+{
+ "request_control": {
+ "transaction_id": "migId",
+ "request_id": "reqId",
+ "invocation_id": "subReqId",
+ "async": true,
+ "callback_url": "host/callback"
+ },
+ "input": {
+ "id": "id"
+ }
+} \ No newline at end of file