1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.clamp.acm.runtime.supervision;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRegisterAckPublisher;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
class SupervisionParticipantHandlerTest {
@Test
void testHandleParticipantDeregister() {
var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
var participantProvider = mock(ParticipantProvider.class);
when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
.thenReturn(Optional.of(participant));
var participantDeregisterMessage = new ParticipantDeregister();
participantDeregisterMessage.setMessageId(UUID.randomUUID());
participantDeregisterMessage.setParticipantId(CommonTestData.getParticipantId());
var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
var handler = new SupervisionParticipantHandler(participantProvider,
mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher,
mock(AutomationCompositionProvider.class));
handler.handleParticipantMessage(participantDeregisterMessage);
verify(participantProvider).updateParticipant(any());
verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
}
@Test
void testHandleParticipantRegister() {
var participantRegisterMessage = new ParticipantRegister();
participantRegisterMessage.setMessageId(UUID.randomUUID());
participantRegisterMessage.setParticipantId(CommonTestData.getParticipantId());
var supportedElementType = new ParticipantSupportedElementType();
supportedElementType.setTypeName("Type");
supportedElementType.setTypeVersion("1.0.0");
participantRegisterMessage.setParticipantSupportedElementType(List.of(supportedElementType));
var participantProvider = mock(ParticipantProvider.class);
var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher,
mock(ParticipantDeregisterAckPublisher.class),
mock(AutomationCompositionProvider.class));
handler.handleParticipantMessage(participantRegisterMessage);
verify(participantProvider).saveParticipant(any());
verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(),
CommonTestData.getParticipantId());
}
@Test
void testHandleParticipantStatus() {
var participantStatusMessage = new ParticipantStatus();
participantStatusMessage.setParticipantId(CommonTestData.getParticipantId());
participantStatusMessage.setState(ParticipantState.ON_LINE);
var supportedElementType = new ParticipantSupportedElementType();
supportedElementType.setTypeName("Type");
supportedElementType.setTypeVersion("1.0.0");
participantStatusMessage.setParticipantSupportedElementType(List.of(supportedElementType));
participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo()));
var participantProvider = mock(ParticipantProvider.class);
var handler = new SupervisionParticipantHandler(participantProvider,
mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
mock(AutomationCompositionProvider.class));
var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
.thenReturn(Optional.of(participant));
handler.handleParticipantMessage(participantStatusMessage);
verify(participantProvider).updateParticipant(any());
}
}
|