summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorraviteja.karumuri <raviteja.karumuri@est.tech>2024-04-30 22:15:58 +0100
committerraviteja.karumuri <raviteja.karumuri@est.tech>2024-06-20 11:38:55 +0100
commit10948b6d86645c7e30d86f787fcf17a0eefd22be (patch)
treed418eb79283071624e203121eac8dbd1f6de92fb
parenta5eea6c8b67ede9db9b741935398e246c6095671 (diff)
Implementing other V3 Controllers
Issue-ID: CCSDK-4008 Change-Id: I00408d0189f26142f50c8ee3ae90fc98647e7a0d Signed-off-by: Raviteja Karumuri <raviteja.karumuri@est.tech>
-rw-r--r--a1-policy-management/api/pms-api-v3.yaml13
-rw-r--r--a1-policy-management/pom.xml10
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3.java54
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3.java20
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3.java69
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3.java81
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/StatusControllerV3.java64
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/RicRepositoryMapper.java35
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/ServiceControllerMapper.java35
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/StatusControllerMapper.java30
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyService.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/Helper.java8
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerTestV3.java128
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerTestV3.java (renamed from a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerTest.java)45
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerTestV3.java123
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerTestV3.java141
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelper.java14
-rw-r--r--csit/scripts/healthcheck/docker-compose.yml2
18 files changed, 846 insertions, 28 deletions
diff --git a/a1-policy-management/api/pms-api-v3.yaml b/a1-policy-management/api/pms-api-v3.yaml
index 2caf7086..3d390569 100644
--- a/a1-policy-management/api/pms-api-v3.yaml
+++ b/a1-policy-management/api/pms-api-v3.yaml
@@ -19,7 +19,7 @@
openapi: 3.0.3
info:
title: 'A1 policy management API'
- version: 3.0.0
+ version: 1.0.0
x-api-id: a31c510b-20e6-4a08-af16-368c44d7fba8
x-audience: external-public
description: "<h2>General</h2><p>The O-RAN Non-RT RIC Policy Management Service\
@@ -168,7 +168,7 @@ paths:
summary: Query Near-RT RIC information
tags:
- NearRT-RIC Repository
- /policyTypes:
+ /policytypes:
get:
operationId: getPolicyTypes
parameters:
@@ -238,7 +238,7 @@ paths:
description: Query policy type identities
tags:
- A1 Policy Management
- /policyTypes/{policyTypeId}:
+ /policytypes/{policyTypeId}:
get:
operationId: getPolicyTypeDefinition
parameters:
@@ -301,7 +301,7 @@ paths:
content:
application/json:
schema:
- type: object
+ $ref: '#/components/schemas/PolicyObject'
examples:
policyObject:
$ref: '#/components/examples/PolicyObject'
@@ -863,6 +863,11 @@ components:
\ false."
nullable: false
type: boolean
+ policyId:
+ description: identity of the Policy
+ type: string
+ example:
+ 'POLICY-ID'
serviceId:
description: the identity of the service owning the policy. This can be
used to group the policies (it is possible to get all policies associated
diff --git a/a1-policy-management/pom.xml b/a1-policy-management/pom.xml
index 9480201e..b9b34a27 100644
--- a/a1-policy-management/pom.xml
+++ b/a1-policy-management/pom.xml
@@ -127,6 +127,16 @@
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.mapstruct</groupId>
+ <artifactId>mapstruct</artifactId>
+ <version>1.5.5.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mapstruct</groupId>
+ <artifactId>mapstruct-processor</artifactId>
+ <version>1.5.5.Final</version>
+ </dependency>
<!-- Actuator dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
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
new file mode 100644
index 00000000..d04254c0
--- /dev/null
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3.java
@@ -0,0 +1,54 @@
+/*-
+ * ========================LICENSE_START=================================
+ * Copyright (C) 2020-2023 Nordix Foundation. 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.controllers.v3;
+
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v3.ConfigurationApi;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.ConfigurationController;
+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")
+@Tag( //
+ name = ConfigurationControllerV3.API_NAME, //
+ description = ConfigurationControllerV3.API_DESCRIPTION //
+)
+@RequestMapping("/a1policymanagement/v1")
+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;
+
+ @Override
+ public Mono<ResponseEntity<String>> getConfiguration(ServerWebExchange exchange) throws Exception {
+ return configurationController.getConfiguration(exchange);
+ }
+
+ @Override
+ public Mono<ResponseEntity<Object>> putConfiguration(Mono<Object> body, ServerWebExchange exchange) throws Exception {
+ return configurationController.putConfiguration(body, exchange);
+ }
+}
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 edc3be12..4d9f3277 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
@@ -57,34 +57,38 @@ public class PolicyControllerV3 implements A1PolicyManagementApi {
@Override
public Mono<ResponseEntity<PolicyObjectInformation>> createPolicy(Mono<PolicyObjectInformation> policyObjectInformation, ServerWebExchange exchange) {
- return policyObjectInformation.flatMap(policyObjectInfo -> {
- return policyService.createPolicyService(policyObjectInfo, exchange);
- });
+ return policyObjectInformation.flatMap(policyObjectInfo -> policyService.createPolicyService(policyObjectInfo, exchange)
+ .doOnError(error -> errorHandlingService.handleError(error)));
}
@Override
public Mono<ResponseEntity<Void>> deletePolicy(String policyId, String accept, ServerWebExchange exchange) throws Exception {
- return policyService.deletePolicyService(policyId, exchange);
+ return policyService.deletePolicyService(policyId, exchange)
+ .doOnError(error -> errorHandlingService.handleError(error));
}
@Override
public Mono<ResponseEntity<Object>> getPolicy(String policyId, String accept, ServerWebExchange exchange) throws Exception {
- return policyService.getPolicyService(policyId, exchange);
+ return policyService.getPolicyService(policyId, exchange)
+ .doOnError(error -> errorHandlingService.handleError(error));
}
@Override
public Mono<ResponseEntity<Flux<PolicyInformation>>> getPolicyIds(String policyTypeId, String nearRtRicId, String serviceId, String typeName, String accept, ServerWebExchange exchange) throws Exception {
- return policyService.getPolicyIdsService(policyTypeId, nearRtRicId, serviceId, typeName, exchange);
+ return policyService.getPolicyIdsService(policyTypeId, nearRtRicId, serviceId, typeName, exchange)
+ .doOnError(error -> errorHandlingService.handleError(error));
}
@Override
public Mono<ResponseEntity<Object>> getPolicyTypeDefinition(String policyTypeId, String accept, ServerWebExchange exchange) throws Exception {
- return policyService.getPolicyTypeDefinitionService(policyTypeId);
+ return policyService.getPolicyTypeDefinitionService(policyTypeId)
+ .doOnError(error -> errorHandlingService.handleError(error));
}
@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, exchange)
+ .doOnError(error -> errorHandlingService.handleError(error));
}
@Override
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
new file mode 100644
index 00000000..9160bad2
--- /dev/null
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3.java
@@ -0,0 +1,69 @@
+/*-
+ * ========================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.controllers.v3;
+
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v3.NearRtRicRepositoryApi;
+import org.onap.ccsdk.oran.a1policymanagementservice.mappers.v3.RicRepositoryMapper;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.RicRepositoryController;
+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")
+@Tag(
+ name = RicRepositoryControllerV3.API_NAME,
+ description = RicRepositoryControllerV3.API_DESCRIPTION
+)
+@RequestMapping("/a1policymanagement/v1")
+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;
+
+ @Autowired
+ 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));
+ }
+
+ @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));
+ }
+}
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
new file mode 100644
index 00000000..1d5461c3
--- /dev/null
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerV3.java
@@ -0,0 +1,81 @@
+/*-
+ * ========================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.controllers.v3;
+
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v3.ServiceRegistryAndSupervisionApi;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.ServiceController;
+import org.onap.ccsdk.oran.a1policymanagementservice.mappers.v3.ServiceControllerMapper;
+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")
+@Tag( //
+ name = ServiceControllerV3.API_NAME, //
+ description = ServiceControllerV3.API_DESCRIPTION //
+)
+@RequestMapping("/a1policymanagement/v1")
+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;
+
+ @Autowired
+ private ServiceControllerMapper serviceControllerMapper;
+
+ @Autowired
+ ErrorHandlingService errorHandlingService;
+
+ @Override
+ public Mono<ResponseEntity<Object>> deleteService(String serviceId, String accept, ServerWebExchange exchange) throws Exception {
+ return serviceController.deleteService(serviceId, exchange);
+ }
+
+ @Override
+ public Mono<ResponseEntity<ServiceStatusList>> getServices(String serviceId, String accept, ServerWebExchange exchange) throws Exception {
+ return serviceController.getServices(serviceId, exchange)
+ .map(responseEntity -> new ResponseEntity<>(serviceControllerMapper.toServiceStatusListV3(
+ responseEntity.getBody()), responseEntity.getStatusCode()))
+ .doOnError(error -> errorHandlingService.handleError(error));
+ }
+
+ @Override
+ public Mono<ResponseEntity<Object>> keepAliveService(String serviceId, String accept, Mono<String> body, ServerWebExchange exchange) throws Exception {
+ return serviceController.keepAliveService(serviceId, exchange);
+ }
+
+ @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));
+ }
+}
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
new file mode 100644
index 00000000..4bed9fe8
--- /dev/null
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/StatusControllerV3.java
@@ -0,0 +1,64 @@
+/*-
+ * ========================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.controllers.v3;
+
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.api.v3.HealthCheckApi;
+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")
+@Tag( //
+ name = StatusControllerV3.API_NAME, //
+ description = StatusControllerV3.API_DESCRIPTION //
+)
+@RequestMapping("/a1policymanagement/v1")
+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;
+
+ @Autowired
+ 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));
+ }
+}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/RicRepositoryMapper.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/RicRepositoryMapper.java
new file mode 100644
index 00000000..c616d247
--- /dev/null
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/RicRepositoryMapper.java
@@ -0,0 +1,35 @@
+/*-
+ * ========================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.mappers.v3;
+
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.RicInfo;
+import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.RicInfoList;
+
+@Mapper(componentModel = "spring")
+public interface RicRepositoryMapper {
+
+ @Mapping(source = "policytypeIds", target = "policyTypeIds")
+ RicInfo toRicInfoV3(org.onap.ccsdk.oran.a1policymanagementservice.models.v2.RicInfo ricInfoV2);
+
+ RicInfoList toRicInfoListV3(org.onap.ccsdk.oran.a1policymanagementservice.models.v2.RicInfoList ricInfoListV2);
+}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/ServiceControllerMapper.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/ServiceControllerMapper.java
new file mode 100644
index 00000000..37f52502
--- /dev/null
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/ServiceControllerMapper.java
@@ -0,0 +1,35 @@
+/*-
+ * ========================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.mappers.v3;
+
+import org.mapstruct.Mapper;
+import org.onap.ccsdk.oran.a1policymanagementservice.models.v2.ServiceRegistrationInfo;
+import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.ServiceStatusList;
+
+@Mapper(componentModel = "spring")
+public interface ServiceControllerMapper {
+
+ ServiceRegistrationInfo toServiceRegistrationInfoV2(
+ org.onap.ccsdk.oran.a1policymanagementservice.models.v3.ServiceRegistrationInfo serviceRegistrationInfo);
+
+ ServiceStatusList toServiceStatusListV3(
+ org.onap.ccsdk.oran.a1policymanagementservice.models.v2.ServiceStatusList serviceStatusList);
+}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/StatusControllerMapper.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/StatusControllerMapper.java
new file mode 100644
index 00000000..17b858ba
--- /dev/null
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/mappers/v3/StatusControllerMapper.java
@@ -0,0 +1,30 @@
+/*-
+ * ========================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.mappers.v3;
+
+import org.mapstruct.Mapper;
+import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.StatusInfo;
+
+@Mapper(componentModel = "spring")
+public interface StatusControllerMapper {
+
+ StatusInfo toStatusInfoV3(org.onap.ccsdk.oran.a1policymanagementservice.models.v2.StatusInfo statusInfo);
+}
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 6cd9b8d3..a892bfa3 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
@@ -81,7 +81,7 @@ public class PolicyService {
return Mono.error(new ServiceException("Schema validation failed", HttpStatus.BAD_REQUEST));
Ric ric = rics.getRic(policyObjectInfo.getNearRtRicId());
PolicyType policyType = policyTypes.getType(policyObjectInfo.getPolicyTypeId());
- Policy policy = helper.buildPolicy(policyObjectInfo, policyType, ric, helper.policyIdGeneration());
+ Policy policy = helper.buildPolicy(policyObjectInfo, policyType, ric, helper.policyIdGeneration(policyObjectInfo));
return helper.isPolicyAlreadyCreated(policy,policies)
.doOnError(error -> errorHandlingService.handleError(error))
.flatMap(policyBuilt -> authorizationService.authCheck(serverWebExchange, policy, AccessType.WRITE)
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 88205919..638d9504 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
@@ -102,8 +102,12 @@ public class Helper {
return true;
}
- public String policyIdGeneration() {
- return UUID.randomUUID().toString();
+ public String policyIdGeneration(PolicyObjectInformation policyObjectInfo) {
+ if (policyObjectInfo.getPolicyId() == null || policyObjectInfo.getPolicyId().isEmpty() ||
+ policyObjectInfo.getPolicyId().isBlank())
+ return UUID.randomUUID().toString();
+ else
+ return policyObjectInfo.getPolicyId().trim();
}
public String toJson(Object jsonObject) {
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerTestV3.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerTestV3.java
new file mode 100644
index 00000000..c634ecc5
--- /dev/null
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerTestV3.java
@@ -0,0 +1,128 @@
+/*-
+ * ========================LICENSE_START=================================
+ * Copyright (C) 2020-2023 Nordix Foundation. 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.controllers.v3;
+
+import org.junit.jupiter.api.*;
+import org.junit.jupiter.api.io.TempDir;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
+import org.onap.ccsdk.oran.a1policymanagementservice.tasks.RefreshConfigTask;
+import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
+import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.TestPropertySource;
+import reactor.core.publisher.Mono;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.time.Duration;
+import java.util.Objects;
+
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.CoreMatchers.equalTo;
+
+@TestMethodOrder(MethodOrderer.MethodName.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@TestPropertySource(properties = { //
+ "server.ssl.key-store=./config/keystore.jks", //
+ "app.webclient.trust-store=./config/truststore.jks", //
+ "app.vardata-directory=./target", //
+ "app.config-file-schema-path=/application_configuration_schema.json" //
+})
+class ConfigurationControllerTestV3 {
+ @Autowired
+ ApplicationContext context;
+
+ @Autowired
+ ApplicationConfig applicationConfig;
+
+ @Autowired
+ private Rics rics;
+
+ @Autowired
+ private TestHelper testHelper;
+
+ @TempDir
+ public static File temporaryFolder;
+ private static File configFile;
+
+ @LocalServerPort
+ private int port;
+
+ @BeforeEach
+ void init() {
+ testHelper.port = port;
+ }
+ @BeforeAll
+ static void setup() throws Exception {
+ Field f1 = RefreshConfigTask.class.getDeclaredField("configRefreshInterval");
+ f1.setAccessible(true);
+ f1.set(null, Duration.ofSeconds(1));
+ }
+
+ public static class MockApplicationConfig extends ApplicationConfig {
+ @Override
+ public String getLocalConfigurationFilePath() {
+ configFile = new File(temporaryFolder, "config.json");
+ return configFile.getAbsolutePath();
+ }
+ }
+
+ /**
+ * Overrides the BeanFactory.
+ */
+ @TestConfiguration
+ static class TestBeanFactory {
+ @Bean
+ public ApplicationConfig getApplicationConfig() {
+ return new MockApplicationConfig();
+ }
+
+ @Bean
+ public ServletWebServerFactory servletContainer() {
+ return new TomcatServletWebServerFactory();
+ }
+ }
+
+ @Test
+ void testPutConfiguration() throws Exception {
+ Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().putForEntity("/configuration",
+ testHelper.configAsString());
+ testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, Objects::isNull);
+ //put Valid Configuration With New Ric should Update Repository. So, will wait until the ric size is 2
+ await().until(rics::size, equalTo(2));
+ //test Get Configuration
+ Mono<ResponseEntity<String>> responseGetConfigMono = testHelper.restClientV3().getForEntity("/configuration");
+ testHelper.testSuccessResponse(responseGetConfigMono, HttpStatus.OK, responseBody -> responseBody.contains("config"));
+ }
+
+ @Test
+ public 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/PolicyControllerTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerTestV3.java
index d92097bd..a8c5fbae 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerTestV3.java
@@ -27,14 +27,13 @@ import org.onap.ccsdk.oran.a1policymanagementservice.config.TestConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.controllers.OpenPolicyAgentSimulatorController;
import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.RappSimulatorController;
-import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.PolicyObjectInformation;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
import org.onap.ccsdk.oran.a1policymanagementservice.util.v3.Helper;
-import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelper;
import org.onap.ccsdk.oran.a1policymanagementservice.utils.MockA1ClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -66,7 +65,7 @@ import static org.mockito.Mockito.when;
"app.filepath=", //
"app.s3.bucket=" // If this is set, S3 will be used to store data.
})
-public class PolicyControllerTest {
+public class PolicyControllerTestV3 {
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@Autowired
@@ -143,7 +142,7 @@ public class PolicyControllerTest {
String policyTypeName = "type1_1.2.3";
String url = "/policies";
testHelper.addPolicyType(policyTypeName, nonRtRicId);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName);
+ String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "");
Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
testHelper.testSuccessResponse(responseMono, HttpStatus.CREATED, responseBody ->
responseBody.contains("{\"scope\":{\"ueId\":\"ue5100\",\"qosId\":\"qos5100\"},\"qosObjectives\":{\"priorityLevel\":5100.0}}"));
@@ -151,13 +150,39 @@ public class PolicyControllerTest {
}
@Test
+ @DisplayName("test Create Policy with PolicyID sending")
+ void testPostPolicyWithPolicyID() throws Exception {
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ testHelper.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "1");
+ Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
+ testHelper.testSuccessHeader(responseMono, "location", headerValue -> headerValue.contains("https://localhost:" + port + "/a1policymanagement/v1/policies/1"));
+ }
+
+ @Test
+ @DisplayName("test Create Policy with exisitng policy id")
+ void testPostPolicyWithExistingPolicyID() throws Exception {
+ String nonRtRicId = "ric.1";
+ String policyTypeName = "type1_1.2.3";
+ String url = "/policies";
+ String policyId = "policy_5g";
+ testHelper.addPolicyType(policyTypeName, nonRtRicId);
+ String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, policyId);
+ testHelper.restClientV3().postForEntity(url, policyBody).block();
+ Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
+ testHelper.testErrorCode(responseMono, HttpStatus.CONFLICT, "Policy already created with ID: " +policyId);
+ }
+
+ @Test
@DisplayName("test delete Policy")
void testDeletePolicy() throws Exception {
String nonRtRicId = "ric.1";
String policyTypeName = "type1_1.2.3";
String url = "/policies";
testHelper.addPolicyType(policyTypeName, nonRtRicId);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName);
+ String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "");
Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
String []locationHeader = Objects.requireNonNull(Objects.requireNonNull(responseMono.block()).getHeaders()
.get("location")).get(0).split("/");
@@ -174,7 +199,7 @@ public class PolicyControllerTest {
String url = "/policies";
testHelper.addPolicyType(policyTypeName, nonRtRicId);
when(helper.jsonSchemaValidation(any())).thenReturn(Boolean.FALSE);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName);
+ String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "");
Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
testHelper.testErrorCode(responseMono, HttpStatus.BAD_REQUEST, " Schema validation failed");
}
@@ -186,7 +211,7 @@ public class PolicyControllerTest {
String url = "/policies";
testHelper.addPolicyType(policyTypeName, " ");
when(helper.jsonSchemaValidation(any())).thenReturn(Boolean.TRUE);
- String policyBody = testHelper.postPolicyBody("noRic", policyTypeName);
+ String policyBody = testHelper.postPolicyBody("noRic", policyTypeName, "");
Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
testHelper.testErrorCode(responseMono, HttpStatus.NOT_FOUND, " Could not find ric: noRic");
}
@@ -199,7 +224,7 @@ public class PolicyControllerTest {
String url = "/policies";
testHelper.addPolicyType(policyTypeName, nonRtRicId);
when(helper.jsonSchemaValidation(any())).thenReturn(Boolean.TRUE);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, "noPolicyType");
+ String policyBody = testHelper.postPolicyBody(nonRtRicId, "noPolicyType", "");
Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
testHelper.testErrorCode(responseMono, HttpStatus.NOT_FOUND, "Could not find type: noPolicyType");
}
@@ -209,7 +234,7 @@ public class PolicyControllerTest {
String policyTypeName = "type1_1.2.3";
String nonRtRicId = "ricOne";
testHelper.addPolicyType(policyTypeName, nonRtRicId);
- Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().getForEntity("/policyTypes" + "?nearRtRicId=\"noRic\"");
+ Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().getForEntity("/policytypes" + "?nearRtRicId=\"noRic\"");
testHelper.testErrorCode(responseMono, HttpStatus.NOT_FOUND, "Near-RT RIC not Found using ID:");
}
@@ -220,7 +245,7 @@ public class PolicyControllerTest {
String policyTypeName = "type1_1.2.3";
String url = "/policies";
testHelper.addPolicyType(policyTypeName, nonRtRicId);
- String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName);
+ String policyBody = testHelper.postPolicyBody(nonRtRicId, policyTypeName, "");
Mono<ResponseEntity<String>> responseMono = testHelper.restClientV3().postForEntity(url, policyBody);
String []locationHeader = Objects.requireNonNull(Objects.requireNonNull(responseMono.block()).getHeaders()
.get("location")).get(0).split("/");
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerTestV3.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerTestV3.java
new file mode 100644
index 00000000..576ae7f6
--- /dev/null
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerTestV3.java
@@ -0,0 +1,123 @@
+/*-
+ * ========================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.controllers.v3;
+
+import org.junit.jupiter.api.*;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
+import org.onap.ccsdk.oran.a1policymanagementservice.config.TestConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.OpenPolicyAgentSimulatorController;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.RappSimulatorController;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
+import org.onap.ccsdk.oran.a1policymanagementservice.utils.MockA1ClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestPropertySource;
+import reactor.core.publisher.Mono;
+
+import java.io.IOException;
+import java.lang.invoke.MethodHandles;
+
+@TestMethodOrder(MethodOrderer.MethodName.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ContextConfiguration(classes = TestConfig.class)
+@TestPropertySource(properties = { //
+ "server.ssl.key-store=./config/keystore.jks", //
+ "app.webclient.trust-store=./config/truststore.jks", //
+ "app.webclient.trust-store-used=true", //
+ "app.vardata-directory=/tmp/pmstestv3", //a
+ "app.filepath=", //
+ "app.s3.bucket=" // If this is set, S3 will be used to store data.
+})
+public class RicRepositoryControllerTestV3 {
+
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @Autowired
+ private TestHelper testHelper;
+
+ @Autowired
+ private ApplicationConfig applicationConfig;
+
+ @Autowired
+ private MockA1ClientFactory a1ClientFactory;
+
+ @Autowired
+ private RappSimulatorController rAppSimulator;
+
+ @Autowired
+ private SecurityContext securityContext;
+
+ @Autowired
+ private OpenPolicyAgentSimulatorController openPolicyAgentSimulatorController;
+
+ @Autowired
+ private PolicyTypes policyTypes;
+
+ @Autowired
+ private Rics rics;
+
+ @LocalServerPort
+ private int port;
+
+ @BeforeEach
+ void init() {
+ testHelper.port = port;
+ this.applicationConfig.setAuthProviderUrl(testHelper.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
+ }
+
+ @AfterEach
+ void reset() {
+ rics.clear();
+ a1ClientFactory.reset();
+ this.rAppSimulator.getTestResults().clear();
+ this.a1ClientFactory.setPolicyTypes(policyTypes); // Default same types in RIC and in this app
+ this.securityContext.setAuthTokenFilePath(null);
+ this.openPolicyAgentSimulatorController.getTestResults().reset();
+ }
+
+ @Test
+ public 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
+ .contains("{\"ricId\":\"ricAdded\",\"managedElementIds\":[],\"state\":\"AVAILABLE\",\"policyTypeIds\":[\"1\"]}"));
+ }
+
+ @Test
+ public void testGetRics() throws IOException {
+ testHelper.addPolicyType("1", "ricAddedOne");
+ testHelper.addPolicyType("2", "ricAddedTwo");
+ Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3().getForEntity("/rics");
+ testHelper.testSuccessResponse(responseEntityMono, HttpStatus.OK, responseBody -> responseBody
+ .contains("{\"rics\":[{\"ricId\":\"ricAddedTwo\",\"managedElementIds\":[],\"state\":\"AVAILABLE\"," +
+ "\"policyTypeIds\":[\"2\"]},{\"ricId\":\"ricAddedOne\",\"managedElementIds\":[]," +
+ "\"state\":\"AVAILABLE\",\"policyTypeIds\":[\"1\"]}]}"));
+ }
+}
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerTestV3.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerTestV3.java
new file mode 100644
index 00000000..9eeaa3af
--- /dev/null
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ServiceControllerTestV3.java
@@ -0,0 +1,141 @@
+/*-
+ * ========================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.controllers.v3;
+
+import com.google.gson.Gson;
+import org.junit.jupiter.api.*;
+import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
+import org.onap.ccsdk.oran.a1policymanagementservice.config.TestConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.OpenPolicyAgentSimulatorController;
+import org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2.RappSimulatorController;
+import org.onap.ccsdk.oran.a1policymanagementservice.models.v3.ServiceRegistrationInfo;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.Service;
+import org.onap.ccsdk.oran.a1policymanagementservice.repository.Services;
+import org.onap.ccsdk.oran.a1policymanagementservice.utils.MockA1ClientFactory;
+import org.onap.ccsdk.oran.a1policymanagementservice.utils.v3.TestHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestPropertySource;
+import reactor.core.publisher.Mono;
+
+import java.lang.invoke.MethodHandles;
+import java.time.Duration;
+
+@TestMethodOrder(MethodOrderer.MethodName.class)
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ContextConfiguration(classes = TestConfig.class)
+@TestPropertySource(properties = { //
+ "server.ssl.key-store=./config/keystore.jks", //
+ "app.webclient.trust-store=./config/truststore.jks", //
+ "app.webclient.trust-store-used=true", //
+ "app.vardata-directory=/tmp/pmstestv3", //a
+ "app.filepath=", //
+ "app.s3.bucket=" // If this is set, S3 will be used to store data.
+})
+public class ServiceControllerTestV3 {
+
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @Autowired
+ private TestHelper testHelper;
+
+ @Autowired
+ private ApplicationConfig applicationConfig;
+
+ @Autowired
+ private Services services;
+
+ @Autowired
+ private MockA1ClientFactory a1ClientFactory;
+
+ @Autowired
+ private RappSimulatorController rAppSimulator;
+
+ @Autowired
+ private SecurityContext securityContext;
+
+ @Autowired
+ private OpenPolicyAgentSimulatorController openPolicyAgentSimulatorController;
+
+ @Autowired
+ private PolicyTypes policyTypes;
+
+ @Autowired
+ private Gson gson;
+
+ @LocalServerPort
+ private int port;
+
+ @BeforeEach
+ void init() {
+ testHelper.port = port;
+ this.applicationConfig.setAuthProviderUrl(testHelper.baseUrl() + OpenPolicyAgentSimulatorController.ACCESS_CONTROL_URL);
+ }
+
+ @AfterEach
+ void reset() {
+ services.clear();
+ a1ClientFactory.reset();
+ this.rAppSimulator.getTestResults().clear();
+ this.a1ClientFactory.setPolicyTypes(policyTypes); // Default same types in RIC and in this app
+ this.securityContext.setAuthTokenFilePath(null);
+ this.openPolicyAgentSimulatorController.getTestResults().reset();
+ }
+
+ @Test
+ public void testPutService() {
+ ServiceRegistrationInfo serviceRegistrationInfo = new ServiceRegistrationInfo("serviceId");
+ serviceRegistrationInfo.callbackUrl("http://callback.com/").keepAliveIntervalSeconds(10L);
+ Mono<ResponseEntity<String>> responseEntityMono = testHelper.restClientV3()
+ .putForEntity("/services", gson.toJson(serviceRegistrationInfo));
+ testHelper.testSuccessResponse(responseEntityMono, HttpStatus.CREATED, responseBody -> services.size() == 1);
+ }
+
+ @Test
+ public 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
+ .contains("http://callback.com/"));
+ }
+
+ @Test
+ public 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() {
+ 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/utils/v3/TestHelper.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelper.java
index bfec3f6b..5463b0a1 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
@@ -25,6 +25,7 @@ import com.google.common.io.CharStreams;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import org.apache.commons.io.FileUtils;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext;
@@ -45,6 +46,7 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -161,13 +163,15 @@ public class TestHelper {
return type;
}
- public String postPolicyBody(String nearRtRicId, String policyTypeName) {
+ public String postPolicyBody(String nearRtRicId, String policyTypeName, String policyId) {
PolicyObjectInformation policyObjectInfo = new PolicyObjectInformation(nearRtRicId, dummyPolicyObject(), 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);
+ return gson.fromJson(postPolicyBody(nearRtRicId, policyTypeName, ""), PolicyObjectInformation.class);
}
public JsonObject dummyPolicyObject() {
@@ -251,4 +255,10 @@ public class TestHelper {
})
.verify();
}
+
+ public String configAsString() throws Exception {
+ File configFile =
+ new File(Objects.requireNonNull(getClass().getClassLoader().getResource("test_application_configuration.json")).getFile());
+ return FileUtils.readFileToString(configFile, "UTF-8");
+ }
}
diff --git a/csit/scripts/healthcheck/docker-compose.yml b/csit/scripts/healthcheck/docker-compose.yml
index d6dda495..0384d441 100644
--- a/csit/scripts/healthcheck/docker-compose.yml
+++ b/csit/scripts/healthcheck/docker-compose.yml
@@ -31,7 +31,7 @@ services:
- 8081:8081
- 8433:8433
volumes:
- - ./config/application_configuration.json:/opt/app/policy-agent/data/application_configuration.json:ro
+ - ./config/application_configuration.json.nosdnc:/opt/app/policy-agent/data/application_configuration.json:ro
# For using own certs instead of the default ones (built into the container),
# place them in config/ directory, update the application-policyagent.yaml file, and uncomment the following lines
# - ./config/keystore-policyagent.jks:/opt/app/policy-agent/etc/cert/keystore.jks:ro