diff options
author | raviteja.karumuri <raviteja.karumuri@est.tech> | 2024-04-26 16:14:43 +0100 |
---|---|---|
committer | raviteja.karumuri <raviteja.karumuri@est.tech> | 2024-05-29 18:01:36 +0100 |
commit | a5eea6c8b67ede9db9b741935398e246c6095671 (patch) | |
tree | 58a0419377f93ba81c901f3285b37f952136ab0a /a1-policy-management/src/main/java/org | |
parent | d3aad19502465a7ff60d54cedbb06af301c99915 (diff) |
Unit Test cases for the V3Controller Endpoints
Issue-ID: CCSDK-4007
Change-Id: Ibc55cc660406b2129a56c0c0e565ab857cb4629b
Signed-off-by: Raviteja Karumuri <raviteja.karumuri@est.tech>
Diffstat (limited to 'a1-policy-management/src/main/java/org')
2 files changed, 11 insertions, 9 deletions
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<ResponseEntity<PolicyObjectInformation>> createPolicy(Mono<PolicyObjectInformation> policyObjectInformation, ServerWebExchange exchange) { return policyObjectInformation.flatMap(policyObjectInfo -> { @@ -90,6 +89,7 @@ public class PolicyControllerV3 implements A1PolicyManagementApi { @Override public Mono<ResponseEntity<Object>> putPolicy(String policyId, Mono<Object> 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<ResponseEntity<Object>> 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<Object>(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<ResponseEntity<Void>> 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)) |