summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test/java
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-06-16 10:42:14 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2023-06-16 09:51:29 +0000
commit0f24f33b124bf326e4b7dbaa2a55cab72696b9ee (patch)
tree6fcf5bc915bd52d1e0071401293ebe0fdc4d9495 /runtime-acm/src/test/java
parenta2320d29b9373041db88395d9fdda7ea84d38807 (diff)
Add support for Prime Deprime Failure Handling in ACM-Runtime
Issue-ID: POLICY-4714 Change-Id: I1f3cf8f0fcebc7c48b3632ad10aa8907c41cdb5a Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/test/java')
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java40
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java27
2 files changed, 48 insertions, 19 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
index 6988cd3c4..1f63c3da8 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java
@@ -53,9 +53,10 @@ class SupervisionAcHandlerTest {
@Test
void testHandleAutomationCompositionStateChangeAckMessage() {
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ automationComposition.setInstanceId(IDENTIFIER);
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
.thenReturn(Optional.of(automationComposition));
@@ -64,38 +65,39 @@ class SupervisionAcHandlerTest {
mock(AcElementPropertiesPublisher.class));
var automationCompositionAckMessage =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
+ getAutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK,
+ automationComposition, DeployState.DEPLOYED, LockState.UNLOCKED);
+ handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
+
+ verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ }
+
+ private AutomationCompositionDeployAck getAutomationCompositionDeployAck(ParticipantMessageType messageType,
+ AutomationComposition automationComposition, DeployState deployState, LockState lockState) {
+ var automationCompositionAckMessage = new AutomationCompositionDeployAck(messageType);
for (var elementEntry : automationComposition.getElements().entrySet()) {
- var acElementDeployAck =
- new AcElementDeployAck(DeployState.DEPLOYED, LockState.UNLOCKED, "", "", Map.of(), true, "");
+ var acElementDeployAck = new AcElementDeployAck(deployState, lockState, "", "", Map.of(), true, "");
automationCompositionAckMessage.getAutomationCompositionResultMap().put(elementEntry.getKey(),
acElementDeployAck);
}
- automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
-
- handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
-
- verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
+ automationCompositionAckMessage.setAutomationCompositionId(automationComposition.getInstanceId());
+ automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ return automationCompositionAckMessage;
}
@Test
void testHandleAutomationCompositionUpdateAckMessage() {
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ automationComposition.setInstanceId(IDENTIFIER);
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
.thenReturn(Optional.of(automationComposition));
var automationCompositionAckMessage =
- new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
- for (var elementEntry : automationComposition.getElements().entrySet()) {
- var acElementDeployAck =
- new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, "", "", Map.of(), true, "");
- automationCompositionAckMessage
- .setAutomationCompositionResultMap(Map.of(elementEntry.getKey(), acElementDeployAck));
- }
+ getAutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK,
+ automationComposition, DeployState.DEPLOYED, LockState.LOCKED);
automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId());
- automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
var handler = new SupervisionAcHandler(automationCompositionProvider,
mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class),
@@ -108,11 +110,11 @@ class SupervisionAcHandlerTest {
@Test
void testHandleAcUpdateAckFailedMessage() {
- var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
automationComposition.setDeployState(DeployState.DEPLOYING);
automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
.thenReturn(Optional.of(automationComposition));
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
index d4cc5e310..9ce63b005 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java
@@ -32,6 +32,7 @@ import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
@@ -78,6 +79,32 @@ class SupervisionHandlerTest {
var acDefinition = CommonTestData.createAcDefinition(
InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMING);
participantPrimeAckMessage.setCompositionId(acDefinition.getCompositionId());
+ acDefinition.getElementStateMap().values().iterator().next()
+ .setParticipantId(CommonTestData.getParticipantId());
+
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))
+ .thenReturn(Optional.of(acDefinition));
+
+ var handler = new SupervisionHandler(acDefinitionProvider);
+
+ handler.handleParticipantMessage(participantPrimeAckMessage);
+ verify(acDefinitionProvider).findAcDefinition(any());
+ verify(acDefinitionProvider).updateAcDefinition(any());
+ }
+
+ @Test
+ void testParticipantPrimeAckFailed() {
+ var participantPrimeAckMessage = new ParticipantPrimeAck();
+ participantPrimeAckMessage.setParticipantId(CommonTestData.getParticipantId());
+ participantPrimeAckMessage.setState(ParticipantState.ON_LINE);
+ participantPrimeAckMessage.setStateChangeResult(StateChangeResult.FAILED);
+
+ var acDefinition = CommonTestData.createAcDefinition(
+ InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMING);
+ participantPrimeAckMessage.setCompositionId(acDefinition.getCompositionId());
+ acDefinition.getElementStateMap().values().iterator().next()
+ .setParticipantId(CommonTestData.getParticipantId());
var acDefinitionProvider = mock(AcDefinitionProvider.class);
when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId()))