From a5eea6c8b67ede9db9b741935398e246c6095671 Mon Sep 17 00:00:00 2001 From: "raviteja.karumuri" Date: Fri, 26 Apr 2024 16:14:43 +0100 Subject: Unit Test cases for the V3Controller Endpoints Issue-ID: CCSDK-4007 Change-Id: Ibc55cc660406b2129a56c0c0e565ab857cb4629b Signed-off-by: Raviteja Karumuri --- .../controllers/v3/PolicyControllerV3.java | 10 +++++----- .../a1policymanagementservice/service/v3/PolicyService.java | 10 ++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'a1-policy-management/src/main/java/org') diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3.java index 83d3ecc8..edc3be12 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3.java @@ -27,8 +27,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.PolicyContro import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyInformation; import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyObjectInformation; import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyTypeInformation; -import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType; -import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric; +import org.onap.ccsdk.oran.a1policymanagementservice.service.v3.ErrorHandlingService; import org.onap.ccsdk.oran.a1policymanagementservice.service.v3.PolicyService; import org.onap.ccsdk.oran.a1policymanagementservice.util.v3.Helper; import org.springframework.beans.factory.annotation.Autowired; @@ -53,9 +52,9 @@ public class PolicyControllerV3 implements A1PolicyManagementApi { @Autowired private Helper helper; - private PolicyType policyType; + @Autowired + private ErrorHandlingService errorHandlingService; - private Ric ric; @Override public Mono> createPolicy(Mono policyObjectInformation, ServerWebExchange exchange) { return policyObjectInformation.flatMap(policyObjectInfo -> { @@ -90,6 +89,7 @@ public class PolicyControllerV3 implements A1PolicyManagementApi { @Override public Mono> putPolicy(String policyId, Mono body, ServerWebExchange exchange) throws Exception { - return body.flatMap(payload -> policyService.putPolicyService(policyId, payload, exchange)); + return body.flatMap(payload -> policyService.putPolicyService(policyId, payload, exchange)) + .doOnError(error -> errorHandlingService.handleError(error)); } } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyService.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyService.java index 66b5ae0c..6cd9b8d3 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyService.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyService.java @@ -112,17 +112,19 @@ public class PolicyService { } public Mono> putPolicyService(String policyId, Object body, ServerWebExchange exchange) { - try { Policy existingPolicy = policies.getPolicy(policyId); PolicyObjectInformation pos = new PolicyObjectInformation(existingPolicy.getRic().getConfig().getRicId(), body, existingPolicy.getType().getId()); Policy updatedPolicy = helper.buildPolicy(pos, existingPolicy.getType(), existingPolicy.getRic(), policyId); Ric ric = existingPolicy.getRic(); - ric.getLock().lock(Lock.LockType.SHARED, "updatePolicy") + return authorizationService.authCheck(exchange, updatedPolicy, AccessType.WRITE) + .doOnError(error -> errorHandlingService.handleError(error)) + .flatMap(policy -> ric.getLock().lock(Lock.LockType.SHARED, "updatePolicy")) + .doOnError(error -> errorHandlingService.handleError(error)) .flatMap(grant -> postPolicy(updatedPolicy, grant)) + .map(header -> new ResponseEntity(policies.get(updatedPolicy.getId()).getJson(), HttpStatus.OK)) .doOnError(error -> errorHandlingService.handleError(error)); - return Mono.just(new ResponseEntity<>(policies.getPolicy(policyId), HttpStatus.OK)); } catch(Exception ex) { return Mono.error(ex); } @@ -198,12 +200,12 @@ public class PolicyService { } private Mono> deletePolicy(Policy policy, Lock.Grant grant) { - System.out.println(); return helper.checkRicStateIdle(policy.getRic()) .doOnError(error -> errorHandlingService.handleError(error)) .flatMap(ric -> helper.checkSupportedType(ric, policy.getType())) .doOnError(error -> errorHandlingService.handleError(error)) .flatMap(ric -> a1ClientFactory.createA1Client(ric)) + .doOnError(error -> errorHandlingService.handleError(error)) .flatMap(a1Client -> a1Client.deletePolicy(policy)) .doOnError(error -> errorHandlingService.handleError(error)) .doOnNext(policyString -> policies.remove(policy)) -- cgit 1.2.3-korg