From 9b069ec9cee455210f0adf542998932b80c2182a Mon Sep 17 00:00:00 2001 From: "mukesh.paliwal" Date: Wed, 3 Mar 2021 18:38:52 +0530 Subject: so-etsi-sol005-adapter UT Issue-ID: SO-3565 Signed-off-by: mukesh.paliwal Change-Id: I5579f1816df9e8d97c6be96349c357dd1b870eb1 --- .../so/adapters/vfc/rest/VfcManagerSol005Test.java | 35 +++++++++++++++++ .../onap/so/adapters/vfc/util/RestfulUtilTest.java | 45 ++++++++++++++++++++++ 2 files changed, 80 insertions(+) (limited to 'src/test/java') 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 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 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 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 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 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 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()); + } } -- cgit 1.2.3-korg