2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2024 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.clamp.acm.participant.policy.endtoend;
24 import static org.assertj.core.api.Assertions.assertThatCode;
26 import java.time.Instant;
27 import java.util.Collections;
28 import java.util.UUID;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.extension.ExtendWith;
31 import org.mockito.Mockito;
32 import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantDeregisterAckListener;
33 import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher;
34 import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantPrimeListener;
35 import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantRegisterAckListener;
36 import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler;
37 import org.onap.policy.clamp.acm.participant.policy.main.parameters.CommonTestData;
38 import org.onap.policy.clamp.acm.participant.policy.main.utils.TestListenerUtils;
39 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantDeregister;
40 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantDeregisterAck;
41 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantPrimeAck;
42 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRegister;
43 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRegisterAck;
44 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
45 import org.onap.policy.common.endpoints.event.comm.TopicSink;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.boot.test.context.SpringBootTest;
48 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
49 import org.springframework.test.context.ActiveProfiles;
50 import org.springframework.test.context.junit.jupiter.SpringExtension;
52 @ExtendWith(SpringExtension.class)
53 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
54 @ActiveProfiles("test")
55 class ParticipantMessagesTest {
57 private static final Object lockit = new Object();
58 private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
59 private static final String TOPIC = "my-topic";
62 private ParticipantHandler participantHandler;
65 void testSendParticipantRegisterMessage() {
66 final var participantRegisterMsg = new ParticipantRegister();
67 participantRegisterMsg.setParticipantId(CommonTestData.getParticipantId());
68 participantRegisterMsg.setTimestamp(Instant.now());
70 synchronized (lockit) {
71 var participantMessagePublisher = new ParticipantMessagePublisher();
72 participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
73 assertThatCode(() -> participantMessagePublisher.sendParticipantRegister(participantRegisterMsg))
74 .doesNotThrowAnyException();
79 void testReceiveParticipantRegisterAckMessage() {
80 final var participantRegisterAckMsg = new ParticipantRegisterAck();
81 participantRegisterAckMsg.setMessage("ParticipantRegisterAck message");
82 participantRegisterAckMsg.setResponseTo(UUID.randomUUID());
83 participantRegisterAckMsg.setResult(true);
85 synchronized (lockit) {
86 var participantRegisterAckListener = new ParticipantRegisterAckListener(participantHandler);
87 assertThatCode(() -> participantRegisterAckListener.onTopicEvent(INFRA, TOPIC, null,
88 participantRegisterAckMsg)).doesNotThrowAnyException();
93 void testSendParticipantDeregisterMessage() {
94 final var participantDeregisterMsg = new ParticipantDeregister();
95 participantDeregisterMsg.setParticipantId(CommonTestData.getParticipantId());
96 participantDeregisterMsg.setTimestamp(Instant.now());
98 synchronized (lockit) {
99 var participantMessagePublisher = new ParticipantMessagePublisher();
100 participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
101 assertThatCode(() -> participantMessagePublisher.sendParticipantDeregister(participantDeregisterMsg))
102 .doesNotThrowAnyException();
107 void testReceiveParticipantDeregisterAckMessage() {
108 final var participantDeregisterAckMsg = new ParticipantDeregisterAck();
109 participantDeregisterAckMsg.setMessage("ParticipantDeregisterAck message");
110 participantDeregisterAckMsg.setResponseTo(UUID.randomUUID());
111 participantDeregisterAckMsg.setResult(true);
113 synchronized (lockit) {
114 var participantDeregisterAckListener = new ParticipantDeregisterAckListener(participantHandler);
115 assertThatCode(() -> participantDeregisterAckListener.onTopicEvent(INFRA, TOPIC, null,
116 participantDeregisterAckMsg)).doesNotThrowAnyException();
121 void testReceiveParticipantUpdateMessage() {
122 var participantPrimeMsg = TestListenerUtils.createParticipantPrimeMsg();
124 synchronized (lockit) {
125 var participantPrimeListener = new ParticipantPrimeListener(participantHandler);
126 assertThatCode(() -> participantPrimeListener.onTopicEvent(INFRA, TOPIC, null, participantPrimeMsg))
127 .doesNotThrowAnyException();
132 void testSendParticipantPrimeAckMessage() {
133 final var participantPrimeAckMsg = new ParticipantPrimeAck();
134 participantPrimeAckMsg.setMessage("ParticipantPrimeAck message");
135 participantPrimeAckMsg.setResponseTo(UUID.randomUUID());
136 participantPrimeAckMsg.setResult(true);
138 synchronized (lockit) {
139 var participantMessagePublisher = new ParticipantMessagePublisher();
140 participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
141 assertThatCode(() -> participantMessagePublisher.sendParticipantPrimeAck(participantPrimeAckMsg))
142 .doesNotThrowAnyException();