aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-intermediary/src/test
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-07-12 11:20:03 +0100
committerAdheli Tavares <adheli.tavares@est.tech>2023-07-24 09:59:25 +0000
commit842dad71f3f10d524b72c4f76262d76c6e4d1cc5 (patch)
treeed1c603f205133a78c03b2bae3b0ff8d1160e952 /participant/participant-intermediary/src/test
parent0d650c2322f2136b26bfd3cf02a5bbb97847842a (diff)
Add support participant restart scenario in ACM intermediary
Issue-ID: POLICY-4745 Change-Id: I8ab71137ef981cb4fdeae4bf9732382b9534b442 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech> (cherry picked from commit 51ef04415186a0de3e50339b7fca04fb5ef079c9)
Diffstat (limited to 'participant/participant-intermediary/src/test')
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java17
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java12
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java19
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java16
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java20
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java215
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java21
7 files changed, 215 insertions, 105 deletions
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
index 4213e978b..fcd8650ea 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
@@ -20,13 +20,18 @@
package org.onap.policy.clamp.acm.participant.intermediary.api.impl;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionOutHandler;
+import org.onap.policy.clamp.acm.participant.intermediary.handler.CacheProvider;
+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.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
@@ -41,7 +46,8 @@ class ParticipantIntermediaryApiImplTest {
@Test
void mockParticipantIntermediaryApiImplTest() throws CoderException {
var automationComposiitonHandler = mock(AutomationCompositionOutHandler.class);
- var apiImpl = new ParticipantIntermediaryApiImpl(automationComposiitonHandler, null);
+ var cacheProvider = mock(CacheProvider.class);
+ var apiImpl = new ParticipantIntermediaryApiImpl(automationComposiitonHandler, cacheProvider);
var uuid = UUID.randomUUID();
var automationCompositionId = UUID.randomUUID();
@@ -58,5 +64,14 @@ class ParticipantIntermediaryApiImplTest {
StateChangeResult.NO_ERROR, "");
verify(automationComposiitonHandler).updateAutomationCompositionElementState(automationCompositionId, uuid,
DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "");
+
+ var map = Map.of(uuid, new AutomationComposition());
+ when(cacheProvider.getAutomationCompositions()).thenReturn(map);
+ var result = apiImpl.getAutomationCompositions();
+ assertEquals(map, result);
+
+ apiImpl.updateCompositionState(uuid, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "");
+ verify(automationComposiitonHandler).updateCompositionState(uuid, AcTypeState.PRIMED,
+ StateChangeResult.NO_ERROR, "");
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java
index 1dbf0b13c..db6a3a554 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java
@@ -38,21 +38,27 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDe
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatusReq;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.utils.coder.CoderException;
class ParticipantCommTest {
@Test
- void participantReqTest() throws CoderException {
+ void participantListenerTest() throws CoderException {
var participantHandler = mock(ParticipantHandler.class);
var participantRegisterAckListener = new ParticipantRegisterAckListener(participantHandler);
+ participantRegisterAckListener.onTopicEvent(null, null, null, new ParticipantRegisterAck());
assertEquals(ParticipantMessageType.PARTICIPANT_REGISTER_ACK.name(), participantRegisterAckListener.getType());
+ assertEquals(participantRegisterAckListener, participantRegisterAckListener.getScoListener());
var participantStatusReqListener = new ParticipantStatusReqListener(participantHandler);
+ participantStatusReqListener.onTopicEvent(null, null, null, new ParticipantStatusReq());
assertEquals(ParticipantMessageType.PARTICIPANT_STATUS_REQ.name(), participantStatusReqListener.getType());
+ assertEquals(participantStatusReqListener, participantStatusReqListener.getScoListener());
var participantDeregisterAckListener = new ParticipantDeregisterAckListener(participantHandler);
assertEquals(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK.name(),
@@ -71,6 +77,10 @@ class ParticipantCommTest {
var automationCompositionStateChangeListener = new AutomationCompositionStateChangeListener(participantHandler);
assertEquals(ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE.name(),
automationCompositionStateChangeListener.getType());
+
+ var participantRestartListener = new ParticipantRestartListener(participantHandler);
+ assertEquals(ParticipantMessageType.PARTICIPANT_RESTART.name(),
+ participantRestartListener.getType());
}
@Test
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
index dd49ee318..6509491ce 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java
@@ -35,6 +35,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
@@ -220,4 +221,22 @@ class AutomationCompositionHandlerTest {
ach.deprime(messageId, compositionId);
verify(listener).deprime(messageId, compositionId);
}
+
+ @Test
+ void restartedTest() {
+ var listener = mock(ThreadHandler.class);
+ var cacheProvider = mock(CacheProvider.class);
+ var ach = new AutomationCompositionHandler(cacheProvider, mock(ParticipantMessagePublisher.class),
+ listener);
+
+ var compositionId = UUID.randomUUID();
+ var messageId = UUID.randomUUID();
+ var list = List.of(new AutomationCompositionElementDefinition());
+ var state = AcTypeState.PRIMED;
+ var participantRestartAc = CommonTestData.createParticipantRestartAc();
+ var automationCompositionList = List.of(participantRestartAc);
+ ach.restarted(messageId, compositionId, list, state, automationCompositionList);
+ verify(cacheProvider).initializeAutomationComposition(compositionId, participantRestartAc);
+ verify(listener).restarted(messageId, compositionId, list, state, automationCompositionList);
+ }
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java
index bbce42351..f207dc511 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProviderTest.java
@@ -75,6 +75,9 @@ class CacheProviderTest {
.isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> cacheProvider.removeElementDefinition(null)).isInstanceOf(NullPointerException.class);
+
+ assertThatThrownBy(() -> cacheProvider.initializeAutomationComposition(null, null))
+ .isInstanceOf(NullPointerException.class);
}
@Test
@@ -125,4 +128,17 @@ class CacheProviderTest {
cacheProvider.removeElementDefinition(compositionId);
assertThat(cacheProvider.getAcElementsDefinitions()).isEmpty();
}
+
+ @Test
+ void testInitializeAutomationComposition() {
+ var parameter = CommonTestData.getParticipantParameters();
+ var cacheProvider = new CacheProvider(parameter);
+
+ var participantRestartAc = CommonTestData.createParticipantRestartAc();
+ var compositionId = UUID.randomUUID();
+ cacheProvider.initializeAutomationComposition(compositionId, participantRestartAc);
+ var result = cacheProvider.getAutomationComposition(participantRestartAc.getAutomationCompositionId());
+ assertEquals(compositionId, result.getCompositionId());
+ assertEquals(participantRestartAc.getAutomationCompositionId(), result.getInstanceId());
+ }
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
index 237cab224..68cffe3cd 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
@@ -33,6 +33,7 @@ import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy;
@@ -45,6 +46,7 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMe
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRestart;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatusReq;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.PropertiesUpdate;
@@ -175,6 +177,24 @@ class ParticipantHandlerTest {
}
@Test
+ void handleParticipantRestartTest() {
+ var participantRestartMsg = new ParticipantRestart();
+ participantRestartMsg.setState(AcTypeState.PRIMED);
+ participantRestartMsg.setCompositionId(UUID.randomUUID());
+ participantRestartMsg.getParticipantDefinitionUpdates().add(new ParticipantDefinition());
+
+ var cacheProvider = mock(CacheProvider.class);
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var acHandler = mock(AutomationCompositionHandler.class);
+ var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
+ publisher, cacheProvider);
+
+ participantHandler.handleParticipantRestart(participantRestartMsg);
+ verify(cacheProvider).addElementDefinition(any(), any());
+ verify(acHandler).restarted(any(), any(), any(), any(), any());
+ }
+
+ @Test
void handleParticipantDeprimeTest() {
var cacheProvider = mock(CacheProvider.class);
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java
index 767a916b5..55d84c5fc 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandlerTest.java
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
+import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -46,115 +47,123 @@ class ThreadHandlerTest {
private static final int TIMEOUT = 400;
@Test
- void test() throws PfModelException {
+ void test() throws PfModelException, IOException {
var listener = mock(AutomationCompositionElementListener.class);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- var threadHandler = new ThreadHandler(listener, intermediaryApi, mock(CacheProvider.class));
-
- var compositionId = UUID.randomUUID();
- var list = List.of(new AutomationCompositionElementDefinition());
- var messageId = UUID.randomUUID();
- threadHandler.prime(messageId, compositionId, list);
- verify(listener, timeout(TIMEOUT)).prime(compositionId, list);
-
- clearInvocations(listener);
- var element = new AcElementDeploy();
- var elementId = UUID.randomUUID();
- element.setId(elementId);
- Map<String, Object> properties = Map.of("key", "value");
- var instanceId = UUID.randomUUID();
- threadHandler.deploy(messageId, instanceId, element, properties);
- verify(listener, timeout(TIMEOUT)).deploy(instanceId, element, properties);
-
- clearInvocations(listener);
- threadHandler.update(messageId, instanceId, element, properties);
- verify(listener, timeout(TIMEOUT)).update(instanceId, element, properties);
-
- clearInvocations(listener);
- threadHandler.lock(messageId, instanceId, elementId);
- verify(listener, timeout(TIMEOUT)).lock(instanceId, elementId);
-
- clearInvocations(listener);
- threadHandler.unlock(messageId, instanceId, elementId);
- verify(listener, timeout(TIMEOUT)).unlock(instanceId, elementId);
-
- clearInvocations(listener);
- threadHandler.undeploy(messageId, instanceId, elementId);
- verify(listener, timeout(TIMEOUT)).undeploy(instanceId, elementId);
-
- clearInvocations(listener);
- threadHandler.delete(messageId, instanceId, elementId);
- verify(listener, timeout(TIMEOUT)).delete(instanceId, elementId);
-
- clearInvocations(listener);
- threadHandler.deprime(messageId, compositionId);
- verify(listener, timeout(TIMEOUT)).deprime(compositionId);
+ try (var threadHandler = new ThreadHandler(listener, intermediaryApi, mock(CacheProvider.class))) {
+
+ var compositionId = UUID.randomUUID();
+ var list = List.of(new AutomationCompositionElementDefinition());
+ var messageId = UUID.randomUUID();
+ threadHandler.prime(messageId, compositionId, list);
+ verify(listener, timeout(TIMEOUT)).prime(compositionId, list);
+
+ clearInvocations(listener);
+ var element = new AcElementDeploy();
+ var elementId = UUID.randomUUID();
+ element.setId(elementId);
+ Map<String, Object> properties = Map.of("key", "value");
+ var instanceId = UUID.randomUUID();
+ threadHandler.deploy(messageId, instanceId, element, properties);
+ verify(listener, timeout(TIMEOUT)).deploy(instanceId, element, properties);
+
+ clearInvocations(listener);
+ threadHandler.update(messageId, instanceId, element, properties);
+ verify(listener, timeout(TIMEOUT)).update(instanceId, element, properties);
+
+ clearInvocations(listener);
+ threadHandler.lock(messageId, instanceId, elementId);
+ verify(listener, timeout(TIMEOUT)).lock(instanceId, elementId);
+
+ clearInvocations(listener);
+ threadHandler.unlock(messageId, instanceId, elementId);
+ verify(listener, timeout(TIMEOUT)).unlock(instanceId, elementId);
+
+ clearInvocations(listener);
+ threadHandler.undeploy(messageId, instanceId, elementId);
+ verify(listener, timeout(TIMEOUT)).undeploy(instanceId, elementId);
+
+ clearInvocations(listener);
+ threadHandler.delete(messageId, instanceId, elementId);
+ verify(listener, timeout(TIMEOUT)).delete(instanceId, elementId);
+
+ clearInvocations(listener);
+ threadHandler.deprime(messageId, compositionId);
+ verify(listener, timeout(TIMEOUT)).deprime(compositionId);
+ }
}
@Test
- void testException() throws PfModelException {
+ void testException() throws PfModelException, IOException {
var listener = mock(AutomationCompositionElementListener.class);
var intermediaryApi = mock(ParticipantIntermediaryApi.class);
- var threadHandler = new ThreadHandler(listener, intermediaryApi, mock(CacheProvider.class));
-
- var compositionId = UUID.randomUUID();
- var list = List.of(new AutomationCompositionElementDefinition());
- doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).prime(compositionId, list);
- var messageId = UUID.randomUUID();
- threadHandler.prime(messageId, compositionId, list);
- verify(intermediaryApi, timeout(TIMEOUT)).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
- StateChangeResult.FAILED, "Composition Defintion prime failed");
-
- clearInvocations(intermediaryApi);
- var element = new AcElementDeploy();
- var elementId = UUID.randomUUID();
- element.setId(elementId);
- Map<String, Object> properties = Map.of("key", "value");
- var instanceId = UUID.randomUUID();
- doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).deploy(instanceId, element,
- properties);
- threadHandler.deploy(messageId, instanceId, element, properties);
- verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Automation composition element deploy failed");
-
- clearInvocations(listener);
- doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).update(instanceId, element,
- properties);
- threadHandler.update(messageId, instanceId, element, properties);
- verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Automation composition element update failed");
-
- clearInvocations(listener);
- doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).lock(instanceId, elementId);
- threadHandler.lock(messageId, instanceId, elementId);
- verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId, null,
- LockState.UNLOCKED, StateChangeResult.FAILED, "Automation composition element lock failed");
-
- clearInvocations(listener);
- doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).unlock(instanceId,
- elementId);
- threadHandler.unlock(messageId, instanceId, elementId);
- verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId, null,
- LockState.LOCKED, StateChangeResult.FAILED, "Automation composition element unlock failed");
-
- clearInvocations(listener);
- doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).undeploy(instanceId,
- elementId);
- threadHandler.undeploy(messageId, instanceId, elementId);
- verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Automation composition element undeploy failed");
-
- clearInvocations(listener);
- doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).delete(instanceId,
- elementId);
- threadHandler.delete(messageId, instanceId, elementId);
- verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId,
- DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Automation composition element delete failed");
-
- clearInvocations(listener);
- doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).deprime(compositionId);
- threadHandler.deprime(messageId, compositionId);
- verify(intermediaryApi, timeout(TIMEOUT)).updateCompositionState(compositionId,
- AcTypeState.PRIMED, StateChangeResult.FAILED, "Composition Defintion deprime failed");
+ try (var threadHandler = new ThreadHandler(listener, intermediaryApi, mock(CacheProvider.class))) {
+
+ var compositionId = UUID.randomUUID();
+ var list = List.of(new AutomationCompositionElementDefinition());
+ doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).prime(compositionId,
+ list);
+ var messageId = UUID.randomUUID();
+ threadHandler.prime(messageId, compositionId, list);
+ verify(intermediaryApi, timeout(TIMEOUT)).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
+ StateChangeResult.FAILED, "Composition Defintion prime failed");
+
+ clearInvocations(intermediaryApi);
+ var element = new AcElementDeploy();
+ var elementId = UUID.randomUUID();
+ element.setId(elementId);
+ Map<String, Object> properties = Map.of("key", "value");
+ var instanceId = UUID.randomUUID();
+ doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).deploy(instanceId,
+ element, properties);
+ threadHandler.deploy(messageId, instanceId, element, properties);
+ verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
+ "Automation composition element deploy failed");
+
+ clearInvocations(listener);
+ doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).update(instanceId,
+ element, properties);
+ threadHandler.update(messageId, instanceId, element, properties);
+ verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.DEPLOYED, null, StateChangeResult.FAILED,
+ "Automation composition element update failed");
+
+ clearInvocations(listener);
+ doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).lock(instanceId,
+ elementId);
+ threadHandler.lock(messageId, instanceId, elementId);
+ verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId,
+ null, LockState.UNLOCKED, StateChangeResult.FAILED, "Automation composition element lock failed");
+
+ clearInvocations(listener);
+ doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).unlock(instanceId,
+ elementId);
+ threadHandler.unlock(messageId, instanceId, elementId);
+ verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId,
+ null, LockState.LOCKED, StateChangeResult.FAILED, "Automation composition element unlock failed");
+
+ clearInvocations(listener);
+ doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).undeploy(instanceId,
+ elementId);
+ threadHandler.undeploy(messageId, instanceId, elementId);
+ verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.DEPLOYED, null, StateChangeResult.FAILED,
+ "Automation composition element undeploy failed");
+
+ clearInvocations(listener);
+ doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).delete(instanceId,
+ elementId);
+ threadHandler.delete(messageId, instanceId, elementId);
+ verify(intermediaryApi, timeout(TIMEOUT)).updateAutomationCompositionElementState(instanceId, elementId,
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
+ "Automation composition element delete failed");
+
+ clearInvocations(listener);
+ doThrow(new PfModelException(Status.INTERNAL_SERVER_ERROR, "Error")).when(listener).deprime(compositionId);
+ threadHandler.deprime(messageId, compositionId);
+ verify(intermediaryApi, timeout(TIMEOUT)).updateCompositionState(compositionId, AcTypeState.PRIMED,
+ StateChangeResult.FAILED, "Composition Defintion deprime failed");
+ }
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
index cc2bd7010..acff103a2 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java
@@ -29,8 +29,12 @@ import java.util.TreeMap;
import java.util.UUID;
import org.onap.policy.clamp.acm.participant.intermediary.handler.DummyParticipantParameters;
import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantIntermediaryParameters;
+import org.onap.policy.clamp.models.acm.concepts.AcElementRestart;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc;
import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
@@ -215,4 +219,21 @@ public class CommonTestData {
stateChange.setTimestamp(Instant.ofEpochMilli(3000));
return stateChange;
}
+
+ /**
+ * Create a ParticipantRestartAc.
+ *
+ * @return a ParticipantRestartAc
+ */
+ public static ParticipantRestartAc createParticipantRestartAc() {
+ var participantRestartAc = new ParticipantRestartAc();
+ participantRestartAc.setAutomationCompositionId(AC_ID_0);
+ var acElementRestart = new AcElementRestart();
+ acElementRestart.setDefinition(getDefinition());
+ acElementRestart.setDeployState(DeployState.DEPLOYED);
+ acElementRestart.setLockState(LockState.LOCKED);
+ acElementRestart.setId(UUID.randomUUID());
+ participantRestartAc.getAcElementList().add(acElementRestart);
+ return participantRestartAc;
+ }
}