From 987ca55ce327ab3f29c6e1f1cef2366cb9ba4c2b Mon Sep 17 00:00:00 2001 From: "raviteja.karumuri" Date: Thu, 15 Aug 2024 12:43:04 +0100 Subject: [PATCH] Improving code-coverage for the Handle non transient policy deletion bug fix - london Issue-ID: CCSDK-4048 Change-Id: I8519f8c2e221d817ee54ed8ef3a8bb894d6bb87e Signed-off-by: Raviteja Karumuri --- .../controllers/v2/ServiceController.java | 2 +- .../controllers/v2/ApplicationTest.java | 27 ++++++++++++++++++++++ docs/consumedapis/consumedapis.rst | 4 ++-- docs/humaninterfaces/humaninterfaces.rst | 2 +- 4 files changed, 31 insertions(+), 4 deletions(-) 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 4bf543ed..84c8cb3c 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 @@ -179,7 +179,7 @@ public class ServiceController { Service service = removeService(serviceId); removePolicies(service, headers); return 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.create(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 a42bd65e..c1525ffa 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 @@ -959,6 +959,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(); @@ -979,6 +980,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 { diff --git a/docs/consumedapis/consumedapis.rst b/docs/consumedapis/consumedapis.rst index 76061348..8fbde338 100755 --- a/docs/consumedapis/consumedapis.rst +++ b/docs/consumedapis/consumedapis.rst @@ -17,6 +17,6 @@ The *A1 Interface - Application Protocol Specification (A1-AP)* describes this i The **London** ONAP A1 Policy functions implement the *A1 Policy* (*A1-P*) parts of A1-AP, supporting versions *v1.1*, *v2.0* and *v3.0*. -An opensource implementation of a `near-RT RIC `_ is available from the `O-RAN Software Community `_. It supports a pre-spec version of the A1-AP. The ONAP A1 Policy functions described here also supports this A1 version (*A1-OSC*). +An opensource implementation of a `near-RT RIC `_ is available from the `O-RAN Software Community `_. It supports a pre-spec version of the A1-AP. The ONAP A1 Policy functions described here also supports this A1 version (*A1-OSC*). -An opensource implementation of an `A1 Simulator `_ is also available from the `O-RAN Software Community `_. It supports all versions of A1-AP. +An opensource implementation of an `A1 Simulator `_ is also available from the `O-RAN Software Community `_. It supports all versions of A1-AP. \ No newline at end of file diff --git a/docs/humaninterfaces/humaninterfaces.rst b/docs/humaninterfaces/humaninterfaces.rst index be271b43..64aebd00 100644 --- a/docs/humaninterfaces/humaninterfaces.rst +++ b/docs/humaninterfaces/humaninterfaces.rst @@ -6,6 +6,6 @@ Human Interfaces ================ The NON-RT RIC Control Panel in O-RAN-SC can be used to interact with the Policy Management Service. -See `NON-RT RIC Control Panel repo `_ from the `O-RAN-SC NONRTRIC Project `_. +See `NON-RT RIC Control Panel repo `_ from the `O-RAN-SC NONRTRIC Project `_. Any "REST Client" application may be used (Postman, ...) to interact with the Policy Management Service application via the :ref:`pms_api` -- 2.16.6