summaryrefslogtreecommitdiffstats
path: root/participant/participant-intermediary/src/test/java
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-06-07 14:25:33 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-06-12 08:47:50 +0100
commit31090c9fbc6c29477acd784a6c9f03766b5cc981 (patch)
tree85b23dd0714707629ba11d190f2237b3ecf7061c /participant/participant-intermediary/src/test/java
parent5ccedbf315e6879005e1748baaccbfda9e81097e (diff)
Add failure handling support in Intermediary
Add Failure handling support in Intermediary, and refactor the communication between Participant and Intermediary. Issue-ID: POLICY-4707 Change-Id: Ica22e0e820efda372886d6d8da9c3526633321e2 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-intermediary/src/test/java')
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java18
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java319
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java213
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java122
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java9
5 files changed, 269 insertions, 412 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 8f70bc7d9..4213e978b 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
@@ -26,8 +26,7 @@ import static org.mockito.Mockito.verify;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
-import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler;
+import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionOutHandler;
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;
@@ -41,22 +40,23 @@ class ParticipantIntermediaryApiImplTest {
@Test
void mockParticipantIntermediaryApiImplTest() throws CoderException {
- var automationComposiitonHandler = mock(AutomationCompositionHandler.class);
- var apiImpl = new ParticipantIntermediaryApiImpl(automationComposiitonHandler);
-
- var acElementListener = mock(AutomationCompositionElementListener.class);
- apiImpl.registerAutomationCompositionElementListener(acElementListener);
- verify(automationComposiitonHandler).registerAutomationCompositionElementListener(acElementListener);
+ var automationComposiitonHandler = mock(AutomationCompositionOutHandler.class);
+ var apiImpl = new ParticipantIntermediaryApiImpl(automationComposiitonHandler, null);
var uuid = UUID.randomUUID();
var automationCompositionId = UUID.randomUUID();
apiImpl.updateAutomationCompositionElementState(automationCompositionId, uuid, DeployState.UNDEPLOYED,
LockState.NONE, StateChangeResult.NO_ERROR, null);
verify(automationComposiitonHandler).updateAutomationCompositionElementState(automationCompositionId, uuid,
- DeployState.UNDEPLOYED, LockState.NONE, null);
+ DeployState.UNDEPLOYED, LockState.NONE, StateChangeResult.NO_ERROR, null);
apiImpl.sendAcElementInfo(automationCompositionId, uuid, USE_STATE, OPERATIONAL_STATE, MAP);
verify(automationComposiitonHandler).sendAcElementInfo(automationCompositionId, uuid, USE_STATE,
OPERATIONAL_STATE, MAP);
+
+ apiImpl.updateAutomationCompositionElementState(automationCompositionId, uuid, DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "");
+ verify(automationComposiitonHandler).updateAutomationCompositionElementState(automationCompositionId, uuid,
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "");
}
}
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 d782ae167..7e0c3da7f 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
@@ -20,17 +20,13 @@
package org.onap.policy.clamp.acm.participant.intermediary.handler;
-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.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@@ -39,242 +35,165 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationComposit
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;
-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.AutomationCompositionDeployAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.PropertiesUpdate;
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;
@ExtendWith(SpringExtension.class)
class AutomationCompositionHandlerTest {
- private final CommonTestData commonTestData = new CommonTestData();
-
- private static final String STATE_VALUE = "STATE_VALUE";
-
- @Test
- void automationCompositionHandlerTest() {
- var ach = commonTestData.getMockAutomationCompositionHandler();
- assertNotNull(ach.getAutomationCompositionMap());
- }
-
@Test
- void updateNullAutomationCompositionHandlerTest() {
- var id = UUID.randomUUID();
-
- var ach = commonTestData.getMockAutomationCompositionHandler();
- assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(null, null, DeployState.UNDEPLOYED, null,
- "Undeployed"));
-
- assertDoesNotThrow(
- () -> ach.updateAutomationCompositionElementState(null, id, DeployState.UNDEPLOYED, null, null));
+ void handleAutomationCompositionStateChangeNullTest() {
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
+ var cacheProvider = mock(CacheProvider.class);
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher,
+ mock(AutomationCompositionElementListener.class));
+
+ var automationCompositionStateChange = new AutomationCompositionStateChange();
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(automationCompositionStateChange));
+
+ automationCompositionStateChange.setAutomationCompositionId(UUID.randomUUID());
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(automationCompositionStateChange));
+ verify(participantMessagePublisher).sendAutomationCompositionAck(any(AutomationCompositionDeployAck.class));
+
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ automationCompositionStateChange.setAutomationCompositionId(automationComposition.getInstanceId());
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ automationCompositionStateChange.setDeployOrderedState(DeployOrder.UPDATE);
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(automationCompositionStateChange));
}
@Test
- void updateAutomationCompositionHandlerTest() {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
-
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- 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());
+ void handleAutomationCompositionStateChangeUndeployTest() throws PfModelException {
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(),
+ automationComposition.getInstanceId(), DeployOrder.UNDEPLOY, LockOrder.NONE);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ when(cacheProvider.getCommonProperties(any(UUID.class), any(UUID.class))).thenReturn(Map.of());
- ach.getAutomationCompositionMap().values().iterator().next().getElements().putIfAbsent(key, value);
- ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, DeployState.DEPLOYED, null,
- "Deployed");
- assertEquals(DeployState.DEPLOYED, value.getDeployState());
-
- ach.getAutomationCompositionMap().values().iterator().next().getElements().clear();
- assertDoesNotThrow(() -> ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key, null,
- LockState.UNLOCKED, null));
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
+ var listener = mock(AutomationCompositionElementListener.class);
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
+ ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
+ verify(listener, times(automationComposition.getElements().size())).undeploy(any(), any());
}
@Test
- void handleAutomationCompositionStateChangeTest() {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
- 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()));
-
- ach.handleAutomationCompositionStateChange(stateChange, List.of());
- var newPartecipantId = CommonTestData.getRndParticipantId();
- stateChange.setAutomationCompositionId(UUID.randomUUID());
- stateChange.setParticipantId(newPartecipantId);
- assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChange, List.of()));
- }
+ void handleAutomationCompositionStateChangeLockTest() throws PfModelException {
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(),
+ automationComposition.getInstanceId(), DeployOrder.NONE, LockOrder.LOCK);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ when(cacheProvider.getCommonProperties(any(UUID.class), any(UUID.class))).thenReturn(Map.of());
- @Test
- 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();
- 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);
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
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);
- ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
- verify(listener, times(0)).deploy(any(), any(), anyMap());
-
- ach.getAutomationCompositionMap().clear();
- updateMsg.setFirstStartPhase(true);
- updateMsg.setStartPhase(0);
- ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
- verify(listener, times(0)).deploy(any(), any(), anyMap());
-
- updateMsg.setAutomationCompositionId(UUID.randomUUID());
- updateMsg.setParticipantUpdatesList(List.of(mock(ParticipantDeploy.class)));
- ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
- verify(listener, times(0)).deploy(any(), any(), anyMap());
-
- updateMsg.setStartPhase(1);
- var participantDeploy = new ParticipantDeploy();
- participantDeploy.setParticipantId(partecipantId);
- var element = new AcElementDeploy();
- element.setDefinition(definition);
- participantDeploy.setAcElementList(List.of(element));
- updateMsg.setParticipantUpdatesList(List.of(participantDeploy));
-
- updateMsg.setStartPhase(0);
- ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
- verify(listener, times(1)).deploy(any(), any(), anyMap());
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
+ ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
+ verify(listener, times(automationComposition.getElements().size())).lock(any(), any());
}
@Test
- void acUndeployTest() throws PfModelException {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
-
- var stateChangeUndeploy =
- commonTestData.getStateChange(partecipantId, uuid, DeployOrder.UNDEPLOY, LockOrder.NONE);
+ void handleAutomationCompositionStateChangeUnlockTest() throws PfModelException {
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(),
+ automationComposition.getInstanceId(), DeployOrder.NONE, LockOrder.UNLOCK);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ when(cacheProvider.getCommonProperties(any(UUID.class), any(UUID.class))).thenReturn(Map.of());
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- stateChangeUndeploy
- .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
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()));
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
+ ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
+ verify(listener, times(automationComposition.getElements().size())).unlock(any(), any());
}
@Test
- void automationCompositionStateLock() throws PfModelException {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
+ void handleAutomationCompositionStateChangeDeleteTest() throws PfModelException {
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ var automationCompositionStateChange = CommonTestData.getStateChange(CommonTestData.getParticipantId(),
+ automationComposition.getInstanceId(), DeployOrder.DELETE, LockOrder.NONE);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ when(cacheProvider.getCommonProperties(any(UUID.class), any(UUID.class))).thenReturn(Map.of());
- var stateChangeLock =
- commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.LOCK);
-
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
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());
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
+ ach.handleAutomationCompositionStateChange(automationCompositionStateChange);
+ verify(listener, times(automationComposition.getElements().size())).delete(any(), any());
}
@Test
- void automationCompositionStateUnlock() throws PfModelException {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
-
- var stateChangeUnlock =
- commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK);
-
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ void handleAcPropertyUpdateTest() throws PfModelException {
+ var cacheProvider = mock(CacheProvider.class);
var listener = mock(AutomationCompositionElementListener.class);
- ach.registerAutomationCompositionElementListener(listener);
- stateChangeUnlock
- .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
- 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());
- ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of());
- verify(listener, times(1)).unlock(any(), any());
- }
+ var participantMessagePublisher = mock(ParticipantMessagePublisher.class);
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
+ var updateMsg = new PropertiesUpdate();
+ assertDoesNotThrow(() -> ach.handleAcPropertyUpdate(updateMsg));
- @Test
- void testgetAutomationCompositionInfoList() {
- var uuid = UUID.randomUUID();
- var partecipantId = CommonTestData.getParticipantId();
- var definition = CommonTestData.getDefinition();
- var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- var result = ach.getAutomationCompositionInfoList();
- assertThat(result).hasSize(1);
- assertThat(result.get(0).getElements()).hasSize(1);
+ updateMsg.setParticipantId(CommonTestData.getParticipantId());
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var participantDeploy = new ParticipantDeploy();
+ participantDeploy.setParticipantId(CommonTestData.getParticipantId());
+ updateMsg.getParticipantUpdatesList().add(participantDeploy);
+
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ updateMsg.setAutomationCompositionId(automationComposition.getInstanceId());
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ var acElementDeploy = new AcElementDeploy();
+ acElementDeploy.setProperties(Map.of());
+ acElementDeploy.setId(automationComposition.getElements().values().iterator().next().getId());
+ participantDeploy.getAcElementList().add(acElementDeploy);
+
+ ach.handleAcPropertyUpdate(updateMsg);
+ verify(listener).update(any(), any(), any());
}
@Test
- void testsendAcElementInfo() {
+ void handleAutomationCompositionDeployTest() throws PfModelException {
+ var cacheProvider = mock(CacheProvider.class);
+ var listener = mock(AutomationCompositionElementListener.class);
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());
- }
+ var ach = new AutomationCompositionHandler(cacheProvider, participantMessagePublisher, listener);
- @Test
- 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);
- ach.registerAutomationCompositionElementListener(listener);
- ach.undeployInstances();
- verify(listener).undeploy(any(), any());
+ var deployMsg = new AutomationCompositionDeploy();
+ assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(deployMsg));
+
+ deployMsg.setParticipantId(CommonTestData.getParticipantId());
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var participantDeploy = new ParticipantDeploy();
+ participantDeploy.setParticipantId(CommonTestData.getParticipantId());
+ deployMsg.getParticipantUpdatesList().add(participantDeploy);
+
+ var automationComposition = CommonTestData.getTestAutomationCompositionMap().values().iterator().next();
+ deployMsg.setAutomationCompositionId(automationComposition.getInstanceId());
+ when(cacheProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ for (var element : automationComposition.getElements().values()) {
+ var acElementDeploy = new AcElementDeploy();
+ acElementDeploy.setProperties(Map.of());
+ acElementDeploy.setId(element.getId());
+ participantDeploy.getAcElementList().add(acElementDeploy);
+ }
+ ach.handleAutomationCompositionDeploy(deployMsg);
+ verify(listener, times(automationComposition.getElements().size())).deploy(any(), 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 30860308e..6cad99fa1 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
@@ -20,136 +20,187 @@
package org.onap.policy.clamp.acm.participant.intermediary.handler;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
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;
-import java.time.Instant;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
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.ParticipantDefinition;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
+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.clamp.models.acm.messages.dmaap.participant.ParticipantAckMessage;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessage;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatusReq;
+import org.onap.policy.clamp.models.acm.messages.dmaap.participant.PropertiesUpdate;
class ParticipantHandlerTest {
- private final CommonTestData commonTestData = new CommonTestData();
+ @Test
+ void handleParticipantStatusReqTest() {
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var cacheProvider = mock(CacheProvider.class);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+ participantHandler.handleParticipantStatusReq(new ParticipantStatusReq());
+ verify(publisher).sendParticipantStatus(any(ParticipantStatus.class));
+ }
@Test
- void handleUpdateTest() {
- var parameters = CommonTestData.getParticipantParameters();
- var automationCompositionHander = commonTestData.getMockAutomationCompositionHandler();
- var publisher = new ParticipantMessagePublisher();
- var emptyParticipantHandler =
- new ParticipantHandler(parameters, publisher, automationCompositionHander);
- var participantPrimeMsg = new ParticipantPrime();
-
- assertThatThrownBy(() ->
- emptyParticipantHandler.handleParticipantPrime(participantPrimeMsg))
- .isInstanceOf(RuntimeException.class);
-
- var participantHandler = commonTestData.getMockParticipantHandler();
-
- var participantId = CommonTestData.getParticipantId();
- participantPrimeMsg.setCompositionId(CommonTestData.AC_ID_1);
- participantPrimeMsg.setParticipantId(participantId);
- participantPrimeMsg.setMessageId(UUID.randomUUID());
- participantPrimeMsg.setTimestamp(Instant.ofEpochMilli(3000));
-
- var heartbeatF = participantHandler.makeHeartbeat(false);
- assertEquals(participantId, heartbeatF.getParticipantId());
- assertThat(heartbeatF.getAutomationCompositionInfoList()).isEmpty();
-
- participantHandler.handleParticipantPrime(participantPrimeMsg);
-
- var heartbeatT = participantHandler.makeHeartbeat(true);
- assertEquals(participantId, heartbeatT.getParticipantId());
- assertThat(heartbeatT.getParticipantDefinitionUpdates()).isNotEmpty();
- assertEquals(participantId, heartbeatT.getParticipantDefinitionUpdates().get(0).getParticipantId());
-
- var pum = setListParticipantDefinition(participantPrimeMsg);
- participantHandler.handleParticipantPrime(pum);
- var heartbeatTAfterUpdate = participantHandler.makeHeartbeat(true);
- assertEquals(participantId, heartbeatTAfterUpdate.getParticipantId());
+ void handleAutomationCompositionDeployTest() {
+ var acHandler = mock(AutomationCompositionHandler.class);
+ var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
+ mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var automationCompositionDeploy = new AutomationCompositionDeploy();
+ participantHandler.handleAutomationCompositionDeploy(automationCompositionDeploy);
+ verify(acHandler).handleAutomationCompositionDeploy(automationCompositionDeploy);
}
- private ParticipantPrime setListParticipantDefinition(ParticipantPrime participantPrimeMsg) {
- var def = new ParticipantDefinition();
- def.setParticipantId(CommonTestData.getParticipantId());
- participantPrimeMsg.setParticipantDefinitionUpdates(List.of(def));
- return participantPrimeMsg;
+ @Test
+ void handleAutomationCompositionStateChangeTest() {
+ var acHandler = mock(AutomationCompositionHandler.class);
+ var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
+ mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var acStateChange = new AutomationCompositionStateChange();
+ participantHandler.handleAutomationCompositionStateChange(acStateChange);
+ verify(acHandler).handleAutomationCompositionStateChange(acStateChange);
+ }
+
+ @Test
+ void handleAcPropertyUpdateTest() {
+ var acHandler = mock(AutomationCompositionHandler.class);
+ var participantHandler = new ParticipantHandler(acHandler, mock(AutomationCompositionOutHandler.class),
+ mock(ParticipantMessagePublisher.class), mock(CacheProvider.class));
+ var propertyUpdateMsg = new PropertiesUpdate();
+ participantHandler.handleAcPropertyUpdate(propertyUpdateMsg);
+ verify(acHandler).handleAcPropertyUpdate(propertyUpdateMsg);
}
@Test
- void checkAppliesTo() {
- var participantHandler = commonTestData.getMockParticipantHandler();
- var participantAckMsg =
- new ParticipantAckMessage(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY);
+ void appliesToTest() {
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), mock(ParticipantMessagePublisher.class), cacheProvider);
+
+ var participantAckMsg = new ParticipantAckMessage(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY);
assertTrue(participantHandler.appliesTo(participantAckMsg));
- var participantMsg =
- new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATUS);
+ var participantMsg = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATUS);
assertTrue(participantHandler.appliesTo(participantMsg));
- var randomId = UUID.randomUUID();
- participantMsg.setParticipantId(randomId);
+ participantMsg.setParticipantId(UUID.randomUUID());
assertFalse(participantHandler.appliesTo(participantMsg));
-
}
@Test
- void getAutomationCompositionInfoListTest() throws CoderException {
- var automationCompositionHandler = mock(AutomationCompositionHandler.class);
- var participantHandler =
- commonTestData.getParticipantHandlerAutomationCompositions(automationCompositionHandler);
- clearInvocations(automationCompositionHandler);
- participantHandler.sendHeartbeat();
- verify(automationCompositionHandler).getAutomationCompositionInfoList();
+ void sendParticipantRegister() {
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ when(cacheProvider.getSupportedAcElementTypes()).thenReturn(List.of(new ParticipantSupportedElementType()));
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+
+ participantHandler.sendParticipantRegister();
+ verify(publisher).sendParticipantRegister(any(ParticipantRegister.class));
}
@Test
- void testHandleParticipantRegisterAck() {
- var parameters = CommonTestData.getParticipantParameters();
- var automationCompositionHandler = commonTestData.getMockAutomationCompositionHandler();
+ void handleParticipantRegisterAckTest() {
var publisher = mock(ParticipantMessagePublisher.class);
- var participantHandler = new ParticipantHandler(parameters, publisher, automationCompositionHandler);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
participantHandler.handleParticipantRegisterAck(new ParticipantRegisterAck());
- verify(publisher).sendParticipantStatus(any());
+ verify(publisher).sendParticipantStatus(any(ParticipantStatus.class));
}
@Test
- void testSendParticipantDeregister() throws PfModelException {
- var commonTestData = new CommonTestData();
- var automationCompositionMap = commonTestData.getTestAutomationCompositionMap();
- var automationCompositionHandler = mock(AutomationCompositionHandler.class);
-
- automationCompositionMap.values().iterator().next().getElements().values().iterator().next()
- .setParticipantId(CommonTestData.getParticipantId());
- when(automationCompositionHandler.getAutomationCompositionMap()).thenReturn(automationCompositionMap);
-
+ void sendParticipantDeregisterTest() {
var publisher = mock(ParticipantMessagePublisher.class);
- var parameters = CommonTestData.getParticipantParameters();
- var participantHandler = new ParticipantHandler(parameters, publisher, automationCompositionHandler);
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
participantHandler.sendParticipantDeregister();
verify(publisher).sendParticipantDeregister(any(ParticipantDeregister.class));
- verify(automationCompositionHandler).undeployInstances();
+ }
+
+ @Test
+ void handleParticipantDeregisterAckTest() {
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), mock(ParticipantMessagePublisher.class),
+ mock(CacheProvider.class));
+ var participantDeregisterAck = new ParticipantDeregisterAck();
+ assertDoesNotThrow(() -> participantHandler.handleParticipantDeregisterAck(participantDeregisterAck));
+ }
+
+ @Test
+ void handleParticipantPrimeTest() {
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+
+ var participantPrime = new ParticipantPrime();
+ participantPrime.setCompositionId(UUID.randomUUID());
+ participantPrime.setParticipantDefinitionUpdates(List.of(createParticipantDefinition()));
+ participantHandler.handleParticipantPrime(participantPrime);
+ verify(cacheProvider).addElementDefinition(any(), any());
+ verify(publisher).sendParticipantPrimeAck(any(ParticipantPrimeAck.class));
+ }
+
+ @Test
+ void handleParticipantDeprimeTest() {
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+ var participantPrime = new ParticipantPrime();
+ var compositionId = UUID.randomUUID();
+ participantPrime.setCompositionId(compositionId);
+ participantHandler.handleParticipantPrime(participantPrime);
+ verify(cacheProvider).removeElementDefinition(compositionId);
+ verify(publisher).sendParticipantPrimeAck(any(ParticipantPrimeAck.class));
+ }
+
+ @Test
+ void sendHeartbeatTest() {
+ var cacheProvider = mock(CacheProvider.class);
+ when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ when(cacheProvider.getAutomationCompositions()).thenReturn(CommonTestData.getTestAutomationCompositionMap());
+ var publisher = mock(ParticipantMessagePublisher.class);
+ var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
+ mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
+ participantHandler.sendHeartbeat();
+ verify(publisher).sendHeartbeat(any(ParticipantStatus.class));
+ }
+
+ private ParticipantDefinition createParticipantDefinition() {
+ var def = new ParticipantDefinition();
+ def.setParticipantId(CommonTestData.getParticipantId());
+ return def;
}
}
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 60812c27a..cc2bd7010 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
@@ -22,28 +22,19 @@ package org.onap.policy.clamp.acm.participant.intermediary.main.parameters;
import java.io.File;
import java.time.Instant;
-import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
-import org.mockito.Mockito;
-import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher;
-import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler;
import org.onap.policy.clamp.acm.participant.intermediary.handler.DummyParticipantParameters;
-import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler;
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.AutomationCompositions;
-import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
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;
import org.onap.policy.common.utils.coder.CoderException;
@@ -59,7 +50,6 @@ public class CommonTestData {
public static final long TIME_INTERVAL = 2000;
public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
public static final Coder CODER = new StandardCoder();
- private static final Object lockit = new Object();
public static final UUID AC_ID_0 = UUID.randomUUID();
public static final UUID AC_ID_1 = UUID.randomUUID();
public static final UUID PARTCICIPANT_ID = UUID.randomUUID();
@@ -69,7 +59,7 @@ public class CommonTestData {
*
* @return ParticipantIntermediaryParameters
*/
- public ParticipantIntermediaryParameters getParticipantIntermediaryParameters() {
+ public static ParticipantIntermediaryParameters getParticipantIntermediaryParameters() {
try {
return CODER.convert(getIntermediaryParametersMap(PARTICIPANT_GROUP_NAME),
ParticipantIntermediaryParameters.class);
@@ -170,70 +160,6 @@ public class CommonTestData {
}
/**
- * Returns a participantMessagePublisher for MessageSender.
- *
- * @return participant Message Publisher
- */
- private ParticipantMessagePublisher getParticipantMessagePublisher() {
- synchronized (lockit) {
- var participantMessagePublisher = new ParticipantMessagePublisher();
- participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
- return participantMessagePublisher;
- }
- }
-
- /**
- * Returns a mocked AutomationCompositionHandler for test cases.
- *
- * @return AutomationCompositionHandler
- */
- public AutomationCompositionHandler getMockAutomationCompositionHandler() {
- return new AutomationCompositionHandler(getParticipantParameters(), getParticipantMessagePublisher());
- }
-
- /**
- * Returns a mocked ParticipantHandler for test cases.
- *
- * @return participant Handler
- */
- public ParticipantHandler getMockParticipantHandler() {
- var parameters = getParticipantParameters();
- var automationCompositionHandler = getMockAutomationCompositionHandler();
- var publisher = new ParticipantMessagePublisher();
- publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
- 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.
- *
- * @return participant Handler
- *
- * @throws CoderException if there is an error with .json file.
- */
- public ParticipantHandler getParticipantHandlerAutomationCompositions(
- AutomationCompositionHandler automationCompositionHandler) {
- Mockito.doReturn(getTestAutomationCompositionMap()).when(automationCompositionHandler)
- .getAutomationCompositionMap();
- var publisher = new ParticipantMessagePublisher();
- publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
- var parameters = getParticipantParameters();
- var participantHandler = new ParticipantHandler(parameters, publisher, automationCompositionHandler);
- participantHandler.sendParticipantRegister();
- participantHandler.handleParticipantStatusReq(null);
- participantHandler.sendParticipantDeregister();
- var participantDeregisterAckMsg = new ParticipantDeregisterAck();
- participantDeregisterAckMsg.setResponseTo(UUID.randomUUID());
- participantHandler.handleParticipantDeregisterAck(participantDeregisterAckMsg);
- return participantHandler;
- }
-
- /**
* Returns a Map of ToscaConceptIdentifier and AutomationComposition for test cases.
*
* @return automationCompositionMap
@@ -269,59 +195,21 @@ public class CommonTestData {
}
/**
- * Returns a map for a elementsOnThisParticipant for test cases.
- *
- * @param uuid UUID
- * @param definition ToscaConceptIdentifier
- * @return a map suitable for elementsOnThisParticipant
- */
- public Map<UUID, AutomationCompositionElement> setAutomationCompositionElementTest(UUID uuid,
- ToscaConceptIdentifier definition, UUID participantId) {
- var acElement = new AutomationCompositionElement();
- acElement.setId(uuid);
- acElement.setParticipantId(participantId);
- acElement.setDefinition(definition);
- acElement.setDeployState(DeployState.UNDEPLOYED);
-
- Map<UUID, AutomationCompositionElement> elementsOnThisParticipant = new LinkedHashMap<>();
- elementsOnThisParticipant.put(uuid, acElement);
- return elementsOnThisParticipant;
- }
-
- /**
- * Returns a AutomationCompositionHandler with elements on the definition,uuid.
- *
- * @param definition ToscaConceptIdentifier
- * @param uuid UUID
- * @return a AutomationCompositionHander with elements
- */
- public AutomationCompositionHandler setTestAutomationCompositionHandler(ToscaConceptIdentifier definition,
- UUID uuid, UUID participantId) {
- var ach = getMockAutomationCompositionHandler();
- ach.getAutomationCompositionMap().putAll(getTestAutomationCompositionMap());
- var acKey = ach.getAutomationCompositionMap().keySet().iterator().next();
- ach.getAutomationCompositionMap().get(acKey)
- .setElements(setAutomationCompositionElementTest(uuid, definition, participantId));
-
- return ach;
- }
-
- /**
* Return a AutomationCompositionStateChange.
*
* @param participantId the participantId
- * @param uuid UUID
+ * @param instanceId th AutomationComposition Id
* @param deployOrder a DeployOrder
* @param lockOrder a LockOrder
* @return a AutomationCompositionStateChange
*/
- public AutomationCompositionStateChange getStateChange(UUID participantId, UUID uuid,
+ public static AutomationCompositionStateChange getStateChange(UUID participantId, UUID instanceId,
DeployOrder deployOrder, LockOrder lockOrder) {
var stateChange = new AutomationCompositionStateChange();
stateChange.setStartPhase(0);
- stateChange.setAutomationCompositionId(UUID.randomUUID());
+ stateChange.setAutomationCompositionId(instanceId);
stateChange.setParticipantId(participantId);
- stateChange.setMessageId(uuid);
+ stateChange.setMessageId(UUID.randomUUID());
stateChange.setDeployOrderedState(deployOrder);
stateChange.setLockOrderedState(lockOrder);
stateChange.setTimestamp(Instant.ofEpochMilli(3000));
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java
index 2cbe15797..e3631f12e 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/TestParticipantIntermediaryParameters.java
@@ -32,20 +32,19 @@ import org.onap.policy.clamp.acm.participant.intermediary.parameters.Participant
* {@link org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters}.
*/
class TestParticipantIntermediaryParameters {
- private final CommonTestData commonTestData = new CommonTestData();
private final ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
@Test
void testParticipantIntermediaryParameterGroup() {
final ParticipantIntermediaryParameters participantParameters =
- commonTestData.getParticipantIntermediaryParameters();
+ CommonTestData.getParticipantIntermediaryParameters();
assertThat(validatorFactory.getValidator().validate(participantParameters)).isEmpty();
}
@Test
void testParticipantIntermediaryParameterGroup_EmptyParameter() {
final ParticipantIntermediaryParameters participantParameters =
- commonTestData.getParticipantIntermediaryParameters();
+ CommonTestData.getParticipantIntermediaryParameters();
participantParameters.setClampAutomationCompositionTopics(null);
assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
}
@@ -53,7 +52,7 @@ class TestParticipantIntermediaryParameters {
@Test
void testParticipantIntermediaryParameters_NullTopicSinks() {
final ParticipantIntermediaryParameters participantParameters =
- commonTestData.getParticipantIntermediaryParameters();
+ CommonTestData.getParticipantIntermediaryParameters();
participantParameters.getClampAutomationCompositionTopics().setTopicSinks(null);
assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
}
@@ -61,7 +60,7 @@ class TestParticipantIntermediaryParameters {
@Test
void testParticipantIntermediaryParameters_NullTopicSources() {
final ParticipantIntermediaryParameters participantParameters =
- commonTestData.getParticipantIntermediaryParameters();
+ CommonTestData.getParticipantIntermediaryParameters();
participantParameters.getClampAutomationCompositionTopics().setTopicSources(null);
assertThat(validatorFactory.getValidator().validate(participantParameters)).isNotEmpty();
}