aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-intermediary
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2021-10-22 12:30:32 +0100
committerlapentafd <francesco.lapenta@est.tech>2021-10-26 11:54:04 +0100
commitfe96e1e67b8b26958084e241f11caac269ebf3f0 (patch)
treec0e88915e0fbb7f06b33d543afa2301e4a0c50d0 /participant/participant-intermediary
parent962a9d16895c9ae75230cad5c7d8a1d4e453f2ad (diff)
Code Coverage in clamp participant intermediary
Issue-ID: POLICY-3452 Change-Id: If4fe15d4e74a7f04b77fb1d6dc70f1b7cd32baa6 Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'participant/participant-intermediary')
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java92
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java100
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java102
-rw-r--r--participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json142
4 files changed, 399 insertions, 37 deletions
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java
index 29387959b..e77dd69ee 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java
@@ -21,20 +21,29 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.mock;
import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopStateChange;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopUpdate;
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.main.parameters.CommonTestData;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@@ -45,14 +54,14 @@ class ControlLoopHandlerTest {
@Test
void controlLoopHandlerTest() {
- ControlLoopHandler clh = commonTestData.getMockControlLoopHandler();
+ var clh = commonTestData.getMockControlLoopHandler();
assertNotNull(clh.getControlLoops());
assertNotNull(clh.getControlLoopMap());
assertNotNull(clh.getElementsOnThisParticipant());
- UUID elementId1 = UUID.randomUUID();
- ControlLoopElement element = new ControlLoopElement();
+ var elementId1 = UUID.randomUUID();
+ var element = new ControlLoopElement();
element.setId(elementId1);
element.setDefinition(new ToscaConceptIdentifier(
"org.onap.policy.controlloop.PolicyControlLoopParticipant", "1.0.1"));
@@ -62,22 +71,21 @@ class ControlLoopHandlerTest {
ControlLoopElementListener listener = mock(ControlLoopElementListener.class);
clh.registerControlLoopElementListener(listener);
assertThat(clh.getListeners()).contains(listener);
-
}
@Test
void updateNullControlLoopHandlerTest() {
- UUID id = UUID.randomUUID();
+ var id = UUID.randomUUID();
- ControlLoopHandler clh = commonTestData.getMockControlLoopHandler();
+ var clh = commonTestData.getMockControlLoopHandler();
assertNull(clh.updateControlLoopElementState(null, null, ControlLoopOrderedState.UNINITIALISED,
ControlLoopState.PASSIVE));
assertNull(clh.updateControlLoopElementState(null, id, ControlLoopOrderedState.UNINITIALISED,
ControlLoopState.PASSIVE));
- ClElementStatistics clElementStatistics = new ClElementStatistics();
- ToscaConceptIdentifier controlLoopId = new ToscaConceptIdentifier("defName", "0.0.1");
+ var clElementStatistics = new ClElementStatistics();
+ var controlLoopId = new ToscaConceptIdentifier("defName", "0.0.1");
clElementStatistics.setParticipantId(controlLoopId);
clElementStatistics.setControlLoopState(ControlLoopState.RUNNING);
clElementStatistics.setTimeStamp(Instant.now());
@@ -85,9 +93,77 @@ class ControlLoopHandlerTest {
clh.updateControlLoopElementStatistics(id, clElementStatistics);
assertNull(clh.updateControlLoopElementState(controlLoopId, id, ControlLoopOrderedState.UNINITIALISED,
ControlLoopState.PASSIVE));
+ }
+
+ @Test
+ void updateControlLoopHandlerTest() throws CoderException {
+ var uuid = UUID.randomUUID();
+ var id = CommonTestData.getParticipantId();
+
+ var clh = setTestControlLoopHandler(id, uuid);
+ var key = clh.getElementsOnThisParticipant().keySet().iterator().next();
+ var value = clh.getElementsOnThisParticipant().get(key);
+ assertEquals(ControlLoopState.UNINITIALISED, value.getState());
+ clh.updateControlLoopElementState(id, uuid, ControlLoopOrderedState.UNINITIALISED,
+ ControlLoopState.PASSIVE);
+ assertEquals(ControlLoopState.PASSIVE, value.getState());
+
+ var clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setParticipantId(id);
+ clElementStatistics.setControlLoopState(ControlLoopState.RUNNING);
+ clElementStatistics.setTimeStamp(Instant.now());
+
+ assertNotEquals(uuid, value.getClElementStatistics().getId());
+ clh.updateControlLoopElementStatistics(uuid, clElementStatistics);
+ assertEquals(uuid, value.getClElementStatistics().getId());
+ }
+
+ @Test
+ void handleControlLoopUpdateExceptionTest() throws CoderException {
+ var uuid = UUID.randomUUID();
+ var id = CommonTestData.getParticipantId();
+
+ var stateChange = new ControlLoopStateChange();
+ stateChange.setControlLoopId(id);
+ stateChange.setParticipantId(id);
+ stateChange.setMessageId(uuid);
+ stateChange.setOrderedState(ControlLoopOrderedState.RUNNING);
+ stateChange.setCurrentState(ControlLoopState.UNINITIALISED);
+ stateChange.setTimestamp(Instant.ofEpochMilli(3000));
+
+ var clh = setTestControlLoopHandler(id, uuid);
+ clh.handleControlLoopStateChange(stateChange);
+ var newid = new ToscaConceptIdentifier("id", "1.2.3");
+ stateChange.setControlLoopId(newid);
+ stateChange.setParticipantId(newid);
+ assertDoesNotThrow(() -> clh.handleControlLoopStateChange(stateChange));
+
+ List<ControlLoopElementDefinition> clElementDefinitions = new ArrayList<>();
+ var cld = new ControlLoopElementDefinition();
+ cld.setClElementDefinitionId(id);
+ clElementDefinitions.add(cld);
+ var updateMsg = new ControlLoopUpdate();
+ updateMsg.setControlLoopId(id);
+ updateMsg.setMessageId(uuid);
+ updateMsg.setParticipantId(id);
+ updateMsg.setStartPhase(0);
+ assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
+ updateMsg.setStartPhase(1);
+ assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
+ }
+
+ private ControlLoopHandler setTestControlLoopHandler(ToscaConceptIdentifier id, UUID uuid) throws CoderException {
+ var clh = commonTestData.getMockControlLoopHandler();
+ var key = commonTestData.getTestControlLoopMap().keySet().iterator().next();
+ var value = commonTestData.getTestControlLoopMap().get(key);
+ clh.getControlLoopMap().put(key, value);
+ var keyElem = commonTestData.setControlLoopElementTest(uuid, id).keySet().iterator().next();
+ var valueElem = commonTestData.setControlLoopElementTest(uuid, id).get(keyElem);
+ clh.getElementsOnThisParticipant().put(keyElem, valueElem);
+ return clh;
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java
index 63db364ca..d00697521 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandlerTest.java
@@ -23,23 +23,28 @@ package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantAckMessage;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessage;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegisterAck;
-import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.controlloop.participant.intermediary.main.parameters.CommonTestData;
-import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-
class ParticipantHandlerTest {
private CommonTestData commonTestData = new CommonTestData();
@@ -48,11 +53,11 @@ class ParticipantHandlerTest {
@Test
void mockParticipantHandlerTest() {
- ParticipantHandler participantHandler = commonTestData.getMockParticipantHandler();
+ var participantHandler = commonTestData.getMockParticipantHandler();
assertNull(participantHandler.getParticipant(null, null));
assertEquals("org.onap.PM_CDS_Blueprint 1.0.1", participantHandler.getParticipantId().toString());
- ToscaConceptIdentifier id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
assertEquals(id, participantHandler.getParticipantId());
assertEquals(id, participantHandler.getParticipantType());
assertThat(participantHandler.getClElementDefinitionCommonProperties(id)).isEmpty();
@@ -61,27 +66,27 @@ class ParticipantHandlerTest {
@Test
void handleUpdateTest() {
- ParticipantParameters parameters = CommonTestData.getParticipantParameters();
- ControlLoopHandler controlLoopHander = commonTestData.getMockControlLoopHandler();
- ParticipantMessagePublisher publisher = new ParticipantMessagePublisher();
- ParticipantHandler emptyParticipantHandler =
+ var parameters = CommonTestData.getParticipantParameters();
+ var controlLoopHander = commonTestData.getMockControlLoopHandler();
+ var publisher = new ParticipantMessagePublisher();
+ var emptyParticipantHandler =
new ParticipantHandler(parameters, publisher, controlLoopHander);
- ParticipantUpdate participantUpdateMsg = new ParticipantUpdate();
+ var participantUpdateMsg = new ParticipantUpdate();
assertThatThrownBy(() ->
emptyParticipantHandler.handleParticipantUpdate(participantUpdateMsg))
.isInstanceOf(RuntimeException.class);
- ParticipantHandler participantHandler = commonTestData.getMockParticipantHandler();
- ToscaConceptIdentifier id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var participantHandler = commonTestData.getMockParticipantHandler();
+
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
participantUpdateMsg.setControlLoopId(id);
participantUpdateMsg.setParticipantId(id);
participantUpdateMsg.setParticipantType(id);
participantUpdateMsg.setMessageId(UUID.randomUUID());
participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000));
-
- ParticipantStatus heartbeatF = participantHandler.makeHeartbeat(false);
+ var heartbeatF = participantHandler.makeHeartbeat(false);
assertEquals(id, heartbeatF.getParticipantId());
assertEquals(ParticipantState.UNKNOWN, heartbeatF.getParticipantStatistics().getState());
assertThat(heartbeatF.getControlLoopInfoList()).isEmpty();
@@ -89,30 +94,83 @@ class ParticipantHandlerTest {
participantHandler.handleParticipantUpdate(participantUpdateMsg);
assertThat(participantHandler.getClElementDefinitionCommonProperties(id)).isEmpty();
- ParticipantStatus heartbeatT = participantHandler.makeHeartbeat(true);
+ var heartbeatT = participantHandler.makeHeartbeat(true);
assertEquals(id, heartbeatT.getParticipantId());
assertEquals(ParticipantState.TERMINATED, heartbeatT.getParticipantStatistics().getState());
assertThat(heartbeatT.getParticipantDefinitionUpdates()).isNotEmpty();
assertEquals(id, heartbeatT.getParticipantDefinitionUpdates().get(0).getParticipantId());
+ var pum = setListParticipantDefinition(participantUpdateMsg);
+ participantHandler.handleParticipantUpdate(pum);
+ var heartbeatTAfterUpdate = participantHandler.makeHeartbeat(true);
+ assertEquals(id, heartbeatTAfterUpdate.getParticipantId());
+ assertEquals(ParticipantState.PASSIVE, heartbeatTAfterUpdate.getParticipantStatistics().getState());
+
+ }
+
+ 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);
+ return participantUpdateMsg;
}
@Test
void handleParticipantTest() {
- ParticipantHandler participantHandler = commonTestData.getMockParticipantHandler();
- ToscaConceptIdentifier id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- Participant p = participantHandler.getParticipant(id.getName(), id.getVersion());
+ var participantHandler = commonTestData.getMockParticipantHandler();
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var p = participantHandler.getParticipant(id.getName(), id.getVersion());
assertEquals(ParticipantState.UNKNOWN, p.getParticipantState());
participantHandler.updateParticipantState(id, ParticipantState.PASSIVE);
- Participant p2 = participantHandler.getParticipant(id.getName(), id.getVersion());
+ var p2 = participantHandler.getParticipant(id.getName(), id.getVersion());
assertEquals(ParticipantState.PASSIVE, p2.getParticipantState());
- ParticipantRegisterAck participantRegisterAckMsg = new ParticipantRegisterAck();
+ var participantRegisterAckMsg = new ParticipantRegisterAck();
participantRegisterAckMsg.setState(ParticipantState.TERMINATED);
participantHandler.handleParticipantRegisterAck(participantRegisterAckMsg);
assertEquals(ParticipantHealthStatus.HEALTHY, participantHandler.makeHeartbeat(false).getHealthStatus());
+ var emptyid = new ToscaConceptIdentifier("", ID_VERSION);
+ assertNull(participantHandler.updateParticipantState(emptyid, ParticipantState.PASSIVE));
+
+ var sameid = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var participant = participantHandler.updateParticipantState(sameid, ParticipantState.PASSIVE);
+ assertEquals(participant.getDefinition(), sameid);
+
+ }
+
+ @Test
+ void checkAppliesTo() {
+ var participantHandler = commonTestData.getMockParticipantHandler();
+ var participantAckMsg =
+ new ParticipantAckMessage(ParticipantMessageType.CONTROL_LOOP_UPDATE);
+ assertTrue(participantHandler.appliesTo(participantAckMsg));
+
+ var participantMsg =
+ new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATUS);
+ assertTrue(participantHandler.appliesTo(participantMsg));
+
+ var emptyid = new ToscaConceptIdentifier("", ID_VERSION);
+ participantMsg.setParticipantType(emptyid);
+ assertFalse(participantHandler.appliesTo(participantMsg));
+
+ }
+
+ @Test
+ void getControlLoopInfoListTest() throws CoderException {
+ var participantHandler = commonTestData.getParticipantHandlerControlLoops();
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ participantHandler.sendHeartbeat();
+ assertEquals(id, participantHandler.makeHeartbeat(false)
+ .getControlLoopInfoList()
+ .get(0)
+ .getControlLoopId());
+
}
}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
index af88b5a8a..43f3c8e2b 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java
@@ -20,18 +20,28 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.main.parameters;
+import java.io.File;
+import java.time.Instant;
import java.util.Arrays;
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.controlloop.models.controlloop.concepts.ClElementStatistics;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregisterAck;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ControlLoopHandler;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.DummyParticipantParameters;
import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters;
-import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
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;
@@ -129,7 +139,7 @@ public class CommonTestData {
* @return topic parameters
*/
public static TopicParameters getTopicParams() {
- final TopicParameters topicParams = new TopicParameters();
+ final var topicParams = new TopicParameters();
topicParams.setTopic("POLICY-CLRUNTIME-PARTICIPANT");
topicParams.setTopicCommInfrastructure("dmaap");
topicParams.setServers(Arrays.asList("localhost"));
@@ -152,8 +162,7 @@ public class CommonTestData {
*/
private ParticipantMessagePublisher getParticipantMessagePublisher() {
synchronized (lockit) {
- ParticipantMessagePublisher participantMessagePublisher =
- new ParticipantMessagePublisher();
+ var participantMessagePublisher = new ParticipantMessagePublisher();
participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
return participantMessagePublisher;
}
@@ -176,12 +185,89 @@ public class CommonTestData {
* @return participant Handler
*/
public ParticipantHandler getMockParticipantHandler() {
- ParticipantParameters parameters = getParticipantParameters();
- ControlLoopHandler controlLoopHander = getMockControlLoopHandler();
- ParticipantMessagePublisher publisher = new ParticipantMessagePublisher();
+ var parameters = getParticipantParameters();
+ var controlLoopHandler = getMockControlLoopHandler();
+ var publisher = new ParticipantMessagePublisher();
publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
- ParticipantHandler participantHandler = new ParticipantHandler(parameters, publisher, controlLoopHander);
+ var participantHandler = new ParticipantHandler(parameters, publisher, controlLoopHandler);
return participantHandler;
}
+ /**
+ * Returns a mocked ParticipantHandler for test cases.
+ *
+ * @return participant Handler
+ *
+ * @throws CoderException if there is an error with .json file.
+ */
+ public ParticipantHandler getParticipantHandlerControlLoops() throws CoderException {
+ var controlLoopHandler = Mockito.mock(ControlLoopHandler.class);
+ Mockito.doReturn(getTestControlLoops()).when(controlLoopHandler).getControlLoops();
+ Mockito.doReturn(getTestControlLoopMap()).when(controlLoopHandler).getControlLoopMap();
+ var publisher = new ParticipantMessagePublisher();
+ publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
+ var parameters = getParticipantParameters();
+ var participantHandler = new ParticipantHandler(parameters, publisher, controlLoopHandler);
+ 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 ControlLoop for test cases.
+ *
+ * @return controlLoopMap
+ *
+ * @throws CoderException if there is an error with .json file.
+ */
+ public Map<ToscaConceptIdentifier, ControlLoop> getTestControlLoopMap() throws CoderException {
+ var controlLoops = getTestControlLoops();
+ var controlLoop = controlLoops.getControlLoopList().get(1);
+ var id = getParticipantId();
+ Map<ToscaConceptIdentifier, ControlLoop> controlLoopMap = new LinkedHashMap<>();
+ controlLoopMap.put(id, controlLoop);
+ return controlLoopMap;
+ }
+
+ /**
+ * Returns List of ControlLoop for test cases.
+ *
+ * @return ControlLoops
+ *
+ * @throws CoderException if there is an error with .json file.
+ */
+ public ControlLoops getTestControlLoops() throws CoderException {
+ return new StandardCoder()
+ .decode(new File("src/test/resources/providers/TestControlLoops.json"), ControlLoops.class);
+ }
+
+ /**
+ * Returns a map for a elementsOnThisParticipant for test cases.
+ *
+ * @param uuid UUID and id ToscaConceptIdentifier
+ * @return a map suitable for elementsOnThisParticipant
+ */
+ public Map<UUID, ControlLoopElement> setControlLoopElementTest(UUID uuid, ToscaConceptIdentifier id) {
+ var clElement = new ControlLoopElement();
+ clElement.setId(uuid);
+ clElement.setParticipantId(id);
+ clElement.setDefinition(id);
+ clElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
+
+ var clElementStatistics = new ClElementStatistics();
+ clElementStatistics.setParticipantId(id);
+ clElementStatistics.setControlLoopState(ControlLoopState.UNINITIALISED);
+ clElementStatistics.setTimeStamp(Instant.now());
+
+ clElement.setClElementStatistics(clElementStatistics);
+
+ Map<UUID, ControlLoopElement> elementsOnThisParticipant = new LinkedHashMap<>();
+ elementsOnThisParticipant.put(uuid, clElement);
+ return elementsOnThisParticipant;
+ }
+
}
diff --git a/participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json b/participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json
new file mode 100644
index 000000000..fedda9600
--- /dev/null
+++ b/participant/participant-intermediary/src/test/resources/providers/TestControlLoops.json
@@ -0,0 +1,142 @@
+{
+ "controlLoopList": [
+ {
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.0.0"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "elements": {
+ "709c62b3-8918-41b9-a747-e21eb79c6c20": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c20",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant",
+ "version": "2.3.4"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "DCAE Control Loop Element for the PMSH instance 0 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c21": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c21",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Monitoring Policy Control Loop Element for the PMSH instance 0 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c22": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c22",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Operational Policy Control Loop Element for the PMSH instance 0 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c23": {
+ "id": "709c62b3-8918-41b9-a747-d21eb79c6c23",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant",
+ "version": "2.2.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "CDS Control Loop Element for the PMSH instance 0 control loop"
+ }
+ },
+ "name": "PMSHInstance0",
+ "version": "1.0.1",
+ "description": "PMSH control loop instance 0"
+ },
+ {
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.0.0"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "elements": {
+ "709c62b3-8918-41b9-a747-e21eb79c6c24": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c24",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant",
+ "version": "2.3.4"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "DCAE Control Loop Element for the PMSH instance 1 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c25": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c25",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Monitoring Policy Control Loop Element for the PMSH instance 1 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c26": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c26",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant",
+ "version": "2.3.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "Operational Policy Control Loop Element for the PMSH instance 1 control loop"
+ },
+ "709c62b3-8918-41b9-a747-e21eb79c6c27": {
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c27",
+ "definition": {
+ "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement",
+ "version": "1.2.3"
+ },
+ "participantType": {
+ "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant",
+ "version": "2.2.1"
+ },
+ "state": "UNINITIALISED",
+ "orderedState": "UNINITIALISED",
+ "description": "CDS Control Loop Element for the PMSH instance 1 control loop"
+ }
+ },
+ "name": "PMSHInstance1",
+ "version": "1.0.1",
+ "description": "PMSH control loop instance 1"
+ }
+ ]
+}