summaryrefslogtreecommitdiffstats
path: root/runtime-acm
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2022-12-06 15:44:05 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2022-12-07 09:31:11 +0000
commitdaa511c00a8e1816531a2fa628edebeb10c827c3 (patch)
treebac32464240899053f97eb633a912b7be8f1c824 /runtime-acm
parentaea051f76fcb04579e1cc3ec3337fc16a847b428 (diff)
Increase code coverage in runtime ACM
Issue-ID: POLICY-4475 Change-Id: I936d6f0c20f774e37cef8dfbccaecb8f85660309 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm')
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java63
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java122
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java206
3 files changed, 254 insertions, 137 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
index 85f21930e..792cb4a75 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
@@ -22,6 +22,7 @@
package org.onap.policy.clamp.acm.runtime.commissioning;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -31,11 +32,13 @@ import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
+import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
+import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
class CommissioningProviderTest {
@@ -46,7 +49,7 @@ class CommissioningProviderTest {
* @throws Exception .
*/
@Test
- void testGetAutomationCompositionDefinitions() throws Exception {
+ void testGetAutomationCompositionDefinitions() {
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = mock(ParticipantProvider.class);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
@@ -68,21 +71,27 @@ class CommissioningProviderTest {
* @throws Exception .
*/
@Test
- void testCreateAutomationCompositionDefinitions() throws Exception {
+ void testCreateAutomationCompositionDefinitions() {
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ serviceTemplate.setName("Name");
+ serviceTemplate.setVersion("1.0.0");
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.randomUUID());
acmDefinition.setServiceTemplate(serviceTemplate);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
when(acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate)).thenReturn(acmDefinition);
- // Response should return the number of node templates present in the service template
- var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = mock(ParticipantProvider.class);
- var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
- List<ToscaConceptIdentifier> affectedDefinitions = provider
+ when(participantProvider.getParticipants()).thenReturn(List.of(new Participant()));
+ var acProvider = mock(AutomationCompositionProvider.class);
+ var supervisionHandler = mock(SupervisionHandler.class);
+ var provider =
+ new CommissioningProvider(acDefinitionProvider, acProvider, supervisionHandler, participantProvider);
+ var affectedDefinitions = provider
.createAutomationCompositionDefinitions(serviceTemplate).getAffectedAutomationCompositionDefinitions();
verify(acDefinitionProvider).createAutomationCompositionDefinition(serviceTemplate);
+ verify(supervisionHandler).handleSendCommissionMessage(serviceTemplate.getName(), serviceTemplate.getVersion());
+ // Response should return the number of node templates present in the service template
assertThat(affectedDefinitions).hasSize(7);
}
@@ -92,18 +101,54 @@ class CommissioningProviderTest {
*
*/
@Test
- void testGetToscaServiceTemplateList() throws Exception {
+ void testGetToscaServiceTemplateList() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acProvider = mock(AutomationCompositionProvider.class);
var participantProvider = mock(ParticipantProvider.class);
var provider =
new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
- ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
when(acDefinitionProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate));
var returnedServiceTemplate = provider.getAutomationCompositionDefinitions(null, null);
assertThat(returnedServiceTemplate).isNotNull();
assertThat(returnedServiceTemplate.getServiceTemplates()).isNotEmpty();
}
+
+ @Test
+ void testDeletecDefinitionDabRequest() {
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var acProvider = mock(AutomationCompositionProvider.class);
+ var participantProvider = mock(ParticipantProvider.class);
+
+ var compositionId = UUID.randomUUID();
+ when(acProvider.getAcInstancesByCompositionId(compositionId)).thenReturn(List.of(new AutomationComposition()));
+
+ var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, participantProvider);
+
+ assertThatThrownBy(() -> provider.deleteAutomationCompositionDefinition(compositionId))
+ .hasMessageMatching("Delete instances, to commission automation composition definitions");
+ }
+
+ @Test
+ void testDeleteAutomationCompositionDefinition() {
+ var participantProvider = mock(ParticipantProvider.class);
+ when(participantProvider.getParticipants()).thenReturn(List.of(new Participant()));
+
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var compositionId = UUID.randomUUID();
+ var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ when(acDefinitionProvider.deleteAcDefintion(compositionId)).thenReturn(serviceTemplate);
+
+ var acProvider = mock(AutomationCompositionProvider.class);
+ var supervisionHandler = mock(SupervisionHandler.class);
+ var provider =
+ new CommissioningProvider(acDefinitionProvider, acProvider, supervisionHandler, participantProvider);
+
+ provider.deleteAutomationCompositionDefinition(compositionId);
+
+ verify(supervisionHandler).handleSendDeCommissionMessage();
+ verify(acDefinitionProvider).deleteAcDefintion(compositionId);
+ }
}
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 e01f76bb8..cc915003d 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
@@ -131,6 +131,50 @@ class SupervisionHandlerTest {
}
@Test
+ void testAcTransitioning() {
+ var handler = createSupervisionHandlerForTrigger();
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ automationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
+ automationComposition.setState(AutomationCompositionState.PASSIVE2UNINITIALISED);
+
+ assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
+ .hasMessageMatching("Automation composition is already in state "
+ + "PASSIVE2UNINITIALISED and transitioning to state UNINITIALISED");
+
+ automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
+ automationComposition.setState(AutomationCompositionState.UNINITIALISED2PASSIVE);
+ assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
+ .hasMessageMatching("Automation composition is already in state "
+ + "UNINITIALISED2PASSIVE and transitioning to state PASSIVE");
+
+ automationComposition.setOrderedState(AutomationCompositionOrderedState.RUNNING);
+ automationComposition.setState(AutomationCompositionState.PASSIVE2RUNNING);
+ assertThatThrownBy(() -> handler.triggerAutomationCompositionSupervision(automationComposition))
+ .hasMessageMatching("Automation composition is already in state "
+ + "PASSIVE2RUNNING and transitioning to state RUNNING");
+ }
+
+ @Test
+ void testAcRunningToPassive() throws AutomationCompositionException {
+ var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
+ mock(ParticipantProvider.class), mock(ParticipantRegisterAckPublisher.class),
+ mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class),
+ automationCompositionStateChangePublisher, mock(ParticipantUpdatePublisher.class),
+ AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ automationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
+ automationComposition.setState(AutomationCompositionState.RUNNING);
+
+ handler.triggerAutomationCompositionSupervision(automationComposition);
+
+ verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), eq(1));
+ }
+
+ @Test
void testAcRunningToRunning() {
var handler = createSupervisionHandlerForTrigger();
@@ -158,12 +202,32 @@ class SupervisionHandlerTest {
}
@Test
+ void testAcPassiveToRunning() throws AutomationCompositionException {
+ var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
+ mock(ParticipantProvider.class), mock(ParticipantRegisterAckPublisher.class),
+ mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class),
+ automationCompositionStateChangePublisher, mock(ParticipantUpdatePublisher.class),
+ AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ automationComposition.setOrderedState(AutomationCompositionOrderedState.RUNNING);
+ automationComposition.setState(AutomationCompositionState.PASSIVE);
+
+ handler.triggerAutomationCompositionSupervision(automationComposition);
+
+ verify(automationCompositionStateChangePublisher).send(any(AutomationComposition.class), eq(0));
+ }
+
+ @Test
void testHandleAutomationCompositionStateChangeAckMessage() {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var handler = createSupervisionHandler(automationCompositionProvider, mock(ParticipantProvider.class),
mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
- mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+ mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
+ mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
+ AutomationCompositionState.UNINITIALISED);
var automationCompositionAckMessage =
new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
automationCompositionAckMessage.setAutomationCompositionResultMap(Map.of());
@@ -185,8 +249,9 @@ class SupervisionHandlerTest {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
var handler = createSupervisionHandler(automationCompositionProvider, mock(ParticipantProvider.class),
mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
- mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+ mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
+ mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
+ AutomationCompositionState.UNINITIALISED);
handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
@@ -211,8 +276,9 @@ class SupervisionHandlerTest {
var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider,
mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher,
- mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+ mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
+ mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
+ AutomationCompositionState.UNINITIALISED);
handler.handleParticipantMessage(participantDeregisterMessage);
@@ -235,8 +301,9 @@ class SupervisionHandlerTest {
var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider,
participantRegisterAckPublisher, mock(ParticipantDeregisterAckPublisher.class),
- mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+ mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
+ mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
+ AutomationCompositionState.UNINITIALISED);
handler.handleParticipantMessage(participantRegisterMessage);
@@ -262,8 +329,9 @@ class SupervisionHandlerTest {
participantUpdateAckMessage.setState(ParticipantState.PASSIVE);
var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider,
mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
- mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+ mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
+ mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
+ AutomationCompositionState.UNINITIALISED);
handler.handleParticipantMessage(participantUpdateAckMessage);
@@ -281,8 +349,9 @@ class SupervisionHandlerTest {
var participantProvider = mock(ParticipantProvider.class);
var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider,
mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
- mock(AutomationCompositionUpdatePublisher.class), mock(ParticipantUpdatePublisher.class),
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+ mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
+ mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
+ AutomationCompositionState.UNINITIALISED);
handler.handleParticipantMessage(participantStatusMessage);
verify(participantProvider).saveParticipant(any());
@@ -291,11 +360,11 @@ class SupervisionHandlerTest {
@Test
void testHandleSendCommissionMessage() throws PfModelException {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
- var handler =
- createSupervisionHandler(mock(AutomationCompositionProvider.class), mock(ParticipantProvider.class),
- mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
- mock(AutomationCompositionUpdatePublisher.class), participantUpdatePublisher,
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+ var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
+ mock(ParticipantProvider.class), mock(ParticipantRegisterAckPublisher.class),
+ mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class),
+ mock(AutomationCompositionStateChangePublisher.class), participantUpdatePublisher,
+ AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
handler.handleSendCommissionMessage(participantId.getName(), participantId.getVersion());
verify(participantUpdatePublisher).sendComissioningBroadcast(participantId.getName(),
@@ -305,11 +374,11 @@ class SupervisionHandlerTest {
@Test
void testHandleSendDeCommissionMessage() throws PfModelException {
var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
- var handler =
- createSupervisionHandler(mock(AutomationCompositionProvider.class), mock(ParticipantProvider.class),
- mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
- mock(AutomationCompositionUpdatePublisher.class), participantUpdatePublisher,
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+ var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
+ mock(ParticipantProvider.class), mock(ParticipantRegisterAckPublisher.class),
+ mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionUpdatePublisher.class),
+ mock(AutomationCompositionStateChangePublisher.class), participantUpdatePublisher,
+ AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
handler.handleSendDeCommissionMessage();
verify(participantUpdatePublisher).sendDecomisioning();
@@ -319,6 +388,7 @@ class SupervisionHandlerTest {
ParticipantProvider participantProvider, ParticipantRegisterAckPublisher participantRegisterAckPublisher,
ParticipantDeregisterAckPublisher participantDeregisterAckPublisher,
AutomationCompositionUpdatePublisher automationCompositionUpdatePublisher,
+ AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher,
ParticipantUpdatePublisher participantUpdatePublisher, AutomationCompositionOrderedState orderedState,
AutomationCompositionState state) {
var automationComposition =
@@ -327,18 +397,17 @@ class SupervisionHandlerTest {
automationComposition.setOrderedState(orderedState);
automationComposition.setState(state);
when(automationCompositionProvider.findAutomationComposition(identifier))
- .thenReturn(Optional.of(automationComposition));
+ .thenReturn(Optional.of(automationComposition));
var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
when(acDefinitionProvider.getServiceTemplateList(any(), any())).thenReturn(List
.of(Objects.requireNonNull(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML))));
-
- var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
+ when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()))
+ .thenReturn(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML));
return new SupervisionHandler(automationCompositionProvider, participantProvider, acDefinitionProvider,
automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher);
-
}
private SupervisionHandler createSupervisionHandlerForTrigger() {
@@ -346,7 +415,6 @@ class SupervisionHandlerTest {
mock(AcDefinitionProvider.class), mock(AutomationCompositionUpdatePublisher.class),
mock(AutomationCompositionStateChangePublisher.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ParticipantUpdatePublisher.class));
-
}
private SupervisionHandler createSupervisionHandlerForTrigger(
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
index 11a060029..2cfe7eb3c 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java
@@ -21,123 +21,87 @@
package org.onap.policy.clamp.acm.runtime.supervision.comm;
-import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
-import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
-import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
+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.ParticipantUpdateAck;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
-import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
-import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-class SupervisionMessagesTest extends CommonRestController {
+class SupervisionMessagesTest {
private static final String NOT_ACTIVE = "Not Active!";
- private static final Object lockit = new Object();
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
private static final String TOPIC = "my-topic";
- private static SupervisionHandler supervisionHandler;
-
- /**
- * setup Db Provider Parameters.
- *
- * @throws PfModelException if an error occurs
- */
- @BeforeAll
- public static void setupDbProviderParameters() throws PfModelException {
- var acProvider = mock(AutomationCompositionProvider.class);
- var participantProvider = mock(ParticipantProvider.class);
- var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class);
- var automationCompositionUpdatePublisher = Mockito.mock(AutomationCompositionUpdatePublisher.class);
- var automationCompositionStateChangePublisher = Mockito.mock(AutomationCompositionStateChangePublisher.class);
- var participantRegisterAckPublisher = Mockito.mock(ParticipantRegisterAckPublisher.class);
- var participantDeregisterAckPublisher = Mockito.mock(ParticipantDeregisterAckPublisher.class);
- var participantUpdatePublisher = Mockito.mock(ParticipantUpdatePublisher.class);
- supervisionHandler = new SupervisionHandler(acProvider, participantProvider,
- acDefinitionProvider, automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
- participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher);
- }
-
- @Test
- void testSendParticipantRegisterAck() throws Exception {
- final ParticipantRegisterAck participantRegisterAckMsg = new ParticipantRegisterAck();
- participantRegisterAckMsg.setMessage("ParticipantRegisterAck message");
- participantRegisterAckMsg.setResponseTo(UUID.randomUUID());
- participantRegisterAckMsg.setResult(true);
-
- synchronized (lockit) {
- ParticipantRegisterAckPublisher acRegisterAckPublisher = new ParticipantRegisterAckPublisher();
- acRegisterAckPublisher.active(List.of(Mockito.mock(TopicSink.class)));
- assertThatCode(() -> acRegisterAckPublisher.send(participantRegisterAckMsg)).doesNotThrowAnyException();
- }
- }
-
- @Test
- void testReceiveParticipantDeregister() throws Exception {
- final ParticipantDeregister participantDeregisterMsg = new ParticipantDeregister();
- participantDeregisterMsg.setParticipantId(getParticipantId());
- participantDeregisterMsg.setTimestamp(Instant.now());
- participantDeregisterMsg.setParticipantType(getParticipantType());
-
- synchronized (lockit) {
- ParticipantDeregisterListener participantDeregisterListener =
- new ParticipantDeregisterListener(supervisionHandler);
- assertThatCode(
- () -> participantDeregisterListener.onTopicEvent(INFRA, TOPIC, null, participantDeregisterMsg))
- .doesNotThrowAnyException();
- }
- }
-
- @Test
- void testSendParticipantDeregisterAck() throws Exception {
- final ParticipantDeregisterAck participantDeregisterAckMsg = new ParticipantDeregisterAck();
- participantDeregisterAckMsg.setMessage("ParticipantDeregisterAck message");
- participantDeregisterAckMsg.setResponseTo(UUID.randomUUID());
- participantDeregisterAckMsg.setResult(true);
-
- synchronized (lockit) {
- ParticipantDeregisterAckPublisher acDeregisterAckPublisher = new ParticipantDeregisterAckPublisher();
- acDeregisterAckPublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
- assertThatCode(() -> acDeregisterAckPublisher.send(participantDeregisterAckMsg)).doesNotThrowAnyException();
- }
- }
-
- @Test
- void testReceiveParticipantUpdateAckMessage() throws Exception {
- final ParticipantUpdateAck participantUpdateAckMsg = new ParticipantUpdateAck();
- participantUpdateAckMsg.setMessage("ParticipantUpdateAck message");
- participantUpdateAckMsg.setResponseTo(UUID.randomUUID());
- participantUpdateAckMsg.setResult(true);
- participantUpdateAckMsg.setParticipantId(getParticipantId());
- participantUpdateAckMsg.setParticipantType(getParticipantType());
-
- synchronized (lockit) {
- ParticipantUpdateAckListener participantUpdateAckListener =
- new ParticipantUpdateAckListener(supervisionHandler);
- assertThatCode(() -> participantUpdateAckListener.onTopicEvent(INFRA, TOPIC, null, participantUpdateAckMsg))
- .doesNotThrowAnyException();
- }
+
+ @Test
+ void testSendParticipantRegisterAck() {
+ var acRegisterAckPublisher = new ParticipantRegisterAckPublisher();
+ var topicSink = mock(TopicSink.class);
+ acRegisterAckPublisher.active(List.of(topicSink));
+ acRegisterAckPublisher.send(new ParticipantRegisterAck());
+ verify(topicSink).send(anyString());
+ acRegisterAckPublisher.stop();
+ }
+
+ @Test
+ void testSendParticipantRegisterAckNoActive() {
+ var acRegisterAckPublisher = new ParticipantRegisterAckPublisher();
+ assertThatThrownBy(() -> acRegisterAckPublisher.send(new ParticipantRegisterAck()))
+ .hasMessageMatching(NOT_ACTIVE);
+ }
+
+ @Test
+ void testReceiveParticipantDeregister() {
+ final var participantDeregisterMsg = new ParticipantDeregister();
+ var supervisionHandler = mock(SupervisionHandler.class);
+ var participantDeregisterListener = new ParticipantDeregisterListener(supervisionHandler);
+ participantDeregisterListener.onTopicEvent(INFRA, TOPIC, null, participantDeregisterMsg);
+ verify(supervisionHandler).handleParticipantMessage(participantDeregisterMsg);
+ }
+
+ @Test
+ void testSendParticipantDeregisterAck() {
+ var acDeregisterAckPublisher = new ParticipantDeregisterAckPublisher();
+ var topicSink = mock(TopicSink.class);
+ acDeregisterAckPublisher.active(Collections.singletonList(topicSink));
+ acDeregisterAckPublisher.send(new ParticipantDeregisterAck());
+ verify(topicSink).send(anyString());
+ acDeregisterAckPublisher.stop();
+ }
+
+ void testSendParticipantDeregisterAckNoActive() {
+ var acDeregisterAckPublisher = new ParticipantDeregisterAckPublisher();
+ assertThatThrownBy(() -> acDeregisterAckPublisher.send(new ParticipantDeregisterAck()))
+ .hasMessageMatching(NOT_ACTIVE);
+ }
+
+ @Test
+ void testReceiveParticipantUpdateAckMessage() {
+ final var participantUpdateAckMsg = new ParticipantUpdateAck();
+ var supervisionHandler = mock(SupervisionHandler.class);
+ var participantUpdateAckListener = new ParticipantUpdateAckListener(supervisionHandler);
+ participantUpdateAckListener.onTopicEvent(INFRA, TOPIC, null, participantUpdateAckMsg);
+ verify(supervisionHandler).handleParticipantMessage(participantUpdateAckMsg);
}
@Test
@@ -146,6 +110,14 @@ class SupervisionMessagesTest extends CommonRestController {
assertThatThrownBy(() -> publisher.send(getAutomationComposition(), 0)).hasMessage(NOT_ACTIVE);
}
+ private AutomationComposition getAutomationComposition() {
+ var automationComposition = new AutomationComposition();
+ automationComposition.setName("NAME");
+ automationComposition.setVersion("0.0.1");
+ automationComposition.setState(AutomationCompositionState.UNINITIALISED);
+ return automationComposition;
+ }
+
@Test
void testSendAutomationCompositionStateChangePublisher() {
var publisher = new AutomationCompositionStateChangePublisher();
@@ -153,6 +125,7 @@ class SupervisionMessagesTest extends CommonRestController {
publisher.active(List.of(topicSink));
publisher.send(getAutomationComposition(), 0);
verify(topicSink).send(anyString());
+ publisher.stop();
}
@Test
@@ -191,6 +164,14 @@ class SupervisionMessagesTest extends CommonRestController {
verify(topicSink).send(anyString());
}
+ private ToscaConceptIdentifier getParticipantId() {
+ return new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
+ }
+
+ private ToscaConceptIdentifier getParticipantType() {
+ return new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "2.3.1");
+ }
+
@Test
void testParticipantDeregisterAckPublisher() {
var publisher = new ParticipantDeregisterAckPublisher();
@@ -200,19 +181,42 @@ class SupervisionMessagesTest extends CommonRestController {
verify(topicSink).send(anyString());
}
- private AutomationComposition getAutomationComposition() {
- var automationComposition = new AutomationComposition();
- automationComposition.setName("NAME");
- automationComposition.setVersion("0.0.1");
- automationComposition.setState(AutomationCompositionState.UNINITIALISED);
- return automationComposition;
+ @Test
+ void testParticipantRegisterListener() {
+ final var participantRegister = new ParticipantRegister();
+ var supervisionHandler = mock(SupervisionHandler.class);
+ var participantRegisterListener = new ParticipantRegisterListener(supervisionHandler);
+ participantRegisterListener.onTopicEvent(INFRA, TOPIC, null, participantRegister);
+ verify(supervisionHandler).handleParticipantMessage(participantRegister);
}
- private ToscaConceptIdentifier getParticipantId() {
- return new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0");
+ @Test
+ void testParticipantStatusListener() {
+ final var participantStatus = new ParticipantStatus();
+ var supervisionHandler = mock(SupervisionHandler.class);
+ var participantStatusListener = new ParticipantStatusListener(supervisionHandler);
+ participantStatusListener.onTopicEvent(INFRA, TOPIC, null, participantStatus);
+ verify(supervisionHandler).handleParticipantMessage(participantStatus);
}
- private ToscaConceptIdentifier getParticipantType() {
- return new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "2.3.1");
+ @Test
+ void testAutomationCompositionUpdateAckListener() {
+ final var automationCompositionAck =
+ new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE);
+ var supervisionHandler = mock(SupervisionHandler.class);
+ var acUpdateAckListener = new AutomationCompositionUpdateAckListener(supervisionHandler);
+ acUpdateAckListener.onTopicEvent(INFRA, TOPIC, null, automationCompositionAck);
+ verify(supervisionHandler).handleAutomationCompositionUpdateAckMessage(automationCompositionAck);
+ }
+
+ @Test
+ void testAutomationCompositionStateChangeAckListener() {
+ final var automationCompositionAck =
+ new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE);
+ var supervisionHandler = mock(SupervisionHandler.class);
+ var acStateChangeAckListener = new AutomationCompositionStateChangeAckListener(supervisionHandler);
+ acStateChangeAckListener.onTopicEvent(INFRA, TOPIC, null, automationCompositionAck);
+ verify(supervisionHandler).handleAutomationCompositionStateChangeAckMessage(automationCompositionAck);
}
+
}