aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test/java
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-01-04 17:04:37 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-01-06 08:52:36 +0000
commit026cfefbe02cfc87c04f13d4b5ce7085f3ee360b (patch)
tree23566f2de245403b1fd0cc31978bced13eaec3ea /runtime-acm/src/test/java
parentbce4edfb6a9140a07d12470d977352d7b3a4105c (diff)
Refactor register deregister a Participant and Supervise Participants
Refactor register deregister a Participant and Supervise Participants using ON_LINE/OFF_LINE as Participant Status. Issue-ID: POLICY-4497 Change-Id: If9c5b92131c99132c18340e56334fb9453745526 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/SupervisionHandlerTest.java154
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java107
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java28
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java9
4 files changed, 149 insertions, 149 deletions
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 2da869072..fd6c9a008 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,8 +38,6 @@ import org.mockito.Mockito;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionUpdatePublisher;
-import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher;
-import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRegisterAckPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
@@ -47,17 +45,12 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
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.ParticipantMessageType;
-import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
-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.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -109,10 +102,9 @@ class SupervisionHandlerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
- var handler = new SupervisionHandler(automationCompositionProvider, mock(ParticipantProvider.class),
- acDefinitionProvider, mock(AutomationCompositionUpdatePublisher.class),
- automationCompositionStateChangePublisher, mock(ParticipantRegisterAckPublisher.class),
- mock(ParticipantDeregisterAckPublisher.class), mock(ParticipantUpdatePublisher.class));
+ var handler = new SupervisionHandler(automationCompositionProvider, acDefinitionProvider,
+ mock(AutomationCompositionUpdatePublisher.class), automationCompositionStateChangePublisher,
+ mock(ParticipantUpdatePublisher.class));
handler.triggerAutomationCompositionSupervision(automationComposition);
@@ -160,10 +152,9 @@ class SupervisionHandlerTest {
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);
+ mock(AutomationCompositionUpdatePublisher.class), automationCompositionStateChangePublisher,
+ mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
+ AutomationCompositionState.UNINITIALISED);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
@@ -206,10 +197,9 @@ class SupervisionHandlerTest {
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);
+ mock(AutomationCompositionUpdatePublisher.class), automationCompositionStateChangePublisher,
+ mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
+ AutomationCompositionState.UNINITIALISED);
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
@@ -224,8 +214,7 @@ class SupervisionHandlerTest {
@Test
void testHandleAutomationCompositionStateChangeAckMessage() {
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var handler = createSupervisionHandler(automationCompositionProvider, mock(ParticipantProvider.class),
- mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
+ var handler = createSupervisionHandler(automationCompositionProvider,
mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
AutomationCompositionState.UNINITIALISED);
@@ -248,8 +237,7 @@ class SupervisionHandlerTest {
automationCompositionAckMessage.setAutomationCompositionResultMap(Map.of());
automationCompositionAckMessage.setAutomationCompositionId(identifier);
var automationCompositionProvider = mock(AutomationCompositionProvider.class);
- var handler = createSupervisionHandler(automationCompositionProvider, mock(ParticipantProvider.class),
- mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
+ var handler = createSupervisionHandler(automationCompositionProvider,
mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
AutomationCompositionState.UNINITIALISED);
@@ -260,112 +248,31 @@ class SupervisionHandlerTest {
}
@Test
- void testHandleParticipantDeregister() throws PfModelException {
- var participant = new Participant();
- participant.setName(participantId.getName());
- participant.setVersion(participantId.getVersion());
- participant.setParticipantType(participantType);
-
- var participantProvider = mock(ParticipantProvider.class);
- when(participantProvider.findParticipant(participantId.getName(), participantId.getVersion()))
- .thenReturn(Optional.of(participant));
-
- var participantDeregisterMessage = new ParticipantDeregister();
- participantDeregisterMessage.setMessageId(UUID.randomUUID());
- participantDeregisterMessage.setParticipantId(participantId);
- participantDeregisterMessage.setParticipantType(participantType);
- var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
- var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider,
- mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher,
- mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.UNINITIALISED);
-
- handler.handleParticipantMessage(participantDeregisterMessage);
-
- verify(participantProvider).saveParticipant(any());
- verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
- }
-
- @Test
- void testHandleParticipantRegister() throws PfModelException {
- var participant = new Participant();
- participant.setName(participantId.getName());
- participant.setVersion(participantId.getVersion());
- participant.setParticipantType(participantType);
-
- var participantRegisterMessage = new ParticipantRegister();
- participantRegisterMessage.setMessageId(UUID.randomUUID());
- participantRegisterMessage.setParticipantId(participantId);
- participantRegisterMessage.setParticipantType(participantType);
- var participantProvider = mock(ParticipantProvider.class);
- var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
- var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider,
- participantRegisterAckPublisher, mock(ParticipantDeregisterAckPublisher.class),
- mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.UNINITIALISED);
-
- handler.handleParticipantMessage(participantRegisterMessage);
-
- verify(participantProvider).saveParticipant(any());
- verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(), participantId,
- participantType);
- }
-
- @Test
void testParticipantUpdateAck() throws PfModelException {
var participant = new Participant();
participant.setName(participantId.getName());
participant.setVersion(participantId.getVersion());
participant.setParticipantType(participantType);
- var participantProvider = mock(ParticipantProvider.class);
- when(participantProvider.findParticipant(participantId.getName(), participantId.getVersion()))
- .thenReturn(Optional.of(participant));
-
var participantUpdateAckMessage = new ParticipantUpdateAck();
participantUpdateAckMessage.setParticipantId(participantId);
participantUpdateAckMessage.setParticipantType(participantType);
- participantUpdateAckMessage.setState(ParticipantState.PASSIVE);
- var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider,
- mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
+ participantUpdateAckMessage.setState(ParticipantState.ON_LINE);
+ var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class),
mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
AutomationCompositionState.UNINITIALISED);
handler.handleParticipantMessage(participantUpdateAckMessage);
-
- verify(participantProvider).saveParticipant(any());
- }
-
- @Test
- void testHandleParticipantStatus() throws PfModelException {
- var participantStatusMessage = new ParticipantStatus();
- participantStatusMessage.setParticipantId(participantId);
- participantStatusMessage.setParticipantType(participantType);
- participantStatusMessage.setState(ParticipantState.PASSIVE);
- participantStatusMessage.setHealthStatus(ParticipantHealthStatus.HEALTHY);
-
- var participantProvider = mock(ParticipantProvider.class);
- var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), participantProvider,
- mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
- mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
- mock(ParticipantUpdatePublisher.class), AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.UNINITIALISED);
- handler.handleParticipantMessage(participantStatusMessage);
-
- verify(participantProvider).saveParticipant(any());
}
@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),
- mock(AutomationCompositionStateChangePublisher.class), participantUpdatePublisher,
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+ mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
+ participantUpdatePublisher, AutomationCompositionOrderedState.PASSIVE,
+ AutomationCompositionState.UNINITIALISED);
var acmDefinition = new AutomationCompositionDefinition();
handler.handleSendCommissionMessage(acmDefinition);
@@ -376,18 +283,15 @@ class SupervisionHandlerTest {
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),
- mock(AutomationCompositionStateChangePublisher.class), participantUpdatePublisher,
- AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED);
+ mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
+ participantUpdatePublisher, AutomationCompositionOrderedState.PASSIVE,
+ AutomationCompositionState.UNINITIALISED);
handler.handleSendDeCommissionMessage(identifier);
verify(participantUpdatePublisher).sendDecomisioning(identifier);
}
private SupervisionHandler createSupervisionHandler(AutomationCompositionProvider automationCompositionProvider,
- ParticipantProvider participantProvider, ParticipantRegisterAckPublisher participantRegisterAckPublisher,
- ParticipantDeregisterAckPublisher participantDeregisterAckPublisher,
AutomationCompositionUpdatePublisher automationCompositionUpdatePublisher,
AutomationCompositionStateChangePublisher automationCompositionStateChangePublisher,
ParticipantUpdatePublisher participantUpdatePublisher, AutomationCompositionOrderedState orderedState,
@@ -406,24 +310,22 @@ class SupervisionHandlerTest {
when(acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()))
.thenReturn(InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML));
- return new SupervisionHandler(automationCompositionProvider, participantProvider, acDefinitionProvider,
+ return new SupervisionHandler(automationCompositionProvider, acDefinitionProvider,
automationCompositionUpdatePublisher, automationCompositionStateChangePublisher,
- participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher);
+ participantUpdatePublisher);
}
private SupervisionHandler createSupervisionHandlerForTrigger() {
- return new SupervisionHandler(mock(AutomationCompositionProvider.class), mock(ParticipantProvider.class),
- mock(AcDefinitionProvider.class), mock(AutomationCompositionUpdatePublisher.class),
- mock(AutomationCompositionStateChangePublisher.class), mock(ParticipantRegisterAckPublisher.class),
- mock(ParticipantDeregisterAckPublisher.class), mock(ParticipantUpdatePublisher.class));
+ return new SupervisionHandler(mock(AutomationCompositionProvider.class), mock(AcDefinitionProvider.class),
+ mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class),
+ mock(ParticipantUpdatePublisher.class));
}
private SupervisionHandler createSupervisionHandlerForTrigger(
AutomationCompositionUpdatePublisher automationCompositionUpdatePublisher) {
- return new SupervisionHandler(mock(AutomationCompositionProvider.class), mock(ParticipantProvider.class),
- mock(AcDefinitionProvider.class), automationCompositionUpdatePublisher,
- mock(AutomationCompositionStateChangePublisher.class), mock(ParticipantRegisterAckPublisher.class),
- mock(ParticipantDeregisterAckPublisher.class), mock(ParticipantUpdatePublisher.class));
+ return new SupervisionHandler(mock(AutomationCompositionProvider.class), mock(AcDefinitionProvider.class),
+ automationCompositionUpdatePublisher, mock(AutomationCompositionStateChangePublisher.class),
+ mock(ParticipantUpdatePublisher.class));
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
new file mode 100644
index 000000000..9e35f2cf5
--- /dev/null
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java
@@ -0,0 +1,107 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.supervision;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Optional;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher;
+import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRegisterAckPublisher;
+import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+
+class SupervisionParticipantHandlerTest {
+ private static final ToscaConceptIdentifier PARTICIPANT_ID = new ToscaConceptIdentifier("ParticipantId", "1.0.0");
+ private static final ToscaConceptIdentifier PARTICIPANT_TYPE =
+ new ToscaConceptIdentifier("ParticipantType", "1.0.0");
+
+ @Test
+ void testHandleParticipantDeregister() {
+ var participant = new Participant();
+ participant.setName(PARTICIPANT_ID.getName());
+ participant.setVersion(PARTICIPANT_ID.getVersion());
+ participant.setParticipantType(PARTICIPANT_TYPE);
+
+ var participantProvider = mock(ParticipantProvider.class);
+ when(participantProvider.findParticipant(PARTICIPANT_ID)).thenReturn(Optional.of(participant));
+
+ var participantDeregisterMessage = new ParticipantDeregister();
+ participantDeregisterMessage.setMessageId(UUID.randomUUID());
+ participantDeregisterMessage.setParticipantId(PARTICIPANT_ID);
+ participantDeregisterMessage.setParticipantType(PARTICIPANT_TYPE);
+ var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
+ var handler = new SupervisionParticipantHandler(participantProvider,
+ mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher);
+
+ handler.handleParticipantMessage(participantDeregisterMessage);
+
+ verify(participantProvider).saveParticipant(any());
+ verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
+ }
+
+ @Test
+ void testHandleParticipantRegister() {
+ var participant = new Participant();
+ participant.setName(PARTICIPANT_ID.getName());
+ participant.setVersion(PARTICIPANT_ID.getVersion());
+ participant.setParticipantType(PARTICIPANT_TYPE);
+
+ var participantRegisterMessage = new ParticipantRegister();
+ participantRegisterMessage.setMessageId(UUID.randomUUID());
+ participantRegisterMessage.setParticipantId(PARTICIPANT_ID);
+ participantRegisterMessage.setParticipantType(PARTICIPANT_TYPE);
+ var participantProvider = mock(ParticipantProvider.class);
+ var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
+ var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher,
+ mock(ParticipantDeregisterAckPublisher.class));
+
+ handler.handleParticipantMessage(participantRegisterMessage);
+
+ verify(participantProvider).saveParticipant(any());
+ verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(), PARTICIPANT_ID,
+ PARTICIPANT_TYPE);
+ }
+
+ @Test
+ void testHandleParticipantStatus() {
+ var participantStatusMessage = new ParticipantStatus();
+ participantStatusMessage.setParticipantId(PARTICIPANT_ID);
+ participantStatusMessage.setParticipantType(PARTICIPANT_TYPE);
+ participantStatusMessage.setState(ParticipantState.ON_LINE);
+
+ var participantProvider = mock(ParticipantProvider.class);
+ var handler = new SupervisionParticipantHandler(participantProvider,
+ mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class));
+ handler.handleParticipantMessage(participantStatusMessage);
+
+ verify(participantProvider).saveParticipant(any());
+ }
+}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
index a6d4d3b0d..0142f294c 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,14 +36,12 @@ import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionUpdatePublisher;
-import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantStatusReqPublisher;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
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.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
@@ -81,7 +79,6 @@ class SupervisionScannerTest {
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var automationCompositionUpdatePublisher = mock(AutomationCompositionUpdatePublisher.class);
var participantProvider = mock(ParticipantProvider.class);
- var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud");
@@ -90,7 +87,7 @@ class SupervisionScannerTest {
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
- participantStatusReqPublisher, acRuntimeParameterGroup);
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
@@ -108,12 +105,11 @@ class SupervisionScannerTest {
var automationCompositionUpdatePublisher = mock(AutomationCompositionUpdatePublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var participantProvider = mock(ParticipantProvider.class);
- var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
- participantStatusReqPublisher, acRuntimeParameterGroup);
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class));
@@ -133,18 +129,16 @@ class SupervisionScannerTest {
when(participantProvider.getParticipants(null, null)).thenReturn(List.of(participant));
var automationCompositionUpdatePublisher = mock(AutomationCompositionUpdatePublisher.class);
- var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
- participantStatusReqPublisher, acRuntimeParameterGroup);
+ acRuntimeParameterGroup);
supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier());
supervisionScanner.run(true);
verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class));
- verify(participantStatusReqPublisher, times(0)).send(any(ToscaConceptIdentifier.class));
}
@Test
@@ -169,13 +163,12 @@ class SupervisionScannerTest {
var participantProvider = mock(ParticipantProvider.class);
var automationCompositionUpdatePublisher = mock(AutomationCompositionUpdatePublisher.class);
- var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
- participantStatusReqPublisher, acRuntimeParameterGroup);
+ acRuntimeParameterGroup);
supervisionScanner.run(false);
@@ -196,27 +189,24 @@ class SupervisionScannerTest {
var participant = new Participant();
participant.setName(PARTICIPANT_NAME);
participant.setVersion(PARTICIPANT_VERSION);
- participant.setHealthStatus(ParticipantHealthStatus.HEALTHY);
- participant.setParticipantState(ParticipantState.ACTIVE);
+ participant.setParticipantState(ParticipantState.OFF_LINE);
participant.setDefinition(new ToscaConceptIdentifier("unknown", "0.0.0"));
participant.setParticipantType(PARTICIPANT_TYPE);
var participantProvider = mock(ParticipantProvider.class);
when(participantProvider.getParticipants()).thenReturn(List.of(participant));
var automationCompositionUpdatePublisher = mock(AutomationCompositionUpdatePublisher.class);
- var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class);
var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider,
automationCompositionStateChangePublisher, automationCompositionUpdatePublisher, participantProvider,
- participantStatusReqPublisher, acRuntimeParameterGroup);
+ acRuntimeParameterGroup);
supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier());
supervisionScanner.run(true);
- verify(participantStatusReqPublisher).send(any(ToscaConceptIdentifier.class));
- verify(participantProvider).saveParticipant(any());
+ verify(participantProvider, times(0)).saveParticipant(any());
supervisionScanner.run(true);
- verify(participantProvider, times(2)).saveParticipant(any());
+ verify(participantProvider, times(1)).saveParticipant(any());
}
}
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 b545fd957..b7d2d9303 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2023 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,6 +33,7 @@ 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.acm.runtime.supervision.SupervisionParticipantHandler;
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.AutomationCompositionState;
@@ -75,7 +76,7 @@ class SupervisionMessagesTest {
@Test
void testReceiveParticipantDeregister() {
final var participantDeregisterMsg = new ParticipantDeregister();
- var supervisionHandler = mock(SupervisionHandler.class);
+ var supervisionHandler = mock(SupervisionParticipantHandler.class);
var participantDeregisterListener = new ParticipantDeregisterListener(supervisionHandler);
participantDeregisterListener.onTopicEvent(INFRA, TOPIC, null, participantDeregisterMsg);
verify(supervisionHandler).handleParticipantMessage(participantDeregisterMsg);
@@ -192,7 +193,7 @@ class SupervisionMessagesTest {
@Test
void testParticipantRegisterListener() {
final var participantRegister = new ParticipantRegister();
- var supervisionHandler = mock(SupervisionHandler.class);
+ var supervisionHandler = mock(SupervisionParticipantHandler.class);
var participantRegisterListener = new ParticipantRegisterListener(supervisionHandler);
participantRegisterListener.onTopicEvent(INFRA, TOPIC, null, participantRegister);
verify(supervisionHandler).handleParticipantMessage(participantRegister);
@@ -201,7 +202,7 @@ class SupervisionMessagesTest {
@Test
void testParticipantStatusListener() {
final var participantStatus = new ParticipantStatus();
- var supervisionHandler = mock(SupervisionHandler.class);
+ var supervisionHandler = mock(SupervisionParticipantHandler.class);
var participantStatusListener = new ParticipantStatusListener(supervisionHandler);
participantStatusListener.onTopicEvent(INFRA, TOPIC, null, participantStatus);
verify(supervisionHandler).handleParticipantMessage(participantStatus);