2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 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.participant.intermediary.api.impl;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.verify;
27 import java.util.UUID;
28 import org.junit.jupiter.api.Test;
29 import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
30 import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
31 import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
32 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
33 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
34 import org.onap.policy.clamp.models.acm.concepts.DeployState;
35 import org.onap.policy.clamp.models.acm.concepts.LockState;
36 import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
37 import org.onap.policy.models.base.PfModelException;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
40 class AcElementListenerV3Test {
43 void lockTest() throws PfModelException {
44 var intermediaryApi = mock(ParticipantIntermediaryApi.class);
45 var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
46 var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
48 var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of());
49 acElementListenerV2.lock(compositionElement, instanceElement);
50 verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
51 instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
55 void deleteTest() throws PfModelException {
56 var intermediaryApi = mock(ParticipantIntermediaryApi.class);
57 var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
58 var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
60 var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of());
61 acElementListenerV2.delete(compositionElement, instanceElement);
62 verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
63 instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
67 void updateTest() throws PfModelException {
68 var intermediaryApi = mock(ParticipantIntermediaryApi.class);
69 var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
70 var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
72 var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of());
73 acElementListenerV2.update(compositionElement, instanceElement, instanceElement);
74 verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
75 instanceElement.elementId(), DeployState.DEPLOYED, null,
76 StateChangeResult.NO_ERROR, "Update not supported");
80 void unlockTest() throws PfModelException {
81 var intermediaryApi = mock(ParticipantIntermediaryApi.class);
82 var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
83 var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
85 var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of());
86 acElementListenerV2.unlock(compositionElement, instanceElement);
87 verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
88 instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
92 void primeTest() throws PfModelException {
93 var intermediaryApi = mock(ParticipantIntermediaryApi.class);
94 var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
95 var compositionId = UUID.randomUUID();
96 var toscaConceptIdentifier = new ToscaConceptIdentifier();
97 var composition = new CompositionDto(compositionId, Map.of(toscaConceptIdentifier, Map.of()), Map.of());
98 acElementListenerV2.prime(composition);
99 verify(intermediaryApi)
100 .updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
104 void deprimeTest() throws PfModelException {
105 var intermediaryApi = mock(ParticipantIntermediaryApi.class);
106 var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
107 var compositionId = UUID.randomUUID();
108 var toscaConceptIdentifier = new ToscaConceptIdentifier();
109 var composition = new CompositionDto(compositionId, Map.of(toscaConceptIdentifier, Map.of()), Map.of());
110 acElementListenerV2.deprime(composition);
111 verify(intermediaryApi)
112 .updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed");
116 void migrateTest() throws PfModelException {
117 var intermediaryApi = mock(ParticipantIntermediaryApi.class);
118 var acElementListenerV2 = createAcElementListenerV3(intermediaryApi);
119 var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
121 var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of());
122 acElementListenerV2.migrate(compositionElement, compositionElement, instanceElement, instanceElement, 0);
123 verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
124 instanceElement.elementId(), DeployState.DEPLOYED, null,
125 StateChangeResult.NO_ERROR, "Migrated");
129 void migratePrecheckTest() throws PfModelException {
130 var intermediaryApi = mock(ParticipantIntermediaryApi.class);
131 var acElementListenerV1 = createAcElementListenerV3(intermediaryApi);
132 var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
134 var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of());
135 acElementListenerV1.migratePrecheck(compositionElement, compositionElement, instanceElement, instanceElement);
136 verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
137 instanceElement.elementId(), DeployState.DEPLOYED, null,
138 StateChangeResult.NO_ERROR, "Migration Precheck completed");
142 void reviewTest() throws PfModelException {
143 var intermediaryApi = mock(ParticipantIntermediaryApi.class);
144 var acElementListenerV1 = createAcElementListenerV3(intermediaryApi);
145 var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
147 var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of());
148 acElementListenerV1.review(compositionElement, instanceElement);
149 verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
150 instanceElement.elementId(), DeployState.DEPLOYED, null,
151 StateChangeResult.NO_ERROR, "Review completed");
155 void prepareTest() throws PfModelException {
156 var intermediaryApi = mock(ParticipantIntermediaryApi.class);
157 var acElementListenerV1 = createAcElementListenerV3(intermediaryApi);
158 var compositionElement = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
160 var instanceElement = new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of());
161 acElementListenerV1.prepare(compositionElement, instanceElement);
162 verify(intermediaryApi).updateAutomationCompositionElementState(instanceElement.instanceId(),
163 instanceElement.elementId(), DeployState.UNDEPLOYED, null,
164 StateChangeResult.NO_ERROR, "Prepare completed");
167 private AcElementListenerV3 createAcElementListenerV3(ParticipantIntermediaryApi intermediaryApi) {
168 return new AcElementListenerV3(intermediaryApi) {
170 public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
171 // dummy implementation
175 public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) {
176 // dummy implementation