aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-intermediary/src/test
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-02-10 15:28:50 +0000
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-02-13 16:28:28 +0000
commite45da39db2625accf9ba3a77dc936a87d560fb5e (patch)
tree626de1ca14703df7dd1a81526966481cd57cc456 /participant/participant-intermediary/src/test
parent1191f992ddf1f6bcc94e7fa246ee3efbc71a3a8f (diff)
Deployment and undeployment on Participant Intermediary
Handle AC Element Instance Deployment and undeployment on Participant Intermediary. Issue-ID: POLICY-4507 Change-Id: I6a6976a8893450467ee609a1a476dbfa473a0e82 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-intermediary/src/test')
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java16
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java98
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java26
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;
}