diff options
author | rameshiyer27 <ramesh.murugan.iyer@est.tech> | 2023-06-28 10:57:33 +0100 |
---|---|---|
committer | Adheli Tavares <adheli.tavares@est.tech> | 2023-07-05 09:18:01 +0000 |
commit | fdd9179e8713e68916a16ea949b1125a358b560e (patch) | |
tree | 9c37560677ae9689b5b207d32c46a067a2d49f88 /runtime-acm/src/test/java | |
parent | 85751a7d52cc6efbea69c08f71f550ae32c61043 (diff) |
Add validation for Participant availability
Validation added to check if the participant is online before executing all the ACM operations
Issue-ID: POLICY-4746
Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech>
Change-Id: Ibbdb299822e5fc6462db9688a3ec853076b1e7e9
Diffstat (limited to 'runtime-acm/src/test/java')
6 files changed, 54 insertions, 18 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 fbaa4fed5..08d20bacc 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 @@ -24,6 +24,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.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; @@ -34,6 +35,7 @@ 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.participants.AcmParticipantProvider; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantPrimePublisher; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; @@ -58,7 +60,7 @@ class CommissioningProviderTest { var acProvider = mock(AutomationCompositionProvider.class); var acDefinitionProvider = mock(AcDefinitionProvider.class); - var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null); + var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null); var serviceTemplates = provider.getAutomationCompositionDefinitions(null, null); assertThat(serviceTemplates.getServiceTemplates()).isEmpty(); @@ -85,7 +87,7 @@ class CommissioningProviderTest { when(acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate)).thenReturn(acmDefinition); var acProvider = mock(AutomationCompositionProvider.class); - var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null); + var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null); var affectedDefinitions = provider.createAutomationCompositionDefinition(serviceTemplate) .getAffectedAutomationCompositionDefinitions(); verify(acDefinitionProvider).createAutomationCompositionDefinition(serviceTemplate); @@ -103,7 +105,7 @@ class CommissioningProviderTest { var acDefinitionProvider = mock(AcDefinitionProvider.class); var acProvider = mock(AutomationCompositionProvider.class); - var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null); + var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); when(acDefinitionProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate)); @@ -120,7 +122,7 @@ class CommissioningProviderTest { var compositionId = UUID.randomUUID(); when(acProvider.getAcInstancesByCompositionId(compositionId)).thenReturn(List.of(new AutomationComposition())); - var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null); + var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null); assertThatThrownBy(() -> provider.deleteAutomationCompositionDefinition(compositionId)) .hasMessageMatching("Delete instances, to commission automation composition definitions"); @@ -140,7 +142,7 @@ class CommissioningProviderTest { when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition); var acProvider = mock(AutomationCompositionProvider.class); - var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null); + var provider = new CommissioningProvider(acDefinitionProvider, acProvider, null, null, null); provider.deleteAutomationCompositionDefinition(compositionId); @@ -157,7 +159,7 @@ class CommissioningProviderTest { var participantPrimePublisher = mock(ParticipantPrimePublisher.class); var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class), - new AcTypeStateResolver(), participantPrimePublisher); + mock(AcmParticipantProvider.class), new AcTypeStateResolver(), participantPrimePublisher); var acTypeStateUpdate = new AcTypeStateUpdate(); acTypeStateUpdate.setPrimeOrder(PrimeOrder.PRIME); @@ -175,11 +177,14 @@ class CommissioningProviderTest { when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition); var participantPrimePublisher = mock(ParticipantPrimePublisher.class); + var acmParticipantProvider = mock(AcmParticipantProvider.class); var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class), - new AcTypeStateResolver(), participantPrimePublisher); + acmParticipantProvider, new AcTypeStateResolver(), participantPrimePublisher); var acTypeStateUpdate = new AcTypeStateUpdate(); acTypeStateUpdate.setPrimeOrder(PrimeOrder.DEPRIME); + + doNothing().when(acmParticipantProvider).verifyParticipantState(any()); provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate); verify(participantPrimePublisher, timeout(1000).times(1)).sendDepriming(compositionId); } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java index fac4440a2..e8e595b4a 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java @@ -40,10 +40,16 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController; 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.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.AcTypeStateUpdate; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse; import org.onap.policy.clamp.models.acm.messages.rest.commissioning.PrimeOrder; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; +import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; +import org.onap.policy.clamp.models.acm.utils.AcmUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -65,6 +71,8 @@ class CommissioningControllerTest extends CommonRestController { @Autowired private AcDefinitionProvider acDefinitionProvider; + @Autowired + private ParticipantProvider participantProvider; @LocalServerPort private int randomServerPort; @@ -223,6 +231,8 @@ class CommissioningControllerTest extends CommonRestController { var serviceTemplateCreate = new ToscaServiceTemplate(serviceTemplate); serviceTemplateCreate.setName(name); var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplateCreate); + return acmDefinition.getCompositionId(); } + } 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 54a0c9613..13da979c8 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 @@ -24,6 +24,7 @@ package org.onap.policy.clamp.acm.runtime.instantiation; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -34,6 +35,7 @@ import java.util.Optional; import java.util.UUID; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.acm.runtime.participants.AcmParticipantProvider; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException; @@ -96,8 +98,9 @@ class AutomationCompositionInstantiationProviderTest { when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition)); var acProvider = mock(AutomationCompositionProvider.class); var supervisionAcHandler = mock(SupervisionAcHandler.class); + var acmParticipantProvider = mock(AcmParticipantProvider.class); var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, - null, supervisionAcHandler); + null, supervisionAcHandler, acmParticipantProvider); var automationCompositionCreate = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud"); automationCompositionCreate.setCompositionId(compositionId); @@ -134,6 +137,7 @@ class AutomationCompositionInstantiationProviderTest { when(acProvider.deleteAutomationComposition(automationCompositionUpdate.getInstanceId())) .thenReturn(automationCompositionUpdate); + doNothing().when(acmParticipantProvider).verifyParticipantState(any()); instantiationProvider.deleteAutomationComposition(automationCompositionCreate.getCompositionId(), automationCompositionCreate.getInstanceId()); @@ -148,9 +152,10 @@ class AutomationCompositionInstantiationProviderTest { var acProvider = mock(AutomationCompositionProvider.class); var acDefinitionProvider = mock(AcDefinitionProvider.class); var supervisionAcHandler = mock(SupervisionAcHandler.class); + var acmParticipantProvider = mock(AcmParticipantProvider.class); var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, - acDefinitionProvider, null, supervisionAcHandler); + acDefinitionProvider, null, supervisionAcHandler, acmParticipantProvider); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); @@ -181,7 +186,7 @@ class AutomationCompositionInstantiationProviderTest { var acDefinitionProvider = mock(AcDefinitionProvider.class); var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, - acDefinitionProvider, null, null); + acDefinitionProvider, null, null, null); when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); @@ -207,9 +212,10 @@ class AutomationCompositionInstantiationProviderTest { var acProvider = mock(AutomationCompositionProvider.class); when(acProvider.createAutomationComposition(automationCompositionCreate)) .thenReturn(automationCompositionCreate); + var acmParticipantProvider = mock(AcmParticipantProvider.class); var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, - acDefinitionProvider, null, null); + acDefinitionProvider, null, null, acmParticipantProvider); var instantiationResponse = instantiationProvider.createAutomationComposition( automationCompositionCreate.getCompositionId(), automationCompositionCreate); @@ -226,6 +232,7 @@ class AutomationCompositionInstantiationProviderTest { @Test void testCreateAutomationCompositions_CommissionedAcElementNotFound() { var acDefinitionProvider = mock(AcDefinitionProvider.class); + var acmParticipantProvider = mock(AcmParticipantProvider.class); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var compositionId = acDefinition.getCompositionId(); when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition)); @@ -235,7 +242,7 @@ class AutomationCompositionInstantiationProviderTest { var acProvider = mock(AutomationCompositionProvider.class); var provider = new AutomationCompositionInstantiationProvider(acProvider, - acDefinitionProvider, null, null); + acDefinitionProvider, null, null, acmParticipantProvider); assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition)) .hasMessageMatching(AC_ELEMENT_NAME_NOT_FOUND); @@ -256,7 +263,7 @@ class AutomationCompositionInstantiationProviderTest { when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); var provider = new AutomationCompositionInstantiationProvider(acProvider, - mock(AcDefinitionProvider.class), null, null); + mock(AcDefinitionProvider.class), null, null, null); var compositionId = automationComposition.getCompositionId(); assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition)) @@ -275,7 +282,7 @@ class AutomationCompositionInstantiationProviderTest { when(acProvider.getAutomationComposition(automationComposition.getInstanceId())) .thenReturn(automationComposition); var provider = new AutomationCompositionInstantiationProvider(acProvider, - mock(AcDefinitionProvider.class), null, null); + mock(AcDefinitionProvider.class), null, null, null); var compositionId = automationComposition.getCompositionId(); var wrongCompositionId = UUID.randomUUID(); @@ -301,7 +308,7 @@ class AutomationCompositionInstantiationProviderTest { when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition)); var acProvider = mock(AutomationCompositionProvider.class); var provider = - new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null, null); + new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null, null, null); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud"); @@ -329,8 +336,9 @@ class AutomationCompositionInstantiationProviderTest { .thenReturn(automationComposition); var supervisionAcHandler = mock(SupervisionAcHandler.class); + var acmParticipantProvider = mock(AcmParticipantProvider.class); var provider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, - new AcInstanceStateResolver(), supervisionAcHandler); + new AcInstanceStateResolver(), supervisionAcHandler, acmParticipantProvider); var acInstanceStateUpdate = new AcInstanceStateUpdate(); acInstanceStateUpdate.setDeployOrder(DeployOrder.DEPLOY); 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 8948f5f53..d57d0f3b7 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 @@ -47,6 +47,7 @@ import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceSt import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; +import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -77,6 +78,9 @@ class InstantiationControllerTest extends CommonRestController { private AcDefinitionProvider acDefinitionProvider; @Autowired + private ParticipantProvider participantProvider; + + @Autowired private AutomationCompositionInstantiationProvider instantiationProvider; @LocalServerPort @@ -335,6 +339,11 @@ class InstantiationControllerTest extends CommonRestController { serviceTemplateCreate.setName(name); var acmDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); acDefinitionProvider.updateAcDefinition(acmDefinition); + saveDummyParticipantInDb(); return acmDefinition.getCompositionId(); } + + private void saveDummyParticipantInDb() { + participantProvider.saveParticipant(CommonTestData.createParticipant(CommonTestData.getParticipantId())); + } } 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 4ff759c13..8de5ccabe 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 @@ -35,6 +35,7 @@ import java.util.Map; 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.participants.AcmParticipantProvider; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionParticipantHandler; @@ -144,7 +145,8 @@ class SupervisionMessagesTest { @Test void testParticipantPrimePublisherDecommissioning() { - var publisher = new ParticipantPrimePublisher(mock(ParticipantProvider.class)); + var publisher = new ParticipantPrimePublisher(mock(ParticipantProvider.class), + mock(AcmParticipantProvider.class)); var topicSink = mock(TopicSink.class); publisher.active(List.of(topicSink)); publisher.sendDepriming(UUID.randomUUID()); @@ -165,7 +167,7 @@ class SupervisionMessagesTest { participantId); var participantProvider = mock(ParticipantProvider.class); when(participantProvider.getSupportedElementMap()).thenReturn(supportedElementMap); - var publisher = new ParticipantPrimePublisher(participantProvider); + var publisher = new ParticipantPrimePublisher(participantProvider, mock(AcmParticipantProvider.class)); var topicSink = mock(TopicSink.class); publisher.active(List.of(topicSink)); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java index 69c1302bc..5c82713b0 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java @@ -28,6 +28,7 @@ import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeEx 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.Participant; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; @@ -92,6 +93,7 @@ public class CommonTestData { public static Participant createParticipant(UUID participantId) { var participant = new Participant(); participant.setParticipantId(participantId); + participant.setParticipantState(ParticipantState.ON_LINE); return participant; } |