diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-04-05 16:32:38 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-04-11 10:06:21 +0100 |
commit | 9f1fdf9f419c1724a9cf75a20fdd24df191766bd (patch) | |
tree | 16db3d01d45ae45a4fc776d9d23596ec2c6bcc58 /participant/participant-intermediary/src/test/java/org | |
parent | 2ca7552978f5389ef5ed2e5d4be3cb43e446f7c6 (diff) |
Add UseState and OperationalState support in ACM
Issue-ID: POLICY-4639
Change-Id: Iac5249c054bf41d830463826a8f61f477c48235b
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-intermediary/src/test/java/org')
2 files changed, 92 insertions, 16 deletions
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 35da039a5..25b1facf5 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 @@ -24,7 +24,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +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.UUID; @@ -41,6 +46,7 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCom import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; +import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -49,6 +55,8 @@ class AutomationCompositionHandlerTest { private final CommonTestData commonTestData = new CommonTestData(); + private static final String STATE_VALUE = "STATE_VALUE"; + @Test void automationCompositionHandlerTest() { var ach = commonTestData.getMockAutomationCompositionHandler(); @@ -116,10 +124,11 @@ class AutomationCompositionHandlerTest { } @Test - void handleAutomationCompositionDeployTest() { + void handleAutomationCompositionDeployTest() throws PfModelException { var acd = new AutomationCompositionElementDefinition(); var definition = CommonTestData.getDefinition(); acd.setAcElementDefinitionId(definition); + acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class)); var updateMsg = new AutomationCompositionDeploy(); updateMsg.setAutomationCompositionId(UUID.randomUUID()); var uuid = UUID.randomUUID(); @@ -130,19 +139,25 @@ class AutomationCompositionHandlerTest { updateMsg.setStartPhase(0); var acElementDefinitions = List.of(acd); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); - assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); + var listener = mock(AutomationCompositionElementListener.class); + ach.registerAutomationCompositionElementListener(listener); + ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions); + verify(listener, times(0)).deploy(any(), any(), anyMap()); updateMsg.setFirstStartPhase(false); updateMsg.setStartPhase(1); - assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); + ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions); + verify(listener, times(0)).deploy(any(), any(), anyMap()); ach.getAutomationCompositionMap().clear(); updateMsg.setFirstStartPhase(true); updateMsg.setStartPhase(0); - assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); + ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions); + verify(listener, times(0)).deploy(any(), any(), anyMap()); updateMsg.setAutomationCompositionId(UUID.randomUUID()); updateMsg.setParticipantUpdatesList(List.of(mock(ParticipantDeploy.class))); - assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); + ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions); + verify(listener, times(0)).deploy(any(), any(), anyMap()); updateMsg.setStartPhase(1); var participantDeploy = new ParticipantDeploy(); @@ -152,15 +167,13 @@ class AutomationCompositionHandlerTest { participantDeploy.setAcElementList(List.of(element)); updateMsg.setParticipantUpdatesList(List.of(participantDeploy)); - var acd2 = new AutomationCompositionElementDefinition(); - acd2.setAcElementDefinitionId(definition); - acd2.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class)); - assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, List.of(acd2))); - + updateMsg.setStartPhase(0); + ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions); + verify(listener, times(1)).deploy(any(), any(), anyMap()); } @Test - void acUndeployTest() { + void acUndeployTest() throws PfModelException { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); @@ -171,14 +184,46 @@ class AutomationCompositionHandlerTest { var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); stateChangeUndeploy .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey()); - ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of()); + var listener = mock(AutomationCompositionElementListener.class); + ach.registerAutomationCompositionElementListener(listener); + + var acd = new AutomationCompositionElementDefinition(); + acd.setAcElementDefinitionId(definition); + acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class)); + ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of(acd)); + verify(listener, times(1)).undeploy(any(), any()); + stateChangeUndeploy.setAutomationCompositionId(UUID.randomUUID()); stateChangeUndeploy.setParticipantId(CommonTestData.getRndParticipantId()); assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of())); } @Test - void automationCompositionStateUnlock() { + void automationCompositionStateLock() throws PfModelException { + var uuid = UUID.randomUUID(); + var partecipantId = CommonTestData.getParticipantId(); + var definition = CommonTestData.getDefinition(); + + var stateChangeLock = + commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.LOCK); + + var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); + var listener = mock(AutomationCompositionElementListener.class); + ach.registerAutomationCompositionElementListener(listener); + stateChangeLock + .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey()); + var acd = new AutomationCompositionElementDefinition(); + acd.setAcElementDefinitionId(definition); + acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class)); + ach.handleAutomationCompositionStateChange(stateChangeLock, List.of(acd)); + stateChangeLock.setAutomationCompositionId(UUID.randomUUID()); + stateChangeLock.setParticipantId(CommonTestData.getRndParticipantId()); + ach.handleAutomationCompositionStateChange(stateChangeLock, List.of()); + verify(listener, times(1)).lock(any(), any()); + } + + @Test + void automationCompositionStateUnlock() throws PfModelException { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); @@ -187,11 +232,41 @@ class AutomationCompositionHandlerTest { commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); + var listener = mock(AutomationCompositionElementListener.class); + ach.registerAutomationCompositionElementListener(listener); stateChangeUnlock .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey()); - ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of()); + var acd = new AutomationCompositionElementDefinition(); + acd.setAcElementDefinitionId(definition); + acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class)); + ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of(acd)); stateChangeUnlock.setAutomationCompositionId(UUID.randomUUID()); stateChangeUnlock.setParticipantId(CommonTestData.getRndParticipantId()); - assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of())); + ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of()); + verify(listener, times(1)).unlock(any(), any()); + } + + @Test + void testGetUseState() 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.getUseState(uuid, uuid)).thenReturn(STATE_VALUE); + ach.registerAutomationCompositionElementListener(listener); + assertEquals(STATE_VALUE, ach.getUseState(uuid, uuid)); + } + + @Test + void testGetOperationalState() 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)); } } 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 4dcfd1428..140fd947a 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 @@ -163,7 +163,7 @@ public class CommonTestData { } public static ToscaConceptIdentifier getDefinition() { - return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.1"); + return new ToscaConceptIdentifier("org.onap.domain.pmsh.PMSH_DCAEMicroservice", "1.2.3"); } /** @@ -308,6 +308,7 @@ public class CommonTestData { public AutomationCompositionStateChange getStateChange(UUID participantId, UUID uuid, DeployOrder deployOrder, LockOrder lockOrder) { var stateChange = new AutomationCompositionStateChange(); + stateChange.setStartPhase(0); stateChange.setAutomationCompositionId(UUID.randomUUID()); stateChange.setParticipantId(participantId); stateChange.setMessageId(uuid); |