Fixed managedElement required issue 38/140538/3
authorsaul.gill <saul.gill@est.tech>
Thu, 20 Mar 2025 16:13:12 +0000 (16:13 +0000)
committersaul.gill <saul.gill@est.tech>
Mon, 24 Mar 2025 09:45:39 +0000 (09:45 +0000)
Issue-ID: CCSDK-4107
Change-Id: I6a5c1fb5e7be673d13c622f0fcbbaa3e883f4dfe
Signed-off-by: saul.gill <saul.gill@est.tech>
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RicRepositoryController.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/RicRepositoryControllerV3.java
a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/ConfigurationControllerV3Test.java
a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/v3/TestHelperTest.java
a1-policy-management/src/test/resources/test_application_configuration_me_empty.json [new file with mode: 0644]
a1-policy-management/src/test/resources/test_application_configuration_me_null.json [new file with mode: 0644]

index f5f0f7e..24c1d25 100644 (file)
@@ -2,7 +2,7 @@
  * ========================LICENSE_START=================================
  * ONAP : ccsdk oran
  * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2019-2025 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.
@@ -148,13 +148,20 @@ public class ApplicationConfigParser {
                         "Configuration error, controller configuration not found: " + controllerName);
             }
 
-            RicConfig ricConfig = RicConfig.builder() //
-                    .ricId(get(ricJsonObj, "name", "id", "ricId").getAsString()) //
-                    .baseUrl(get(ricJsonObj, "baseUrl").getAsString()) //
-                    .managedElementIds(parseManagedElementIds(get(ricJsonObj, "managedElementIds").getAsJsonArray())) //
+            RicConfig.RicConfigBuilder ricConfigBuilder = RicConfig.builder()
+                    .ricId(get(ricJsonObj, "name", "id", "ricId").getAsString())
+                    .baseUrl(get(ricJsonObj, "baseUrl").getAsString())
                     .controllerConfig(controllerConfig)
-                    .customAdapterClass(getString(ricJsonObj, "customAdapterClass", "")) //
-                    .build();
+                    .customAdapterClass(getString(ricJsonObj, "customAdapterClass", ""));
+
+            if (ricJsonObj.has("managedElementIds")) {
+                ricConfigBuilder
+                    .managedElementIds(parseManagedElementIds(get(ricJsonObj, "managedElementIds").getAsJsonArray()));
+            } else {
+                ricConfigBuilder.managedElementIds(null);
+            }
+
+            RicConfig ricConfig = ricConfigBuilder.build();
             if (!ricConfig.getBaseUrl().isEmpty()) {
                 result.add(ricConfig);
             } else {
index 53abcd7..ee3ce6d 100644 (file)
@@ -41,9 +41,7 @@ import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.server.ServerWebExchange;
 import reactor.core.publisher.Mono;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 @RestController("ricRepositoryControllerV2")
 @RequiredArgsConstructor
@@ -124,9 +122,16 @@ public class RicRepositoryController implements NearRtRicRepositoryApi {
     }
 
     private RicInfo toRicInfo(Ric ric) {
-        return new RicInfo().ricId(ric.id())
-                .managedElementIds((List<String>) ric.getManagedElementIds())
+        RicInfo ricInfo =  new RicInfo().ricId(ric.id())
                 .policytypeIds((List<String>) ric.getSupportedPolicyTypeNames())
                 .state(toRicState(ric.getState()));
+        
+        if (ric.getConfig().getManagedElementIds() == null) {
+            ricInfo.setManagedElementIds(new ArrayList<>());
+        } else {
+            ricInfo.managedElementIds((List<String>) ric.getConfig().getManagedElementIds());
+        }
+
+        return ricInfo;
     }
 }
index ce2769e..ff33c7c 100644 (file)
@@ -40,8 +40,7 @@ import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.server.ServerWebExchange;
 import reactor.core.publisher.Mono;
 
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 
 @RestController("ricRepositoryControllerV3")
 @RequiredArgsConstructor
@@ -93,10 +92,17 @@ public class RicRepositoryControllerV3 implements NearRtRicRepositoryApi {
     }
 
     private RicInfo toRicInfo(Ric ric) {
-        return new RicInfo().ricId(ric.id())
-                .managedElementIds((List<String>) ric.getManagedElementIds())
+        RicInfo ricInfo =  new RicInfo().ricId(ric.id())
                 .policyTypeIds((List<String>) ric.getSupportedPolicyTypeNames())
                 .state(toRicState(ric.getState()));
+
+        if (ric.getConfig().getManagedElementIds() == null) {
+            ricInfo.setManagedElementIds(new ArrayList<>());
+        } else {
+            ricInfo.managedElementIds((List<String>) ric.getConfig().getManagedElementIds());
+        }
+
+        return ricInfo;
     }
 
     private RicInfo.StateEnum toRicState(Ric.RicState state) {
index d9fa63a..666b37e 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ========================LICENSE_START=================================
- * Copyright (C) 2020-2023 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2020-2025 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.
@@ -53,6 +53,10 @@ import static org.hamcrest.CoreMatchers.equalTo;
         "app.config-file-schema-path=/application_configuration_schema.json" //
 })
 class ConfigurationControllerV3Test {
+
+    @Autowired
+    private RefreshConfigTask refreshConfigTask;
+
     @Autowired
     ApplicationContext context;
 
@@ -119,6 +123,46 @@ class ConfigurationControllerV3Test {
         testHelperTest.testSuccessResponse(responseGetConfigMono, HttpStatus.OK, responseBody -> responseBody.contains("config"));
     }
 
+    @Test
+    void testPutConfigurationMeNull() throws Exception {
+        Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3().putForEntity("/configuration",
+                testHelperTest.configAsStringMeNull());
+        testHelperTest.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 = testHelperTest.restClientV3().getForEntity("/configuration");
+        testHelperTest.testSuccessResponse(responseGetConfigMono, HttpStatus.OK, responseBody -> !responseBody.contains("\"managedElementIds\""));
+
+        refreshConfigTask.start();
+
+        Mono<ResponseEntity<String>> responseGetRicsMono = testHelperTest.restClientV3().getForEntity("/rics");
+        testHelperTest.testSuccessResponse(responseGetRicsMono, HttpStatus.OK, responseBody -> responseBody.contains("\"managedElementIds\":[]"));
+
+        Mono<ResponseEntity<String>> responseGetRicMono = testHelperTest.restClientV3().getForEntity("/rics/ric1");
+        testHelperTest.testSuccessResponse(responseGetRicMono, HttpStatus.OK, responseBody -> responseBody.contains("\"managedElementIds\":[]"));
+    }
+
+    @Test
+    void testPutConfigurationMeEmpty() throws Exception {
+        Mono<ResponseEntity<String>> responseEntityMono = testHelperTest.restClientV3().putForEntity("/configuration",
+                testHelperTest.configAsStringMeEmpty());
+        testHelperTest.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 = testHelperTest.restClientV3().getForEntity("/configuration");
+        testHelperTest.testSuccessResponse(responseGetConfigMono, HttpStatus.OK, responseBody -> responseBody.contains("\"managedElementIds\":[]"));
+
+        refreshConfigTask.start();
+
+        Mono<ResponseEntity<String>> responseGetRicsMono = testHelperTest.restClientV3().getForEntity("/rics");
+        testHelperTest.testSuccessResponse(responseGetRicsMono, HttpStatus.OK, responseBody -> responseBody.contains("\"managedElementIds\":[]"));
+
+        Mono<ResponseEntity<String>> responseGetRicMono = testHelperTest.restClientV3().getForEntity("/rics/ric1");
+        testHelperTest.testSuccessResponse(responseGetRicMono, HttpStatus.OK, responseBody -> responseBody.contains("\"managedElementIds\":[]"));
+    }
+
     @Test
     void testHealthCheck() {
         Mono<ResponseEntity<String>> responseHealthCheckMono = testHelperTest.restClientV3().getForEntity("/status");
index c36429c..a7b8cc9 100644 (file)
@@ -324,4 +324,16 @@ public class TestHelperTest {
                 new File(Objects.requireNonNull(getClass().getClassLoader().getResource("test_application_configuration.json")).getFile());
         return FileUtils.readFileToString(configFile, "UTF-8");
     }
+
+    public String configAsStringMeNull() throws Exception {
+        File configFile =
+                new File(Objects.requireNonNull(getClass().getClassLoader().getResource("test_application_configuration_me_null.json")).getFile());
+        return FileUtils.readFileToString(configFile, "UTF-8");
+    }
+
+    public String configAsStringMeEmpty() throws Exception {
+        File configFile =
+                new File(Objects.requireNonNull(getClass().getClassLoader().getResource("test_application_configuration_me_empty.json")).getFile());
+        return FileUtils.readFileToString(configFile, "UTF-8");
+    }
 }
diff --git a/a1-policy-management/src/test/resources/test_application_configuration_me_empty.json b/a1-policy-management/src/test/resources/test_application_configuration_me_empty.json
new file mode 100644 (file)
index 0000000..0bb0985
--- /dev/null
@@ -0,0 +1,32 @@
+{
+   "config": {
+      "description": "Test",
+      "controller": [
+         {
+            "name": "controller1",
+            "baseUrl": "http://localhost:8083/",
+            "userName": "user",
+            "password": "password"
+         }
+      ],
+      "ric": [
+         {
+            "name": "ric1",
+            "controller": "controller1",
+            "baseUrl": "http://localhost:8083/",
+            "customAdapterClass": "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2$Factory",
+            "managedElementIds": []
+         },
+         {
+            "name": "ric2",
+            "baseUrl": "http://localhost:8085/",
+            "managedElementIds": []
+         },
+         {
+            "name": "ric3_noBaseURL",
+            "baseUrl": "",
+            "managedElementIds": []
+         }
+      ]      
+   }
+}
diff --git a/a1-policy-management/src/test/resources/test_application_configuration_me_null.json b/a1-policy-management/src/test/resources/test_application_configuration_me_null.json
new file mode 100644 (file)
index 0000000..4fa7ff9
--- /dev/null
@@ -0,0 +1,29 @@
+{
+   "config": {
+      "description": "Test",
+      "controller": [
+         {
+            "name": "controller1",
+            "baseUrl": "http://localhost:8083/",
+            "userName": "user",
+            "password": "password"
+         }
+      ],
+      "ric": [
+         {
+            "name": "ric1",
+            "controller": "controller1",
+            "baseUrl": "http://localhost:8083/",
+            "customAdapterClass": "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2$Factory"
+         },
+         {
+            "name": "ric2",
+            "baseUrl": "http://localhost:8085/"
+         },
+         {
+            "name": "ric3_noBaseURL",
+            "baseUrl": ""
+         }
+      ]      
+   }
+}