aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test/java/org
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2023-06-20 08:20:25 +0000
committerGerrit Code Review <gerrit@onap.org>2023-06-20 08:20:25 +0000
commita859910c602a5384ddd3e1b85e95bc800c099640 (patch)
treeab5273837149326d27e4ec54f9de0ee6e336b0ef /runtime-acm/src/test/java/org
parent66dc6337aae9cfbd2c01bc6f727d9e289e7ad63f (diff)
parent0f24f33b124bf326e4b7dbaa2a55cab72696b9ee (diff)
Merge "Add support for Prime Deprime Failure Handling in ACM-Runtime"
Diffstat (limited to 'runtime-acm/src/test/java/org')
-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()))