diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-07-11 11:19:34 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2023-07-12 07:55:23 +0000 |
commit | b13d8dc3a73bc372dabe47ebd88ed1892ee688ea (patch) | |
tree | 50b943e34be0f2e7e6792f17154071957e85f852 /runtime-acm/src/test | |
parent | b28ae291bc1b4a7426d4c6e5098c0a20f3948796 (diff) |
Add support participant restart in ACM runtime
Issue-ID: POLICY-4744
Change-Id: I33d31751be7ca5d7c215a2b465564d3ab0c7bee6
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/test')
4 files changed, 280 insertions, 28 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 08d20bacc..d7c79bc3b 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 @@ -188,4 +188,57 @@ class CommissioningProviderTest { provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate); verify(participantPrimePublisher, timeout(1000).times(1)).sendDepriming(compositionId); } + + @Test + void testBadRequest() { + var acProvider = mock(AutomationCompositionProvider.class); + var provider = new CommissioningProvider(mock(AcDefinitionProvider.class), acProvider, + mock(AcmParticipantProvider.class), new AcTypeStateResolver(), mock(ParticipantPrimePublisher.class)); + + var compositionId = UUID.randomUUID(); + when(acProvider.getAcInstancesByCompositionId(compositionId)).thenReturn(List.of(new AutomationComposition())); + + var toscaServiceTemplate = new ToscaServiceTemplate(); + assertThatThrownBy(() -> provider.updateCompositionDefinition(compositionId, toscaServiceTemplate)) + .hasMessageMatching("There are ACM instances, Update of ACM Definition not allowed"); + + var acTypeStateUpdate = new AcTypeStateUpdate(); + assertThatThrownBy(() -> provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate)) + .hasMessageMatching("There are instances, Priming/Depriming not allowed"); + } + + @Test + void testPrimedBadRequest() { + var acDefinitionProvider = mock(AcDefinitionProvider.class); + var toscaServiceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + var acmDefinition = CommonTestData.createAcDefinition(toscaServiceTemplate, AcTypeState.PRIMED); + var compositionId = acmDefinition.getCompositionId(); + when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition); + + var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class), + mock(AcmParticipantProvider.class), new AcTypeStateResolver(), mock(ParticipantPrimePublisher.class)); + + assertThatThrownBy(() -> provider.updateCompositionDefinition(compositionId, toscaServiceTemplate)) + .hasMessageMatching("ACM not in COMMISSIONED state, Update of ACM Definition not allowed"); + + assertThatThrownBy(() -> provider.deleteAutomationCompositionDefinition(compositionId)) + .hasMessageMatching("ACM not in COMMISSIONED state, Delete of ACM Definition not allowed"); + } + + @Test + void testPrimingBadRequest() { + var acDefinitionProvider = mock(AcDefinitionProvider.class); + var toscaServiceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + var acmDefinition = CommonTestData.createAcDefinition(toscaServiceTemplate, AcTypeState.PRIMED); + acmDefinition.setRestarting(true); + var compositionId = acmDefinition.getCompositionId(); + when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition); + + var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class), + mock(AcmParticipantProvider.class), new AcTypeStateResolver(), mock(ParticipantPrimePublisher.class)); + + var acTypeStateUpdate = new AcTypeStateUpdate(); + assertThatThrownBy(() -> provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate)) + .hasMessageMatching("There is a restarting process, Priming/Depriming not allowed"); + } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java index 13da979c8..3ac2efc1a 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java @@ -145,6 +145,115 @@ class AutomationCompositionInstantiationProviderTest { } @Test + void testInstantiationUpdate() throws AutomationCompositionException { + var acDefinitionProvider = mock(AcDefinitionProvider.class); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + var compositionId = acDefinition.getCompositionId(); + when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition)); + + var automationCompositionUpdate = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); + automationCompositionUpdate.setCompositionId(compositionId); + automationCompositionUpdate.setDeployState(DeployState.DEPLOYED); + automationCompositionUpdate.setLockState(LockState.LOCKED); + var acProvider = mock(AutomationCompositionProvider.class); + when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId())) + .thenReturn(automationCompositionUpdate); + when(acProvider.updateAutomationComposition(automationCompositionUpdate)) + .thenReturn(automationCompositionUpdate); + + var supervisionAcHandler = mock(SupervisionAcHandler.class); + var acmParticipantProvider = mock(AcmParticipantProvider.class); + var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, + null, supervisionAcHandler, acmParticipantProvider); + var instantiationResponse = instantiationProvider.updateAutomationComposition( + automationCompositionUpdate.getCompositionId(), automationCompositionUpdate); + + verify(supervisionAcHandler).update(any()); + verify(acProvider).updateAutomationComposition(automationCompositionUpdate); + InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionUpdate); + } + + @Test + void testUpdateBadRequest() throws AutomationCompositionException { + var automationCompositionUpdate = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); + automationCompositionUpdate.setDeployState(DeployState.DEPLOYING); + automationCompositionUpdate.setLockState(LockState.NONE); + var acProvider = mock(AutomationCompositionProvider.class); + when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId())) + .thenReturn(automationCompositionUpdate); + + var instantiationProvider = + new AutomationCompositionInstantiationProvider(acProvider, mock(AcDefinitionProvider.class), null, + mock(SupervisionAcHandler.class), mock(AcmParticipantProvider.class)); + + var compositionId = automationCompositionUpdate.getCompositionId(); + assertThatThrownBy( + () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate)) + .hasMessageMatching( + "Not allowed to update in the state " + automationCompositionUpdate.getDeployState()); + } + + @Test + void testUpdateRestartedBadRequest() throws AutomationCompositionException { + var automationCompositionUpdate = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); + automationCompositionUpdate.setDeployState(DeployState.DEPLOYED); + automationCompositionUpdate.setLockState(LockState.LOCKED); + automationCompositionUpdate.setRestarting(true); + var acProvider = mock(AutomationCompositionProvider.class); + when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId())) + .thenReturn(automationCompositionUpdate); + + var instantiationProvider = + new AutomationCompositionInstantiationProvider(acProvider, mock(AcDefinitionProvider.class), null, + mock(SupervisionAcHandler.class), mock(AcmParticipantProvider.class)); + + var compositionId = automationCompositionUpdate.getCompositionId(); + assertThatThrownBy( + () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate)) + .hasMessageMatching("There is a restarting process, Update not allowed"); + + automationCompositionUpdate.setDeployState(DeployState.UNDEPLOYED); + automationCompositionUpdate.setLockState(LockState.NONE); + + var instanceId = automationCompositionUpdate.getInstanceId(); + assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(compositionId, instanceId)) + .hasMessageMatching("There is a restarting process, Delete not allowed"); + } + + @Test + void testUpdateCompositionRestartedBadRequest() throws AutomationCompositionException { + var acDefinitionProvider = mock(AcDefinitionProvider.class); + var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); + acDefinition.setRestarting(true); + var compositionId = acDefinition.getCompositionId(); + when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition)); + + var automationCompositionUpdate = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); + automationCompositionUpdate.setCompositionId(compositionId); + automationCompositionUpdate.setDeployState(DeployState.DEPLOYED); + automationCompositionUpdate.setLockState(LockState.LOCKED); + var acProvider = mock(AutomationCompositionProvider.class); + when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId())) + .thenReturn(automationCompositionUpdate); + when(acProvider.updateAutomationComposition(automationCompositionUpdate)) + .thenReturn(automationCompositionUpdate); + + var supervisionAcHandler = mock(SupervisionAcHandler.class); + var acmParticipantProvider = mock(AcmParticipantProvider.class); + var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, + null, supervisionAcHandler, acmParticipantProvider); + assertThatThrownBy( + () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate)) + .hasMessageMatching("\"AutomationComposition\" INVALID, item has status INVALID\n" + + " item \"ServiceTemplate.restarting\" value \"true\" INVALID," + + " There is a restarting process in composition\n"); + } + + @Test void testInstantiationDelete() { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Delete"); @@ -154,8 +263,8 @@ class AutomationCompositionInstantiationProviderTest { var supervisionAcHandler = mock(SupervisionAcHandler.class); var acmParticipantProvider = mock(AcmParticipantProvider.class); - var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, - acDefinitionProvider, null, supervisionAcHandler, acmParticipantProvider); + var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, + null, supervisionAcHandler, acmParticipantProvider); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); @@ -178,15 +287,15 @@ class AutomationCompositionInstantiationProviderTest { verify(supervisionAcHandler).delete(any(), any()); } - private void assertThatDeleteThrownBy(AutomationComposition automationComposition, - DeployState deployState, LockState lockState) { + private void assertThatDeleteThrownBy(AutomationComposition automationComposition, DeployState deployState, + LockState lockState) { automationComposition.setDeployState(deployState); automationComposition.setLockState(lockState); var acProvider = mock(AutomationCompositionProvider.class); var acDefinitionProvider = mock(AcDefinitionProvider.class); - var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, - acDefinitionProvider, null, null, null); + var instantiationProvider = + new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null, null, null); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); @@ -214,8 +323,8 @@ class AutomationCompositionInstantiationProviderTest { .thenReturn(automationCompositionCreate); var acmParticipantProvider = mock(AcmParticipantProvider.class); - var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, - acDefinitionProvider, null, null, acmParticipantProvider); + var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, + null, null, acmParticipantProvider); var instantiationResponse = instantiationProvider.createAutomationComposition( automationCompositionCreate.getCompositionId(), automationCompositionCreate); @@ -241,8 +350,8 @@ class AutomationCompositionInstantiationProviderTest { automationComposition.setCompositionId(compositionId); var acProvider = mock(AutomationCompositionProvider.class); - var provider = new AutomationCompositionInstantiationProvider(acProvider, - acDefinitionProvider, null, null, acmParticipantProvider); + var provider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null, null, + acmParticipantProvider); assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition)) .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND); @@ -262,8 +371,8 @@ class AutomationCompositionInstantiationProviderTest { var acProvider = mock(AutomationCompositionProvider.class); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); - var provider = new AutomationCompositionInstantiationProvider(acProvider, - mock(AcDefinitionProvider.class), null, null, null); + var provider = new AutomationCompositionInstantiationProvider(acProvider, mock(AcDefinitionProvider.class), + null, null, null); var compositionId = automationComposition.getCompositionId(); assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition)) @@ -281,8 +390,8 @@ class AutomationCompositionInstantiationProviderTest { var acProvider = mock(AutomationCompositionProvider.class); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); - var provider = new AutomationCompositionInstantiationProvider(acProvider, - mock(AcDefinitionProvider.class), null, null, null); + var provider = new AutomationCompositionInstantiationProvider(acProvider, mock(AcDefinitionProvider.class), + null, null, null); var compositionId = automationComposition.getCompositionId(); var wrongCompositionId = UUID.randomUUID(); @@ -315,7 +424,7 @@ class AutomationCompositionInstantiationProviderTest { automationComposition.setCompositionId(compositionId); assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition)) .hasMessageMatching("\"AutomationComposition\" INVALID, item has status INVALID\n" - + " item \"ServiceTemplate\" value \"COMMISSIONED\" INVALID," + + " item \"ServiceTemplate.state\" value \"COMMISSIONED\" INVALID," + " Commissioned automation composition definition not primed\n"); } @@ -332,8 +441,7 @@ class AutomationCompositionInstantiationProviderTest { automationComposition.setCompositionId(compositionId); automationComposition.setInstanceId(instanceId); var acProvider = mock(AutomationCompositionProvider.class); - when(acProvider.getAutomationComposition(instanceId)) - .thenReturn(automationComposition); + when(acProvider.getAutomationComposition(instanceId)).thenReturn(automationComposition); var supervisionAcHandler = mock(SupervisionAcHandler.class); var acmParticipantProvider = mock(AcmParticipantProvider.class); @@ -367,7 +475,6 @@ class AutomationCompositionInstantiationProviderTest { acInstanceStateUpdate.setDeployOrder(DeployOrder.NONE); acInstanceStateUpdate.setLockOrder(LockOrder.LOCK); provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate); - verify(supervisionAcHandler).lock(any(AutomationComposition.class), - any(AutomationCompositionDefinition.class)); + verify(supervisionAcHandler).lock(any(AutomationComposition.class), any(AutomationCompositionDefinition.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 index e441befb2..ed8a85664 100644 --- 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 @@ -26,22 +26,34 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.Set; 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.comm.ParticipantDeregisterAckPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRegisterAckPublisher; +import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRestartPublisher; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; +import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; +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.concepts.ParticipantSupportedElementType; 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.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; class SupervisionParticipantHandlerTest { + + private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json"; + @Test void testHandleParticipantDeregister() { var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); @@ -54,9 +66,10 @@ class SupervisionParticipantHandlerTest { participantDeregisterMessage.setMessageId(UUID.randomUUID()); participantDeregisterMessage.setParticipantId(CommonTestData.getParticipantId()); var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class); - var handler = new SupervisionParticipantHandler(participantProvider, - mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher, - mock(AutomationCompositionProvider.class)); + var handler = + new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), + participantDeregisterAckPublisher, mock(AutomationCompositionProvider.class), + mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class)); handler.handleParticipantMessage(participantDeregisterMessage); @@ -77,8 +90,8 @@ class SupervisionParticipantHandlerTest { var participantProvider = mock(ParticipantProvider.class); var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class); var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher, - mock(ParticipantDeregisterAckPublisher.class), - mock(AutomationCompositionProvider.class)); + mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionProvider.class), + mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class)); handler.handleParticipantMessage(participantRegisterMessage); verify(participantProvider).saveParticipant(any()); @@ -87,6 +100,58 @@ class SupervisionParticipantHandlerTest { } @Test + void testHandleParticipantRestart() { + var participantRegisterMessage = new ParticipantRegister(); + participantRegisterMessage.setMessageId(UUID.randomUUID()); + var participantId = CommonTestData.getParticipantId(); + participantRegisterMessage.setParticipantId(participantId); + var supportedElementType = new ParticipantSupportedElementType(); + supportedElementType.setTypeName("Type"); + supportedElementType.setTypeVersion("1.0.0"); + participantRegisterMessage.setParticipantSupportedElementType(List.of(supportedElementType)); + + var participant = new Participant(); + participant.setParticipantId(participantId); + var participantProvider = mock(ParticipantProvider.class); + when(participantProvider.findParticipant(participantId)).thenReturn(Optional.of(participant)); + var compositionId = UUID.randomUUID(); + var composition2Id = UUID.randomUUID(); + when(participantProvider.getCompositionIds(participantId)).thenReturn(Set.of(compositionId, composition2Id)); + + var acDefinitionProvider = mock(AcDefinitionProvider.class); + var acDefinition = new AutomationCompositionDefinition(); + acDefinition.setState(AcTypeState.COMMISSIONED); + acDefinition.setCompositionId(composition2Id); + when(acDefinitionProvider.getAcDefinition(composition2Id)).thenReturn(acDefinition); + + acDefinition = new AutomationCompositionDefinition(); + acDefinition.setCompositionId(compositionId); + acDefinition.setState(AcTypeState.PRIMED); + var nodeTemplateState = new NodeTemplateState(); + nodeTemplateState.setParticipantId(participantId); + acDefinition.setElementStateMap(Map.of("code", nodeTemplateState)); + when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acDefinition); + + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud"); + automationComposition.getElements().values().iterator().next().setParticipantId(participantId); + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) + .thenReturn(List.of(automationComposition)); + + var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class); + var participantRestartPublisher = mock(ParticipantRestartPublisher.class); + var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher, + mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider, acDefinitionProvider, + participantRestartPublisher); + handler.handleParticipantMessage(participantRegisterMessage); + + verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(), participantId); + verify(acDefinitionProvider).updateAcDefinition(any(AutomationCompositionDefinition.class)); + verify(participantRestartPublisher).send(any(), any(AutomationCompositionDefinition.class), any()); + } + + @Test void testHandleParticipantStatus() { var participantStatusMessage = new ParticipantStatus(); participantStatusMessage.setParticipantId(CommonTestData.getParticipantId()); @@ -98,14 +163,16 @@ class SupervisionParticipantHandlerTest { participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo())); var participantProvider = mock(ParticipantProvider.class); - var handler = new SupervisionParticipantHandler(participantProvider, - mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), - mock(AutomationCompositionProvider.class)); + var automationCompositionProvider = mock(AutomationCompositionProvider.class); + var handler = + new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider, + mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class)); var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); when(participantProvider.findParticipant(CommonTestData.getParticipantId())) .thenReturn(Optional.of(participant)); handler.handleParticipantMessage(participantStatusMessage); - verify(participantProvider).updateParticipant(any()); + verify(automationCompositionProvider).upgradeStates(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 8de5ccabe..06684d863 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 @@ -222,6 +222,31 @@ class SupervisionMessagesTest { } @Test + void testParticipantRestartPublisher() { + var publisher = new ParticipantRestartPublisher(); + var topicSink = mock(TopicSink.class); + publisher.active(List.of(topicSink)); + + 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 acElements = AcmUtils.extractAcElementsFromServiceTemplate(serviceTemplate); + acmDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, AcTypeState.PRIMED)); + + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); + + var participantId = automationComposition.getElements().values().iterator().next().getParticipantId(); + acmDefinition.getElementStateMap().values().iterator().next().setParticipantId(participantId); + + publisher.send(participantId, acmDefinition, List.of(automationComposition)); + verify(topicSink).send(anyString()); + } + + @Test void testParticipantRegisterListener() { final var participantRegister = new ParticipantRegister(); var supervisionHandler = mock(SupervisionParticipantHandler.class); |