2 * ============LICENSE_START=======================================================
3 * Copyright (C) 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.runtime.supervision;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
28 import java.util.Optional;
29 import java.util.UUID;
30 import org.junit.jupiter.api.Test;
31 import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher;
32 import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRegisterAckPublisher;
33 import org.onap.policy.clamp.models.acm.concepts.Participant;
34 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
35 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
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.clamp.models.acm.persistence.provider.ParticipantProvider;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
41 class SupervisionParticipantHandlerTest {
42 private static final ToscaConceptIdentifier PARTICIPANT_ID = new ToscaConceptIdentifier("ParticipantId", "1.0.0");
43 private static final ToscaConceptIdentifier PARTICIPANT_TYPE =
44 new ToscaConceptIdentifier("ParticipantType", "1.0.0");
47 void testHandleParticipantDeregister() {
48 var participant = new Participant();
49 participant.setName(PARTICIPANT_ID.getName());
50 participant.setVersion(PARTICIPANT_ID.getVersion());
51 participant.setParticipantType(PARTICIPANT_TYPE);
53 var participantProvider = mock(ParticipantProvider.class);
54 when(participantProvider.findParticipant(PARTICIPANT_ID)).thenReturn(Optional.of(participant));
56 var participantDeregisterMessage = new ParticipantDeregister();
57 participantDeregisterMessage.setMessageId(UUID.randomUUID());
58 participantDeregisterMessage.setParticipantId(PARTICIPANT_ID);
59 participantDeregisterMessage.setParticipantType(PARTICIPANT_TYPE);
60 var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
61 var handler = new SupervisionParticipantHandler(participantProvider,
62 mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher);
64 handler.handleParticipantMessage(participantDeregisterMessage);
66 verify(participantProvider).saveParticipant(any());
67 verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
71 void testHandleParticipantRegister() {
72 var participant = new Participant();
73 participant.setName(PARTICIPANT_ID.getName());
74 participant.setVersion(PARTICIPANT_ID.getVersion());
75 participant.setParticipantType(PARTICIPANT_TYPE);
77 var participantRegisterMessage = new ParticipantRegister();
78 participantRegisterMessage.setMessageId(UUID.randomUUID());
79 participantRegisterMessage.setParticipantId(PARTICIPANT_ID);
80 participantRegisterMessage.setParticipantType(PARTICIPANT_TYPE);
81 var participantProvider = mock(ParticipantProvider.class);
82 var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
83 var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher,
84 mock(ParticipantDeregisterAckPublisher.class));
86 handler.handleParticipantMessage(participantRegisterMessage);
88 verify(participantProvider).saveParticipant(any());
89 verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(), PARTICIPANT_ID,
94 void testHandleParticipantStatus() {
95 var participantStatusMessage = new ParticipantStatus();
96 participantStatusMessage.setParticipantId(PARTICIPANT_ID);
97 participantStatusMessage.setParticipantType(PARTICIPANT_TYPE);
98 participantStatusMessage.setState(ParticipantState.ON_LINE);
100 var participantProvider = mock(ParticipantProvider.class);
101 var handler = new SupervisionParticipantHandler(participantProvider,
102 mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class));
103 handler.handleParticipantMessage(participantStatusMessage);
105 verify(participantProvider).saveParticipant(any());