From b2393969603cb943bc76f2b65da748b871ee9d17 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Thu, 7 Dec 2023 08:58:32 +0000 Subject: Add validation for AC instance element id Issue-ID: POLICY-4900 Change-Id: I78be5924950eec508856be5850a3a749860e0e49 Signed-off-by: FrancescoFioraEst --- .../AutomationCompositionInstantiationProvider.java | 2 ++ .../runtime/instantiation/InstantiationUtils.java | 21 +++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'runtime-acm') diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java index af4e844d5..9f126406b 100755 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java @@ -237,6 +237,8 @@ public class AutomationCompositionInstantiationProvider { acDefinitionOpt.get().getServiceTemplate(), acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName())); + result.addResult(automationCompositionProvider.validateElementIds(automationComposition)); + if (result.isValid()) { for (var element : automationComposition.getElements().values()) { var name = element.getDefinition().getName(); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java index 38c63fa9b..8639dffcd 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java @@ -25,6 +25,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; import java.io.File; +import java.util.ArrayList; +import java.util.UUID; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; import org.onap.policy.common.utils.coder.Coder; @@ -56,6 +58,13 @@ public class InstantiationUtils { // add suffix to name automationComposition.setName(automationComposition.getName() + suffix); + var elements = new ArrayList<>(automationComposition.getElements().values()); + automationComposition.getElements().clear(); + for (var element : elements) { + // set unique UUID to the element + element.setId(UUID.randomUUID()); + automationComposition.getElements().put(element.getId(), element); + } return automationComposition; } catch (CoderException e) { fail("Cannot read or decode " + path); @@ -83,18 +92,6 @@ public class InstantiationUtils { } } - /** - * Assert that Instantiation Response contains proper AutomationCompositions. - * - * @param response InstantiationResponse - * @param affectedAutomationComposition ToscaConceptIdentifier - */ - public static void assertInstantiationResponse(InstantiationResponse response, - ToscaConceptIdentifier affectedAutomationComposition) { - assertThat(response).isNotNull(); - assertEquals(response.getAffectedAutomationComposition(), affectedAutomationComposition); - } - /** * Assert that Instantiation Response contains AutomationComposition equals to automationComposition. * -- cgit 1.2.3-korg