diff options
author | Liam Fallon <liam.fallon@est.tech> | 2023-02-14 10:24:57 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2023-02-14 10:24:57 +0000 |
commit | 06339bee0cf891144ca781983ba99d170b10b2b7 (patch) | |
tree | f704bdd75e1106153a8a5af129aaed7be043c46f /participant/participant-intermediary/src/test | |
parent | c4747fc9ff4199748784e83970712fa90690c474 (diff) | |
parent | e45da39db2625accf9ba3a77dc936a87d560fb5e (diff) |
Merge "Deployment and undeployment on Participant Intermediary"
Diffstat (limited to 'participant/participant-intermediary/src/test')
3 files changed, 70 insertions, 70 deletions
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 9b0f910ea..d86c9d0a4 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,9 +27,8 @@ 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.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +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 { @@ -47,11 +46,10 @@ class ParticipantIntermediaryApiImplTest { var acElementListener = Mockito.mock(AutomationCompositionElementListener.class); apiImpl.registerAutomationCompositionElementListener(acElementListener); - var acElement = apiImpl.updateAutomationCompositionElementState(UUID.randomUUID(), uuid, - AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE, - ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); - assertEquals(AutomationCompositionOrderedState.UNINITIALISED, acElement.getOrderedState()); + apiImpl.updateAutomationCompositionElementState(UUID.randomUUID(), uuid, DeployState.UNDEPLOYED, + LockState.NONE); + var acElement = automationComposiitonHandler.getElementsOnThisParticipant().get(uuid); + assertEquals(DeployState.UNDEPLOYED, acElement.getDeployState()); assertEquals(uuid, acElement.getId()); - } } 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 ae8a8b2a0..35da039a5 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,6 @@ 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.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import java.util.List; @@ -33,14 +32,15 @@ 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.main.parameters.CommonTestData; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +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.ParticipantDeploy; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeploy; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +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.tosca.authorative.concepts.ToscaNodeTemplate; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -55,15 +55,7 @@ class AutomationCompositionHandlerTest { assertNotNull(ach.getAutomationCompositionMap()); assertNotNull(ach.getElementsOnThisParticipant()); - var elementId1 = UUID.randomUUID(); - var element = new AutomationCompositionElement(); - element.setId(elementId1); - element.setDefinition( - new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "1.0.1")); - - element.setOrderedState(AutomationCompositionOrderedState.PASSIVE); - - AutomationCompositionElementListener listener = mock(AutomationCompositionElementListener.class); + var listener = mock(AutomationCompositionElementListener.class); ach.registerAutomationCompositionElementListener(listener); assertThat(ach.getListeners()).contains(listener); } @@ -73,11 +65,11 @@ class AutomationCompositionHandlerTest { var id = UUID.randomUUID(); var ach = commonTestData.getMockAutomationCompositionHandler(); - assertNull(ach.updateAutomationCompositionElementState(null, null, - AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE)); + assertDoesNotThrow( + () -> ach.updateAutomationCompositionElementState(null, null, DeployState.UNDEPLOYED, LockState.NONE)); - assertNull(ach.updateAutomationCompositionElementState(null, id, - AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE)); + assertDoesNotThrow( + () -> ach.updateAutomationCompositionElementState(null, id, DeployState.UNDEPLOYED, LockState.NONE)); } @Test @@ -89,29 +81,29 @@ class AutomationCompositionHandlerTest { var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); var key = ach.getElementsOnThisParticipant().keySet().iterator().next(); var value = ach.getElementsOnThisParticipant().get(key); - assertEquals(AutomationCompositionState.UNINITIALISED, value.getState()); - ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid, - AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE); - assertEquals(AutomationCompositionState.PASSIVE, value.getState()); + assertEquals(DeployState.UNDEPLOYED, value.getDeployState()); + assertEquals(LockState.LOCKED, value.getLockState()); + ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid, DeployState.DEPLOYED, + LockState.UNLOCKED); + assertEquals(DeployState.DEPLOYED, value.getDeployState()); ach.getAutomationCompositionMap().values().iterator().next().getElements().putIfAbsent(key, value); - ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, - AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.RUNNING); - assertEquals(AutomationCompositionState.RUNNING, value.getState()); + ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, DeployState.DEPLOYED, + LockState.UNLOCKED); + assertEquals(DeployState.DEPLOYED, value.getDeployState()); ach.getElementsOnThisParticipant().remove(key, value); ach.getAutomationCompositionMap().values().iterator().next().getElements().clear(); - assertNull(ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, - AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.RUNNING)); - + assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, + DeployState.DEPLOYED, LockState.UNLOCKED)); } @Test - void handleAutomationCompositionUpdateExceptionTest() { + void handleAutomationCompositionStateChangeTest() { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); - var stateChange = commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.RUNNING); + var stateChange = commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); assertDoesNotThrow(() -> ach .handleAutomationCompositionStateChange(mock(AutomationCompositionStateChange.class), List.of())); @@ -121,20 +113,30 @@ class AutomationCompositionHandlerTest { stateChange.setAutomationCompositionId(UUID.randomUUID()); stateChange.setParticipantId(newPartecipantId); assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChange, List.of())); + } + @Test + void handleAutomationCompositionDeployTest() { var acd = new AutomationCompositionElementDefinition(); + var definition = CommonTestData.getDefinition(); acd.setAcElementDefinitionId(definition); var updateMsg = new AutomationCompositionDeploy(); updateMsg.setAutomationCompositionId(UUID.randomUUID()); + var uuid = UUID.randomUUID(); updateMsg.setMessageId(uuid); + var partecipantId = CommonTestData.getParticipantId(); updateMsg.setParticipantId(partecipantId); + updateMsg.setFirstStartPhase(true); updateMsg.setStartPhase(0); var acElementDefinitions = List.of(acd); + var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); + updateMsg.setFirstStartPhase(false); updateMsg.setStartPhase(1); assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); ach.getAutomationCompositionMap().clear(); + updateMsg.setFirstStartPhase(true); updateMsg.setStartPhase(0); assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); @@ -145,9 +147,9 @@ class AutomationCompositionHandlerTest { updateMsg.setStartPhase(1); var participantDeploy = new ParticipantDeploy(); participantDeploy.setParticipantId(partecipantId); - var element = new AutomationCompositionElement(); + var element = new AcElementDeploy(); element.setDefinition(definition); - participantDeploy.setAutomationCompositionElementList(List.of(element)); + participantDeploy.setAcElementList(List.of(element)); updateMsg.setParticipantUpdatesList(List.of(participantDeploy)); var acd2 = new AutomationCompositionElementDefinition(); @@ -158,34 +160,38 @@ class AutomationCompositionHandlerTest { } @Test - void automationCompositionStateChangeUninitialisedTest() { + void acUndeployTest() { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); - var stateChangeUninitialised = - commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.UNINITIALISED); + var stateChangeUndeploy = + commonTestData.getStateChange(partecipantId, uuid, DeployOrder.UNDEPLOY, LockOrder.NONE); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); - ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of()); - stateChangeUninitialised.setAutomationCompositionId(UUID.randomUUID()); - stateChangeUninitialised.setParticipantId(CommonTestData.getRndParticipantId()); - assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of())); + stateChangeUndeploy + .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey()); + ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of()); + stateChangeUndeploy.setAutomationCompositionId(UUID.randomUUID()); + stateChangeUndeploy.setParticipantId(CommonTestData.getRndParticipantId()); + assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of())); } @Test - void automationCompositionStateChangePassiveTest() { + void automationCompositionStateUnlock() { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); - var stateChangePassive = - commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.PASSIVE); + var stateChangeUnlock = + commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); - ach.handleAutomationCompositionStateChange(stateChangePassive, List.of()); - stateChangePassive.setAutomationCompositionId(UUID.randomUUID()); - stateChangePassive.setParticipantId(CommonTestData.getRndParticipantId()); - assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangePassive, List.of())); + stateChangeUnlock + .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey()); + ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of()); + stateChangeUnlock.setAutomationCompositionId(UUID.randomUUID()); + stateChangeUnlock.setParticipantId(CommonTestData.getRndParticipantId()); + assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of())); } } 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 9641edc2e..4dcfd1428 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 @@ -37,11 +37,12 @@ import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHan import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantIntermediaryParameters; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; +import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck; +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.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.parameters.TopicParameters; import org.onap.policy.common.utils.coder.Coder; @@ -272,7 +273,7 @@ public class CommonTestData { acElement.setId(uuid); acElement.setParticipantId(participantId); acElement.setDefinition(definition); - acElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + acElement.setDeployState(DeployState.UNDEPLOYED); Map<UUID, AutomationCompositionElement> elementsOnThisParticipant = new LinkedHashMap<>(); elementsOnThisParticipant.put(uuid, acElement); @@ -289,14 +290,8 @@ public class CommonTestData { public AutomationCompositionHandler setTestAutomationCompositionHandler(ToscaConceptIdentifier definition, UUID uuid, UUID participantId) { var ach = getMockAutomationCompositionHandler(); - - var key = getTestAutomationCompositionMap().keySet().iterator().next(); - var value = getTestAutomationCompositionMap().get(key); - ach.getAutomationCompositionMap().put(key, value); - - var keyElem = setAutomationCompositionElementTest(uuid, definition, participantId).keySet().iterator().next(); - var valueElem = setAutomationCompositionElementTest(uuid, definition, participantId).get(keyElem); - ach.getElementsOnThisParticipant().put(keyElem, valueElem); + ach.getAutomationCompositionMap().putAll(getTestAutomationCompositionMap()); + ach.getElementsOnThisParticipant().putAll(setAutomationCompositionElementTest(uuid, definition, participantId)); return ach; } @@ -306,17 +301,18 @@ public class CommonTestData { * * @param participantId the participantId * @param uuid UUID - * @param state a AutomationCompositionOrderedState + * @param deployOrder a DeployOrder + * @param lockOrder a LockOrder * @return a AutomationCompositionStateChange */ public AutomationCompositionStateChange getStateChange(UUID participantId, UUID uuid, - AutomationCompositionOrderedState state) { + DeployOrder deployOrder, LockOrder lockOrder) { var stateChange = new AutomationCompositionStateChange(); stateChange.setAutomationCompositionId(UUID.randomUUID()); stateChange.setParticipantId(participantId); stateChange.setMessageId(uuid); - stateChange.setOrderedState(state); - stateChange.setCurrentState(AutomationCompositionState.UNINITIALISED); + stateChange.setDeployOrderedState(deployOrder); + stateChange.setLockOrderedState(lockOrder); stateChange.setTimestamp(Instant.ofEpochMilli(3000)); return stateChange; } |