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;
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.instantiation.InstantiationUtils;
33 import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher;
34 import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher;
35 import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
36 import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck;
37 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
38 import org.onap.policy.clamp.models.acm.concepts.DeployState;
39 import org.onap.policy.clamp.models.acm.concepts.LockState;
40 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
41 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
42 import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
44 class SupervisionAcHandlerTest {
45 private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
46 private static final UUID IDENTIFIER = UUID.randomUUID();
49 void testHandleAutomationCompositionStateChangeAckMessage() {
50 var automationCompositionProvider = mock(AutomationCompositionProvider.class);
51 var automationComposition =
52 InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
53 when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
54 .thenReturn(Optional.of(automationComposition));
56 var handler = new SupervisionAcHandler(automationCompositionProvider,
57 mock(AutomationCompositionDeployPublisher.class),
58 mock(AutomationCompositionStateChangePublisher.class));
60 var automationCompositionAckMessage =
61 new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
62 for (var elementEntry : automationComposition.getElements().entrySet()) {
63 var acElementDeployAck = new AcElementDeployAck(null, DeployState.DEPLOYED, LockState.UNLOCKED, true, "");
64 automationCompositionAckMessage.getAutomationCompositionResultMap().put(elementEntry.getKey(),
67 automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
69 handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage);
71 verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));
75 void testHandleAutomationCompositionUpdateAckMessage() {
76 var automationCompositionProvider = mock(AutomationCompositionProvider.class);
77 var automationComposition =
78 InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
79 when(automationCompositionProvider.findAutomationComposition(IDENTIFIER))
80 .thenReturn(Optional.of(automationComposition));
82 var automationCompositionAckMessage =
83 new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
84 for (var elementEntry : automationComposition.getElements().entrySet()) {
85 var acElementDeployAck = new AcElementDeployAck(null, DeployState.DEPLOYED, LockState.LOCKED, true, "");
86 automationCompositionAckMessage
87 .setAutomationCompositionResultMap(Map.of(elementEntry.getKey(), acElementDeployAck));
89 automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId());
90 automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER);
92 var handler = new SupervisionAcHandler(automationCompositionProvider,
93 mock(AutomationCompositionDeployPublisher.class),
94 mock(AutomationCompositionStateChangePublisher.class));
96 handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage);
98 verify(automationCompositionProvider).updateAutomationComposition(any(AutomationComposition.class));