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 15:29:43 +0100
commite1870f96ec0a0e731f82e0c158ae970409112046 (patch)
treeef1cefce8cb313e1fe02c091700a1fa538e7e426
parent4700a7873253828e24f0dc18866be308f636064d (diff)
Improving code-coverage for the Handle non transient policy deletion bug fix - montreal
Issue-ID: CCSDK-4049 Change-Id: Ia47d9ea46bc87d491fe9976a52b81764910aef5b 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 58b87c63..4d5a9ba3 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 2ff44169..daa3a1d8 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
@@ -964,6 +964,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();
@@ -985,6 +986,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);