diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-06-21 11:41:02 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-06-23 10:55:42 +0100 |
commit | 8c178b15ff4c514ba07edd5aea039945b290e1c6 (patch) | |
tree | dff88bcd37981c3d2140241ac525edb858835a4a /runtime-acm/src/test/java/org/onap | |
parent | 4d6cd92e9e18f1702e2092ba881db0d3d9ffc37e (diff) |
Add Timeuot support in prime/deprime
Issue-ID: POLICY-4734
Change-Id: I581610bb1a025e76a5af77e1deb2cd7b97ce7101
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm/src/test/java/org/onap')
2 files changed, 63 insertions, 16 deletions
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 99af72801..9b596c89a 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 @@ -33,17 +33,18 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.UUID; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher; 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.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; +import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -52,18 +53,52 @@ class SupervisionScannerTest { private static final String AC_JSON = "src/test/resources/rest/acm/AutomationCompositionSmoke.json"; - private static final AcDefinitionProvider acDefinitionProvider = mock(AcDefinitionProvider.class); + private static final UUID compositionId = UUID.randomUUID(); - private static UUID compositionId; - - @BeforeAll - public static void setUpBeforeAll() { + private AcDefinitionProvider createAcDefinitionProvider(AcTypeState acTypeState, + StateChangeResult stateChangeResult) { var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = new AutomationCompositionDefinition(); - compositionId = UUID.randomUUID(); + acDefinition.setState(acTypeState); + acDefinition.setStateChangeResult(stateChangeResult); acDefinition.setCompositionId(compositionId); acDefinition.setServiceTemplate(serviceTemplate); + var acDefinitionProvider = mock(AcDefinitionProvider.class); when(acDefinitionProvider.getAllAcDefinitions()).thenReturn(List.of(Objects.requireNonNull(acDefinition))); + return acDefinitionProvider; + } + + private AcDefinitionProvider createAcDefinitionProvider() { + return createAcDefinitionProvider(AcTypeState.PRIMED, StateChangeResult.NO_ERROR); + } + + @Test + void testScannerOrderedFailed() { + var acDefinitionProvider = createAcDefinitionProvider(AcTypeState.PRIMING, StateChangeResult.FAILED); + var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); + var supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider, + mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class), + acRuntimeParameterGroup); + supervisionScanner.run(); + verify(acDefinitionProvider, times(0)).updateAcDefinition(any(AutomationCompositionDefinition.class)); + } + + @Test + void testScannerOrderedPriming() { + var acDefinitionProvider = createAcDefinitionProvider(AcTypeState.PRIMING, StateChangeResult.NO_ERROR); + var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); + var supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider, + mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class), + acRuntimeParameterGroup); + supervisionScanner.run(); + verify(acDefinitionProvider, times(0)).updateAcDefinition(any(AutomationCompositionDefinition.class)); + + acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1); + supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider, + mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class), + acRuntimeParameterGroup); + supervisionScanner.run(); + verify(acDefinitionProvider).updateAcDefinition(any(AutomationCompositionDefinition.class)); } @Test @@ -77,7 +112,7 @@ class SupervisionScannerTest { when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) .thenReturn(List.of(automationComposition)); - var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, + var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(), automationCompositionStateChangePublisher, automationCompositionDeployPublisher, acRuntimeParameterGroup); supervisionScanner.run(); @@ -98,7 +133,7 @@ class SupervisionScannerTest { var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); - var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, + var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(), automationCompositionStateChangePublisher, automationCompositionDeployPublisher, acRuntimeParameterGroup); supervisionScanner.run(); @@ -106,7 +141,6 @@ class SupervisionScannerTest { verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class)); } - @Test void testScannerDelete() { var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_JSON, "Crud"); @@ -120,7 +154,7 @@ class SupervisionScannerTest { var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); - var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, + var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(), automationCompositionStateChangePublisher, automationCompositionDeployPublisher, acRuntimeParameterGroup); supervisionScanner.run(); @@ -139,7 +173,7 @@ class SupervisionScannerTest { var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); - var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, + var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(), automationCompositionStateChangePublisher, automationCompositionDeployPublisher, acRuntimeParameterGroup); @@ -164,8 +198,8 @@ class SupervisionScannerTest { var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1); - //verify timeout scenario - var scannerObj2 = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, + // verify timeout scenario + var scannerObj2 = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(), automationCompositionStateChangePublisher, automationCompositionDeployPublisher, acRuntimeParameterGroup); @@ -198,7 +232,7 @@ class SupervisionScannerTest { var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); - var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, + var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(), automationCompositionStateChangePublisher, automationCompositionDeployPublisher, acRuntimeParameterGroup); @@ -232,7 +266,7 @@ class SupervisionScannerTest { var automationCompositionStateChangePublisher = mock(AutomationCompositionStateChangePublisher.class); var acRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); - var supervisionScanner = new SupervisionScanner(automationCompositionProvider, acDefinitionProvider, + var supervisionScanner = new SupervisionScanner(automationCompositionProvider, createAcDefinitionProvider(), automationCompositionStateChangePublisher, automationCompositionDeployPublisher, acRuntimeParameterGroup); 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 e0accc4a0..4ff759c13 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 @@ -60,6 +60,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; class SupervisionMessagesTest { + private static final String AC_INSTANTIATION_UPDATE_JSON = + "src/test/resources/rest/acm/AutomationCompositionUpdate.json"; private static final String NOT_ACTIVE = "Not Active!"; private static final CommInfrastructure INFRA = CommInfrastructure.NOOP; private static final String TOPIC = "my-topic"; @@ -207,6 +209,17 @@ class SupervisionMessagesTest { } @Test + void testAcElementPropertiesPublisher() { + var publisher = new AcElementPropertiesPublisher(); + var topicSink = mock(TopicSink.class); + publisher.active(List.of(topicSink)); + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); + publisher.send(automationComposition); + verify(topicSink).send(anyString()); + } + + @Test void testParticipantRegisterListener() { final var participantRegister = new ParticipantRegister(); var supervisionHandler = mock(SupervisionParticipantHandler.class); |