From 57aa480c5a0e9a823c13024f71e84f7673d7ed23 Mon Sep 17 00:00:00 2001 From: AndrewLamb Date: Thu, 1 Oct 2020 10:32:00 +0100 Subject: SO-ETSI-NFVO Delete NS Backend Service Issue-ID: SO-2870 Change-Id: I476e78a7f528d460eb6dc9bd9019e7407ff167e3 Signed-off-by: AndrewLamb --- .../nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java | 5 ++++ .../lcm/rest/NsLifecycleManagementController.java | 5 ++-- .../rest/NsLifecycleManagementControllerTest.java | 32 ++++++++++++++++------ 3 files changed, 32 insertions(+), 10 deletions(-) (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service') diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java index 2ebf55ff7f..ae9f55e1c5 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java @@ -82,4 +82,9 @@ public class NsLifeCycleManager { return etsiSoNsLcmManagerUrlProvider.getNsLcmOpOccUri(nsLcmOpOccId); } + + public void deleteNs(final String nsInstanceId) { + logger.info("Will execute Delete Ns for nsInstanceId: {}", nsInstanceId); + jobExecutorService.runDeleteNsJob(nsInstanceId); + } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java index cfda89f3f0..78ab9e96cc 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java @@ -35,7 +35,6 @@ import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance; import org.onap.so.etsi.nfvo.ns.lcm.model.TerminateNsRequest; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.DeleteMapping; @@ -109,7 +108,9 @@ public class NsLifecycleManagementController { produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity deleteNs(@PathVariable("nsInstanceId") final String nsInstanceId) { logger.debug("Received delete NS request for nsInstanceId: {}", nsInstanceId); - return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet"); + nsLifeCycleManager.deleteNs(nsInstanceId); + logger.info("Successfully deleted NS for nsInstanceId: {}", nsInstanceId); + return ResponseEntity.noContent().build(); } /** diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java index 4b1195244c..585b0e1811 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java @@ -19,17 +19,14 @@ */ package org.onap.so.etsi.nfvo.ns.lcm.rest; -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import java.net.URISyntaxException; -import java.time.LocalDateTime; import java.util.List; import java.util.UUID; import org.junit.Before; @@ -173,11 +170,30 @@ public class NsLifecycleManagementControllerTest { } @Test - public void testCreateNs_ValidDeleteNsRequest() { - final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + UUID.randomUUID().toString(); + public void testDeleteNs_SuccessfulCase() { + final String nsInstId = UUID.randomUUID().toString(); + doNothing().when(mockedJobExecutorService).runDeleteNsJob(eq(nsInstId)); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + nsInstId; final ResponseEntity responseEntity = testRestTemplate.exchange(baseUrl, HttpMethod.DELETE, null, Void.class); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + } + + @Test + public void testDeleteNs_nsRequestProcessingExceptionThrown_returnInlineResponse400() { + final String nsInstId = UUID.randomUUID().toString(); + final String message = "Unable to process request"; + doThrow(new NsRequestProcessingException(message, new InlineResponse400().detail(message))) + .when(mockedJobExecutorService).runDeleteNsJob(eq(nsInstId)); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + nsInstId; + final ResponseEntity responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.DELETE, null, InlineResponse400.class); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); } @Test -- cgit 1.2.3-korg