aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2021-11-22 19:40:39 +0000
committerlapentafd <francesco.lapenta@est.tech>2021-11-22 22:39:59 +0000
commit59376f8370c4a4de4dd34bf297a4fccf7149b27a (patch)
tree781e6d70c931d07a365e6018976b3077030896fc
parentf0a58426aa87795d4fa29eedb5bf2c14f5f6896f (diff)
Code coverage clamp
Issue-ID: POLICY-3452 Change-Id: I7ee191e590689e42822614d79a398012c454be42 Signed-off-by: lapentafd <francesco.lapenta@est.tech>
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java44
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivatorTest.java8
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java52
3 files changed, 86 insertions, 18 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 5f24db7b2..43b43e3bf 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
@@ -29,7 +29,6 @@ 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;
@@ -39,12 +38,14 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
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.controlloop.concepts.ParticipantUpdates;
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.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ExtendWith(SpringExtension.class)
@@ -108,6 +109,11 @@ class ControlLoopHandlerTest {
ControlLoopState.PASSIVE);
assertEquals(ControlLoopState.PASSIVE, value.getState());
+ clh.getControlLoopMap().values().iterator().next().getElements().putIfAbsent(key, value);
+ clh.updateControlLoopElementState(id, key, ControlLoopOrderedState.PASSIVE,
+ ControlLoopState.RUNNING);
+ assertEquals(ControlLoopState.RUNNING, value.getState());
+
var clElementStatistics = new ClElementStatistics();
clElementStatistics.setParticipantId(id);
clElementStatistics.setControlLoopState(ControlLoopState.RUNNING);
@@ -116,35 +122,63 @@ class ControlLoopHandlerTest {
assertNotEquals(uuid, value.getClElementStatistics().getId());
clh.updateControlLoopElementStatistics(uuid, clElementStatistics);
assertEquals(uuid, value.getClElementStatistics().getId());
+
+ clh.getElementsOnThisParticipant().remove(key, value);
+ clh.getControlLoopMap().values().iterator().next().getElements().clear();
+ assertNull(clh.updateControlLoopElementState(id, key, ControlLoopOrderedState.PASSIVE,
+ ControlLoopState.RUNNING));
+
}
@Test
void handleControlLoopUpdateExceptionTest() throws CoderException {
var uuid = UUID.randomUUID();
var id = CommonTestData.getParticipantId();
-
var stateChange = getStateChange(id, uuid, ControlLoopOrderedState.RUNNING);
-
var clh = commonTestData.setTestControlLoopHandler(id, uuid);
+ assertDoesNotThrow(() -> clh.handleControlLoopStateChange(mock(ControlLoopStateChange.class), List.of()));
+
clh.handleControlLoopStateChange(stateChange, List.of());
var newid = new ToscaConceptIdentifier("id", "1.2.3");
stateChange.setControlLoopId(newid);
stateChange.setParticipantId(newid);
assertDoesNotThrow(() -> clh.handleControlLoopStateChange(stateChange, List.of()));
- 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);
+ var clElementDefinitions = List.of(cld);
assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
updateMsg.setStartPhase(1);
assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
assertThat(clh.getClElementInstanceProperties(uuid)).isEmpty();
+
+ clh.getControlLoopMap().clear();
+ updateMsg.setStartPhase(0);
+ assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
+
+ updateMsg.setControlLoopId(new ToscaConceptIdentifier("new", "0.0.1"));
+ updateMsg.setParticipantUpdatesList(List.of(mock(ParticipantUpdates.class)));
+ assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
+
+ updateMsg.setStartPhase(1);
+ var participantUpdate = new ParticipantUpdates();
+ participantUpdate.setParticipantId(id);
+ var element = new ControlLoopElement();
+ element.setParticipantType(id);
+ element.setDefinition(id);
+ participantUpdate.setControlLoopElementList(List.of(element));
+ updateMsg.setParticipantUpdatesList(List.of(participantUpdate));
+
+ var cld2 = new ControlLoopElementDefinition();
+ cld2.setClElementDefinitionId(id);
+ cld2.setControlLoopElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
+ assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, List.of(cld2)));
+
}
@Test
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivatorTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivatorTest.java
index bbe0412ed..8c400c12f 100644
--- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivatorTest.java
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivatorTest.java
@@ -21,6 +21,7 @@
package org.onap.policy.clamp.controlloop.participant.intermediary.handler;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
+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;
@@ -40,6 +41,8 @@ import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.Par
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardCoderObject;
+import org.springframework.context.event.ContextClosedEvent;
+import org.springframework.context.event.ContextRefreshedEvent;
class IntermediaryActivatorTest {
private static final Coder CODER = new StandardCoder();
@@ -86,12 +89,15 @@ class IntermediaryActivatorTest {
activator.getMsgDispatcher().onTopicEvent(null, "msg", sco);
verify(listenerSecond, times(1)).onTopicEvent(any(), any(), any());
- activator.stop();
+ activator.close();
assertFalse(activator.isAlive());
// repeat stop - should throw an exception
assertThatIllegalStateException().isThrownBy(() -> activator.stop());
assertFalse(activator.isAlive());
+
+ assertDoesNotThrow(() -> activator.handleContextRefreshEvent(mock(ContextRefreshedEvent.class)));
+ assertDoesNotThrow(() -> activator.handleContextClosedEvent(mock(ContextClosedEvent.class)));
}
}
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
index a314b30a0..ece676a71 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java
@@ -73,7 +73,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
assertThatThrownBy(() -> handler.triggerControlLoopSupervision(List.of()))
.hasMessageMatching("The list of control loops for supervision is empty");
@@ -86,7 +86,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), controlLoopUpdatePublisher,
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
handler.triggerControlLoopSupervision(List.of(identifier));
@@ -95,12 +95,38 @@ class SupervisionHandlerTest {
}
@Test
+ void testTriggerControlLoopUninitialised() throws ControlLoopException, PfModelException, CoderException {
+ var controlLoopProvider = mock(ControlLoopProvider.class);
+ var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
+ var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class),
+ mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
+ mock(ParticipantDeregisterAckPublisher.class), controlLoopUpdatePublisher,
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.UNINITIALISED);
+
+ assertThatThrownBy(() -> handler.triggerControlLoopSupervision(List.of(identifier)))
+ .hasMessageMatching("Control loop is already in state UNINITIALISED");
+ }
+
+ @Test
+ void testTriggerControlLoopRunning() throws ControlLoopException, PfModelException, CoderException {
+ var controlLoopProvider = mock(ControlLoopProvider.class);
+ var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
+ var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class),
+ mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
+ mock(ParticipantDeregisterAckPublisher.class), controlLoopUpdatePublisher,
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.RUNNING);
+
+ assertThatThrownBy(() -> handler.triggerControlLoopSupervision(List.of(identifier)))
+ .hasMessageMatching("Control loop can't transition from state UNINITIALISED to state RUNNING");
+ }
+
+ @Test
void testHandleControlLoopStateChangeAckMessage() throws PfModelException, CoderException {
var controlLoopProvider = mock(ControlLoopProvider.class);
var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
var controlLoopAckMessage = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
controlLoopAckMessage.setControlLoopResultMap(Map.of());
controlLoopAckMessage.setControlLoopId(identifier);
@@ -121,7 +147,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
handler.handleControlLoopUpdateAckMessage(controlLoopAckMessage);
@@ -147,7 +173,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider,
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
participantDeregisterAckPublisher, mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
handler.handleParticipantMessage(participantDeregisterMessage);
@@ -171,7 +197,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider,
mock(MonitoringProvider.class), participantRegisterAckPublisher,
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
handler.handleParticipantMessage(participantRegisterMessage);
@@ -198,7 +224,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider,
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- mock(ParticipantUpdatePublisher.class));
+ mock(ParticipantUpdatePublisher.class), ControlLoopOrderedState.PASSIVE);
handler.handleParticipantMessage(participantUpdateAckMessage);
@@ -218,7 +244,8 @@ class SupervisionHandlerTest {
var monitoringProvider = mock(MonitoringProvider.class);
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider, monitoringProvider,
mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
- mock(ControlLoopUpdatePublisher.class), mock(ParticipantUpdatePublisher.class));
+ mock(ControlLoopUpdatePublisher.class), mock(ParticipantUpdatePublisher.class),
+ ControlLoopOrderedState.PASSIVE);
handler.handleParticipantMessage(participantStatusMessage);
verify(participantProvider).createParticipants(anyList());
@@ -231,7 +258,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- participantUpdatePublisher);
+ participantUpdatePublisher, ControlLoopOrderedState.PASSIVE);
handler.handleSendCommissionMessage(participantId.getName(), participantId.getVersion());
verify(participantUpdatePublisher).sendComissioningBroadcast(participantId.getName(),
@@ -244,7 +271,7 @@ class SupervisionHandlerTest {
var handler = createSupervisionHandler(mock(ControlLoopProvider.class), mock(ParticipantProvider.class),
mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class),
mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class),
- participantUpdatePublisher);
+ participantUpdatePublisher, ControlLoopOrderedState.PASSIVE);
handler.handleSendDeCommissionMessage();
verify(participantUpdatePublisher).sendDecomisioning();
@@ -255,11 +282,12 @@ class SupervisionHandlerTest {
ParticipantRegisterAckPublisher participantRegisterAckPublisher,
ParticipantDeregisterAckPublisher participantDeregisterAckPublisher,
ControlLoopUpdatePublisher controlLoopUpdatePublisher,
- ParticipantUpdatePublisher participantUpdatePublisher) throws PfModelException, CoderException {
+ ParticipantUpdatePublisher participantUpdatePublisher,
+ ControlLoopOrderedState orderedState) throws PfModelException, CoderException {
var controlLoopsCreate = InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Crud");
var controlLoop = controlLoopsCreate.getControlLoopList().get(0);
- controlLoop.setOrderedState(ControlLoopOrderedState.PASSIVE);
+ controlLoop.setOrderedState(orderedState);
var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);