2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2023 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.acm.participant.intermediary.comm;
23 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertFalse;
26 import static org.junit.jupiter.api.Assertions.assertThrows;
27 import static org.mockito.Mockito.mock;
29 import java.util.Collections;
30 import java.util.List;
31 import org.junit.jupiter.api.Test;
32 import org.mockito.Mockito;
33 import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler;
34 import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
35 import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
36 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
37 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
38 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
39 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck;
40 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
41 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
42 import org.onap.policy.common.endpoints.event.comm.TopicSink;
43 import org.onap.policy.common.utils.coder.CoderException;
45 class ParticipantCommTest {
48 void participantReqTest() throws CoderException {
49 var participantHandler = mock(ParticipantHandler.class);
51 var participantRegisterAckListener = new ParticipantRegisterAckListener(participantHandler);
52 assertEquals(ParticipantMessageType.PARTICIPANT_REGISTER_ACK.name(), participantRegisterAckListener.getType());
54 var participantStatusReqListener = new ParticipantStatusReqListener(participantHandler);
55 assertEquals(ParticipantMessageType.PARTICIPANT_STATUS_REQ.name(), participantStatusReqListener.getType());
57 var participantDeregisterAckListener = new ParticipantDeregisterAckListener(participantHandler);
58 assertEquals(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK.name(),
59 participantDeregisterAckListener.getType());
61 var participantPrimeListener = new ParticipantPrimeListener(participantHandler);
62 assertEquals(ParticipantMessageType.PARTICIPANT_PRIME.name(), participantPrimeListener.getType());
64 var acPropertyUpdateListener = new AcPropertyUpdateListener(participantHandler);
65 assertEquals(ParticipantMessageType.PROPERTIES_UPDATE.name(), acPropertyUpdateListener.getType());
67 var automationCompositionUpdateListener = new AutomationCompositionDeployListener(participantHandler);
68 assertEquals(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY.name(),
69 automationCompositionUpdateListener.getType());
71 var automationCompositionStateChangeListener = new AutomationCompositionStateChangeListener(participantHandler);
72 assertEquals(ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE.name(),
73 automationCompositionStateChangeListener.getType());
77 void participantMessagePublisherTest() {
78 var publisher = new ParticipantMessagePublisher();
79 publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
80 var participantStatus = new ParticipantStatus();
81 assertDoesNotThrow(() -> publisher.sendParticipantStatus(participantStatus));
83 assertDoesNotThrow(() -> publisher.sendHeartbeat(participantStatus));
85 var participantRegister = new ParticipantRegister();
86 assertDoesNotThrow(() -> publisher.sendParticipantRegister(participantRegister));
88 var participantDeregister = new ParticipantDeregister();
89 assertDoesNotThrow(() -> publisher.sendParticipantDeregister(participantDeregister));
91 var participantPrimeAck = new ParticipantPrimeAck();
92 assertDoesNotThrow(() -> publisher.sendParticipantPrimeAck(participantPrimeAck));
94 var automationCompositionAck = mock(AutomationCompositionDeployAck.class);
95 assertDoesNotThrow(() -> publisher.sendAutomationCompositionAck(automationCompositionAck));
99 void participantMessagePublisherExceptionsTest() {
100 var publisher = new ParticipantMessagePublisher();
102 var participantStatus = new ParticipantStatus();
103 assertThrows(AutomationCompositionRuntimeException.class,
104 () -> publisher.sendParticipantStatus(participantStatus));
105 assertThrows(AutomationCompositionRuntimeException.class, () -> publisher.sendHeartbeat(participantStatus));
107 var participantRegister = new ParticipantRegister();
108 assertThrows(AutomationCompositionRuntimeException.class,
109 () -> publisher.sendParticipantRegister(participantRegister));
111 var participantDeregister = new ParticipantDeregister();
112 assertThrows(AutomationCompositionRuntimeException.class,
113 () -> publisher.sendParticipantDeregister(participantDeregister));
115 var automationCompositionAck = mock(AutomationCompositionDeployAck.class);
116 assertThrows(AutomationCompositionRuntimeException.class,
117 () -> publisher.sendAutomationCompositionAck(automationCompositionAck));
119 List<TopicSink> emptyList = Collections.emptyList();
120 assertThrows(IllegalArgumentException.class, () -> publisher.active(emptyList));
126 void messageSenderTest() throws CoderException {
127 var participantHandler = mock(ParticipantHandler.class);
128 var participantParameters = CommonTestData.getParticipantParameters();
129 var messageSender = new MessageSender(participantHandler, participantParameters);
131 assertFalse(messageSender.makeTimerPool().isTerminated());
132 messageSender.close();