aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authormukesh.paliwal <mukesh.paliwal1@huawei.com>2021-03-03 18:38:52 +0530
committermukesh.paliwal <mukesh.paliwal1@huawei.com>2021-03-03 18:38:52 +0530
commit9b069ec9cee455210f0adf542998932b80c2182a (patch)
treec3f8ae13a6531433c2e618f96270e80c86150ec9 /src/test/java
parentc9b19cda255407d749c09343369e7d6812da32ea (diff)
so-etsi-sol005-adapter UT
Issue-ID: SO-3565 Signed-off-by: mukesh.paliwal <mukesh.paliwal1@huawei.com> Change-Id: I5579f1816df9e8d97c6be96349c357dd1b870eb1
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/so/adapters/vfc/rest/VfcManagerSol005Test.java35
-rw-r--r--src/test/java/org/onap/so/adapters/vfc/util/RestfulUtilTest.java45
2 files changed, 80 insertions, 0 deletions
diff --git a/src/test/java/org/onap/so/adapters/vfc/rest/VfcManagerSol005Test.java b/src/test/java/org/onap/so/adapters/vfc/rest/VfcManagerSol005Test.java
index 799283d..15dc744 100644
--- a/src/test/java/org/onap/so/adapters/vfc/rest/VfcManagerSol005Test.java
+++ b/src/test/java/org/onap/so/adapters/vfc/rest/VfcManagerSol005Test.java
@@ -19,6 +19,7 @@ import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.so.adapters.vfc.exceptions.ApplicationException;
import org.onap.so.adapters.vfc.model.NSResourceInputParameter;
+import org.onap.so.adapters.vfc.model.NsOperationKey;
import org.onap.so.adapters.vfc.model.RestfulResponse;
import org.onap.so.adapters.vfc.util.JsonUtil;
import org.onap.so.adapters.vfc.util.RestfulUtil;
@@ -61,6 +62,7 @@ public class VfcManagerSol005Test {
RestfulResponse vfcrestfulResponse = new RestfulResponse();
NSResourceInputParameter nsResourceInputParameter = new NSResourceInputParameter();
ResourceOperationStatus resourceOperationStatus = new ResourceOperationStatus();
+ NsOperationKey nsOperationKey = new NsOperationKey();
@Test
public void createNs() throws ApplicationException, Exception {
@@ -218,4 +220,37 @@ public class VfcManagerSol005Test {
vfcManagerSol005.instantiateNs(nsInstanceId, nsResourceInputParameter);
}
+
+ @Test
+ public void deleteNs() throws Exception {
+ String nsInstanceId = "c9f0a95e-dea0-4698-96e5-5a79bc5a233d";
+ ClassLoader classLoader = ClassLoader.getSystemClassLoader();
+ File file = new File(classLoader.getResource("json/createNsReq.json").getFile());
+ String content = new String(Files.readAllBytes(file.toPath())).replace("\n", "");
+ nsResourceInputParameter = JsonUtil.unMarshal(content, NSResourceInputParameter.class);
+ instanceNfvoMapping.setInstanceId("b1bb0ce7-2222-4fa7-95ed-4840d70a1101");
+ instanceNfvoMapping.setPassword("sacjnasnc");
+ instanceNfvoMapping.setUsername("admin");
+ instanceNfvoMapping.setNfvoName("external_nfvo");
+ instanceNfvoMapping.setEndpoint("http://sample.com/");
+ instanceNfvoMapping.setApiRoot("xyz");
+ nsOperationKey.setServiceId("1");
+ resourceOperationStatus.setStatus("processing");
+ resourceOperationStatus.setOperationId(nsResourceInputParameter.getNsOperationKey().getOperationId());
+ resourceOperationStatus.setServiceId(nsResourceInputParameter.getNsOperationKey().getServiceId());
+ resourceOperationStatus
+ .setResourceTemplateUUID(nsResourceInputParameter.getNsOperationKey().getNodeTemplateUUID());
+ Map<String, String> header = new HashMap<>();
+ header.put("Location", "http://192.168.10.57:5000/ns_lcm_op_ops/12204a12-7da2-4ddf-8c2f-992a1a1acebf");
+ vfcrestfulResponse.setStatus(202);
+ vfcrestfulResponse.setResponseContent(null);
+ vfcrestfulResponse.setRespHeaderMap(header);
+ when(instanceNfvoMappingRepository.findOneByInstanceId(nsInstanceId)).thenReturn(instanceNfvoMapping);
+ when(restfulUtil.send(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()))
+ .thenReturn(vfcrestfulResponse);
+ when(resourceOperationStatusRepository.save(resourceOperationStatus)).thenReturn(resourceOperationStatus);
+ when(instanceNfvoMappingRepository.save(instanceNfvoMapping)).thenReturn(instanceNfvoMapping);
+ vfcManagerSol005.deleteNs(nsOperationKey, nsInstanceId);
+
+ }
}
diff --git a/src/test/java/org/onap/so/adapters/vfc/util/RestfulUtilTest.java b/src/test/java/org/onap/so/adapters/vfc/util/RestfulUtilTest.java
index 4b6baa5..a3a3fd2 100644
--- a/src/test/java/org/onap/so/adapters/vfc/util/RestfulUtilTest.java
+++ b/src/test/java/org/onap/so/adapters/vfc/util/RestfulUtilTest.java
@@ -42,6 +42,8 @@ import org.springframework.http.HttpStatus;
import javax.ws.rs.HttpMethod;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
@@ -98,6 +100,13 @@ public class RestfulUtilTest {
assertEquals(HttpStatus.OK.value(), restfulResponse.getStatus());
assertEquals("GET", restfulResponse.getResponseContent());
+ Map<String, String> requestHeader = new HashMap<>();
+ requestHeader.put("a", "b");
+ RestfulResponse restfulResponse1 =
+ restfulUtil.send("test", HttpMethod.GET, "some request content", requestHeader);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), restfulResponse1.getStatus());
+
}
@Test
@@ -115,6 +124,13 @@ public class RestfulUtilTest {
assertEquals(HttpStatus.OK.value(), restfulResponse.getStatus());
assertEquals("POST", restfulResponse.getResponseContent());
+ Map<String, String> requestHeader = new HashMap<>();
+ requestHeader.put("a", "b");
+ RestfulResponse restfulResponse1 =
+ restfulUtil.send("test", HttpMethod.POST, "some request content", requestHeader);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), restfulResponse1.getStatus());
+
}
@Test
@@ -131,6 +147,13 @@ public class RestfulUtilTest {
assertEquals(HttpStatus.OK.value(), restfulResponse.getStatus());
assertEquals("PUT", restfulResponse.getResponseContent());
+ Map<String, String> requestHeader = new HashMap<>();
+ requestHeader.put("a", "b");
+ RestfulResponse restfulResponse1 =
+ restfulUtil.send("test", HttpMethod.PUT, "some request content", requestHeader);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), restfulResponse1.getStatus());
+
}
@Test
@@ -147,6 +170,13 @@ public class RestfulUtilTest {
assertEquals(HttpStatus.OK.value(), restfulResponse.getStatus());
assertEquals("DELETE", restfulResponse.getResponseContent());
+ Map<String, String> requestHeader = new HashMap<>();
+ requestHeader.put("a", "b");
+ RestfulResponse restfulResponse1 =
+ restfulUtil.send("test", HttpMethod.DELETE, "some request content", requestHeader);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), restfulResponse1.getStatus());
+
}
@Test
@@ -159,6 +189,21 @@ public class RestfulUtilTest {
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), restfulResponse.getStatus());
assertEquals("Error processing request to VFC", restfulResponse.getResponseContent());
+ Map<String, String> requestHeader = new HashMap<>();
+ requestHeader.put("a", "b");
+ RestfulResponse restfulResponse1 =
+ restfulUtil.send("test", HttpMethod.OPTIONS, "some request content", requestHeader);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), restfulResponse1.getStatus());
}
+ @Test
+ public void getNfvoFromAAITest() throws Exception {
+
+ doReturn("https://testHost/").when(restfulUtil).getMsbHost();
+
+ RestfulResponse restfulResponse = restfulUtil.getNfvoFromAAI("test");
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), restfulResponse.getStatus());
+ }
}