summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2021-11-11 12:04:23 +0000
committerlapentafd <francesco.lapenta@est.tech>2021-11-11 12:04:29 +0000
commitf10ebc63cc72caa9c7cebd7bd1636305b343611d (patch)
treeab451b9d4bdaacaba2dae027737f623aeb91a8ad
parente920b54e30c58f117d0c021ca82301900c9d5541 (diff)
Code Coverage Clamp Intermediary
Issue-ID: POLICY-3452 Change-Id: I388a1868fcaa95549f0d48ffb6713ab2526e2ed5 Signed-off-by: lapentafd <francesco.lapenta@est.tech>
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java102
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantCommTest.java119
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandlerTest.java59
-rw-r--r--participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/main/parameters/CommonTestData.java20
4 files changed, 282 insertions, 18 deletions
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
new file mode 100644
index 000000000..b08e796b7
--- /dev/null
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
@@ -0,0 +1,102 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.participant.intermediary.api.impl;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.time.Instant;
+import java.util.UUID;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics;
+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.ParticipantHealthStatus;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
+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;
+
+class ParticipantIntermediaryApiImplTest {
+
+ private CommonTestData commonTestData = new CommonTestData();
+ private static final String ID_NAME = "org.onap.PM_CDS_Blueprint";
+ private static final String ID_VERSION = "1.0.1";
+
+ private static final String ID_NAME_E = "org.onap.domain.pmsh.PMSHControlLoopDefinition";
+ private static final String ID_VERSION_E = "1.0.0";
+
+ private static final String ID_NAME_TYPE = "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant";
+ private static final String ID_VERSION_TYPE = "2.3.4";
+
+ @Test
+ void mockParticipantIntermediaryApiImplTest() throws CoderException {
+ var uuid = UUID.randomUUID();
+ var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ var participantHandler = commonTestData.getParticipantHandlerControlLoops();
+ var controlLoopHandler = commonTestData.setTestControlLoopHandler(id, uuid);
+ var apiImpl = new ParticipantIntermediaryApiImpl(participantHandler, controlLoopHandler);
+ var clElementListener = Mockito.mock(ControlLoopElementListener.class);
+ apiImpl.registerControlLoopElementListener(clElementListener);
+
+ assertNotNull(apiImpl.getControlLoops(id.getName(), id.getVersion()));
+ assertThat(apiImpl.getClElementDefinitionCommonProperties(id)).isEmpty();
+
+ var participantStatistics = new ParticipantStatistics();
+ participantStatistics.setParticipantId(id);
+ participantStatistics.setTimeStamp(Instant.ofEpochMilli(123456L));
+ participantStatistics.setState(ParticipantState.PASSIVE);
+ participantStatistics.setHealthStatus(ParticipantHealthStatus.HEALTHY);
+ apiImpl.updateParticipantStatistics(participantStatistics);
+
+ var participants = apiImpl.getParticipants(id.getName(), id.getVersion());
+ assertEquals(ParticipantState.UNKNOWN, participants.get(0).getParticipantState());
+
+ var participant = apiImpl.updateParticipantState(id, ParticipantState.TERMINATED);
+ assertEquals(ParticipantState.TERMINATED, participant.getParticipantState());
+
+ var elements = apiImpl.getControlLoopElements(ID_NAME_E, ID_VERSION_E);
+ assertFalse(elements.containsKey(uuid));
+
+ var element = apiImpl.getControlLoopElement(elements.keySet().iterator().next());
+ var idType = new ToscaConceptIdentifier(ID_NAME_TYPE, ID_VERSION_TYPE);
+ assertEquals(idType, element.getParticipantType());
+
+ var clElementStatistics = new ClElementStatistics();
+ var controlLoopId = new ToscaConceptIdentifier("defName", "0.0.1");
+ clElementStatistics.setParticipantId(controlLoopId);
+ clElementStatistics.setControlLoopState(ControlLoopState.RUNNING);
+ clElementStatistics.setTimeStamp(Instant.now());
+
+ apiImpl.updateControlLoopElementStatistics(uuid, clElementStatistics);
+ var clElement = apiImpl.updateControlLoopElementState(id, uuid, ControlLoopOrderedState.UNINITIALISED,
+ ControlLoopState.PASSIVE, ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
+ assertEquals(ControlLoopOrderedState.UNINITIALISED, clElement.getOrderedState());
+ assertEquals(uuid, clElement.getId());
+
+ }
+}
diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantCommTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantCommTest.java
new file mode 100644
index 000000000..a40a41853
--- /dev/null
+++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/ParticipantCommTest.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.Collections;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
+import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.controlloop.participant.intermediary.main.parameters.CommonTestData;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.utils.coder.CoderException;
+
+class ParticipantCommTest {
+
+ private CommonTestData commonTestData = new CommonTestData();
+
+ @Test
+ void participantReqTest() throws CoderException {
+ var participantHandler = commonTestData.getParticipantHandlerControlLoops();
+
+ var participantRegisterAckListener = new ParticipantRegisterAckListener(participantHandler);
+ assertEquals(ParticipantMessageType.PARTICIPANT_REGISTER_ACK.name(),
+ participantRegisterAckListener.getType());
+
+ var participantStatusReqListener = new ParticipantStatusReqListener(participantHandler);
+ assertEquals(ParticipantMessageType.PARTICIPANT_STATUS_REQ.name(),
+ participantStatusReqListener.getType());
+
+ var participantDeregisterAckListener = new ParticipantDeregisterAckListener(participantHandler);
+ assertEquals(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK.name(),
+ participantDeregisterAckListener.getType());
+
+ var participantUpdateListener = new ParticipantUpdateListener(participantHandler);
+ assertEquals(ParticipantMessageType.PARTICIPANT_UPDATE.name(),
+ participantUpdateListener.getType());
+
+ var controlLoopUpdateListener = new ControlLoopUpdateListener(participantHandler);
+ assertEquals(ParticipantMessageType.CONTROL_LOOP_UPDATE.name(),
+ controlLoopUpdateListener.getType());
+
+ var controlLoopStateChangeListener = new ControlLoopStateChangeListener(participantHandler);
+ assertEquals(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE.name(),
+ controlLoopStateChangeListener.getType());
+ }
+
+ @Test
+ void participantMessagePublisherExceptionsTest() {
+ var participantMessagePublisher = new ParticipantMessagePublisher();
+
+ var participantStatus = Mockito.mock(ParticipantStatus.class);
+ assertThrows(ControlLoopRuntimeException.class, () -> {
+ participantMessagePublisher.sendParticipantStatus(participantStatus);
+ });
+ assertThrows(ControlLoopRuntimeException.class, () -> {
+ participantMessagePublisher.sendHeartbeat(participantStatus);
+ });
+
+ var participantRegister = Mockito.mock(ParticipantRegister.class);
+ assertThrows(ControlLoopRuntimeException.class, () -> {
+ participantMessagePublisher.sendParticipantRegister(participantRegister);
+ });
+
+ var participantDeregister = Mockito.mock(ParticipantDeregister.class);
+ assertThrows(ControlLoopRuntimeException.class, () -> {
+ participantMessagePublisher.sendParticipantDeregister(participantDeregister);
+ });
+
+ var controlLoopAck = Mockito.mock(ControlLoopAck.class);
+ assertThrows(ControlLoopRuntimeException.class, () -> {
+ participantMessagePublisher.sendControlLoopAck(controlLoopAck);
+ });
+
+ List<TopicSink> emptyList = Collections.emptyList();
+ assertThrows(IllegalArgumentException.class, () -> {
+ participantMessagePublisher.active(emptyList);
+ });
+
+ participantMessagePublisher.stop();
+ }
+
+ @Test
+ void messageSenderTest() throws CoderException {
+ var participantHandler = commonTestData.getParticipantHandlerControlLoops();
+ var participantParameters = CommonTestData.getParticipantParameters();
+ var messageSender = new MessageSender(participantHandler, participantParameters);
+ messageSender.run();
+ assertFalse(messageSender.makeTimerPool().isTerminated());
+ messageSender.close();
+ }
+
+}
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 676747d04..5f24db7b2 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
@@ -100,7 +100,7 @@ class ControlLoopHandlerTest {
var uuid = UUID.randomUUID();
var id = CommonTestData.getParticipantId();
- var clh = setTestControlLoopHandler(id, uuid);
+ var clh = commonTestData.setTestControlLoopHandler(id, uuid);
var key = clh.getElementsOnThisParticipant().keySet().iterator().next();
var value = clh.getElementsOnThisParticipant().get(key);
assertEquals(ControlLoopState.UNINITIALISED, value.getState());
@@ -123,15 +123,9 @@ class ControlLoopHandlerTest {
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 stateChange = getStateChange(id, uuid, ControlLoopOrderedState.RUNNING);
- var clh = setTestControlLoopHandler(id, uuid);
+ var clh = commonTestData.setTestControlLoopHandler(id, uuid);
clh.handleControlLoopStateChange(stateChange, List.of());
var newid = new ToscaConceptIdentifier("id", "1.2.3");
stateChange.setControlLoopId(newid);
@@ -150,20 +144,49 @@ class ControlLoopHandlerTest {
assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
updateMsg.setStartPhase(1);
assertDoesNotThrow(() -> clh.handleControlLoopUpdate(updateMsg, clElementDefinitions));
+ assertThat(clh.getClElementInstanceProperties(uuid)).isEmpty();
}
- private ControlLoopHandler setTestControlLoopHandler(ToscaConceptIdentifier id, UUID uuid) throws CoderException {
- var clh = commonTestData.getMockControlLoopHandler();
+ @Test
+ void controlLoopStateChangeUninitialisedTest() throws CoderException {
+ var uuid = UUID.randomUUID();
+ var id = CommonTestData.getParticipantId();
- var key = commonTestData.getTestControlLoopMap().keySet().iterator().next();
- var value = commonTestData.getTestControlLoopMap().get(key);
- clh.getControlLoopMap().put(key, value);
+ var stateChangeUninitialised = getStateChange(id, uuid, ControlLoopOrderedState.UNINITIALISED);
- var keyElem = commonTestData.setControlLoopElementTest(uuid, id).keySet().iterator().next();
- var valueElem = commonTestData.setControlLoopElementTest(uuid, id).get(keyElem);
- clh.getElementsOnThisParticipant().put(keyElem, valueElem);
+ var clh = commonTestData.setTestControlLoopHandler(id, uuid);
+ clh.handleControlLoopStateChange(stateChangeUninitialised, List.of());
+ var newid = new ToscaConceptIdentifier("id", "1.2.3");
+ stateChangeUninitialised.setControlLoopId(newid);
+ stateChangeUninitialised.setParticipantId(newid);
+ assertDoesNotThrow(() -> clh.handleControlLoopStateChange(stateChangeUninitialised, List.of()));
+ }
- return clh;
+ @Test
+ void controlLoopStateChangePassiveTest() throws CoderException {
+ var uuid = UUID.randomUUID();
+ var id = CommonTestData.getParticipantId();
+
+ var stateChangePassive = getStateChange(id, uuid, ControlLoopOrderedState.PASSIVE);
+
+ var clh = commonTestData.setTestControlLoopHandler(id, uuid);
+ clh.handleControlLoopStateChange(stateChangePassive, List.of());
+ var newid = new ToscaConceptIdentifier("id", "1.2.3");
+ stateChangePassive.setControlLoopId(newid);
+ stateChangePassive.setParticipantId(newid);
+ assertDoesNotThrow(() -> clh.handleControlLoopStateChange(stateChangePassive, List.of()));
+ }
+
+
+ private ControlLoopStateChange getStateChange(ToscaConceptIdentifier id, UUID uuid, ControlLoopOrderedState state) {
+ var stateChange = new ControlLoopStateChange();
+ stateChange.setControlLoopId(id);
+ stateChange.setParticipantId(id);
+ stateChange.setMessageId(uuid);
+ stateChange.setOrderedState(state);
+ stateChange.setCurrentState(ControlLoopState.UNINITIALISED);
+ stateChange.setTimestamp(Instant.ofEpochMilli(3000));
+ return stateChange;
}
}
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 43f3c8e2b..9bbf8964c 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
@@ -270,4 +270,24 @@ public class CommonTestData {
return elementsOnThisParticipant;
}
+ /**
+ * Returns a ControlLoopHandler with elements on the id,uuid.
+ *
+ * @param id ToscaConceptIdentifier and uuid UUID
+ * @return a ControlLoopHander with elements
+ */
+ public ControlLoopHandler setTestControlLoopHandler(ToscaConceptIdentifier id, UUID uuid) throws CoderException {
+ var clh = getMockControlLoopHandler();
+
+ var key = getTestControlLoopMap().keySet().iterator().next();
+ var value = getTestControlLoopMap().get(key);
+ clh.getControlLoopMap().put(key, value);
+
+ var keyElem = setControlLoopElementTest(uuid, id).keySet().iterator().next();
+ var valueElem = setControlLoopElementTest(uuid, id).get(keyElem);
+ clh.getElementsOnThisParticipant().put(keyElem, valueElem);
+
+ return clh;
+ }
+
}