diff options
author | lapentafd <francesco.lapenta@est.tech> | 2024-08-29 12:45:10 +0100 |
---|---|---|
committer | Francesco Davide Lapenta <francesco.lapenta@est.tech> | 2024-08-30 10:35:16 +0000 |
commit | 05b965436624e2f44873bc11e8ab534220c68e2a (patch) | |
tree | cdfa46fcb3d4e9e538139e3a52135fdc2280be02 /a1-policy-management/src | |
parent | 8458aa547f5bc3415b4f337935410a5ff19299e8 (diff) |
Update newdelhi branch HEAD
Select&squash recent updates & fixes from master branch, adapted for new-delhi branch. Including:
https://gerrit.onap.org/r/c/ccsdk/oran/+/138693
Set serviceId in v2 policy_info to optional and blank by default - master
https://gerrit.onap.org/r/c/ccsdk/oran/+/138734
new onap logo
https://gerrit.onap.org/r/c/ccsdk/oran/+/138762
Improving code-coverage for the Handle non transient policy deletion bug fix - master
https://gerrit.onap.org/r/c/ccsdk/oran/+/138788
Enable springboot test for AsyncRestClientTest
https://gerrit.onap.org/r/c/ccsdk/oran/+/138787
Re-arrange application properties
*PARTIAL
https://gerrit.onap.org/r/c/ccsdk/oran/+/138772
Improve tests/issues found in Sonar report - A1 Oslo-Part2
https://gerrit.onap.org/r/c/ccsdk/oran/+/138827
Dependecy update in a1pms using spring parent 3.3.2
https://gerrit.onap.org/r/c/ccsdk/oran/+/138862
Improve tests/issues found in Sonar report - A1 Oslo/NewDelhi/Montreal/London-Part3-master
Issue-ID: CCSDK-3968
Change-Id: I40f7585e9416f03c8bec2b00d57dadb05bc624ca
Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'a1-policy-management/src')
37 files changed, 455 insertions, 295 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/Application.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/Application.java index 714fd2e4..1791222f 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/Application.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/Application.java @@ -25,7 +25,6 @@ import java.lang.invoke.MethodHandles; import org.onap.ccsdk.oran.a1policymanagementservice.tasks.RefreshConfigTask; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1AdapterJsonHelper.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1AdapterJsonHelper.java index ab93ea3e..66d32110 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1AdapterJsonHelper.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1AdapterJsonHelper.java @@ -92,26 +92,4 @@ class A1AdapterJsonHelper { return Mono.error(ex); } } - - public static Mono<String> getValueFromResponse(String response, String key) { - return getOutput(response) // - .map(responseParams -> { - if (!responseParams.has(key)) { - return ""; - } - return responseParams.get(key).toString(); - }); - } - - public static Mono<String> extractPolicySchema(String inputString) { - try { - JSONObject jsonObject = new JSONObject(inputString); - JSONObject schemaObject = jsonObject.getJSONObject("policySchema"); - String schemaString = schemaObject.toString(); - return Mono.just(schemaString); - } catch (Exception ex) { // invalid json - logger.debug("Invalid json {}", ex.getMessage()); - return Mono.error(ex); - } - } } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java index b5c10bf6..947c50db 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactory.java @@ -21,20 +21,18 @@ package org.onap.ccsdk.oran.a1policymanagementservice.clients; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Constructor; - import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1Client.A1ProtocolType; import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig; -import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ControllerConfig; import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig; import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException; import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import reactor.core.publisher.Mono; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Constructor; + /** * Factory for A1 clients that supports four different protocol versions of the * A1 api. @@ -43,12 +41,9 @@ public class A1ClientFactory { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private final ApplicationConfig appConfig; - private final AsyncRestClientFactory restClientFactory; public A1ClientFactory(ApplicationConfig appConfig, SecurityContext securityContext) { - this.appConfig = appConfig; this.restClientFactory = new AsyncRestClientFactory(appConfig.getWebClientConfig(), securityContext); } @@ -95,28 +90,19 @@ public class A1ClientFactory { } } - private ControllerConfig getControllerConfig(Ric ric) throws ServiceException { - ControllerConfig controllerConfig = ric.getConfig().getControllerConfig(); - if (controllerConfig == null) { - ric.setProtocolVersion(A1ProtocolType.UNKNOWN); - throw new ServiceException("No controller configured for Near-RT RIC: " + ric.id()); - } - return controllerConfig; - } - private A1Client createCustomAdapter(Ric ric) throws ServiceException { try { if (ric.getConfig().getCustomAdapterClass() != null && !ric.getConfig().getCustomAdapterClass().isEmpty()) { Class<?> clazz = Class.forName(ric.getConfig().getCustomAdapterClass()); if (A1Client.class.isAssignableFrom(clazz)) { Constructor<?> constructor = clazz.getConstructor(RicConfig.class, AsyncRestClientFactory.class); - logger.debug("A1Client (" + clazz.getTypeName() + ") being created for ric: {}", - ric.getConfig().getRicId()); + logger.debug("A1Client \"{}\" being created for ric: {}", + clazz.getTypeName(), ric.getConfig().getRicId()); return (A1Client) constructor.newInstance(ric.getConfig(), this.restClientFactory); } else if (A1Client.Factory.class.isAssignableFrom(clazz)) { A1Client.Factory factory = (A1Client.Factory) clazz.getDeclaredConstructor().newInstance(); - logger.debug("A1Client (" + clazz.getTypeName() + ") factory creating client for ric: {}", - ric.getConfig().getRicId()); + logger.debug("A1Client \"{}\" factory creating client for ric: {}", + clazz.getTypeName(), ric.getConfig().getRicId()); return factory.create(ric.getConfig(), this.restClientFactory); } else { throw new ServiceException("The custom class must either implement A1Client.Factory or A1Client"); diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClient.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClient.java index 04ecf045..f62d0807 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClient.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClient.java @@ -100,7 +100,6 @@ public class CcsdkA1AdapterClient implements A1Client { * CCSDK_A1_ADAPTER_STD_V2_0_0 with * @param ricConfig the configuration of the Near-RT RIC to communicate * with - * @param controllerConfig the configuration of the CCSDK A1 Adapter to use * * @throws IllegalArgumentException when the protocolType is wrong. */ @@ -119,7 +118,6 @@ public class CcsdkA1AdapterClient implements A1Client { * CCSDK_A1_ADAPTER_STD_V2_0_0 with * @param ricConfig the configuration of the Near-RT RIC to communicate * with - * @param controllerConfig the configuration of the CCSDK A1 Adapter to use * @param restClient the REST client to use * * @throws IllegalArgumentException when the protocolType is illegal. @@ -131,8 +129,8 @@ public class CcsdkA1AdapterClient implements A1Client { this.restClient = restClient; this.ricConfig = ricConfig; this.protocolType = protocolType; - logger.debug("A1Client (" + getClass().getTypeName() + ") created for ric: {}, a1Controller: {}", - ricConfig.getRicId(), ricConfig.getControllerConfig()); + logger.debug("A1Client \"{}\" created for ric: {}, a1Controller: {}", + getClass().getTypeName(), ricConfig.getRicId(), ricConfig.getControllerConfig()); } else { logger.error("Not supported protocoltype: {}", protocolType); diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java index 17681cb6..f536076b 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1Client.java @@ -143,7 +143,7 @@ public class OscA1Client implements A1Client { public OscA1Client(RicConfig ricConfig, AsyncRestClient restClient) { this.restClient = restClient; uri = new UriBuilder(ricConfig); - logger.debug("A1Client (" + getClass().getTypeName() + ") created for ric: {}", ricConfig.getRicId()); + logger.debug("A1Client \"{}\" created for ric: {}", getClass().getTypeName(), ricConfig.getRicId()); } public static Mono<String> extractCreateSchema(String policyTypeResponse, String policyTypeId) { diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java index 2f06b6a6..b033aeaa 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion1.java @@ -109,7 +109,7 @@ public class StdA1ClientVersion1 implements A1Client { public StdA1ClientVersion1(AsyncRestClient restClient, RicConfig ricConfig) { this.restClient = restClient; this.uri = new UriBuilder(ricConfig); - logger.debug("A1Client (" + getClass().getTypeName() + ") created for ric: {}", ricConfig.getRicId()); + logger.debug("A1Client \"{}\" created for ric: {}", getClass().getTypeName(), ricConfig.getRicId()); } @Override diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java index 6f907539..3362b790 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientVersion2.java @@ -138,7 +138,7 @@ public class StdA1ClientVersion2 implements A1Client { public StdA1ClientVersion2(RicConfig ricConfig, AsyncRestClient restClient) { this.restClient = restClient; uriBuiler = new OranV2UriBuilder(ricConfig); - logger.debug("A1Client (" + getClass().getTypeName() + ") created for ric: {}", ricConfig.getRicId()); + logger.debug("A1Client \"{}\" created for ric: {}", getClass().getTypeName(), ricConfig.getRicId()); } public static Mono<String> extractPolicySchema(String policyTypeResponse, String policyTypeId) { diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java index 45305f84..f5f0f7e7 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java @@ -84,7 +84,7 @@ public class ApplicationConfigParser { Map<String, ControllerConfig> controllerConfigs = parseControllerConfigs(pmsConfigJson); List<RicConfig> ricConfigs = parseRics(pmsConfigJson, controllerConfigs); - checkConfigurationConsistency(ricConfigs, controllerConfigs); + checkConfigurationConsistency(ricConfigs); return ConfigParserResult.builder() // .ricConfigs(ricConfigs) // @@ -123,8 +123,7 @@ public class ApplicationConfigParser { return CharStreams.toString(new InputStreamReader(in, StandardCharsets.UTF_8)); } - private void checkConfigurationConsistency(List<RicConfig> ricConfigs, - Map<String, ControllerConfig> controllerConfigs) throws ServiceException { + private void checkConfigurationConsistency(List<RicConfig> ricConfigs) throws ServiceException { Set<String> ricUrls = new HashSet<>(); Set<String> ricNames = new HashSet<>(); for (RicConfig ric : ricConfigs) { @@ -218,8 +217,4 @@ public class ApplicationConfigParser { private JsonArray getAsJsonArray(JsonObject obj, String memberName) throws ServiceException { return get(obj, memberName).getAsJsonArray(); } - - private static String getAsString(JsonObject obj, String memberName) throws ServiceException { - return get(obj, memberName).getAsString(); - } } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/authorization/AuthorizationResult.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/authorization/AuthorizationResult.java index 796c44e9..dc717d38 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/authorization/AuthorizationResult.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/authorization/AuthorizationResult.java @@ -32,7 +32,7 @@ import lombok.Getter; @Builder public class AuthorizationResult { - @Schema(name = "result", description = "If true, the access is granted", required = true) + @Schema(name = "result", description = "If true, the access is granted", requiredMode = Schema.RequiredMode.REQUIRED) @JsonProperty(value = "result", required = true) @SerializedName("result") @Getter diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/authorization/PolicyAuthorizationRequest.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/authorization/PolicyAuthorizationRequest.java index 8dd4e7bb..cb93006a 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/authorization/PolicyAuthorizationRequest.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/authorization/PolicyAuthorizationRequest.java @@ -51,25 +51,25 @@ public class PolicyAuthorizationRequest { READ, WRITE, DELETE } - @Schema(name = "access_type", description = "Access type", required = true) + @Schema(name = "access_type", description = "Access type", requiredMode = Schema.RequiredMode.REQUIRED) @JsonProperty(value = "access_type", required = true) @SerializedName("access_type") @Getter private AccessType accessType; - @Schema(name = "policy_type_id", description = "Policy type identifier", required = true) + @Schema(name = "policy_type_id", description = "Policy type identifier", requiredMode = Schema.RequiredMode.REQUIRED) @SerializedName("policy_type_id") @JsonProperty(value = "policy_type_id", required = true) private String policyTypeId; - @Schema(name = "auth_token", description = "Authorization token", required = true) + @Schema(name = "auth_token", description = "Authorization token", requiredMode = Schema.RequiredMode.REQUIRED) @SerializedName("auth_token") @JsonProperty(value = "auth_token", required = true) private String authToken; } - @Schema(name = "input", description = "Input", required = true) + @Schema(name = "input", description = "Input", requiredMode = Schema.RequiredMode.REQUIRED) @JsonProperty(value = "input", required = true) @SerializedName("input") private Input input; diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java index 4b0d6b58..51ac59bc 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationController.java @@ -39,7 +39,7 @@ import reactor.core.publisher.Mono; import java.io.IOException; import java.util.Optional; -@RestController("ConfigurationControllerV2") +@RestController("configurationControllerV2") @Tag( // name = ConfigurationController.API_NAME, // description = ConfigurationController.API_DESCRIPTION // 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 630be491..9299ffeb 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 @@ -36,6 +36,7 @@ import java.util.List; import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v2.A1PolicyManagementApi; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.authorization.AuthorizationCheck; @@ -51,7 +52,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.models.v2.PolicyStatusInfo; import org.onap.ccsdk.oran.a1policymanagementservice.repository.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; @@ -62,7 +62,8 @@ import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -@RestController("PolicyControllerV2") +@RestController("policyControllerV2") +@RequiredArgsConstructor @Tag(// name = PolicyController.API_NAME, // description = PolicyController.API_DESCRIPTION // @@ -71,7 +72,6 @@ public class PolicyController implements A1PolicyManagementApi { public static final String API_NAME = "A1 Policy Management"; public static final String API_DESCRIPTION = ""; - public static class RejectionException extends Exception { private static final long serialVersionUID = 1L; @@ -84,24 +84,16 @@ public class PolicyController implements A1PolicyManagementApi { } } - @Autowired - private Rics rics; - @Autowired - private PolicyTypes policyTypes; - @Autowired - private Policies policies; - @Autowired - private A1ClientFactory a1ClientFactory; - @Autowired - private Services services; - @Autowired - private ObjectMapper objectMapper; - @Autowired - private AuthorizationCheck authorization; + private final Rics rics; + private final PolicyTypes policyTypes; + private final Policies policies; + private final A1ClientFactory a1ClientFactory; + private final Services services; + private final ObjectMapper objectMapper; + private final AuthorizationCheck authorization; private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private static Gson gson = new GsonBuilder() // - .create(); // + private static final Gson gson = new GsonBuilder().create(); @Override public Mono<ResponseEntity<PolicyTypeDefinition>> getPolicyTypeDefinition(String policyTypeId, ServerWebExchange exchange) diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java index 8907774b..f7872a38 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java @@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v2.NearRtRicRepositoryApi; import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.EntityNotFoundException; import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.InvalidRequestException; @@ -32,7 +33,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.models.v2.RicInfoList; import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes; import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric; import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; @@ -42,7 +42,8 @@ import reactor.core.publisher.Mono; import java.util.ArrayList; import java.util.List; -@RestController("RicRepositoryControllerV2") +@RestController("ricRepositoryControllerV2") +@RequiredArgsConstructor @Tag( // name = RicRepositoryController.API_NAME, // description = RicRepositoryController.API_DESCRIPTION // @@ -52,17 +53,11 @@ public class RicRepositoryController implements NearRtRicRepositoryApi { public static final String API_NAME = "NearRT-RIC Repository"; public static final String API_DESCRIPTION = ""; - @Autowired - private Rics rics; + private final Rics rics; + final PolicyTypes types; + final ObjectMapper objectMapper; - @Autowired - PolicyTypes types; - - @Autowired - ObjectMapper objectMapper; - - private static Gson gson = new GsonBuilder() // - .create(); // + private static final Gson gson = new GsonBuilder().create(); private static final String GET_RIC_BRIEF = "Returns info for one Near-RT RIC"; private static final String GET_RIC_DETAILS = 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..4da11a9d 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 @@ -21,6 +21,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v2.ServiceRegistryAndSupervisionApi; import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException; import org.onap.ccsdk.oran.a1policymanagementservice.models.v2.ServiceRegistrationInfo; @@ -32,7 +33,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.Service; import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; @@ -48,7 +48,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -@RestController("ServiceControllerV2") +@RestController("serviceControllerV2") +@RequiredArgsConstructor @Tag( // name = ServiceController.API_NAME, // description = ServiceController.API_DESCRIPTION // @@ -64,13 +65,7 @@ public class ServiceController implements ServiceRegistryAndSupervisionApi { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - @Autowired - private PolicyController policyController; - - ServiceController(Services services, Policies policies) { - this.services = services; - this.policies = policies; - } + private final PolicyController policyController; private static final String GET_SERVICE_DETAILS = "Either information about a registered service with given identity or all registered services are returned."; @@ -138,7 +133,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/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/StatusController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/StatusController.java index 4ec3652d..b2cb69ce 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/StatusController.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/StatusController.java @@ -29,7 +29,7 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; -@RestController("StatusControllerV2") +@RestController("statusControllerV2") @Tag( name = StatusController.API_NAME, description = StatusController.API_DESCRIPTION ) diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3.java index 42e777b8..40f84647 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3.java @@ -19,17 +19,18 @@ package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v3; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v3.ConfigurationApi; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.ConfigurationController; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.Consts; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; -@RestController("ConfigurationControllerV3") +@RestController("configurationControllerV3") +@RequiredArgsConstructor @Tag( // name = ConfigurationControllerV3.API_NAME, // description = ConfigurationControllerV3.API_DESCRIPTION // @@ -39,9 +40,7 @@ public class ConfigurationControllerV3 implements ConfigurationApi { public static final String API_NAME = "Management of configuration"; public static final String API_DESCRIPTION = "API used to create or fetch the application configuration"; - - @Autowired - private ConfigurationController configurationController; + private final ConfigurationController configurationController; @Override public Mono<ResponseEntity<String>> getConfiguration(ServerWebExchange exchange) throws Exception { 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 4d9f3277..08aa7c7b 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 @@ -21,6 +21,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v3; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v3.A1PolicyManagementApi; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.Consts; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.PolicyController; @@ -29,15 +30,14 @@ import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyObjectInfor import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyTypeInformation; 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; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -@RestController("PolicyControllerV3") +@RestController("policyControllerV3") +@RequiredArgsConstructor @Tag(// name = PolicyController.API_NAME, // description = PolicyController.API_DESCRIPTION // @@ -46,54 +46,49 @@ import reactor.core.publisher.Mono; public class PolicyControllerV3 implements A1PolicyManagementApi { public static final String API_NAME = "A1 Policy Management"; public static final String API_DESCRIPTION = "API to create,update and get policies or policy definitions"; - @Autowired - private PolicyService policyService; - @Autowired - private Helper helper; - - @Autowired - private ErrorHandlingService errorHandlingService; + private final PolicyService policyService; + private final ErrorHandlingService errorHandlingService; @Override public Mono<ResponseEntity<PolicyObjectInformation>> createPolicy(Mono<PolicyObjectInformation> policyObjectInformation, ServerWebExchange exchange) { return policyObjectInformation.flatMap(policyObjectInfo -> policyService.createPolicyService(policyObjectInfo, exchange) - .doOnError(error -> errorHandlingService.handleError(error))); + .doOnError(errorHandlingService::handleError)); } @Override public Mono<ResponseEntity<Void>> deletePolicy(String policyId, String accept, ServerWebExchange exchange) throws Exception { return policyService.deletePolicyService(policyId, exchange) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } @Override public Mono<ResponseEntity<Object>> getPolicy(String policyId, String accept, ServerWebExchange exchange) throws Exception { return policyService.getPolicyService(policyId, exchange) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } @Override - public Mono<ResponseEntity<Flux<PolicyInformation>>> getPolicyIds(String policyTypeId, String nearRtRicId, String serviceId, String typeName, String accept, ServerWebExchange exchange) throws Exception { + public Mono<ResponseEntity<Flux<PolicyInformation>>> getAllPolicies(String policyTypeId, String nearRtRicId, String serviceId, String typeName, String accept, ServerWebExchange exchange) throws Exception { return policyService.getPolicyIdsService(policyTypeId, nearRtRicId, serviceId, typeName, exchange) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } @Override public Mono<ResponseEntity<Object>> getPolicyTypeDefinition(String policyTypeId, String accept, ServerWebExchange exchange) throws Exception { return policyService.getPolicyTypeDefinitionService(policyTypeId) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } @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) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } @Override public Mono<ResponseEntity<Object>> putPolicy(String policyId, Mono<Object> body, ServerWebExchange exchange) throws Exception { return body.flatMap(payload -> policyService.putPolicyService(policyId, payload, exchange)) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3.java index 6254a15e..89d47d7f 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3.java @@ -21,6 +21,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v3; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v3.NearRtRicRepositoryApi; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.Consts; import org.onap.ccsdk.oran.a1policymanagementservice.mappers.v3.RicRepositoryMapper; @@ -28,14 +29,14 @@ import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.RicRepositor import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.RicInfo; import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.RicInfoList; import org.onap.ccsdk.oran.a1policymanagementservice.service.v3.ErrorHandlingService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; -@RestController("RicRepositoryControllerV3") +@RestController("ricRepositoryControllerV3") +@RequiredArgsConstructor @Tag( name = RicRepositoryControllerV3.API_NAME, description = RicRepositoryControllerV3.API_DESCRIPTION @@ -45,26 +46,24 @@ public class RicRepositoryControllerV3 implements NearRtRicRepositoryApi { public static final String API_NAME = "NearRT-RIC Repository V3"; public static final String API_DESCRIPTION = "API used to get the NearRT-RIC for the managed element"; - @Autowired - private RicRepositoryController ricRepositoryController; - @Autowired - private RicRepositoryMapper ricRepositoryMapper; + private final RicRepositoryController ricRepositoryController; - @Autowired - ErrorHandlingService errorHandlingService; + private final RicRepositoryMapper ricRepositoryMapper; + + private final ErrorHandlingService errorHandlingService; @Override public Mono<ResponseEntity<RicInfo>> getRic(String managedElementId, String ricId, String accept, ServerWebExchange exchange) throws Exception { return ricRepositoryController.getRic(managedElementId, ricId, exchange) .map(responseEntity -> new ResponseEntity<>(ricRepositoryMapper.toRicInfoV3(responseEntity.getBody()), responseEntity.getStatusCode())) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } @Override public Mono<ResponseEntity<RicInfoList>> getRics(String policyTypeId, String accept, ServerWebExchange exchange) throws Exception { return ricRepositoryController.getRics(policyTypeId, exchange) .map(responseEntity -> new ResponseEntity<>(ricRepositoryMapper.toRicInfoListV3(responseEntity.getBody()), responseEntity.getStatusCode())) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3.java index a0ffeed3..d29e37a6 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3.java @@ -21,6 +21,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v3; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v3.ServiceRegistryAndSupervisionApi; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.Consts; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.ServiceController; @@ -28,14 +29,14 @@ import org.onap.ccsdk.oran.a1policymanagementservice.mappers.v3.ServiceControlle import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.ServiceRegistrationInfo; import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.ServiceStatusList; import org.onap.ccsdk.oran.a1policymanagementservice.service.v3.ErrorHandlingService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; -@RestController("ServiceControllerV3") +@RestController("serviceControllerV3") +@RequiredArgsConstructor @Tag( // name = ServiceControllerV3.API_NAME, // description = ServiceControllerV3.API_DESCRIPTION // @@ -46,14 +47,11 @@ public class ServiceControllerV3 implements ServiceRegistryAndSupervisionApi { public static final String API_NAME = "Service Registry and Supervision"; public static final String API_DESCRIPTION = "API used to keep the service Alive with in the timeout period"; - @Autowired - private ServiceController serviceController; + private final ServiceController serviceController; - @Autowired - private ServiceControllerMapper serviceControllerMapper; + private final ServiceControllerMapper serviceControllerMapper; - @Autowired - ErrorHandlingService errorHandlingService; + private final ErrorHandlingService errorHandlingService; @Override public Mono<ResponseEntity<Object>> deleteService(String serviceId, String accept, ServerWebExchange exchange) throws Exception { @@ -65,7 +63,7 @@ public class ServiceControllerV3 implements ServiceRegistryAndSupervisionApi { return serviceController.getServices(serviceId, exchange) .map(responseEntity -> new ResponseEntity<>(serviceControllerMapper.toServiceStatusListV3( responseEntity.getBody()), responseEntity.getStatusCode())) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } @Override @@ -75,8 +73,7 @@ public class ServiceControllerV3 implements ServiceRegistryAndSupervisionApi { @Override public Mono<ResponseEntity<Object>> putService(Mono<ServiceRegistrationInfo> serviceRegistrationInfo, ServerWebExchange exchange) throws Exception { - return serviceController.putService(serviceRegistrationInfo.map(serviceRegistrationInfoV2 -> - serviceControllerMapper.toServiceRegistrationInfoV2(serviceRegistrationInfoV2)), exchange) - .doOnError(error -> errorHandlingService.handleError(error)); + return serviceController.putService(serviceRegistrationInfo.map(serviceControllerMapper::toServiceRegistrationInfoV2), exchange) + .doOnError(errorHandlingService::handleError); } } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/StatusControllerV3.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/StatusControllerV3.java index dbbb2fc0..5ef32901 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/StatusControllerV3.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/StatusControllerV3.java @@ -21,21 +21,21 @@ package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v3; import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v3.HealthCheckApi; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.Consts; -import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.RicRepositoryController; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.StatusController; import org.onap.ccsdk.oran.a1policymanagementservice.mappers.v3.StatusControllerMapper; import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.StatusInfo; import org.onap.ccsdk.oran.a1policymanagementservice.service.v3.ErrorHandlingService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; -@RestController("StatusControllerV3") +@RestController("statusControllerV3") +@RequiredArgsConstructor @Tag( // name = StatusControllerV3.API_NAME, // description = StatusControllerV3.API_DESCRIPTION // @@ -46,20 +46,18 @@ public class StatusControllerV3 implements HealthCheckApi { public static final String API_NAME = "Health Check"; public static final String API_DESCRIPTION = "API used to get the health status and statistics of this service"; - @Autowired - private StatusController statusController; - @Autowired - private StatusControllerMapper statusControllerMapper; + private final StatusController statusController; - @Autowired - ErrorHandlingService errorHandlingService; + private final StatusControllerMapper statusControllerMapper; + + private final ErrorHandlingService errorHandlingService; @Override public Mono<ResponseEntity<StatusInfo>> getStatus(ServerWebExchange exchange) throws Exception { return statusController.getStatus(exchange) .map(statusInfoResponseEntity -> new ResponseEntity<>(statusControllerMapper.toStatusInfoV3 (statusInfoResponseEntity.getBody()), statusInfoResponseEntity.getStatusCode())) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/datastore/S3ObjectStore.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/datastore/S3ObjectStore.java index 1c67ff7d..d014ad53 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/datastore/S3ObjectStore.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/datastore/S3ObjectStore.java @@ -141,7 +141,7 @@ class S3ObjectStore implements DataStore { return Mono.fromFuture(future) // .map(f -> s3Bucket) // .doOnError(t -> logger.debug("Could not create S3 bucket: {}", t.getMessage())) - .onErrorResume(t -> Mono.just(s3Bucket)); + .onErrorResume(t -> Mono.just("Not Created")); } @Override 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 ac4320a1..af6f0abe 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 @@ -21,19 +21,19 @@ package org.onap.ccsdk.oran.a1policymanagementservice.service.v3; +import lombok.RequiredArgsConstructor; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.authorization.AuthorizationCheck; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.authorization.PolicyAuthorizationRequest.Input.AccessType; import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; @Service +@RequiredArgsConstructor public class AuthorizationService { - @Autowired - private AuthorizationCheck authorization; + private final AuthorizationCheck authorization; public Mono<Policy> authCheck (ServerWebExchange serverWebExchange, Policy policy, AccessType accessType){ return authorization.doAccessControl(serverWebExchange.getRequest().getHeaders().toSingleValueMap(), diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/ErrorHandlingService.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/ErrorHandlingService.java index 693ae513..b445150a 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/ErrorHandlingService.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/ErrorHandlingService.java @@ -20,7 +20,6 @@ package org.onap.ccsdk.oran.a1policymanagementservice.service.v3; -import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.PolicyController; import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException; import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.ProblemDetails; import org.slf4j.Logger; 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 a892bfa3..868a336f 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 @@ -21,6 +21,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.service.v3; import com.google.gson.Gson; +import lombok.RequiredArgsConstructor; import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.authorization.PolicyAuthorizationRequest.Input.AccessType; import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.Consts; @@ -33,7 +34,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.*; import org.onap.ccsdk.oran.a1policymanagementservice.util.v3.Helper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -47,32 +47,18 @@ import java.util.Collection; import java.util.Map; @Service +@RequiredArgsConstructor public class PolicyService { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - @Autowired - private Helper helper; - - @Autowired - private Rics rics; - - @Autowired - private PolicyTypes policyTypes; - - @Autowired - private Policies policies; - - @Autowired - private AuthorizationService authorizationService; - - @Autowired - private A1ClientFactory a1ClientFactory; - - @Autowired - private ErrorHandlingService errorHandlingService; - - @Autowired - private Gson gson; + private final Helper helper; + private final Rics rics; + private final PolicyTypes policyTypes; + private final Policies policies; + private final AuthorizationService authorizationService; + private final A1ClientFactory a1ClientFactory; + private final ErrorHandlingService errorHandlingService; + private final Gson gson; public Mono<ResponseEntity<PolicyObjectInformation>> createPolicyService (PolicyObjectInformation policyObjectInfo, ServerWebExchange serverWebExchange) { @@ -83,15 +69,15 @@ public class PolicyService { PolicyType policyType = policyTypes.getType(policyObjectInfo.getPolicyTypeId()); Policy policy = helper.buildPolicy(policyObjectInfo, policyType, ric, helper.policyIdGeneration(policyObjectInfo)); return helper.isPolicyAlreadyCreated(policy,policies) - .doOnError(error -> errorHandlingService.handleError(error)) + .doOnError(errorHandlingService::handleError) .flatMap(policyBuilt -> authorizationService.authCheck(serverWebExchange, policy, AccessType.WRITE) - .doOnError(error -> errorHandlingService.handleError(error)) + .doOnError(errorHandlingService::handleError) .flatMap(policyNotUsed -> ric.getLock().lock(Lock.LockType.SHARED, "createPolicy")) .flatMap(grant -> postPolicy(policy, grant)) .map(locationHeaderValue -> new ResponseEntity<PolicyObjectInformation>(policyObjectInfo,helper.createHttpHeaders( "location",helper.buildURI(policy.getId(), serverWebExchange)), HttpStatus.CREATED)) - .doOnError(error -> errorHandlingService.handleError(error))); + .doOnError(errorHandlingService::handleError)); } catch (Exception ex) { return Mono.error(ex); } @@ -100,15 +86,15 @@ public class PolicyService { private Mono<String> postPolicy(Policy policy, Lock.Grant grant) { return helper.checkRicStateIdle(policy.getRic()) - .doOnError(error -> errorHandlingService.handleError(error)) + .doOnError(errorHandlingService::handleError) .flatMap(ric -> helper.checkSupportedType(ric, policy.getType())) - .doOnError(error -> errorHandlingService.handleError(error)) - .flatMap(ric -> a1ClientFactory.createA1Client(ric)) + .doOnError(errorHandlingService::handleError) + .flatMap(a1ClientFactory::createA1Client) .flatMap(a1Client -> a1Client.putPolicy(policy)) - .doOnError(error -> errorHandlingService.handleError(error)) + .doOnError(errorHandlingService::handleError) .doOnNext(policyString -> policies.put(policy)) .doFinally(releaseLock -> grant.unlockBlocking()) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } public Mono<ResponseEntity<Object>> putPolicyService(String policyId, Object body, ServerWebExchange exchange) { @@ -119,12 +105,12 @@ public class PolicyService { Policy updatedPolicy = helper.buildPolicy(pos, existingPolicy.getType(), existingPolicy.getRic(), policyId); Ric ric = existingPolicy.getRic(); return authorizationService.authCheck(exchange, updatedPolicy, AccessType.WRITE) - .doOnError(error -> errorHandlingService.handleError(error)) + .doOnError(errorHandlingService::handleError) .flatMap(policy -> ric.getLock().lock(Lock.LockType.SHARED, "updatePolicy")) - .doOnError(error -> errorHandlingService.handleError(error)) + .doOnError(errorHandlingService::handleError) .flatMap(grant -> postPolicy(updatedPolicy, grant)) .map(header -> new ResponseEntity<Object>(policies.get(updatedPolicy.getId()).getJson(), HttpStatus.OK)) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } catch(Exception ex) { return Mono.error(ex); } @@ -178,7 +164,7 @@ public class PolicyService { Policy policy = policies.getPolicy(policyId); return authorizationService.authCheck(serverWebExchange, policy, AccessType.READ) .map(x -> new ResponseEntity<Object>(policy.getJson(), HttpStatus.OK)) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } public Mono<ResponseEntity<Object>> getPolicyTypeDefinitionService(String policyTypeId) @@ -193,24 +179,24 @@ public class PolicyService { throws EntityNotFoundException { Policy singlePolicy = policies.getPolicy(policyId); return authorizationService.authCheck(serverWebExchange, singlePolicy, AccessType.WRITE) - .doOnError(error -> errorHandlingService.handleError(error)) + .doOnError(errorHandlingService::handleError) .flatMap(policy -> policy.getRic().getLock().lock(Lock.LockType.SHARED, "deletePolicy")) .flatMap(grant -> deletePolicy(singlePolicy, grant)) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } private Mono<ResponseEntity<Void>> deletePolicy(Policy policy, Lock.Grant grant) { return helper.checkRicStateIdle(policy.getRic()) - .doOnError(error -> errorHandlingService.handleError(error)) + .doOnError(errorHandlingService::handleError) .flatMap(ric -> helper.checkSupportedType(ric, policy.getType())) - .doOnError(error -> errorHandlingService.handleError(error)) - .flatMap(ric -> a1ClientFactory.createA1Client(ric)) - .doOnError(error -> errorHandlingService.handleError(error)) + .doOnError(errorHandlingService::handleError) + .flatMap(a1ClientFactory::createA1Client) + .doOnError(errorHandlingService::handleError) .flatMap(a1Client -> a1Client.deletePolicy(policy)) - .doOnError(error -> errorHandlingService.handleError(error)) + .doOnError(errorHandlingService::handleError) .doOnNext(policyString -> policies.remove(policy)) .doFinally(releaseLock -> grant.unlockBlocking()) .map(successResponse -> new ResponseEntity<Void>(HttpStatus.NO_CONTENT)) - .doOnError(error -> errorHandlingService.handleError(error)); + .doOnError(errorHandlingService::handleError); } } 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 638d9504..0cb91353 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 @@ -22,6 +22,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.util.v3; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import lombok.RequiredArgsConstructor; import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException; import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyInformation; import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyObjectInformation; @@ -29,7 +30,6 @@ import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyTypeInforma import org.onap.ccsdk.oran.a1policymanagementservice.repository.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; @@ -45,14 +45,15 @@ import java.util.UUID; import java.util.stream.Collectors; @Component +@RequiredArgsConstructor public class Helper { - @Autowired - private Services services; + private final Services services; private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - private static Gson gson = new GsonBuilder().create(); + private static final Gson gson = new GsonBuilder().create(); + public void keepServiceAlive(String name) { Service s = this.services.get(name); if (s != null) { diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java index b3c77355..ca0622c6 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java @@ -21,8 +21,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.clients; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; @@ -144,20 +143,20 @@ class A1ClientFactoryTest { @DisplayName("test Custom Adapter Creation") void testCustomAdapterCreation() { - Ric ric = new Ric(ricConfig("", CustomA1AdapterFactory.class.getName())); - A1Client client = factoryUnderTest.createA1Client(ric).block(); - + Ric ricLocal = new Ric(ricConfig("", CustomA1AdapterFactory.class.getName())); + A1Client client = factoryUnderTest.createA1Client(ricLocal).block(); + assertNotNull(client); assertEquals(client.getClass(), StdA1ClientVersion2.class); - ric = new Ric(ricConfig("", "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2")); - client = factoryUnderTest.createA1Client(ric).block(); - + ricLocal = new Ric(ricConfig("", "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2")); + client = factoryUnderTest.createA1Client(ricLocal).block(); + assertNotNull(client); assertEquals(client.getClass(), StdA1ClientVersion2.class); - ric = new Ric( + ricLocal = new Ric( ricConfig("", "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2$Factory")); - client = factoryUnderTest.createA1Client(ric).block(); - + client = factoryUnderTest.createA1Client(ricLocal).block(); + assertNotNull(client); assertEquals(client.getClass(), StdA1ClientVersion2.class); Exception e = Assertions.assertThrows(Exception.class, () -> { diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/MetersTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/MetersTest.java index 922d139d..c714268d 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/MetersTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/MetersTest.java @@ -22,8 +22,8 @@ package org.onap.ccsdk.oran.a1policymanagementservice.configuration; import static org.assertj.core.api.Assertions.assertThat; -import io.micrometer.prometheus.PrometheusConfig; -import io.micrometer.prometheus.PrometheusMeterRegistry; +import io.micrometer.prometheusmetrics.PrometheusConfig; +import io.micrometer.prometheusmetrics.PrometheusMeterRegistry; import java.time.Instant; import java.util.Arrays; 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..3a7bc799 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 @@ -28,8 +28,6 @@ import static org.mockito.Mockito.doReturn; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import java.lang.invoke.MethodHandles; import java.nio.charset.StandardCharsets; @@ -104,7 +102,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.context.TestPropertySource; import org.springframework.util.FileSystemUtils; -import org.springframework.web.reactive.function.client.WebClientRequestException; import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Mono; @@ -163,8 +160,6 @@ class ApplicationTest { @Autowired OpenPolicyAgentSimulatorController openPolicyAgentSimulatorController; - private static Gson gson = new GsonBuilder().create(); - /** * Overrides the BeanFactory. */ @@ -235,7 +230,6 @@ class ApplicationTest { } @Test - @SuppressWarnings("squid:S2925") // "Thread.sleep" should not be used in tests. @DisplayName("test ZZ Actuator") void testZZActuator() throws Exception { // The test must be run last, hence the "ZZ" in the name. All succeeding tests @@ -251,15 +245,9 @@ class ApplicationTest { client.post("/actuator/loggers/org.springframework.boot.actuate", "{\"configuredLevel\":\"trace\"}").block(); // This will stop the web server and all coming tests will fail. - client.post("/actuator/shutdown", "").block(); - - Thread.sleep(1000); - - StepVerifier.create(restClient().get("/rics")) // Any call - .expectSubscription() // - .expectErrorMatches(t -> t instanceof WebClientRequestException) // - .verify(); - + ResponseEntity<String> entity = client.postForEntity("/actuator/shutdown", "").block(); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(((String) entity.getBody())).contains("Shutting down"); } @Test @@ -275,16 +263,16 @@ class ApplicationTest { waitforS3(); { - Policies policies = new Policies(this.applicationConfig); - policies.restoreFromDatabase(ric, this.policyTypes).blockLast(); - assertThat(policies.size()).isEqualTo(noOfPolicies); + Policies policiesLocal = new Policies(this.applicationConfig); + policiesLocal.restoreFromDatabase(ric, this.policyTypes).blockLast(); + assertThat(policiesLocal.size()).isEqualTo(noOfPolicies); } { restClient().delete("/policies/id2").block(); - Policies policies = new Policies(this.applicationConfig); - policies.restoreFromDatabase(ric, this.policyTypes).blockLast(); - assertThat(policies.size()).isEqualTo(noOfPolicies - 1); + Policies policiesAfterDelete = new Policies(this.applicationConfig); + policiesAfterDelete.restoreFromDatabase(ric, this.policyTypes).blockLast(); + assertThat(policiesAfterDelete.size()).isEqualTo(noOfPolicies - 1); } } @@ -399,7 +387,7 @@ class ApplicationTest { @Test @DisplayName("test Get Rics") - void testGetRics() throws Exception { + void testGetRics() throws JsonProcessingException { addRic("ric1"); this.addPolicyType("type1", "ric1"); String url = "/rics?policytype_id=type1"; @@ -791,7 +779,7 @@ class ApplicationTest { @Test @DisplayName("test Get Policy Types") - void testGetPolicyTypes() throws Exception { + void testGetPolicyTypes() throws JsonProcessingException { String TYPE_ID_1 = "A_type1_1.9.0"; String TYPE_ID_2 = "A_type1_2.0.0"; String TYPE_ID_3 = "A_type1_1.5.0"; @@ -956,6 +944,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,8 +966,34 @@ 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 { + void testServiceSupervision() throws JsonProcessingException { putService("service1", 2, HttpStatus.CREATED); addPolicyType("type1", "ric1"); @@ -1151,7 +1166,7 @@ class ApplicationTest { assertThat(test.isFailed()).isFalse(); } assertThat(policies.size()).isZero(); - logger.info("Concurrency test took " + Duration.between(startTime, Instant.now())); + logger.info("Concurrency test took: {}", Duration.between(startTime, Instant.now())); assertThat(nonRespondingRic.getState()).isEqualTo(RicState.UNAVAILABLE); nonRespondingRic.setState(RicState.AVAILABLE); 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 888325b2..a42d034a 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 @@ -86,7 +86,7 @@ class ConcurrencyTestRunnable implements Runnable { System.out.println(Thread.currentThread() + result.getBody()); } catch (Exception e) { - logger.error(Thread.currentThread() + "Concurrency test printStatusInfo exception " + e.toString()); + logger.error("{} Concurrency test printStatusInfo exception {}", Thread.currentThread(), e.toString()); } } @@ -107,7 +107,7 @@ class ConcurrencyTestRunnable implements Runnable { deletePolicy(name + "-"); } } catch (Exception e) { - logger.error("Concurrency test exception " + e.toString()); + logger.error("Concurrency test exception {}", e.toString()); printStatusInfo(); failed = true; } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java index 42e3b0c9..e46b8367 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java @@ -134,14 +134,14 @@ class ConfigurationControllerTest { } private String configAsString() throws Exception { - File configFile = + File configFileLocal = new File(getClass().getClassLoader().getResource("test_application_configuration.json").getFile()); - return FileUtils.readFileToString(configFile, "UTF-8"); + return FileUtils.readFileToString(configFileLocal, "UTF-8"); } @Test @DisplayName("put Invalid Configuration should Return Error 400") - void putInvalidConfiguration_shouldReturnError400() throws Exception { + void putInvalidConfiguration_shouldReturnError400() { String url = "a1-policy/v2/configuration"; // Valid JSON but invalid configuration. 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 e81a936d..211a9a39 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 @@ -254,4 +254,63 @@ class PolicyControllerV3Test { testHelper.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody -> responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}")); } + + @Test + @DisplayName("test get all Policies") + void testGetAllPolicies() throws Exception { + String nonRtRicIdOne = "ric.11"; + String nonRtRicIdTwo = "ric.22"; + String policyTypeName = "type1_1.2.3"; + String url = "/policies"; + testHelper.addPolicyType(policyTypeName, nonRtRicIdOne); + String policyBodyOne = testHelper.postPolicyBody(nonRtRicIdOne, policyTypeName, "policyOne"); + testHelper.addPolicyType(policyTypeName, nonRtRicIdTwo); + String policyBodyTwo = testHelper.postPolicyBody(nonRtRicIdTwo, policyTypeName, "policyTwo"); + testHelper.restClientV3().postForEntity(url, policyBodyOne).block(); + testHelper.restClientV3().postForEntity(url, policyBodyTwo).block(); + Mono<ResponseEntity<String>> responseMonoGet = testHelper.restClientV3().getForEntity(url); + testHelper.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody -> + responseBody.contains("[{\"policyId\":\"policyTwo\",\"nearRtRicId\":\"ric.22\"},{\"policyId\":\"policyOne\",\"nearRtRicId\":\"ric.11\"}]")); } + + @Test + @DisplayName("test get PolicyType") + void testGetPolicyType() throws Exception { + String nonRtRicId = "ric.1"; + String policyTypeName = "type1_1.2.3"; + String url = "/policy-types"; + testHelper.addPolicyType(policyTypeName, nonRtRicId); + Mono<ResponseEntity<String>> responseMonoGet = testHelper.restClientV3().getForEntity(url+"/" +policyTypeName); + testHelper.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody -> !(responseBody.isEmpty())); + } + + @Test + @DisplayName("test get All PolicyTypes") + void testGetAllPolicyTypes() throws Exception { + String nonRtRicId = "ric.1"; + String policyTypeName = "type1_1.2.3"; + String url = "/policy-types"; + testHelper.addPolicyType(policyTypeName, nonRtRicId); + Mono<ResponseEntity<String>> responseMonoGet = testHelper.restClientV3().getForEntity(url); + testHelper.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody -> responseBody.contains( + "{\"policyTypeId\":\"type1_1.2.3\",\"nearRtRicId\":\"ric.1\"}]" + )); + } + + @Test + @DisplayName("test update Policy") + void testUpdatePolicy() throws Exception { + String nonRtRicId = "ric.1"; + String policyTypeName = "type1_1.2.3"; + String url = "/policies"; + testHelper.addPolicyType(policyTypeName, nonRtRicId); + String policyBodyForPost = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "policyOne"); + testHelper.restClientV3().postForEntity(url, policyBodyForPost).block(); + String policyBodyForPut = testHelper.putPolicyBody(nonRtRicId, policyTypeName, "policyOne", "ue5200", + "qos5200", "5200.0"); + testHelper.restClientV3().putForEntity(url+"/policyOne", policyBodyForPut).block(); + Mono<ResponseEntity<String>> responseMonoGet = testHelper.restClientV3().getForEntity(url+"/policyOne"); + testHelper.testSuccessResponse(responseMonoGet, HttpStatus.OK, responseBody -> + responseBody.contains("{\"scope\":{\"ueId\":\"ue5200\",\"qosId\":\"qos5200\"},\"qosObjectives\":{\"priorityLevel\":5200.0}")); + } +}
\ No newline at end of file diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/datastore/S3ObjectStoreTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/datastore/S3ObjectStoreTest.java new file mode 100644 index 00000000..941b7770 --- /dev/null +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/datastore/S3ObjectStoreTest.java @@ -0,0 +1,134 @@ +/*- + * ========================LICENSE_START================================= + * ONAP : ccsdk oran + * ====================================================================== + * Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved. + * ====================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ + +package org.onap.ccsdk.oran.a1policymanagementservice.datastore; + +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig; +import org.reactivestreams.Publisher; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.testcontainers.containers.localstack.LocalStackContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; +import reactor.test.StepVerifier; + +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.function.Predicate; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@Testcontainers +@ExtendWith({MockitoExtension.class, OutputCaptureExtension.class}) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class S3ObjectStoreTest { + + static ApplicationConfig appConfig; + private static S3ObjectStore s3ObjectStore; + private static final String bucketName = "s3bucket"; + + @Container + private static final LocalStackContainer localstack = + new LocalStackContainer(DockerImageName.parse("localstack/localstack:0.11.3")) + .withServices(LocalStackContainer.Service.S3); + + @BeforeAll + static void init() { + appConfig = mock(ApplicationConfig.class); + when(appConfig.isS3Enabled()).thenReturn(Boolean.TRUE); + when(appConfig.getS3EndpointOverride()).thenReturn(localstack.getEndpoint().toString()); + when(appConfig.getS3AccessKeyId()).thenReturn(localstack.getAccessKey()); + when(appConfig.getS3SecretAccessKey()).thenReturn(localstack.getSecretKey()); + when(appConfig.getS3Bucket()).thenReturn(bucketName); + s3ObjectStore = new S3ObjectStore(appConfig, "location"); + } + @Test + @Order(1) + void testGetS3AsynchClient() { + assertNotNull(s3ObjectStore); + } + + @Test + @Order(2) + void testCreateAndDeleteS3BucketSuccess(CapturedOutput capturedOutput) { + + testSuccess(s3ObjectStore.createDataStore(), actual -> actual.equals(bucketName)); + assertFalse(capturedOutput.getOut().contains("Could not create S3 bucket:")); + + testSuccess(s3ObjectStore.deleteBucket(), actual -> actual.equals(bucketName)); + } + + @Test + @Order(3) + void testWriteAndReadAndDeleteObjectSuccess(CapturedOutput capturedOutput) { + + testSuccess(s3ObjectStore.createDataStore(), actual -> actual.equals(bucketName)); + byte[] fileData = "testData".getBytes(StandardCharsets.UTF_8); + new String(fileData); + testSuccess(s3ObjectStore.writeObject("test", fileData), + actual -> Arrays.equals(actual, fileData)); + assertFalse(capturedOutput.getOut().contains("Failed to store object")); + testSuccess(s3ObjectStore.readObject("test"), + actual -> Arrays.equals(actual, fileData)); + testSuccess(s3ObjectStore.deleteAllObjects(), actual -> actual.equals("OK")); + } + + @Test + @Order(4) + void testListObjectsSuccess() { + + s3ObjectStore.createDataStore().block(); + String objectName = "test"; + byte[] fileData = "testData".getBytes(StandardCharsets.UTF_8); + testSuccess(s3ObjectStore.writeObject(objectName, fileData), + actual -> Arrays.equals(actual, fileData)); + testSuccess(s3ObjectStore.listObjects(""), actual -> actual.equals(objectName)); + } + + @Test + @Order(5) + void testCreateAndDeleteS3BucketError(CapturedOutput capturedOutput) { + + when(appConfig.getS3Bucket()).thenReturn("S3Bucket"); + + testFailure(s3ObjectStore.createDataStore(), actual -> actual.equals("Not Created")); + + testFailure(s3ObjectStore.deleteBucket(), actual -> actual.equals("NOK")); + assertTrue(capturedOutput.getOut().contains("Could not delete bucket:")); + } + + <T> void testSuccess(Publisher<T> publisher, Predicate<T> equalityCheck) { + StepVerifier.create(publisher) + .expectNextMatches(equalityCheck) + .verifyComplete(); + } + + <T> void testFailure(Publisher<T> publisher, Predicate<T> equalityCheck) { + StepVerifier.create(publisher) + .expectNextMatches(equalityCheck) + .verifyComplete(); + } +} diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java index e4d78599..ff818caf 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java @@ -20,25 +20,22 @@ package org.onap.ccsdk.oran.a1policymanagementservice.repository; -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; - -import java.io.IOException; -import java.lang.invoke.MethodHandles; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; -import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException; import org.onap.ccsdk.oran.a1policymanagementservice.repository.Lock.LockType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import java.lang.invoke.MethodHandles; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; + @ExtendWith(MockitoExtension.class) class LockTest { @@ -66,7 +63,7 @@ class LockTest { @Test @DisplayName("test Lock") - void testLock() throws IOException, ServiceException { + void testLock() { Lock lock = new Lock("l1"); Lock.Grant grant = lock.lockBlocking(LockType.SHARED, "test"); grant.unlockBlocking(); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java index 3b1ee8f7..c2db815a 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java @@ -20,27 +20,10 @@ package org.onap.ccsdk.oran.a1policymanagementservice.tasks; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - import com.google.common.base.Charsets; import com.google.common.io.Resources; import com.google.gson.JsonObject; import com.google.gson.JsonParser; - -import java.io.IOException; -import java.net.URL; -import java.time.Duration; -import java.util.Arrays; -import java.util.Optional; -import java.util.Properties; - import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -55,14 +38,20 @@ import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationCo import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfigParser.ConfigParserResult; import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ConfigurationFile; import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig; -import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies; -import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes; -import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric; -import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics; -import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services; - +import org.onap.ccsdk.oran.a1policymanagementservice.repository.*; import reactor.test.StepVerifier; +import java.io.IOException; +import java.net.URL; +import java.time.Duration; +import java.util.Arrays; +import java.util.Optional; +import java.util.Properties; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + @ExtendWith(MockitoExtension.class) class RefreshConfigTaskTest { @@ -74,11 +63,11 @@ class RefreshConfigTaskTest { @Mock ConfigurationFile configurationFileMock; - private RefreshConfigTask createTestObject(boolean configFileExists) { - return createTestObject(configFileExists, spy(new Rics()), new Policies(appConfig), true); + private RefreshConfigTask createTestObject(boolean stubConfigFileExists) { + return createTestObject(spy(new Rics()), new Policies(appConfig), stubConfigFileExists); } - private RefreshConfigTask createTestObject(boolean configFileExists, Rics rics, Policies policies, + private RefreshConfigTask createTestObject(Rics rics, Policies policies, boolean stubConfigFileExists) { SecurityContext secContext = new SecurityContext(""); @@ -118,8 +107,30 @@ class RefreshConfigTaskTest { } @Test + @DisplayName("test handle updated ric config method with type removed") + void testHandleUpdatedRicConfigRemoved() { + + String ricId = "ric1"; + refreshTaskUnderTest = this.createTestObject(false); + refreshTaskUnderTest.handleUpdatedRicConfig(buildRicConfigUpdate(ricId, "ric_baseurl_removed", + Type.REMOVED)); + verify(refreshTaskUnderTest.rics, times(1)).remove(anyString()); + } + + @Test + @DisplayName("test handle updated ric config method with type changed and no ric available before") + void testHandleUpdatedRicConfigNullRicChanged() { + + String ricId = "ric1"; + refreshTaskUnderTest = this.createTestObject(false); + refreshTaskUnderTest.handleUpdatedRicConfig(buildRicConfigUpdate(ricId, "ric_baseurl_changed", + Type.CHANGED)); + verify(refreshTaskUnderTest.rics, times(1)).put(any(Ric.class)); + } + + @Test @DisplayName("test when File Exists But Json Is Incorrect then No Rics Are Put In Repository") - void whenFileExistsButJsonIsIncorrect_thenNoRicsArePutInRepository() throws Exception { + void whenFileExistsButJsonIsIncorrect_thenNoRicsArePutInRepository() { refreshTaskUnderTest = this.createTestObject(true); // When @@ -148,4 +159,16 @@ class RefreshConfigTaskTest { String string = Resources.toString(url, Charsets.UTF_8); return Optional.of(JsonParser.parseString(string).getAsJsonObject()); } + + private ApplicationConfig.RicConfigUpdate buildRicConfigUpdate(String ricID, String baseUrl, + Type event) { + return new ApplicationConfig.RicConfigUpdate(buildRicConfig(ricID, baseUrl), event); + } + + private RicConfig buildRicConfig(String ricID, String baseUrl) { + return RicConfig.builder() + .ricId(ricID) + .baseUrl(baseUrl) + .build(); + } } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java index 91b762c5..0cd9db20 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java @@ -54,7 +54,7 @@ public class MockA1Client implements A1Client { @Setter private String errorInject; - public MockA1Client(String ricId, ApplicationConfig appConfig, PolicyTypes policyTypes, Duration asynchDelay) { + public MockA1Client(ApplicationConfig appConfig, PolicyTypes policyTypes, Duration asynchDelay) { this.policyTypes = policyTypes; this.asynchDelay = asynchDelay; ApplicationConfig cfg = spy(appConfig); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1ClientFactory.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1ClientFactory.java index be7dfcb3..974c3b08 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1ClientFactory.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1ClientFactory.java @@ -59,7 +59,7 @@ public class MockA1ClientFactory extends A1ClientFactory { public MockA1Client getOrCreateA1Client(String ricId) { if (!clients.containsKey(ricId)) { logger.debug("Creating client for RIC: {}", ricId); - MockA1Client client = spy(new MockA1Client(ricId, appConfig, policyTypes, asynchDelay)); + MockA1Client client = spy(new MockA1Client(appConfig, policyTypes, asynchDelay)); clients.put(ricId, client); } return clients.get(ricId); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelper.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelper.java index 5463b0a1..b0b5858a 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelper.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelper.java @@ -170,10 +170,31 @@ public class TestHelper { return gson.toJson(policyObjectInfo); } + public String putPolicyBody(String nearRtRicId, String policyTypeName, String policyId, String ueId, String qosId, + String priorityLevel) { + PolicyObjectInformation policyObjectInfo = new PolicyObjectInformation(nearRtRicId, dummyPolicyObjectForPut( + ueId, qosId, priorityLevel), policyTypeName); + if (policyId != null && !policyId.isEmpty() && !policyId.isBlank()) + policyObjectInfo.setPolicyId(policyId); + return gson.toJson(policyObjectInfo); + } + public PolicyObjectInformation policyObjectInfo(String nearRtRicId, String policyTypeName) { return gson.fromJson(postPolicyBody(nearRtRicId, policyTypeName, ""), PolicyObjectInformation.class); } + public JsonObject dummyPolicyObjectForPut(String... values) { + return JsonParser.parseString("{\n" + + " \"scope\": {\n" + + " \"ueId\": \"" + values[0] + "\",\n" + + " \"qosId\": \"" + values[1] + "\"\n" + + " },\n" + + " \"qosObjectives\": {\n" + + " \"priorityLevel\": " + values[2] + "\n" + + " }\n" + + " }").getAsJsonObject(); + } + public JsonObject dummyPolicyObject() { return JsonParser.parseString("{\n" + " \"scope\": {\n" + |