summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-12-13 14:12:25 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2024-01-02 09:43:57 +0000
commit664af40d4c073404d6c067731e25fc44dab3f2c2 (patch)
treea37c1821e6e200d79f036398d06d1c37bd58c594 /runtime-acm/src/test
parent7189a95de7687a8c37a05d40306e743df5fdf5b3 (diff)
Add validation in AC instance elements Id in update
Issue-ID: POLICY-4905 Change-Id: If49a7829fa8acfe375cf7bb1d7ed6859f8a3f190 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/test')
-rwxr-xr-xruntime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java32
1 files changed, 21 insertions, 11 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
index 8dca6693c..87bfe1b38 100755
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
+import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -39,7 +40,6 @@ import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup
import org.onap.policy.clamp.acm.runtime.participants.AcmParticipantProvider;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
-import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
@@ -149,7 +149,7 @@ class AutomationCompositionInstantiationProviderTest {
}
@Test
- void testInstantiationUpdate() throws AutomationCompositionException {
+ void testInstantiationUpdate() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
var compositionId = acDefinition.getCompositionId();
@@ -158,13 +158,13 @@ class AutomationCompositionInstantiationProviderTest {
var automationCompositionUpdate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
automationCompositionUpdate.setCompositionId(compositionId);
+ automationCompositionUpdate.setInstanceId(UUID.randomUUID());
automationCompositionUpdate.setDeployState(DeployState.DEPLOYED);
automationCompositionUpdate.setLockState(LockState.LOCKED);
var acProvider = mock(AutomationCompositionProvider.class);
- when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId()))
- .thenReturn(automationCompositionUpdate);
- when(acProvider.updateAutomationComposition(automationCompositionUpdate))
- .thenReturn(automationCompositionUpdate);
+ var acmFromDb = new AutomationComposition(automationCompositionUpdate);
+ when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId())).thenReturn(acmFromDb);
+ when(acProvider.updateAutomationComposition(acmFromDb)).thenReturn(acmFromDb);
var supervisionAcHandler = mock(SupervisionAcHandler.class);
var acmParticipantProvider = mock(AcmParticipantProvider.class);
@@ -175,12 +175,22 @@ class AutomationCompositionInstantiationProviderTest {
automationCompositionUpdate.getCompositionId(), automationCompositionUpdate);
verify(supervisionAcHandler).update(any());
- verify(acProvider).updateAutomationComposition(automationCompositionUpdate);
+ verify(acProvider).updateAutomationComposition(acmFromDb);
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionUpdate);
+
+ var elements = new ArrayList<>(automationCompositionUpdate.getElements().values());
+ automationCompositionUpdate.getElements().clear();
+ for (var element : elements) {
+ element.setId(UUID.randomUUID());
+ automationCompositionUpdate.getElements().put(element.getId(), element);
+ }
+ assertThatThrownBy(
+ () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate))
+ .hasMessageStartingWith("Element id not present ");
}
@Test
- void testUpdateBadRequest() throws AutomationCompositionException {
+ void testUpdateBadRequest() {
var automationCompositionUpdate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
automationCompositionUpdate.setDeployState(DeployState.DEPLOYING);
@@ -210,7 +220,7 @@ class AutomationCompositionInstantiationProviderTest {
}
@Test
- void testUpdateRestartedBadRequest() throws AutomationCompositionException {
+ void testUpdateRestartedBadRequest() {
var automationCompositionUpdate =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud");
automationCompositionUpdate.setDeployState(DeployState.DEPLOYED);
@@ -239,7 +249,7 @@ class AutomationCompositionInstantiationProviderTest {
}
@Test
- void testUpdateCompositionRestartedBadRequest() throws AutomationCompositionException {
+ void testUpdateCompositionRestartedBadRequest() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED);
acDefinition.setRestarting(true);