aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorraviteja.karumuri <raviteja.karumuri@est.tech>2024-08-15 12:43:04 +0100
committerraviteja.karumuri <raviteja.karumuri@est.tech>2024-08-15 13:04:04 +0100
commita1d0a4a7f3eca233f76e041ad5cc3f78ff0f7a53 (patch)
treed75cc3a7a35215f77c3db8c7a51a1ce3c126a3e8
parent568a204a34bf3ba28789cee7f84eef77485e1c27 (diff)
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 <raviteja.karumuri@est.tech>
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ServiceController.java2
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java27
2 files changed, 28 insertions, 1 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 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();
@@ -977,6 +978,32 @@ class ApplicationTest {
}
@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 {
putService("service1", 2, HttpStatus.CREATED);