aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-intermediary/src
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 /participant/participant-intermediary/src
parentf0a58426aa87795d4fa29eedb5bf2c14f5f6896f (diff)
Code coverage clamp
Issue-ID: POLICY-3452 Change-Id: I7ee191e590689e42822614d79a398012c454be42 Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'participant/participant-intermediary/src')
-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
2 files changed, 46 insertions, 6 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)));
}
}
}