2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.participant.intermediary.comm;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.jupiter.api.Assertions.assertThrows;
27 import java.util.Collections;
28 import java.util.List;
29 import org.junit.jupiter.api.Test;
30 import org.mockito.Mockito;
31 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
32 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck;
33 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister;
34 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType;
35 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister;
36 import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus;
37 import org.onap.policy.clamp.controlloop.participant.intermediary.main.parameters.CommonTestData;
38 import org.onap.policy.common.endpoints.event.comm.TopicSink;
39 import org.onap.policy.common.utils.coder.CoderException;
41 class ParticipantCommTest {
43 private CommonTestData commonTestData = new CommonTestData();
46 void participantReqTest() throws CoderException {
47 var participantHandler = commonTestData.getParticipantHandlerControlLoops();
49 var participantRegisterAckListener = new ParticipantRegisterAckListener(participantHandler);
50 assertEquals(ParticipantMessageType.PARTICIPANT_REGISTER_ACK.name(),
51 participantRegisterAckListener.getType());
53 var participantStatusReqListener = new ParticipantStatusReqListener(participantHandler);
54 assertEquals(ParticipantMessageType.PARTICIPANT_STATUS_REQ.name(),
55 participantStatusReqListener.getType());
57 var participantDeregisterAckListener = new ParticipantDeregisterAckListener(participantHandler);
58 assertEquals(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK.name(),
59 participantDeregisterAckListener.getType());
61 var participantUpdateListener = new ParticipantUpdateListener(participantHandler);
62 assertEquals(ParticipantMessageType.PARTICIPANT_UPDATE.name(),
63 participantUpdateListener.getType());
65 var controlLoopUpdateListener = new ControlLoopUpdateListener(participantHandler);
66 assertEquals(ParticipantMessageType.CONTROL_LOOP_UPDATE.name(),
67 controlLoopUpdateListener.getType());
69 var controlLoopStateChangeListener = new ControlLoopStateChangeListener(participantHandler);
70 assertEquals(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE.name(),
71 controlLoopStateChangeListener.getType());
75 void participantMessagePublisherExceptionsTest() {
76 var participantMessagePublisher = new ParticipantMessagePublisher();
78 var participantStatus = Mockito.mock(ParticipantStatus.class);
79 assertThrows(ControlLoopRuntimeException.class, () -> {
80 participantMessagePublisher.sendParticipantStatus(participantStatus);
82 assertThrows(ControlLoopRuntimeException.class, () -> {
83 participantMessagePublisher.sendHeartbeat(participantStatus);
86 var participantRegister = Mockito.mock(ParticipantRegister.class);
87 assertThrows(ControlLoopRuntimeException.class, () -> {
88 participantMessagePublisher.sendParticipantRegister(participantRegister);
91 var participantDeregister = Mockito.mock(ParticipantDeregister.class);
92 assertThrows(ControlLoopRuntimeException.class, () -> {
93 participantMessagePublisher.sendParticipantDeregister(participantDeregister);
96 var controlLoopAck = Mockito.mock(ControlLoopAck.class);
97 assertThrows(ControlLoopRuntimeException.class, () -> {
98 participantMessagePublisher.sendControlLoopAck(controlLoopAck);
101 List<TopicSink> emptyList = Collections.emptyList();
102 assertThrows(IllegalArgumentException.class, () -> {
103 participantMessagePublisher.active(emptyList);
106 participantMessagePublisher.stop();
110 void messageSenderTest() throws CoderException {
111 var participantHandler = commonTestData.getParticipantHandlerControlLoops();
112 var participantParameters = CommonTestData.getParticipantParameters();
113 var messageSender = new MessageSender(participantHandler, participantParameters);
115 assertFalse(messageSender.makeTimerPool().isTerminated());
116 messageSender.close();