diff options
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); |