From c7f757e98066775ed2fdeb67f3d31777e8430624 Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Mon, 28 Nov 2022 09:40:36 +0100 Subject: A1-PMS, make service id optional in PUT Policy Improved API documentation. Fixed a bug that lead to that a policy could be connected to several services if the service_id was changed. Change-Id: I211f5db32747fc912b7ba85bfbc15ce50ee725dd Issue-ID: CCSDK-3819 Signed-off-by: PatrikBuhr --- .../controllers/v2/ApplicationTest.java | 48 ++++++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'a1-policy-management/src/test') 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 76838bb8..bec55735 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 @@ -434,7 +434,7 @@ class ApplicationTest { } private String putPolicyBody(String serviceName, String ricId, String policyTypeName, String policyInstanceId, - boolean isTransient) { + boolean isTransient, String statusNotificationUri) { PolicyInfo info = new PolicyInfo(); info.policyId = policyInstanceId; info.policyTypeId = policyTypeName; @@ -445,12 +445,12 @@ class ApplicationTest { if (isTransient) { info.isTransient = isTransient; } - info.statusNotificationUri = "statusNotificationUri"; + info.statusNotificationUri = statusNotificationUri; return gson.toJson(info); } private String putPolicyBody(String serviceName, String ricId, String policyTypeName, String policyInstanceId) { - return putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId, false); + return putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId, false, "statusUri"); } @Test @@ -465,7 +465,7 @@ class ApplicationTest { // PUT a transient policy String url = "/policies"; - String policyBody = putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId, true); + String policyBody = putPolicyBody(serviceName, ricId, policyTypeName, policyInstanceId, true, "statusNotif"); this.rics.getRic(ricId).setState(Ric.RicState.AVAILABLE); restClient().put(url, policyBody).block(); @@ -506,6 +506,27 @@ class ApplicationTest { this.rics.getRic(ricId).setState(Ric.RicState.AVAILABLE); } + @Test + void testPutPolicy_NoServiceNoStatusUri() throws Exception { + String ricId = "ric.1"; + String policyTypeName = "type1_1.2.3"; + String policyInstanceId = "instance_1.2.3"; + + addPolicyType(policyTypeName, ricId); + + // PUT a transient policy + String url = "/policies"; + String policyBody = putPolicyBody(null, ricId, policyTypeName, policyInstanceId, true, null); + this.rics.getRic(ricId).setState(Ric.RicState.AVAILABLE); + + restClient().put(url, policyBody).block(); + + Policy policy = policies.getPolicy(policyInstanceId); + assertThat(policy).isNotNull(); + assertThat(policy.getOwnerServiceId()).isBlank(); + assertThat(policy.getStatusNotificationUri()).isBlank(); + } + @Test /** * Test that HttpStatus and body from failing REST call to A1 is passed on to @@ -553,6 +574,25 @@ class ApplicationTest { assertThat(policyInfo.policyTypeId).isEmpty(); } + @Test + void testUpdateService() throws Exception { + this.addRic("ric1"); + this.addPolicy("p", "type1", "", "ric1"); + + String url = "/policies?service_id="; + String resp = restClient().get(url).block(); + assertThat(resp).contains("[\"p\"]"); + + this.addPolicy("p", "type1", "service", "ric1"); + url = "/policies?service_id="; + resp = restClient().get(url).block(); + assertThat(resp).contains("[]"); + + url = "/policies?service_id=service"; + resp = restClient().get(url).block(); + assertThat(resp).contains("[\"p\"]"); + } + @Test void testRefuseToUpdatePolicy() throws Exception { // Test that only the json can be changed for a already created policy -- cgit 1.2.3-korg