diff options
Diffstat (limited to 'runtime-controlloop/src')
-rw-r--r-- | runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java | 52 |
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 abaa52c12..5ed4a4fc0 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 @@ -74,7 +74,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"); @@ -87,7 +87,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)); @@ -96,12 +96,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); @@ -122,7 +148,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); @@ -148,7 +174,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); @@ -172,7 +198,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); @@ -199,7 +225,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); @@ -219,7 +245,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).saveParticipant(any()); @@ -232,7 +259,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(), @@ -245,7 +272,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(); @@ -256,11 +283,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); |