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.ArrayList;
29 import java.util.Optional;
30 import java.util.UUID;
31 import org.junit.jupiter.api.Test;
32 import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher;
33 import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRegisterAckPublisher;
34 import org.onap.policy.clamp.models.acm.concepts.Participant;
35 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
36 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
37 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
38 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
39 import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
42 class SupervisionParticipantHandlerTest {
43 private static final ToscaConceptIdentifier PARTICIPANT_ID = new ToscaConceptIdentifier("ParticipantId", "1.0.0");
44 private static final ToscaConceptIdentifier PARTICIPANT_TYPE =
45 new ToscaConceptIdentifier("ParticipantType", "1.0.0");
48 void testHandleParticipantDeregister() {
49 var participant = new Participant();
50 participant.setName(PARTICIPANT_ID.getName());
51 participant.setVersion(PARTICIPANT_ID.getVersion());
52 participant.setParticipantType(PARTICIPANT_TYPE);
54 var participantProvider = mock(ParticipantProvider.class);
55 when(participantProvider.findParticipant(PARTICIPANT_ID)).thenReturn(Optional.of(participant));
57 var participantDeregisterMessage = new ParticipantDeregister();
58 participantDeregisterMessage.setMessageId(UUID.randomUUID());
59 participantDeregisterMessage.setParticipantId(PARTICIPANT_ID);
60 participantDeregisterMessage.setParticipantType(PARTICIPANT_TYPE);
61 var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
62 var handler = new SupervisionParticipantHandler(participantProvider,
63 mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher);
65 handler.handleParticipantMessage(participantDeregisterMessage);
67 verify(participantProvider).updateParticipant(any());
68 verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
72 void testHandleParticipantRegister() {
73 var participant = new Participant();
74 participant.setName(PARTICIPANT_ID.getName());
75 participant.setVersion(PARTICIPANT_ID.getVersion());
76 participant.setParticipantType(PARTICIPANT_TYPE);
78 var participantRegisterMessage = new ParticipantRegister();
79 participantRegisterMessage.setMessageId(UUID.randomUUID());
80 participantRegisterMessage.setParticipantId(PARTICIPANT_ID);
81 participantRegisterMessage.setParticipantType(PARTICIPANT_TYPE);
82 var participantProvider = mock(ParticipantProvider.class);
83 var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
84 var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher,
85 mock(ParticipantDeregisterAckPublisher.class));
86 participantRegisterMessage.setParticipantSupportedElementType(new ArrayList<>());
88 handler.handleParticipantMessage(participantRegisterMessage);
90 verify(participantProvider).saveParticipant(any());
91 verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(), PARTICIPANT_ID,
96 void testHandleParticipantStatus() {
97 var participantStatusMessage = new ParticipantStatus();
98 participantStatusMessage.setParticipantId(PARTICIPANT_ID);
99 participantStatusMessage.setParticipantType(PARTICIPANT_TYPE);
100 participantStatusMessage.setState(ParticipantState.ON_LINE);
101 participantStatusMessage.setParticipantSupportedElementType(new ArrayList<>());
103 var participantProvider = mock(ParticipantProvider.class);
104 var handler = new SupervisionParticipantHandler(participantProvider,
105 mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class));
106 var participant = new Participant();
107 when(participantProvider.findParticipant(PARTICIPANT_ID)).thenReturn(Optional.of(participant));
108 handler.handleParticipantMessage(participantStatusMessage);
110 verify(participantProvider).updateParticipant(any());