diff options
Diffstat (limited to 'runtime-acm')
13 files changed, 302 insertions, 294 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java index 29b337edd..03a2f4e25 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java @@ -43,6 +43,7 @@ import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.ObjectValidationResult; import org.onap.policy.common.parameters.ValidationStatus; import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -80,9 +81,10 @@ public class AutomationCompositionInstantiationProvider { if (!validationResult.isValid()) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); } - automationComposition = automationCompositionProvider.saveAutomationComposition(automationComposition); + automationComposition = automationCompositionProvider.createAutomationComposition(automationComposition); var response = new InstantiationResponse(); + response.setInstanceId(automationComposition.getInstanceId()); response.setAffectedAutomationComposition(automationComposition.getKey().asIdentifier()); return response; @@ -99,9 +101,10 @@ public class AutomationCompositionInstantiationProvider { if (!validationResult.isValid()) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); } - automationCompositionProvider.saveAutomationComposition(automationComposition); + automationCompositionProvider.updateAutomationComposition(automationComposition); var response = new InstantiationResponse(); + response.setInstanceId(automationComposition.getInstanceId()); response.setAffectedAutomationComposition(automationComposition.getKey().asIdentifier()); return response; @@ -134,7 +137,8 @@ public class AutomationCompositionInstantiationProvider { * @return the result of the deletion */ public InstantiationResponse deleteAutomationComposition(String name, String version) { - var automationCompositionOpt = automationCompositionProvider.findAutomationComposition(name, version); + var automationCompositionOpt = + automationCompositionProvider.findAutomationComposition(new ToscaConceptIdentifier(name, version)); if (automationCompositionOpt.isEmpty()) { throw new PfModelRuntimeException(Response.Status.NOT_FOUND, "Automation composition not found"); } @@ -144,8 +148,10 @@ public class AutomationCompositionInstantiationProvider { "Automation composition state is still " + automationComposition.getState()); } var response = new InstantiationResponse(); - response.setAffectedAutomationComposition( - automationCompositionProvider.deleteAutomationComposition(name, version).getKey().asIdentifier()); + automationComposition = + automationCompositionProvider.deleteAutomationComposition(automationComposition.getInstanceId()); + response.setInstanceId(automationComposition.getInstanceId()); + response.setAffectedAutomationComposition(automationComposition.getKey().asIdentifier()); return response; } @@ -199,7 +205,7 @@ public class AutomationCompositionInstantiationProvider { automationComposition.setCascadedOrderedState(command.getOrderedState()); supervisionHandler.triggerAutomationCompositionSupervision(automationComposition); - automationCompositionProvider.saveAutomationComposition(automationComposition); + automationCompositionProvider.updateAutomationComposition(automationComposition); var response = new InstantiationResponse(); response.setAffectedAutomationComposition(command.getAutomationCompositionIdentifier()); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java index b5d7645da..de67360f8 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java @@ -235,7 +235,7 @@ public class SupervisionHandler { automationCompositionAckMessage.getAutomationCompositionResultMap().entrySet()); updated |= setPrimed(automationComposition.get()); if (updated) { - automationCompositionProvider.saveAutomationComposition(automationComposition.get()); + automationCompositionProvider.updateAutomationComposition(automationComposition.get()); } } else { LOGGER.warn("AutomationComposition not found in database {}", diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java index e2f8b6777..129569b6b 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java @@ -242,7 +242,7 @@ public class SupervisionScanner { automationComposition.getState(), automationComposition.getOrderedState()); automationComposition.setState(automationComposition.getOrderedState().asState()); - automationCompositionProvider.saveAutomationComposition(automationComposition); + automationCompositionProvider.updateAutomationComposition(automationComposition); // Clear missed report counter on automation composition clearFaultAndCounter(automationComposition); 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/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java index 864179844..115adcb50 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 @@ -45,6 +45,7 @@ import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvide import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; @@ -66,14 +67,13 @@ class AutomationCompositionInstantiationProviderTest { private static final String ORDERED_STATE_INVALID = "ordered state invalid or not specified on command"; private static final String AC_ELEMENT_NAME_NOT_FOUND = "\"AutomationComposition\" INVALID, item has status INVALID\n" - + " \"entry PMSHInstance0AcElementNotFound\" INVALID, item has status INVALID\n" - + " \"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n" - + " \"entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement\"" - + " INVALID, Not found\n"; - private static final String AC_DEFINITION_NOT_FOUND = - "\"AutomationComposition\" INVALID, item has status INVALID\n" - + " item \"ServiceTemplate\" value \"\" INVALID," - + " Commissioned automation composition definition not found\n"; + + " \"entry PMSHInstance0AcElementNotFound\" INVALID, item has status INVALID\n" + + " \"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n" + + " \"entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement\"" + + " INVALID, Not found\n"; + private static final String AC_DEFINITION_NOT_FOUND = "\"AutomationComposition\" INVALID, item has status INVALID\n" + + " item \"ServiceTemplate\" value \"\" INVALID," + + " Commissioned automation composition definition not found\n"; private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); @@ -101,12 +101,13 @@ class AutomationCompositionInstantiationProviderTest { var automationCompositionCreate = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud"); automationCompositionCreate.setCompositionId(compositionId); - when(acProvider.saveAutomationComposition(automationCompositionCreate)).thenReturn(automationCompositionCreate); + when(acProvider.createAutomationComposition(automationCompositionCreate)) + .thenReturn(automationCompositionCreate); var instantiationResponse = instantiationProvider.createAutomationComposition(automationCompositionCreate); InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionCreate); - verify(acProvider).saveAutomationComposition(automationCompositionCreate); + verify(acProvider).createAutomationComposition(automationCompositionCreate); when(acProvider.getAutomationCompositions(automationCompositionCreate.getName(), automationCompositionCreate.getVersion())).thenReturn(List.of(automationCompositionCreate)); @@ -123,14 +124,12 @@ class AutomationCompositionInstantiationProviderTest { instantiationResponse = instantiationProvider.updateAutomationComposition(automationCompositionUpdate); InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionUpdate); - verify(acProvider).saveAutomationComposition(automationCompositionUpdate); + verify(acProvider).updateAutomationComposition(automationCompositionUpdate); when(acProvider.findAutomationComposition(automationCompositionUpdate.getKey().asIdentifier())) .thenReturn(Optional.of(automationCompositionUpdate)); - when(acProvider.findAutomationComposition(automationCompositionUpdate.getName(), - automationCompositionUpdate.getVersion())).thenReturn(Optional.of(automationCompositionUpdate)); - when(acProvider.deleteAutomationComposition(automationCompositionUpdate.getName(), - automationCompositionUpdate.getVersion())).thenReturn(automationCompositionUpdate); + when(acProvider.deleteAutomationComposition(automationCompositionUpdate.getInstanceId())) + .thenReturn(automationCompositionUpdate); var instantiationCommand = InstantiationUtils.getInstantiationCommandFromResource(AC_INSTANTIATION_CHANGE_STATE_JSON, "Crud"); @@ -146,8 +145,7 @@ class AutomationCompositionInstantiationProviderTest { instantiationProvider.deleteAutomationComposition(automationCompositionCreate.getName(), automationCompositionCreate.getVersion()); - verify(acProvider).deleteAutomationComposition(automationCompositionCreate.getName(), - automationCompositionCreate.getVersion()); + verify(acProvider).deleteAutomationComposition(automationCompositionCreate.getInstanceId()); } @Test @@ -172,11 +170,13 @@ class AutomationCompositionInstantiationProviderTest { } } automationComposition.setState(AutomationCompositionState.UNINITIALISED); + automationComposition.setInstanceId(UUID.randomUUID()); - when(acProvider.findAutomationComposition(automationComposition.getName(), automationComposition.getVersion())) - .thenReturn(Optional.of(automationComposition)); - when(acProvider.deleteAutomationComposition(automationComposition.getName(), - automationComposition.getVersion())).thenReturn(automationComposition); + when(acProvider.findAutomationComposition( + new ToscaConceptIdentifier(automationComposition.getName(), automationComposition.getVersion()))) + .thenReturn(Optional.of(automationComposition)); + when(acProvider.deleteAutomationComposition(automationComposition.getInstanceId())) + .thenReturn(automationComposition); instantiationProvider.deleteAutomationComposition(automationComposition.getName(), automationComposition.getVersion()); @@ -193,8 +193,8 @@ class AutomationCompositionInstantiationProviderTest { var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, supervisionHandler, participantProvider, acDefinitionProvider); - when(acProvider.findAutomationComposition(automationComposition.getName(), automationComposition.getVersion())) - .thenReturn(Optional.of(automationComposition)); + var key = new ToscaConceptIdentifier(automationComposition.getName(), automationComposition.getVersion()); + when(acProvider.findAutomationComposition(key)).thenReturn(Optional.of(automationComposition)); assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(automationComposition.getName(), automationComposition.getVersion())).hasMessageMatching(String.format(DELETE_BAD_REQUEST, state)); @@ -209,9 +209,11 @@ class AutomationCompositionInstantiationProviderTest { var automationCompositionCreate = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "NoDuplicates"); automationCompositionCreate.setCompositionId(compositionId); + automationCompositionCreate.setInstanceId(UUID.randomUUID()); var acProvider = mock(AutomationCompositionProvider.class); - when(acProvider.saveAutomationComposition(automationCompositionCreate)).thenReturn(automationCompositionCreate); + when(acProvider.createAutomationComposition(automationCompositionCreate)) + .thenReturn(automationCompositionCreate); var participantProvider = Mockito.mock(ParticipantProvider.class); var supervisionHandler = mock(SupervisionHandler.class); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java index dd6e8f3fc..9c364b2db 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/rest/InstantiationControllerTest.java @@ -166,6 +166,7 @@ class InstantiationControllerTest extends CommonRestController { assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); var instResponse = resp.readEntity(InstantiationResponse.class); InstantiationUtils.assertInstantiationResponse(instResponse, automationCompositionFromRsc); + automationCompositionFromRsc.setInstanceId(instResponse.getInstanceId()); var automationCompositionsFromDb = instantiationProvider.getAutomationCompositions( automationCompositionFromRsc.getKey().getName(), automationCompositionFromRsc.getKey().getVersion()); @@ -227,12 +228,13 @@ class InstantiationControllerTest extends CommonRestController { InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Update"); automationCompositionCreate.setCompositionId(compositionId); - instantiationProvider.createAutomationComposition(automationCompositionCreate); + var response = instantiationProvider.createAutomationComposition(automationCompositionCreate); var invocationBuilder = super.sendRequest(INSTANTIATION_ENDPOINT); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Update"); automationComposition.setCompositionId(compositionId); + automationComposition.setInstanceId(response.getInstanceId()); var resp = invocationBuilder.put(Entity.json(automationComposition)); assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); 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..3a707cd52 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()); @@ -171,7 +235,7 @@ class SupervisionHandlerTest { handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage); - verify(automationCompositionProvider).saveAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); } @Test @@ -185,12 +249,13 @@ 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); - verify(automationCompositionProvider).saveAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); } @Test @@ -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/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java index 03a0ec59e..1455e9246 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 @@ -96,7 +96,7 @@ class SupervisionScannerTest { participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup); supervisionScanner.run(false); - verify(automationCompositionProvider, times(0)).saveAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class)); } @Test @@ -120,7 +120,7 @@ class SupervisionScannerTest { participantStatusReqPublisher, participantUpdatePublisher, acRuntimeParameterGroup); supervisionScanner.run(false); - verify(automationCompositionProvider, times(1)).saveAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider, times(1)).updateAutomationComposition(any(AutomationComposition.class)); } @Test @@ -148,7 +148,7 @@ class SupervisionScannerTest { supervisionScanner.handleParticipantStatus(participant.getKey().asIdentifier()); supervisionScanner.run(true); - verify(automationCompositionProvider, times(0)).saveAutomationComposition(any(AutomationComposition.class)); + verify(automationCompositionProvider, times(0)).updateAutomationComposition(any(AutomationComposition.class)); verify(participantStatusReqPublisher, times(0)).send(any(ToscaConceptIdentifier.class)); } 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); } + } diff --git a/runtime-acm/src/test/resources/rest/monitoring/TestAcElementStatistics.json b/runtime-acm/src/test/resources/rest/monitoring/TestAcElementStatistics.json deleted file mode 100644 index c63c3ea1d..000000000 --- a/runtime-acm/src/test/resources/rest/monitoring/TestAcElementStatistics.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "acElementStatistics":[ - { - "participantId":{ - "name":"name1", - "version":"1.001" - }, - "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", - "timeStamp": "2021-01-10T13:45:00.000Z", - "state": "UNINITIALISED", - "acElementUptime":250 - }, - { - "participantId":{ - "name":"name1", - "version":"1.001" - }, - "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", - "timeStamp": "2021-01-10T15:45:00.000Z", - "state": "UNINITIALISED", - "acElementUptime":450 - }, - { - "participantId":{ - "name":"name2", - "version":"1.001" - }, - "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", - "timeStamp": "2021-01-10T14:25:00.000Z", - "state": "UNINITIALISED", - "acElementUptime":330 - }, - { - "participantId":{ - "name":"name2", - "version":"1.001" - }, - "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", - "timeStamp": "2021-01-10T16:35:00.000Z", - "state": "UNINITIALISED", - "acElementUptime":650 - } - ] -}
\ No newline at end of file diff --git a/runtime-acm/src/test/resources/rest/monitoring/TestAcElementStatistics_Invalid.json b/runtime-acm/src/test/resources/rest/monitoring/TestAcElementStatistics_Invalid.json deleted file mode 100644 index 59af47828..000000000 --- a/runtime-acm/src/test/resources/rest/monitoring/TestAcElementStatistics_Invalid.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "acElementStatisticsList":[ - { - "participantId":{ - "name":"name1", - "version":"1.001" - }, - "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", - "state": "UNINITIALISED", - "acElementUptime":250 - } - ] -}
\ No newline at end of file diff --git a/runtime-acm/src/test/resources/rest/monitoring/TestParticipantStatistics.json b/runtime-acm/src/test/resources/rest/monitoring/TestParticipantStatistics.json deleted file mode 100644 index acd88e24b..000000000 --- a/runtime-acm/src/test/resources/rest/monitoring/TestParticipantStatistics.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "statisticsList":[ - { - "participantId":{ - "name":"name1", - "version":"1.001" - }, - "timeStamp": "2021-01-10T13:45:00.000Z", - "state": "PASSIVE", - "healthStatus": "HEALTHY", - "eventCount":250, - "lastExecutionTime":100, - "averageExecutionTime":90, - "upTime":1000, - "lastStart":3000 - }, - { - "participantId":{ - "name":"name1", - "version":"1.001" - }, - "timeStamp": "2021-01-10T15:45:00.000Z", - "state": "PASSIVE", - "healthStatus": "HEALTHY", - "eventCount":262, - "lastExecutionTime":100, - "averageExecutionTime":90, - "upTime":2000, - "lastStart":3000 - }, - { - "participantId":{ - "name":"name2", - "version":"1.001" - }, - "timeStamp": "2021-01-27T14:25:00.000Z", - "state": "PASSIVE", - "healthStatus": "HEALTHY", - "eventCount":245, - "lastExecutionTime":1020, - "averageExecutionTime":85, - "upTime":1050, - "lastStart":3100 - } - ] -}
\ No newline at end of file diff --git a/runtime-acm/src/test/resources/rest/monitoring/TestParticipantStatistics_Invalid.json b/runtime-acm/src/test/resources/rest/monitoring/TestParticipantStatistics_Invalid.json deleted file mode 100644 index 7281822f0..000000000 --- a/runtime-acm/src/test/resources/rest/monitoring/TestParticipantStatistics_Invalid.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "participantStatisticsList":[ - { - "participantId":{ - "name":"name3", - "version":"1.001" - }, - "state": "PASSIVE", - "eventCount":250, - "lastExecutionTime":100, - "averageExecutionTime":90, - "upTime":1000, - "lastStart":3000 - } - ] -}
\ No newline at end of file |