aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/test/java/org
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2024-01-16 09:39:06 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2024-03-26 17:00:53 +0000
commit1cf51a2280fb2f9a0435b8a3f2c64492cb7e6659 (patch)
tree345e7748d5efedd14aa3570655f2c1681fc6f56c /models/src/test/java/org
parentb7291f81e63c5d4e30351ed0429167937934bc71 (diff)
Recursive updates of the properties
Merge properties during update and migrate. Issue-ID: POLICY-4951 Change-Id: I0c9a896a5abb8331937a73d7e39fbce2d87b415f Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/test/java/org')
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java70
-rw-r--r--models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java18
2 files changed, 87 insertions, 1 deletions
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
index bc8741e65..1561533e8 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java
@@ -293,4 +293,74 @@ class AcmUtilsTest {
nodeTemplates.put("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", nodeTemplate);
return nodeTemplates;
}
+
+ @Test
+ void testRecursiveMergeMap() {
+ var oldProperties = """
+ chart:
+ chartId:
+ name: acelement
+ version: 0.1.0
+ namespace: default
+ releaseName: acm-starter
+ podName: acm-starter
+ """;
+
+ var newProperties = """
+ chart:
+ releaseName: acm-starter-new
+ podName: null
+ """;
+
+ Map<String, Object> map = CommonTestData.getObject(oldProperties, Map.class);
+ Map<String, Object> mapMigrate = CommonTestData.getObject(newProperties, Map.class);
+
+ AcmUtils.recursiveMerge(map, mapMigrate);
+ assertEquals("default", ((Map<String, Object>) map.get("chart")).get("namespace"));
+ assertEquals("acm-starter-new", ((Map<String, Object>) map.get("chart")).get("releaseName"));
+ assertNotNull(((Map<String, Object>) map.get("chart")).get("chartId"));
+ assertNull(((Map<String, Object>) map.get("chart")).get("podName"));
+ }
+
+ @Test
+ void testRecursiveMergeList() {
+ var oldProperties = """
+ baseUrl: http://{{address}}:30800
+ httpHeaders:
+ Content-Type: application/json
+ Authorization: Basic YWNtVXNlcjp6YiFYenRHMzQ=
+ configurationEntities:
+ - configurationEntityId:
+ name: onap.policy.clamp.ac.starter
+ version: 1.0.0
+ restSequence:
+ - restRequestId:
+ name: request1
+ version: 1.0.1
+ myParameterToUpdate: 9
+ myParameterToRemove: 8
+ """;
+
+ var newProperties = """
+ configurationEntities:
+ - myParameterToUpdate: "90"
+ myParameterToRemove: null
+ myParameter: "I am new"
+ """;
+
+ Map<String, Object> map = CommonTestData.getObject(oldProperties, Map.class);
+ Map<String, Object> mapMigrate = CommonTestData.getObject(newProperties, Map.class);
+
+ AcmUtils.recursiveMerge(map, mapMigrate);
+ assertEquals("http://{{address}}:30800", map.get("baseUrl"));
+ assertEquals("application/json", ((Map<String, Object>) map.get("httpHeaders")).get("Content-Type"));
+ var configurationEntities = (List<Object>) map.get("configurationEntities");
+ var subMap = (Map<String, Object>) configurationEntities.get(0);
+ assertEquals("onap.policy.clamp.ac.starter",
+ ((Map<String, Object>) subMap.get("configurationEntityId")).get("name"));
+ assertThat((List<Object>) subMap.get("restSequence")).isNotEmpty();
+ assertEquals("90", subMap.get("myParameterToUpdate"));
+ assertNull(subMap.get("myParameterToRemove"));
+ assertEquals("I am new", subMap.get("myParameter"));
+ }
}
diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
index 03a3fb11a..131c8eefd 100644
--- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
+++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/CommonTestData.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,6 +83,22 @@ public class CommonTestData {
}
/**
+ * Get Object from string in yaml format.
+ *
+ * @param yaml the string in yaml format
+ * @param clazz the Class of the Object
+ * @return the Object
+ */
+ public static <T> T getObject(String yaml, Class<T> clazz) {
+ try {
+ return YAML_TRANSLATOR.decode(yaml, clazz);
+ } catch (CoderException e) {
+ fail("Cannot decode " + yaml);
+ return null;
+ }
+ }
+
+ /**
* Get new AutomationCompositionElementDefinition.
*
* @param id the ToscaConceptIdentifier