aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java')
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java101
1 files changed, 43 insertions, 58 deletions
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 4b58ae177..8aac93138 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
@@ -34,8 +34,6 @@ 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.AutomationCompositionElementDefinition;
-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.kafka.participant.AutomationCompositionDeploy;
import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionMigration;
@@ -52,6 +50,8 @@ import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRe
import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus;
import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatusReq;
import org.onap.policy.clamp.models.acm.messages.kafka.participant.PropertiesUpdate;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
+import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
class ParticipantHandlerTest {
@@ -59,8 +59,8 @@ class ParticipantHandlerTest {
void handleParticipantStatusReqTest() {
var publisher = mock(ParticipantMessagePublisher.class);
var cacheProvider = mock(CacheProvider.class);
- var participantHandler =
- new ParticipantHandler(mock(AutomationCompositionHandler.class), publisher, cacheProvider);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AcLockHandler.class), mock(AcDefinitionHandler.class), publisher, cacheProvider);
participantHandler.handleParticipantStatusReq(new ParticipantStatusReq());
verify(publisher).sendParticipantStatus(any(ParticipantStatus.class));
}
@@ -68,8 +68,8 @@ class ParticipantHandlerTest {
@Test
void handleAutomationCompositionDeployTest() {
var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler =
- new ParticipantHandler(acHandler, mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var participantHandler = new ParticipantHandler(acHandler, mock(AcLockHandler.class),
+ mock(AcDefinitionHandler.class), mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
var automationCompositionDeploy = new AutomationCompositionDeploy();
participantHandler.handleAutomationCompositionDeploy(automationCompositionDeploy);
verify(acHandler).handleAutomationCompositionDeploy(automationCompositionDeploy);
@@ -78,18 +78,27 @@ class ParticipantHandlerTest {
@Test
void handleAutomationCompositionStateChangeTest() {
var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler =
- new ParticipantHandler(acHandler, mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var acLockHandler = mock(AcLockHandler.class);
+ var participantHandler = new ParticipantHandler(acHandler, acLockHandler, mock(AcDefinitionHandler.class),
+ mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
var acStateChange = new AutomationCompositionStateChange();
+
+ acStateChange.setDeployOrderedState(DeployOrder.DEPLOY);
+ acStateChange.setLockOrderedState(LockOrder.NONE);
participantHandler.handleAutomationCompositionStateChange(acStateChange);
verify(acHandler).handleAutomationCompositionStateChange(acStateChange);
+
+ acStateChange.setDeployOrderedState(DeployOrder.NONE);
+ acStateChange.setLockOrderedState(LockOrder.LOCK);
+ participantHandler.handleAutomationCompositionStateChange(acStateChange);
+ verify(acLockHandler).handleAutomationCompositionStateChange(acStateChange);
}
@Test
void handleAutomationCompositionMigrationTest() {
var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler =
- new ParticipantHandler(acHandler, mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var participantHandler = new ParticipantHandler(acHandler, mock(AcLockHandler.class),
+ mock(AcDefinitionHandler.class), mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
var migrationMsg = new AutomationCompositionMigration();
participantHandler.handleAutomationCompositionMigration(migrationMsg);
verify(acHandler).handleAutomationCompositionMigration(migrationMsg);
@@ -98,8 +107,8 @@ class ParticipantHandlerTest {
@Test
void handleAcPropertyUpdateTest() {
var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler =
- new ParticipantHandler(acHandler, mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var participantHandler = new ParticipantHandler(acHandler, mock(AcLockHandler.class),
+ mock(AcDefinitionHandler.class), mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
var propertyUpdateMsg = new PropertiesUpdate();
participantHandler.handleAcPropertyUpdate(propertyUpdateMsg);
verify(acHandler).handleAcPropertyUpdate(propertyUpdateMsg);
@@ -110,7 +119,8 @@ class ParticipantHandlerTest {
var cacheProvider = mock(CacheProvider.class);
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
- mock(ParticipantMessagePublisher.class), cacheProvider);
+ mock(AcLockHandler.class), mock(AcDefinitionHandler.class), mock(ParticipantMessagePublisher.class),
+ cacheProvider);
var participantAckMsg = new ParticipantAckMessage(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY);
assertTrue(participantHandler.appliesTo(participantAckMsg));
@@ -128,8 +138,8 @@ class ParticipantHandlerTest {
var cacheProvider = mock(CacheProvider.class);
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
when(cacheProvider.getSupportedAcElementTypes()).thenReturn(List.of(new ParticipantSupportedElementType()));
- var participantHandler =
- new ParticipantHandler(mock(AutomationCompositionHandler.class), publisher, cacheProvider);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AcLockHandler.class), mock(AcDefinitionHandler.class), publisher, cacheProvider);
participantHandler.sendParticipantRegister();
verify(publisher).sendParticipantRegister(any(ParticipantRegister.class));
@@ -140,8 +150,8 @@ class ParticipantHandlerTest {
var publisher = mock(ParticipantMessagePublisher.class);
var cacheProvider = mock(CacheProvider.class);
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
- var participantHandler =
- new ParticipantHandler(mock(AutomationCompositionHandler.class), publisher, cacheProvider);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AcLockHandler.class), mock(AcDefinitionHandler.class), publisher, cacheProvider);
participantHandler.handleParticipantRegisterAck(new ParticipantRegisterAck());
verify(publisher).sendParticipantStatus(any(ParticipantStatus.class));
@@ -152,8 +162,8 @@ class ParticipantHandlerTest {
var publisher = mock(ParticipantMessagePublisher.class);
var cacheProvider = mock(CacheProvider.class);
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
- var participantHandler =
- new ParticipantHandler(mock(AutomationCompositionHandler.class), publisher, cacheProvider);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AcLockHandler.class), mock(AcDefinitionHandler.class), publisher, cacheProvider);
participantHandler.sendParticipantDeregister();
verify(publisher).sendParticipantDeregister(any(ParticipantDeregister.class));
@@ -162,28 +172,25 @@ class ParticipantHandlerTest {
@Test
void handleParticipantDeregisterAckTest() {
var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
- mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ mock(AcLockHandler.class), mock(AcDefinitionHandler.class), mock(ParticipantMessagePublisher.class),
+ mock(CacheProvider.class));
var participantDeregisterAck = new ParticipantDeregisterAck();
assertDoesNotThrow(() -> participantHandler.handleParticipantDeregisterAck(participantDeregisterAck));
}
@Test
void handleParticipantPrimeTest() {
- var cacheProvider = mock(CacheProvider.class);
- when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
-
var participantPrime = new ParticipantPrime();
participantPrime.setCompositionId(UUID.randomUUID());
participantPrime.setMessageId(UUID.randomUUID());
- participantPrime.setParticipantDefinitionUpdates(List.of(createParticipantDefinition()));
- var publisher = mock(ParticipantMessagePublisher.class);
- var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler = new ParticipantHandler(acHandler, publisher, cacheProvider);
+ var acHandler = mock(AcDefinitionHandler.class);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AcLockHandler.class), acHandler, mock(ParticipantMessagePublisher.class),
+ mock(CacheProvider.class));
participantHandler.handleParticipantPrime(participantPrime);
- verify(cacheProvider).addElementDefinition(any(), any());
- verify(acHandler).prime(any(), any(), any());
+ verify(acHandler).handlePrime(participantPrime);
}
@Test
@@ -191,32 +198,15 @@ class ParticipantHandlerTest {
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, publisher, cacheProvider);
+ var acHandler = mock(AcDefinitionHandler.class);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AcLockHandler.class), acHandler, 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());
- var publisher = mock(ParticipantMessagePublisher.class);
- var acHandler = mock(AutomationCompositionHandler.class);
- var participantHandler = new ParticipantHandler(acHandler, publisher, cacheProvider);
- var participantPrime = new ParticipantPrime();
- var compositionId = UUID.randomUUID();
- participantPrime.setCompositionId(compositionId);
- var messageId = UUID.randomUUID();
- participantPrime.setMessageId(messageId);
- participantHandler.handleParticipantPrime(participantPrime);
- verify(acHandler).deprime(messageId, compositionId);
+ verify(acHandler).handleParticipantRestart(participantRestartMsg);
}
@Test
@@ -226,16 +216,11 @@ class ParticipantHandlerTest {
when(cacheProvider.getAutomationCompositions()).thenReturn(CommonTestData.getTestAutomationCompositionMap());
var publisher = mock(ParticipantMessagePublisher.class);
when(publisher.isActive()).thenReturn(true);
- var participantHandler =
- new ParticipantHandler(mock(AutomationCompositionHandler.class), publisher, cacheProvider);
+ var acHandler = mock(AcDefinitionHandler.class);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AcLockHandler.class), acHandler, publisher, cacheProvider);
participantHandler.sendHeartbeat();
verify(publisher).sendHeartbeat(any(ParticipantStatus.class));
}
- private ParticipantDefinition createParticipantDefinition() {
- var def = new ParticipantDefinition();
- def.setParticipantId(CommonTestData.getParticipantId());
- def.setAutomationCompositionElementDefinitionList(List.of(new AutomationCompositionElementDefinition()));
- return def;
- }
}