diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-05-10 17:11:04 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-05-16 08:19:07 +0100 |
commit | 722523f568a682f1e48f6998c24c945802fec782 (patch) | |
tree | ffe6e47aa4c339023772a15d816af8b509b8142e /participant/participant-intermediary/src/test/java | |
parent | b4b9a1f3c81a1c64271e38d879a84f6b134d3a54 (diff) |
Add participant capability to send message with status and properties
Add participant capability to send message with status and properties
to ACM-R when those values need to be change.
Issue-ID: POLICY-4679
Change-Id: Idca5796c199b235e1f829097316c50688a351e80
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-intermediary/src/test/java')
5 files changed, 74 insertions, 60 deletions
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerTest.java index 6255b886c..93809ab96 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AutomationCompositionElementListenerTest.java @@ -20,7 +20,6 @@ package org.onap.policy.clamp.acm.participant.intermediary.api.impl; -import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import java.util.UUID; @@ -33,9 +32,6 @@ class AutomationCompositionElementListenerTest { @Test void defaultTest() throws PfModelException { var listener = new DummyAcElementListener(); - assertThat(listener.getStatusProperties(UUID.randomUUID(), UUID.randomUUID())).isNotNull().isEmpty(); - assertThat(listener.getOperationalState(UUID.randomUUID(), UUID.randomUUID())).isNotNull().isEmpty(); - assertThat(listener.getUseState(UUID.randomUUID(), UUID.randomUUID())).isNotNull().isEmpty(); assertThatCode(() -> listener.lock(UUID.randomUUID(), UUID.randomUUID())).doesNotThrowAnyException(); assertThatCode(() -> listener.unlock(UUID.randomUUID(), UUID.randomUUID())).doesNotThrowAnyException(); } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java index d86c9d0a4..aa39f5a3f 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java @@ -20,36 +20,42 @@ package org.onap.policy.clamp.acm.participant.intermediary.api.impl; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; -import org.mockito.Mockito; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; -import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData; +import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.common.utils.coder.CoderException; class ParticipantIntermediaryApiImplTest { - private final CommonTestData commonTestData = new CommonTestData(); + private static final String USE_STATE = "useState"; + private static final String OPERATIONAL_STATE = "operationState"; + private static final Map<String, Object> MAP = Map.of("key", 1); @Test void mockParticipantIntermediaryApiImplTest() throws CoderException { - var uuid = UUID.randomUUID(); - var definition = CommonTestData.getDefinition(); - var participantId = CommonTestData.getParticipantId(); - var automationComposiitonHandler = - commonTestData.setTestAutomationCompositionHandler(definition, uuid, participantId); + var automationComposiitonHandler = mock(AutomationCompositionHandler.class); var apiImpl = new ParticipantIntermediaryApiImpl(automationComposiitonHandler); - var acElementListener = Mockito.mock(AutomationCompositionElementListener.class); + + var acElementListener = mock(AutomationCompositionElementListener.class); apiImpl.registerAutomationCompositionElementListener(acElementListener); + verify(automationComposiitonHandler).registerAutomationCompositionElementListener(acElementListener); + + var uuid = UUID.randomUUID(); + var automationCompositionId = UUID.randomUUID(); + apiImpl.updateAutomationCompositionElementState(automationCompositionId, uuid, DeployState.UNDEPLOYED, + LockState.NONE, null); + verify(automationComposiitonHandler).updateAutomationCompositionElementState(automationCompositionId, uuid, + DeployState.UNDEPLOYED, LockState.NONE, null); - apiImpl.updateAutomationCompositionElementState(UUID.randomUUID(), uuid, DeployState.UNDEPLOYED, - LockState.NONE); - var acElement = automationComposiitonHandler.getElementsOnThisParticipant().get(uuid); - assertEquals(DeployState.UNDEPLOYED, acElement.getDeployState()); - assertEquals(uuid, acElement.getId()); + apiImpl.sendAcElementInfo(automationCompositionId, uuid, USE_STATE, OPERATIONAL_STATE, MAP); + verify(automationComposiitonHandler).sendAcElementInfo(automationCompositionId, uuid, USE_STATE, + OPERATIONAL_STATE, MAP); } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java index 25b1facf5..d782ae167 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java @@ -29,13 +29,14 @@ import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import java.util.List; +import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; +import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; @@ -61,11 +62,6 @@ class AutomationCompositionHandlerTest { void automationCompositionHandlerTest() { var ach = commonTestData.getMockAutomationCompositionHandler(); assertNotNull(ach.getAutomationCompositionMap()); - assertNotNull(ach.getElementsOnThisParticipant()); - - var listener = mock(AutomationCompositionElementListener.class); - ach.registerAutomationCompositionElementListener(listener); - assertThat(ach.getListeners()).contains(listener); } @Test @@ -73,11 +69,11 @@ class AutomationCompositionHandlerTest { var id = UUID.randomUUID(); var ach = commonTestData.getMockAutomationCompositionHandler(); - assertDoesNotThrow( - () -> ach.updateAutomationCompositionElementState(null, null, DeployState.UNDEPLOYED, LockState.NONE)); + assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(null, null, DeployState.UNDEPLOYED, null, + "Undeployed")); assertDoesNotThrow( - () -> ach.updateAutomationCompositionElementState(null, id, DeployState.UNDEPLOYED, LockState.NONE)); + () -> ach.updateAutomationCompositionElementState(null, id, DeployState.UNDEPLOYED, null, null)); } @Test @@ -87,23 +83,23 @@ class AutomationCompositionHandlerTest { var definition = CommonTestData.getDefinition(); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); - var key = ach.getElementsOnThisParticipant().keySet().iterator().next(); - var value = ach.getElementsOnThisParticipant().get(key); - assertEquals(DeployState.UNDEPLOYED, value.getDeployState()); - assertEquals(LockState.LOCKED, value.getLockState()); - ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid, DeployState.DEPLOYED, - LockState.UNLOCKED); + var acKey = ach.getAutomationCompositionMap().keySet().iterator().next(); + var key = ach.getAutomationCompositionMap().get(acKey).getElements().keySet().iterator().next(); + var value = ach.getAutomationCompositionMap().get(acKey).getElements().get(key); + value.setDeployState(DeployState.DEPLOYING); + value.setLockState(LockState.NONE); + ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid, DeployState.DEPLOYED, null, + "Deployed"); assertEquals(DeployState.DEPLOYED, value.getDeployState()); ach.getAutomationCompositionMap().values().iterator().next().getElements().putIfAbsent(key, value); - ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, DeployState.DEPLOYED, - LockState.UNLOCKED); + ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, DeployState.DEPLOYED, null, + "Deployed"); assertEquals(DeployState.DEPLOYED, value.getDeployState()); - ach.getElementsOnThisParticipant().remove(key, value); ach.getAutomationCompositionMap().values().iterator().next().getElements().clear(); - assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, - DeployState.DEPLOYED, LockState.UNLOCKED)); + assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, null, + LockState.UNLOCKED, null)); } @Test @@ -246,27 +242,39 @@ class AutomationCompositionHandlerTest { verify(listener, times(1)).unlock(any(), any()); } + @Test - void testGetUseState() throws PfModelException { + void testgetAutomationCompositionInfoList() { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); - var listener = mock(AutomationCompositionElementListener.class); - when(listener.getUseState(uuid, uuid)).thenReturn(STATE_VALUE); - ach.registerAutomationCompositionElementListener(listener); - assertEquals(STATE_VALUE, ach.getUseState(uuid, uuid)); + var result = ach.getAutomationCompositionInfoList(); + assertThat(result).hasSize(1); + assertThat(result.get(0).getElements()).hasSize(1); + } + + @Test + void testsendAcElementInfo() { + var participantMessagePublisher = mock(ParticipantMessagePublisher.class); + var ach = new AutomationCompositionHandler(CommonTestData.getParticipantParameters(), + participantMessagePublisher); + ach.getAutomationCompositionMap().putAll(commonTestData.getTestAutomationCompositionMap()); + var key = ach.getAutomationCompositionMap().keySet().iterator().next(); + var keyElement = ach.getAutomationCompositionMap().get(key).getElements().keySet().iterator().next(); + ach.sendAcElementInfo(key, keyElement, "useState", "operationalState", Map.of("key", 1)); + verify(participantMessagePublisher).sendParticipantStatus(any()); } @Test - void testGetOperationalState() throws PfModelException { + void testUndeployInstances() throws PfModelException { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); var listener = mock(AutomationCompositionElementListener.class); - when(listener.getOperationalState(uuid, uuid)).thenReturn(STATE_VALUE); ach.registerAutomationCompositionElementListener(listener); - assertEquals(STATE_VALUE, ach.getOperationalState(uuid, uuid)); + ach.undeployInstances(); + verify(listener).undeploy(any(), any()); } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java index 3fed5bb56..30860308e 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java @@ -26,6 +26,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -66,7 +67,6 @@ class ParticipantHandlerTest { var participantHandler = commonTestData.getMockParticipantHandler(); var participantId = CommonTestData.getParticipantId(); - participantPrimeMsg.setAutomationCompositionId(CommonTestData.AC_ID_1); participantPrimeMsg.setCompositionId(CommonTestData.AC_ID_1); participantPrimeMsg.setParticipantId(participantId); participantPrimeMsg.setMessageId(UUID.randomUUID()); @@ -115,13 +115,12 @@ class ParticipantHandlerTest { @Test void getAutomationCompositionInfoListTest() throws CoderException { - var participantHandler = commonTestData.getParticipantHandlerAutomationCompositions(); + var automationCompositionHandler = mock(AutomationCompositionHandler.class); + var participantHandler = + commonTestData.getParticipantHandlerAutomationCompositions(automationCompositionHandler); + clearInvocations(automationCompositionHandler); participantHandler.sendHeartbeat(); - assertEquals(CommonTestData.AC_ID_1, participantHandler.makeHeartbeat(false) - .getAutomationCompositionInfoList() - .get(0) - .getAutomationCompositionId()); - + verify(automationCompositionHandler).getAutomationCompositionInfoList(); } @Test @@ -140,9 +139,7 @@ class ParticipantHandlerTest { var commonTestData = new CommonTestData(); var automationCompositionMap = commonTestData.getTestAutomationCompositionMap(); var automationCompositionHandler = mock(AutomationCompositionHandler.class); - var listener = mock(DummyAcElementListener.class); - when(automationCompositionHandler.getListeners()).thenReturn(List.of(listener)); automationCompositionMap.values().iterator().next().getElements().values().iterator().next() .setParticipantId(CommonTestData.getParticipantId()); when(automationCompositionHandler.getAutomationCompositionMap()).thenReturn(automationCompositionMap); @@ -153,6 +150,6 @@ class ParticipantHandlerTest { participantHandler.sendParticipantDeregister(); verify(publisher).sendParticipantDeregister(any(ParticipantDeregister.class)); - verify(listener).undeploy(any(), any()); + verify(automationCompositionHandler).undeployInstances(); } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java index 140fd947a..e627da611 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java @@ -201,6 +201,11 @@ public class CommonTestData { return new ParticipantHandler(parameters, publisher, automationCompositionHandler); } + public ParticipantHandler getParticipantHandlerAutomationCompositions() { + var automationCompositionHandler = Mockito.mock(AutomationCompositionHandler.class); + return getParticipantHandlerAutomationCompositions(automationCompositionHandler); + } + /** * Returns a mocked ParticipantHandler for test cases. * @@ -208,8 +213,8 @@ public class CommonTestData { * * @throws CoderException if there is an error with .json file. */ - public ParticipantHandler getParticipantHandlerAutomationCompositions() throws CoderException { - var automationCompositionHandler = Mockito.mock(AutomationCompositionHandler.class); + public ParticipantHandler getParticipantHandlerAutomationCompositions( + AutomationCompositionHandler automationCompositionHandler) { Mockito.doReturn(getTestAutomationCompositionMap()).when(automationCompositionHandler) .getAutomationCompositionMap(); var publisher = new ParticipantMessagePublisher(); @@ -291,7 +296,9 @@ public class CommonTestData { UUID uuid, UUID participantId) { var ach = getMockAutomationCompositionHandler(); ach.getAutomationCompositionMap().putAll(getTestAutomationCompositionMap()); - ach.getElementsOnThisParticipant().putAll(setAutomationCompositionElementTest(uuid, definition, participantId)); + var acKey = ach.getAutomationCompositionMap().keySet().iterator().next(); + ach.getAutomationCompositionMap().get(acKey) + .setElements(setAutomationCompositionElementTest(uuid, definition, participantId)); return ach; } |