aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-controlloop
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2021-11-22 19:40:39 +0000
committerlapentafd <francesco.lapenta@est.tech>2021-11-22 22:39:59 +0000
commit59376f8370c4a4de4dd34bf297a4fccf7149b27a (patch)
tree781e6d70c931d07a365e6018976b3077030896fc /runtime-controlloop
parentf0a58426aa87795d4fa29eedb5bf2c14f5f6896f (diff)
Code coverage clamp
Issue-ID: POLICY-3452 Change-Id: I7ee191e590689e42822614d79a398012c454be42 Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'runtime-controlloop')
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java52
1 files changed, 40 insertions, 12 deletions
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
index a314b30a0..ece676a71 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
@@ -73,7 +73,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
assertThatThrownBy(() -> handler.triggerControlLoopSupervision(List.of()))
.hasMessageMatching("The list of control loops for supervision is empty");
@@ -86,7 +86,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), controlLoopUpdatePublisher,
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
handler.triggerControlLoopSupervision(List.of(identifier));
@@ -95,12 +95,38 @@ class SupervisionHandlerTest {
}
@Test
+ void testTriggerControlLoopUninitialised() throws ControlLoopException, PfModelException, CoderException {
+ var controlLoopProvider = mock(ControlLoopProvider.class);
+ var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
+ var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class),
+ mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
+ mock(ParticipantDeregisterAckPublisher.class), controlLoopUpdatePublisher,
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.UNINITIALISED);
+
+ assertThatThrownBy(() -> handler.triggerControlLoopSupervision(List.of(identifier)))
+ .hasMessageMatching("Control loop is already in state UNINITIALISED");
+ }
+
+ @Test
+ void testTriggerControlLoopRunning() throws ControlLoopException, PfModelException, CoderException {
+ var controlLoopProvider = mock(ControlLoopProvider.class);
+ var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
+ var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class),
+ mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
+ mock(ParticipantDeregisterAckPublisher.class), controlLoopUpdatePublisher,
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.RUNNING);
+
+ assertThatThrownBy(() -> handler.triggerControlLoopSupervision(List.of(identifier)))
+ .hasMessageMatching("Control loop can't transition from state UNINITIALISED to state RUNNING");
+ }
+
+ @Test
void testHandleControlLoopStateChangeAckMessage() throws PfModelException, CoderException {
var controlLoopProvider = mock(ControlLoopProvider.class);
var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
var controlLoopAckMessage = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
controlLoopAckMessage.setControlLoopResultMap(Map.of());
controlLoopAckMessage.setControlLoopId(identifier);
@@ -121,7 +147,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
handler.handleControlLoopUpdateAckMessage(controlLoopAckMessage);
@@ -147,7 +173,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider,
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
participantDeregisterAckPublisher, mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
handler.handleParticipantMessage(participantDeregisterMessage);
@@ -171,7 +197,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider,
mock(MonitoringProvider.class), participantRegisterAckPublisher,
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
handler.handleParticipantMessage(participantRegisterMessage);
@@ -198,7 +224,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider,
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
handler.handleParticipantMessage(participantUpdateAckMessage);
@@ -218,7 +244,8 @@ class SupervisionHandlerTest {
var monitoringProvider = mock(MonitoringProvider.class);
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider, monitoringProvider,
mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
- mock(ControlLoopUpdatePublisher.class), mock(ParticipantUpdatePublisher.class));
+ mock(ControlLoopUpdatePublisher.class), mock(ParticipantUpdatePublisher.class),
+ ControlLoopOrderedState.PASSIVE);
handler.handleParticipantMessage(participantStatusMessage);
verify(participantProvider).createParticipants(anyList());
@@ -231,7 +258,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- participantUpdatePublisher);
+ participantUpdatePublisher, ControlLoopOrderedState.PASSIVE);
handler.handleSendCommissionMessage(participantId.getName(), participantId.getVersion());
verify(participantUpdatePublisher).sendComissioningBroadcast(participantId.getName(),
@@ -244,7 +271,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- participantUpdatePublisher);
+ participantUpdatePublisher, ControlLoopOrderedState.PASSIVE);
handler.handleSendDeCommissionMessage();
verify(participantUpdatePublisher).sendDecomisioning();
@@ -255,11 +282,12 @@ class SupervisionHandlerTest {
ParticipantRegisterAckPublisher participantRegisterAckPublisher,
ParticipantDeregisterAckPublisher participantDeregisterAckPublisher,
ControlLoopUpdatePublisher controlLoopUpdatePublisher,
- ParticipantUpdatePublisher participantUpdatePublisher) throws PfModelException, CoderException {
+ ParticipantUpdatePublisher participantUpdatePublisher,
+ ControlLoopOrderedState orderedState) throws PfModelException, CoderException {
var controlLoopsCreate = InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Crud");
var controlLoop = controlLoopsCreate.getControlLoopList().get(0);
- controlLoop.setOrderedState(ControlLoopOrderedState.PASSIVE);
+ controlLoop.setOrderedState(orderedState);
var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);