2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2022 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.assertEquals;
24 import static org.junit.jupiter.api.Assertions.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.acm.participant.intermediary.main.parameters.CommonTestData;
32 import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
33 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionAck;
34 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
35 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
36 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
37 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
38 import org.onap.policy.common.endpoints.event.comm.TopicSink;
39 import org.onap.policy.common.utils.coder.CoderException;
41 class ParticipantCommTest {
43 private final CommonTestData commonTestData = new CommonTestData();
46 void participantReqTest() throws CoderException {
47 var participantHandler = commonTestData.getParticipantHandlerAutomationCompositions();
49 var participantRegisterAckListener = new ParticipantRegisterAckListener(participantHandler);
50 assertEquals(ParticipantMessageType.PARTICIPANT_REGISTER_ACK.name(), participantRegisterAckListener.getType());
52 var participantStatusReqListener = new ParticipantStatusReqListener(participantHandler);
53 assertEquals(ParticipantMessageType.PARTICIPANT_STATUS_REQ.name(), participantStatusReqListener.getType());
55 var participantDeregisterAckListener = new ParticipantDeregisterAckListener(participantHandler);
56 assertEquals(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK.name(),
57 participantDeregisterAckListener.getType());
59 var participantUpdateListener = new ParticipantUpdateListener(participantHandler);
60 assertEquals(ParticipantMessageType.PARTICIPANT_UPDATE.name(), participantUpdateListener.getType());
62 var automationCompositionUpdateListener = new AutomationCompositionUpdateListener(participantHandler);
63 assertEquals(ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE.name(),
64 automationCompositionUpdateListener.getType());
66 var automationCompositionStateChangeListener = new AutomationCompositionStateChangeListener(participantHandler);
67 assertEquals(ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE.name(),
68 automationCompositionStateChangeListener.getType());
72 void participantMessagePublisherExceptionsTest() {
73 var participantMessagePublisher = new ParticipantMessagePublisher();
75 var participantStatus = Mockito.mock(ParticipantStatus.class);
76 assertThrows(AutomationCompositionRuntimeException.class,
77 () -> participantMessagePublisher.sendParticipantStatus(participantStatus));
78 assertThrows(AutomationCompositionRuntimeException.class,
79 () -> participantMessagePublisher.sendHeartbeat(participantStatus));
81 var participantRegister = Mockito.mock(ParticipantRegister.class);
82 assertThrows(AutomationCompositionRuntimeException.class,
83 () -> participantMessagePublisher.sendParticipantRegister(participantRegister));
85 var participantDeregister = Mockito.mock(ParticipantDeregister.class);
86 assertThrows(AutomationCompositionRuntimeException.class,
87 () -> participantMessagePublisher.sendParticipantDeregister(participantDeregister));
89 var automationCompositionAck = Mockito.mock(AutomationCompositionAck.class);
90 assertThrows(AutomationCompositionRuntimeException.class,
91 () -> participantMessagePublisher.sendAutomationCompositionAck(automationCompositionAck));
93 List<TopicSink> emptyList = Collections.emptyList();
94 assertThrows(IllegalArgumentException.class, () -> participantMessagePublisher.active(emptyList));
96 participantMessagePublisher.stop();
100 void messageSenderTest() throws CoderException {
101 var participantHandler = commonTestData.getParticipantHandlerAutomationCompositions();
102 var participantParameters = CommonTestData.getParticipantParameters();
103 var messageSender = new MessageSender(participantHandler, participantParameters);
105 assertFalse(messageSender.makeTimerPool().isTerminated());
106 messageSender.close();