diff options
author | raviteja.karumuri <raviteja.karumuri@est.tech> | 2024-09-02 10:46:34 +0100 |
---|---|---|
committer | RAVITEJA KARUMURI <raviteja.karumuri@est.tech> | 2024-09-04 12:38:34 +0000 |
commit | acfaa81c9975f6c67b6b7043aa598e31ba4b1f12 (patch) | |
tree | c764bfb7c997bd8cc0d8aec9b169020b0b8a6695 | |
parent | bfc1bfe8e02f6e89b6bc8b2a22f40d24d6f94666 (diff) |
Improve tests/issues found in Sonar report - A1 Oslo/NewDelhi/Montreal/London-Part 4-master
Issue-ID: CCSDK-4037
Change-Id: I8baa1d36ca50c7264f6aebcc176370f90bf06c80
Signed-off-by: Raviteja Karumuri <raviteja.karumuri@est.tech>
14 files changed, 63 insertions, 95 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java index cac03208..ba8e7a1d 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java @@ -71,7 +71,7 @@ public class OtelConfig { @PostConstruct public void checkTracingConfig() { - logger.info("Application Yaml Tracing Enabled: " + !tracingDisabled); + logger.info("Application Yaml Tracing Enabled: {}", !tracingDisabled); } public boolean isTracingEnabled() { diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientUtil.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientUtil.java index 68d9ea71..1e652219 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientUtil.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientUtil.java @@ -46,7 +46,7 @@ public class WebClientUtil { private static SpringWebfluxTelemetry springWebfluxTelemetry; - public WebClientUtil(OtelConfig otelConfig, @Autowired(required = false) SpringWebfluxTelemetry springWebfluxTelemetry) { + WebClientUtil(OtelConfig otelConfig, @Autowired(required = false) SpringWebfluxTelemetry springWebfluxTelemetry) { WebClientUtil.otelConfig = otelConfig; if (otelConfig.isTracingEnabled()) { WebClientUtil.springWebfluxTelemetry = springWebfluxTelemetry; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java index 9299ffeb..ea943a08 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java @@ -72,6 +72,7 @@ public class PolicyController implements A1PolicyManagementApi { public static final String API_NAME = "A1 Policy Management"; public static final String API_DESCRIPTION = ""; + public static final String RIC_NOT_FOUND_MSG = "Near-RT RIC not found"; public static class RejectionException extends Exception { private static final long serialVersionUID = 1L; @@ -156,7 +157,7 @@ public class PolicyController implements A1PolicyManagementApi { return policyInfo.flatMap(policyInfoValue -> { String jsonString = gson.toJson(policyInfoValue.getPolicyData()); return Mono.zip(Mono.justOrEmpty(rics.get(policyInfoValue.getRicId())) - .switchIfEmpty(Mono.error(new EntityNotFoundException("Near-RT RIC not found"))), + .switchIfEmpty(Mono.error(new EntityNotFoundException(RIC_NOT_FOUND_MSG))), Mono.justOrEmpty(policyTypes.get(policyInfoValue.getPolicytypeId())) .switchIfEmpty(Mono.error(new EntityNotFoundException("policy type not found")))) .flatMap(tuple -> { @@ -256,7 +257,7 @@ public class PolicyController implements A1PolicyManagementApi { throw new EntityNotFoundException("Policy type identity not found"); } if ((ricId != null && this.rics.get(ricId) == null)) { - throw new EntityNotFoundException("Near-RT RIC not found"); + throw new EntityNotFoundException(RIC_NOT_FOUND_MSG); } Collection<Policy> filtered = policies.filterPolicies(policyTypeId, ricId, serviceId, typeName); @@ -275,7 +276,7 @@ public class PolicyController implements A1PolicyManagementApi { throw new EntityNotFoundException("Policy type not found"); } if ((ricId != null && this.rics.get(ricId) == null)) { - throw new EntityNotFoundException("Near-RT RIC not found"); + throw new EntityNotFoundException(RIC_NOT_FOUND_MSG); } Collection<Policy> filtered = policies.filterPolicies(policyTypeId, ricId, serviceId, typeName); @@ -316,11 +317,8 @@ public class PolicyController implements A1PolicyManagementApi { private PolicyInfo toPolicyInfo(Policy policy) { try { - PolicyInfo policyInfo = new PolicyInfo() - .policyId(policy.getId()) - .policyData(objectMapper.readTree(policy.getJson())) - .ricId(policy.getRic().id()) - .policytypeId(policy.getType().getId()) + PolicyInfo policyInfo = new PolicyInfo(policy.getRic().id(), policy.getId(), + objectMapper.readTree(policy.getJson()), policy.getType().getId()) .serviceId(policy.getOwnerServiceId()) ._transient(policy.isTransient()); if (!policy.getStatusNotificationUri().isEmpty()) { 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 08aa7c7b..1ff85773 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 @@ -82,7 +82,7 @@ public class PolicyControllerV3 implements A1PolicyManagementApi { @Override public Mono<ResponseEntity<Flux<PolicyTypeInformation>>> getPolicyTypes(String nearRtRicId, String typeName, String compatibleWithVersion, String accept, ServerWebExchange exchange) throws Exception { - return policyService.getPolicyTypesService(nearRtRicId, typeName, compatibleWithVersion, exchange) + return policyService.getPolicyTypesService(nearRtRicId, typeName, compatibleWithVersion) .doOnError(errorHandlingService::handleError); } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/AuthorizationService.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/AuthorizationService.java index af6f0abe..4d40d6d3 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/AuthorizationService.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/AuthorizationService.java @@ -37,6 +37,6 @@ public class AuthorizationService { public Mono<Policy> authCheck (ServerWebExchange serverWebExchange, Policy policy, AccessType accessType){ return authorization.doAccessControl(serverWebExchange.getRequest().getHeaders().toSingleValueMap(), - policy, AccessType.WRITE); + policy, accessType); } } 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 868a336f..6d59d386 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 @@ -63,7 +63,7 @@ public class PolicyService { public Mono<ResponseEntity<PolicyObjectInformation>> createPolicyService (PolicyObjectInformation policyObjectInfo, ServerWebExchange serverWebExchange) { try { - if (!helper.jsonSchemaValidation(gson.toJson(policyObjectInfo.getPolicyObject(), Map.class))) + if (Boolean.FALSE.equals(helper.jsonSchemaValidation(gson.toJson(policyObjectInfo.getPolicyObject(), Map.class)))) return Mono.error(new ServiceException("Schema validation failed", HttpStatus.BAD_REQUEST)); Ric ric = rics.getRic(policyObjectInfo.getNearRtRicId()); PolicyType policyType = policyTypes.getType(policyObjectInfo.getPolicyTypeId()); @@ -117,8 +117,7 @@ public class PolicyService { } public Mono<ResponseEntity<Flux<PolicyTypeInformation>>> getPolicyTypesService(String nearRtRicId, String typeName, - String compatibleWithVersion, - ServerWebExchange webExchange) throws Exception { + String compatibleWithVersion) throws ServiceException { if (compatibleWithVersion != null && typeName == null) { throw new ServiceException("Parameter " + Consts.COMPATIBLE_WITH_VERSION_PARAM + " can only be used when " + Consts.TYPE_NAME_PARAM + " is given", HttpStatus.BAD_REQUEST); @@ -126,17 +125,17 @@ public class PolicyService { Collection<PolicyTypeInformation> listOfPolicyTypes = new ArrayList<>(); if (nearRtRicId == null || nearRtRicId.isEmpty() || nearRtRicId.isBlank()) { for(Ric ric : rics.getRics()) { - Collection<PolicyType> policyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName, + Collection<PolicyType> filteredPolicyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName, compatibleWithVersion); - listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(policyTypes, ric)); + listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(filteredPolicyTypes, ric)); } } else { Ric ric = rics.get(nearRtRicId); if (ric == null) throw new EntityNotFoundException("Near-RT RIC not Found using ID: " +nearRtRicId); - Collection<PolicyType> policyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName, + Collection<PolicyType> filteredPolicyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName, compatibleWithVersion); - listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(policyTypes, ric)); + listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(filteredPolicyTypes, ric)); } return Mono.just(new ResponseEntity<>(Flux.fromIterable(listOfPolicyTypes), HttpStatus.OK)); } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/Helper.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/Helper.java index 0cb91353..405d43a3 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/Helper.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/Helper.java @@ -99,7 +99,7 @@ public class Helper { } public Boolean jsonSchemaValidation(Object jsonObject) { - String jsonString = toJson(jsonObject); + toJson(jsonObject); return true; } @@ -122,7 +122,7 @@ public class Helper { } public String buildURI(String policyId, ServerWebExchange serverWebExchange) { - return UriComponentsBuilder.fromHttpRequest(serverWebExchange.getRequest()) + return UriComponentsBuilder.fromUri(serverWebExchange.getRequest().getURI()) .path("/{id}") .buildAndExpand(policyId) .toString(); 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 3a7bc799..5ed8642a 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 @@ -231,7 +231,7 @@ class ApplicationTest { @Test @DisplayName("test ZZ Actuator") - void testZZActuator() throws Exception { + void testZZActuator() { // The test must be run last, hence the "ZZ" in the name. All succeeding tests // will fail. AsyncRestClient client = restClient(baseUrl(), false); @@ -479,12 +479,8 @@ class ApplicationTest { private String putPolicyBody(String serviceName, String ricId, String policyTypeName, String policyInstanceId, boolean isTransient, String statusNotificationUri) throws JsonProcessingException { - PolicyInfo policyInfo = new PolicyInfo(); - policyInfo.setPolicyId(policyInstanceId); - policyInfo.setPolicytypeId(policyTypeName); - policyInfo.setRicId(ricId); + PolicyInfo policyInfo = new PolicyInfo(ricId, policyInstanceId, jsonString(), policyTypeName); policyInfo.setServiceId(serviceName); - policyInfo.setPolicyData(jsonString()); policyInfo.setTransient(isTransient); policyInfo.setStatusNotificationUri(statusNotificationUri); return objectMapper.writeValueAsString(policyInfo); @@ -722,7 +718,6 @@ class ApplicationTest { Policy policy = addPolicy("id", "typeName", "service1", "ric1"); { String response = restClient().get(url).block(); - PolicyInfo policyInfo = objectMapper.readValue(response, PolicyInfo.class); String expectedResponse = "{\"ric_id\":\"ric1\",\"service_id\":\"service1\",\"policy_id\":\"id\",\"policy_data\":{\"servingCellNrcgi\":\"1\"},\"status_notification_uri\":\"/policy-status?id=XXX\",\"policytype_id\":\"typeName\",\"transient\":false}"; assertEquals(objectMapper.readTree(expectedResponse), objectMapper.readTree(response)); } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java index a42d034a..3c7051d5 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java @@ -43,7 +43,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.utils.MockA1Client; import org.onap.ccsdk.oran.a1policymanagementservice.utils.MockA1ClientFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; /** @@ -157,12 +156,8 @@ class ConcurrencyTestRunnable implements Runnable { private String putPolicyBody(String serviceName, String ricId, String policyTypeName, String policyInstanceId, boolean isTransient) throws JsonProcessingException { - PolicyInfo policyInfo = new PolicyInfo(); - policyInfo.setPolicyId(policyInstanceId); - policyInfo.setPolicytypeId(policyTypeName); - policyInfo.setRicId(ricId); + PolicyInfo policyInfo = new PolicyInfo(ricId, policyInstanceId, policyData(), policyTypeName); policyInfo.setServiceId(serviceName); - policyInfo.setPolicyData(policyData()); policyInfo.setStatusNotificationUri("/status"); policyInfo.setTransient(isTransient); return objectMapper.writeValueAsString(policyInfo); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java index 40990f62..1f0ea5d0 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java @@ -120,7 +120,7 @@ class ConfigurationControllerV3Test { } @Test - public void testHealthCheck() { + void testHealthCheck() { Mono<ResponseEntity<String>> responseHealthCheckMono = testHelper.restClientV3().getForEntity("/status"); testHelper.testSuccessResponse(responseHealthCheckMono, HttpStatus.OK, responseBody -> responseBody.contains("status")); } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java index 211a9a39..14604542 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3Test.java @@ -230,7 +230,7 @@ class PolicyControllerV3Test { } @Test - public void testGetPolicyTypesNoRicFound() throws Exception{ + void testGetPolicyTypesNoRicFound() throws Exception{ String policyTypeName = "type1_1.2.3"; String nonRtRicId = "ricOne"; testHelper.addPolicyType(policyTypeName, nonRtRicId); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3Test.java index 5f97df0e..63b61665 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3Test.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3Test.java @@ -103,7 +103,7 @@ class RicRepositoryControllerV3Test { } @Test - public void testGetRic() throws IOException { + void testGetRic() throws IOException { testHelper.addPolicyType("1", "ricAdded"); Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().getForEntity("/rics/ric?ricId=ricAdded"); testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody @@ -111,7 +111,7 @@ class RicRepositoryControllerV3Test { } @Test - public void testGetRics() throws IOException { + void testGetRics() throws IOException { testHelper.addPolicyType("1", "ricAddedOne"); testHelper.addPolicyType("2", "ricAddedTwo"); Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().getForEntity("/rics"); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3Test.java index bfc0b683..426cf6ed 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3Test.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3Test.java @@ -109,7 +109,7 @@ class ServiceControllerV3Test { } @Test - public void testPutService() { + void testPutService() { ServiceRegistrationInfo serviceRegistrationInfo = new ServiceRegistrationInfo("serviceId"); serviceRegistrationInfo.callbackUrl("http://callback.com/").keepAliveIntervalSeconds(10L); Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3() @@ -118,7 +118,7 @@ class ServiceControllerV3Test { } @Test - public void testGetService() { + void testGetService() { services.put(new Service("newServiceId", Duration.ofSeconds(10L), "http://callback.com/")); Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().getForEntity("/services"); testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBoy -> responseBoy @@ -126,14 +126,14 @@ class ServiceControllerV3Test { } @Test - public void testDeleteService() { + void testDeleteService() { services.put(new Service("newServiceId", Duration.ofSeconds(10L), "http://callback.com/")); Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().deleteForEntity("/services/newServiceId"); testHelper.testSuccessResponse(responseEntityMono, HttpStatus.NO_CONTENT, responseBody -> services.size() == 0); } @Test - public void testKeepAliveService() { + void testKeepAliveService() { services.put(new Service("newServiceId", Duration.ofSeconds(10L), "http://callback.com/")); Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().putForEntity("/services/newServiceId/keepalive", ""); testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> services.size() == 1); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyServiceTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyServiceTest.java index 7b550e3a..2e483338 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyServiceTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyServiceTest.java @@ -23,6 +23,8 @@ package org.onap.ccsdk.oran.a1policymanagementservice.service.v3; import com.google.gson.Gson; import com.google.gson.JsonParser; import org.junit.jupiter.api.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.mockito.Mockito; import org.onap.ccsdk.oran.a1policymanagementservice.config.TestConfig; import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.EntityNotFoundException; @@ -70,7 +72,7 @@ import static org.mockito.Mockito.when; @TestPropertySource(properties = { // "app.vardata-directory=/tmp/pmstestv3", // }) -public class PolicyServiceTest { +class PolicyServiceTest { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); @@ -114,7 +116,7 @@ public class PolicyServiceTest { } @Test - public void testPolicyAlreadyCreatedTrue() throws Exception{ + void testPolicyAlreadyCreatedTrue() throws Exception{ String policyTypeName = "uri_type_123"; String nonRtRicId = "Ric_347"; @@ -130,7 +132,7 @@ public class PolicyServiceTest { } @Test - public void testPolicyNotAuthorizedFail() throws IOException { + void testPolicyNotAuthorizedFail() throws IOException { String policyTypeName = "uri_type_123"; String nonRtRicId = "Ric_347"; @@ -144,7 +146,7 @@ public class PolicyServiceTest { } @Test - public void testDeletePolicySuccess() throws Exception { + void testDeletePolicySuccess() throws Exception { String policyTypeName = "uri_type_123"; String nonRtRicId = "Ric_347"; @@ -161,14 +163,14 @@ public class PolicyServiceTest { } @Test - public void testDeletePolicyThrowsException() throws Exception { + void testDeletePolicyThrowsException() { ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class); assertThrows(EntityNotFoundException.class, () -> policyService.deletePolicyService("dummyPolicyID", serverWebExchange)); } @Test - public void testPutPolicy() throws Exception { + void testPutPolicy() throws Exception { String policyTypeName = "uri_type_123"; String nonRtRicId = "Ric_347"; @@ -199,79 +201,58 @@ public class PolicyServiceTest { }); } - @Test - public void testGetPolicyTypes() throws Exception { + @ParameterizedTest + @CsvSource({ + ", , ", + ", uri_type, ", + "Ric_347, uri_type," + }) + @DisplayName("testGetPolicyTypes & testGetPolicyTypesMatchedTypeName & testGetPolicyTypesMatchedTypeNameWithRic") + void testGetPolicyTypes(String nearRtRicID, String typeName, String compatibleWithVersion) throws Exception { String policyTypeName = "uri_type_123"; String nonRtRicId = "Ric_347"; testHelper.addPolicyType(policyTypeName, nonRtRicId); - ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class); when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod(); - Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService(null, null,null, serverWebExchange); + Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = + policyService.getPolicyTypesService(nearRtRicID, typeName, compatibleWithVersion); testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 1); } @Test - public void testGetPolicyTypesEmpty() throws Exception { - ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class); + void testGetPolicyTypesEmpty() throws Exception { when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod(); - Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService(null, null, null, serverWebExchange); - testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 0); + Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService(null, null, null); + testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty()); } @Test - public void testGetPolicyTypesNoRic() { - ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class); - assertThrows(EntityNotFoundException.class, () -> policyService.getPolicyTypesService("NoRic", "","", serverWebExchange)); + void testGetPolicyTypesNoRic() { + assertThrows(EntityNotFoundException.class, () -> policyService.getPolicyTypesService("NoRic", "","")); } @Test - public void testGetPolicyTypesNoMatchedTypeName() throws Exception { + void testGetPolicyTypesNoMatchedTypeName() throws Exception { String policyTypeName = "uri_type_123"; String nonRtRicId = "Ric_347"; testHelper.addPolicyType(policyTypeName, nonRtRicId); when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod(); - ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class); - Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService("", "noTypeName", null, serverWebExchange); + Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService("", "noTypeName", null); testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty()); } @Test - public void testGetPolicyTypesNoMatchedTypeNameWithRic() throws Exception { + void testGetPolicyTypesNoMatchedTypeNameWithRic() throws Exception { String policyTypeName = "uri_type_123"; String nonRtRicId = "Ric_347"; testHelper.addPolicyType(policyTypeName, nonRtRicId); when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod(); - ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class); - Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService("Ric_347", "noTypeName", null, serverWebExchange); + Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService("Ric_347", "noTypeName", null); testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().findAny().isEmpty()); } @Test - public void testGetPolicyTypesMatchedTypeName() throws Exception { - String policyTypeName = "uri_type_123"; - String nonRtRicId = "Ric_347"; - testHelper.addPolicyType(policyTypeName, nonRtRicId); - when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod(); - ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class); - Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService.getPolicyTypesService(null, "uri_type", null, serverWebExchange); - testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 1); - } - - @Test - public void testGetPolicyTypesMatchedTypeNameWithRic() throws Exception { - String policyTypeName = "uri_type_123"; - String nonRtRicId = "Ric_347"; - testHelper.addPolicyType(policyTypeName, nonRtRicId); - ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class); - when(helper.toPolicyTypeInfoCollection(any(), any())).thenCallRealMethod(); - Mono<ResponseEntity<Flux<PolicyTypeInformation>>> responseEntityMono = policyService - .getPolicyTypesService("Ric_347", "uri_type", null, serverWebExchange); - testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody.toStream().count() == 1); - } - - @Test - public void testGetPolicyIds() throws Exception { + void testGetPolicyIds() throws Exception { String policyTypeName = "uri_type_123"; String nonRtRicId = "Ric_347"; testHelper.addPolicyType(policyTypeName, nonRtRicId); @@ -289,7 +270,7 @@ public class PolicyServiceTest { } @Test - public void testGetPolicyIdsNoRic() throws Exception { + void testGetPolicyIdsNoRic() throws Exception { testHelper.addPolicyType("uri_type_123", "Ric_347"); ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class); EntityNotFoundException exception = assertThrows(EntityNotFoundException.class, () -> policyService @@ -298,7 +279,7 @@ public class PolicyServiceTest { } @Test - public void testGetPolicyIdsNoPolicyType() { + void testGetPolicyIdsNoPolicyType() { ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class); EntityNotFoundException exception = assertThrows(EntityNotFoundException.class, () -> policyService .getPolicyIdsService("noPolicyType", "noRic", "", "", serverWebExchange)); @@ -306,7 +287,7 @@ public class PolicyServiceTest { } @Test - public void testGetPolicyService() throws Exception { + void testGetPolicyService() throws Exception { String policyTypeName = "uri_type_123"; String nonRtRicId = "Ric_347"; testHelper.addPolicyType(policyTypeName, nonRtRicId); @@ -323,7 +304,7 @@ public class PolicyServiceTest { } @Test - public void testGetPolicyServiceNoPolicy() throws Exception { + void testGetPolicyServiceNoPolicy() { ServerWebExchange serverWebExchange = Mockito.mock(DefaultServerWebExchange.class); EntityNotFoundException exception = assertThrows(EntityNotFoundException.class, () -> policyService .getPolicyService("NoPolicy", serverWebExchange)); @@ -331,7 +312,7 @@ public class PolicyServiceTest { } @Test - public void testGetPolicyTypeService() throws Exception { + void testGetPolicyTypeService() throws Exception { String policyTypeName = "uri_type_123"; String nonRtRicId = "Ric_347"; PolicyType addedPolicyType = testHelper.addPolicyType(policyTypeName, nonRtRicId); @@ -344,7 +325,7 @@ public class PolicyServiceTest { } @Test - public void testGetPolicyTypeServiceNoPolicyType() { + void testGetPolicyTypeServiceNoPolicyType() { EntityNotFoundException exception = assertThrows(EntityNotFoundException.class, () -> policyService .getPolicyTypeDefinitionService("NoPolicyType")); assertEquals("PolicyType not found with ID: NoPolicyType", exception.getMessage()); |