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.List;
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.acm.runtime.util.CommonTestData;
35 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
36 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
37 import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
38 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
39 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
40 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
41 import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
43 class SupervisionParticipantHandlerTest {
45 void testHandleParticipantDeregister() {
46 var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
48 var participantProvider = mock(ParticipantProvider.class);
49 when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
50 .thenReturn(Optional.of(participant));
52 var participantDeregisterMessage = new ParticipantDeregister();
53 participantDeregisterMessage.setMessageId(UUID.randomUUID());
54 participantDeregisterMessage.setParticipantId(CommonTestData.getParticipantId());
55 var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
56 var handler = new SupervisionParticipantHandler(participantProvider,
57 mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher);
59 handler.handleParticipantMessage(participantDeregisterMessage);
61 verify(participantProvider).updateParticipant(any());
62 verify(participantProvider).resetParticipantAcElementState(any());
63 verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
67 void testHandleParticipantRegister() {
68 var participantRegisterMessage = new ParticipantRegister();
69 participantRegisterMessage.setMessageId(UUID.randomUUID());
70 participantRegisterMessage.setParticipantId(CommonTestData.getParticipantId());
71 var supportedElementType = new ParticipantSupportedElementType();
72 supportedElementType.setTypeName("Type");
73 supportedElementType.setTypeVersion("1.0.0");
74 participantRegisterMessage.setParticipantSupportedElementType(List.of(supportedElementType));
76 var participantProvider = mock(ParticipantProvider.class);
77 var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
78 var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher,
79 mock(ParticipantDeregisterAckPublisher.class));
80 handler.handleParticipantMessage(participantRegisterMessage);
82 verify(participantProvider).saveParticipant(any());
83 verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(),
84 CommonTestData.getParticipantId());
88 void testHandleParticipantStatus() {
89 var participantStatusMessage = new ParticipantStatus();
90 participantStatusMessage.setParticipantId(CommonTestData.getParticipantId());
91 participantStatusMessage.setState(ParticipantState.ON_LINE);
92 var supportedElementType = new ParticipantSupportedElementType();
93 supportedElementType.setTypeName("Type");
94 supportedElementType.setTypeVersion("1.0.0");
95 participantStatusMessage.setParticipantSupportedElementType(List.of(supportedElementType));
96 participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo()));
98 var participantProvider = mock(ParticipantProvider.class);
99 var handler = new SupervisionParticipantHandler(participantProvider,
100 mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class));
101 var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
102 when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
103 .thenReturn(Optional.of(participant));
104 handler.handleParticipantMessage(participantStatusMessage);
106 verify(participantProvider).updateParticipant(any());