summaryrefslogtreecommitdiffstats
path: root/participant/participant-intermediary
diff options
context:
space:
mode:
Diffstat (limited to 'participant/participant-intermediary')
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java9
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java72
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java25
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java76
4 files changed, 103 insertions, 79 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 bc5db8571..9b0f910ea 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
@@ -31,19 +31,18 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedSta
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
class ParticipantIntermediaryApiImplTest {
private final CommonTestData commonTestData = new CommonTestData();
- private static final String ID_NAME = "org.onap.PM_CDS_Blueprint";
- private static final String ID_VERSION = "1.0.1";
@Test
void mockParticipantIntermediaryApiImplTest() throws CoderException {
var uuid = UUID.randomUUID();
- var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- var automationComposiitonHandler = commonTestData.setTestAutomationCompositionHandler(id, uuid);
+ var definition = CommonTestData.getDefinition();
+ var participantId = CommonTestData.getParticipantId();
+ var automationComposiitonHandler =
+ commonTestData.setTestAutomationCompositionHandler(definition, uuid, participantId);
var apiImpl = new ParticipantIntermediaryApiImpl(automationComposiitonHandler);
var acElementListener = Mockito.mock(AutomationCompositionElementListener.class);
apiImpl.registerAutomationCompositionElementListener(acElementListener);
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 8b52c1cfe..dc9e3d307 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
@@ -27,7 +27,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
-import java.time.Instant;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@@ -41,7 +40,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionUpdate;
-import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -83,11 +81,12 @@ class AutomationCompositionHandlerTest {
}
@Test
- void updateAutomationCompositionHandlerTest() throws CoderException {
+ void updateAutomationCompositionHandlerTest() {
var uuid = UUID.randomUUID();
- var id = CommonTestData.getParticipantId();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
- var ach = commonTestData.setTestAutomationCompositionHandler(id, uuid);
+ 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());
@@ -108,26 +107,27 @@ class AutomationCompositionHandlerTest {
}
@Test
- void handleAutomationCompositionUpdateExceptionTest() throws CoderException {
+ void handleAutomationCompositionUpdateExceptionTest() {
var uuid = UUID.randomUUID();
- var id = CommonTestData.getParticipantId();
- var stateChange = getStateChange(id, uuid, AutomationCompositionOrderedState.RUNNING);
- var ach = commonTestData.setTestAutomationCompositionHandler(id, uuid);
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
+ var stateChange = commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.RUNNING);
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
assertDoesNotThrow(() -> ach
.handleAutomationCompositionStateChange(mock(AutomationCompositionStateChange.class), List.of()));
ach.handleAutomationCompositionStateChange(stateChange, List.of());
- var newid = new ToscaConceptIdentifier("id", "1.2.3");
+ var newPartecipantId = CommonTestData.getRndParticipantId();
stateChange.setAutomationCompositionId(UUID.randomUUID());
- stateChange.setParticipantId(newid);
+ stateChange.setParticipantId(newPartecipantId);
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChange, List.of()));
var acd = new AutomationCompositionElementDefinition();
- acd.setAcElementDefinitionId(id);
+ acd.setAcElementDefinitionId(definition);
var updateMsg = new AutomationCompositionUpdate();
updateMsg.setAutomationCompositionId(UUID.randomUUID());
updateMsg.setMessageId(uuid);
- updateMsg.setParticipantId(id);
+ updateMsg.setParticipantId(partecipantId);
updateMsg.setStartPhase(0);
var acElementDefinitions = List.of(acd);
assertDoesNotThrow(() -> ach.handleAutomationCompositionUpdate(updateMsg, acElementDefinitions));
@@ -144,60 +144,50 @@ class AutomationCompositionHandlerTest {
updateMsg.setStartPhase(1);
var participantUpdate = new ParticipantUpdates();
- participantUpdate.setParticipantId(id);
+ participantUpdate.setParticipantId(partecipantId);
var element = new AutomationCompositionElement();
- element.setParticipantType(id);
- element.setDefinition(id);
+ element.setParticipantType(definition);
+ element.setDefinition(definition);
participantUpdate.setAutomationCompositionElementList(List.of(element));
updateMsg.setParticipantUpdatesList(List.of(participantUpdate));
var acd2 = new AutomationCompositionElementDefinition();
- acd2.setAcElementDefinitionId(id);
+ acd2.setAcElementDefinitionId(definition);
acd2.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
assertDoesNotThrow(() -> ach.handleAutomationCompositionUpdate(updateMsg, List.of(acd2)));
}
@Test
- void automationCompositionStateChangeUninitialisedTest() throws CoderException {
+ void automationCompositionStateChangeUninitialisedTest() {
var uuid = UUID.randomUUID();
- var id = CommonTestData.getParticipantId();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
- var stateChangeUninitialised = getStateChange(id, uuid, AutomationCompositionOrderedState.UNINITIALISED);
+ var stateChangeUninitialised =
+ commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.UNINITIALISED);
- var ach = commonTestData.setTestAutomationCompositionHandler(id, uuid);
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of());
- var newid = new ToscaConceptIdentifier("id", "1.2.3");
stateChangeUninitialised.setAutomationCompositionId(UUID.randomUUID());
- stateChangeUninitialised.setParticipantId(newid);
+ stateChangeUninitialised.setParticipantId(CommonTestData.getRndParticipantId());
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of()));
}
@Test
- void automationCompositionStateChangePassiveTest() throws CoderException {
+ void automationCompositionStateChangePassiveTest() {
var uuid = UUID.randomUUID();
- var id = CommonTestData.getParticipantId();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
- var stateChangePassive = getStateChange(id, uuid, AutomationCompositionOrderedState.PASSIVE);
+ var stateChangePassive =
+ commonTestData.getStateChange(partecipantId, uuid, AutomationCompositionOrderedState.PASSIVE);
- var ach = commonTestData.setTestAutomationCompositionHandler(id, uuid);
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
ach.handleAutomationCompositionStateChange(stateChangePassive, List.of());
- var newid = new ToscaConceptIdentifier("id", "1.2.3");
stateChangePassive.setAutomationCompositionId(UUID.randomUUID());
- stateChangePassive.setParticipantId(newid);
+ stateChangePassive.setParticipantId(CommonTestData.getRndParticipantId());
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangePassive, List.of()));
}
- private AutomationCompositionStateChange getStateChange(ToscaConceptIdentifier id, UUID uuid,
- AutomationCompositionOrderedState state) {
- var stateChange = new AutomationCompositionStateChange();
- stateChange.setAutomationCompositionId(UUID.randomUUID());
- stateChange.setParticipantId(id);
- stateChange.setMessageId(uuid);
- stateChange.setOrderedState(state);
- stateChange.setCurrentState(AutomationCompositionState.UNINITIALISED);
- stateChange.setTimestamp(Instant.ofEpochMilli(3000));
- return stateChange;
- }
-
}
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 f6988b0e8..8e65abffb 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
@@ -27,7 +27,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.time.Instant;
-import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@@ -62,39 +61,37 @@ class ParticipantHandlerTest {
var participantHandler = commonTestData.getMockParticipantHandler();
- var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var participantType = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var participantId = CommonTestData.getParticipantId();
participantUpdateMsg.setAutomationCompositionId(CommonTestData.AC_ID_1);
participantUpdateMsg.setCompositionId(CommonTestData.AC_ID_1);
- participantUpdateMsg.setParticipantId(id);
- participantUpdateMsg.setParticipantType(id);
+ participantUpdateMsg.setParticipantId(participantId);
+ participantUpdateMsg.setParticipantType(participantType);
participantUpdateMsg.setMessageId(UUID.randomUUID());
participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000));
var heartbeatF = participantHandler.makeHeartbeat(false);
- assertEquals(id, heartbeatF.getParticipantId());
+ assertEquals(participantId, heartbeatF.getParticipantId());
assertThat(heartbeatF.getAutomationCompositionInfoList()).isEmpty();
participantHandler.handleParticipantUpdate(participantUpdateMsg);
var heartbeatT = participantHandler.makeHeartbeat(true);
- assertEquals(id, heartbeatT.getParticipantId());
+ assertEquals(participantId, heartbeatT.getParticipantId());
assertThat(heartbeatT.getParticipantDefinitionUpdates()).isNotEmpty();
- assertEquals(id, heartbeatT.getParticipantDefinitionUpdates().get(0).getParticipantId());
+ assertEquals(participantId, heartbeatT.getParticipantDefinitionUpdates().get(0).getParticipantId());
var pum = setListParticipantDefinition(participantUpdateMsg);
participantHandler.handleParticipantUpdate(pum);
var heartbeatTAfterUpdate = participantHandler.makeHeartbeat(true);
- assertEquals(id, heartbeatTAfterUpdate.getParticipantId());
+ assertEquals(participantId, heartbeatTAfterUpdate.getParticipantId());
}
private ParticipantUpdate setListParticipantDefinition(ParticipantUpdate participantUpdateMsg) {
- var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
var def = new ParticipantDefinition();
- def.setParticipantId(id);
- def.setParticipantType(id);
- participantDefinitionUpdates.add(def);
- participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates);
+ def.setParticipantId(CommonTestData.getParticipantId());
+ def.setParticipantType(new ToscaConceptIdentifier(ID_NAME, ID_VERSION));
+ participantUpdateMsg.setParticipantDefinitionUpdates(List.of(def));
return participantUpdateMsg;
}
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 0e35c480b..b7d66bec6 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
@@ -21,9 +21,9 @@
package org.onap.policy.clamp.acm.participant.intermediary.main.parameters;
import java.io.File;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -38,7 +38,9 @@ import org.onap.policy.clamp.acm.participant.intermediary.parameters.Participant
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.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
@@ -59,6 +61,8 @@ public class CommonTestData {
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 ToscaConceptIdentifier PARTCICIPANT_ID =
+ new ToscaConceptIdentifier("org.onap.PM_Policy", "0.0.0");
/**
* Get ParticipantIntermediaryParameters.
@@ -110,7 +114,7 @@ public class CommonTestData {
map.put("name", name);
map.put("participantId", getParticipantId());
map.put("description", DESCRIPTION);
- map.put("participantType", getParticipantId());
+ map.put("participantType", getDefinition());
map.put("reportingTimeIntervalMs", TIME_INTERVAL);
map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
map.put("participantSupportedElementTypes", new ArrayList<>());
@@ -152,6 +156,14 @@ public class CommonTestData {
* @return participant Id
*/
public static ToscaConceptIdentifier getParticipantId() {
+ return PARTCICIPANT_ID;
+ }
+
+ public static ToscaConceptIdentifier getRndParticipantId() {
+ return new ToscaConceptIdentifier("diff", "0.0.0");
+ }
+
+ public static ToscaConceptIdentifier getDefinition() {
return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.1");
}
@@ -221,7 +233,7 @@ public class CommonTestData {
*
* @throws CoderException if there is an error with .json file.
*/
- public Map<UUID, AutomationComposition> getTestAutomationCompositionMap() throws CoderException {
+ public Map<UUID, AutomationComposition> getTestAutomationCompositionMap() {
var automationCompositions = getTestAutomationCompositions();
var automationComposition = automationCompositions.getAutomationCompositionList().get(1);
Map<UUID, AutomationComposition> automationCompositionMap = new LinkedHashMap<>();
@@ -236,26 +248,32 @@ public class CommonTestData {
*
* @throws CoderException if there is an error with .json file.
*/
- public AutomationCompositions getTestAutomationCompositions() throws CoderException {
- var automationCompositions = new StandardCoder().decode(
- new File("src/test/resources/providers/TestAutomationCompositions.json"), AutomationCompositions.class);
- automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_0);
- automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_1);
- return automationCompositions;
+ public AutomationCompositions getTestAutomationCompositions() {
+ try {
+ var automationCompositions =
+ new StandardCoder().decode(new File("src/test/resources/providers/TestAutomationCompositions.json"),
+ AutomationCompositions.class);
+ automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_0);
+ automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_1);
+ return automationCompositions;
+ } catch (Exception e) {
+ throw new RuntimeException("cannot read TestAutomationCompositions.json");
+ }
}
/**
* Returns a map for a elementsOnThisParticipant for test cases.
*
- * @param uuid UUID and id ToscaConceptIdentifier
+ * @param uuid UUID
+ * @param definition ToscaConceptIdentifier
* @return a map suitable for elementsOnThisParticipant
*/
public Map<UUID, AutomationCompositionElement> setAutomationCompositionElementTest(UUID uuid,
- ToscaConceptIdentifier id) {
+ ToscaConceptIdentifier definition, ToscaConceptIdentifier participantId) {
var acElement = new AutomationCompositionElement();
acElement.setId(uuid);
- acElement.setParticipantId(id);
- acElement.setDefinition(id);
+ acElement.setParticipantId(participantId);
+ acElement.setDefinition(definition);
acElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
Map<UUID, AutomationCompositionElement> elementsOnThisParticipant = new LinkedHashMap<>();
@@ -264,24 +282,44 @@ public class CommonTestData {
}
/**
- * Returns a AutomationCompositionHandler with elements on the id,uuid.
+ * Returns a AutomationCompositionHandler with elements on the definition,uuid.
*
- * @param id ToscaConceptIdentifier and uuid UUID
+ * @param definition ToscaConceptIdentifier
+ * @param uuid UUID
* @return a AutomationCompositionHander with elements
*/
- public AutomationCompositionHandler setTestAutomationCompositionHandler(ToscaConceptIdentifier id, UUID uuid)
- throws CoderException {
+ public AutomationCompositionHandler setTestAutomationCompositionHandler(ToscaConceptIdentifier definition,
+ UUID uuid, ToscaConceptIdentifier participantId) {
var ach = getMockAutomationCompositionHandler();
var key = getTestAutomationCompositionMap().keySet().iterator().next();
var value = getTestAutomationCompositionMap().get(key);
ach.getAutomationCompositionMap().put(key, value);
- var keyElem = setAutomationCompositionElementTest(uuid, id).keySet().iterator().next();
- var valueElem = setAutomationCompositionElementTest(uuid, id).get(keyElem);
+ var keyElem = setAutomationCompositionElementTest(uuid, definition, participantId).keySet().iterator().next();
+ var valueElem = setAutomationCompositionElementTest(uuid, definition, participantId).get(keyElem);
ach.getElementsOnThisParticipant().put(keyElem, valueElem);
return ach;
}
+ /**
+ * Return a AutomationCompositionStateChange.
+ *
+ * @param participantId the participantId
+ * @param uuid UUID
+ * @param state a AutomationCompositionOrderedState
+ * @return a AutomationCompositionStateChange
+ */
+ public AutomationCompositionStateChange getStateChange(ToscaConceptIdentifier participantId, UUID uuid,
+ AutomationCompositionOrderedState state) {
+ var stateChange = new AutomationCompositionStateChange();
+ stateChange.setAutomationCompositionId(UUID.randomUUID());
+ stateChange.setParticipantId(participantId);
+ stateChange.setMessageId(uuid);
+ stateChange.setOrderedState(state);
+ stateChange.setCurrentState(AutomationCompositionState.UNINITIALISED);
+ stateChange.setTimestamp(Instant.ofEpochMilli(3000));
+ return stateChange;
+ }
}