From: raviteja.karumuri Date: Thu, 15 Aug 2024 11:43:04 +0000 (+0100) Subject: Improving code-coverage for the Handle non transient policy deletion bug fix - master X-Git-Tag: 1.8.0~16 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=a1d0a4a7f3eca233f76e041ad5cc3f78ff0f7a53;p=ccsdk%2Foran.git Improving code-coverage for the Handle non transient policy deletion bug fix - master Issue-ID: CCSDK-4047 Change-Id: Ia9afe1e566d8d76eb56eb49f3184c94c6915e8df Signed-off-by: Raviteja Karumuri --- diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceController.java index 09dfe446..1b885781 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceController.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceController.java @@ -138,7 +138,7 @@ public class ServiceController implements ServiceRegistryAndSupervisionApi { Service service = removeService(serviceId); removePolicies(service, exchange); return Mono.just(new ResponseEntity<>(HttpStatus.NO_CONTENT)); - } catch (ServiceException | NullPointerException e) { + } catch (ServiceException e) { logger.warn("Exception caught during service deletion while deleting service {}: {}", serviceId, e.getMessage()); return ErrorResponse.createMono(e, HttpStatus.NOT_FOUND); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java index 69ee12ba..0519c2d5 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java @@ -956,6 +956,7 @@ class ApplicationTest { assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); // DELETE service + addPolicy("id1", "type1", serviceName); assertThat(services.size()).isEqualTo(1); url = "/services/" + serviceName; restClient().delete(url).block(); @@ -976,6 +977,32 @@ class ApplicationTest { testErrorCode(restClient().get("/services?service_id=XXX"), HttpStatus.NOT_FOUND); } + @Test + @DisplayName("test delete Service with no authorization") + void testDeleteServiceWithNoAuth() throws Exception { + // PUT service + String serviceName = "ac.dc"; + putService(serviceName, 0, HttpStatus.CREATED); + + // No Authorization to Delete + this.applicationConfig + .setAuthProviderUrl(baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL_REJECT); + addPolicy("id1", "type1", serviceName); + assertThat(services.size()).isEqualTo(1); + String url = "/services/" + serviceName; + restClient().delete(url).block(); + assertThat(services.size()).isZero(); + assertThat(policies.size()).isEqualTo(1); + testErrorCode(restClient().get("/policies/id1"), HttpStatus.UNAUTHORIZED); + } + + @Test + @DisplayName("test delete Service with no service") + void testDeleteServiceWithNoService() { + String url = "/services/" + "NoService"; + testErrorCode(restClient().delete(url), HttpStatus.NOT_FOUND); + } + @Test @DisplayName("test Service Supervision") void testServiceSupervision() throws Exception {