d52f5841cbb851e7a604466e27243d8951795daa
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.acm.participant.sim.main.handler;
22
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.spy;
25 import static org.mockito.Mockito.verify;
26
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.UUID;
31 import org.junit.jupiter.api.Test;
32 import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
33 import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
34 import org.onap.policy.clamp.acm.participant.intermediary.api.ElementState;
35 import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
36 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
37 import org.onap.policy.clamp.acm.participant.intermediary.api.impl.ParticipantIntermediaryApiImpl;
38 import org.onap.policy.clamp.acm.participant.sim.comm.CommonTestData;
39 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
40 import org.onap.policy.clamp.models.acm.concepts.DeployState;
41 import org.onap.policy.clamp.models.acm.concepts.LockState;
42 import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
44
45 class AutomationCompositionElementHandlerTest {
46
47     private static final ToscaConceptIdentifier ELEMENT_DEFINITION_ID = new ToscaConceptIdentifier("name", "1.0.0");
48     private static final CompositionElementDto COMPOSITION_ELEMENT =
49         new CompositionElementDto(UUID.randomUUID(), ELEMENT_DEFINITION_ID, Map.of(), Map.of());
50     private static final InstanceElementDto INSTANCE_ELEMENT =
51         new InstanceElementDto(UUID.randomUUID(), UUID.randomUUID(), Map.of(), new HashMap<>());
52     private static final CompositionDto COMPOSITION = new CompositionDto(UUID.randomUUID(),
53         Map.of(ELEMENT_DEFINITION_ID, Map.of()), Map.of(ELEMENT_DEFINITION_ID, new HashMap<>()));
54
55     @Test
56     void testDeploy() {
57         var config = CommonTestData.createSimConfig();
58         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
59         var simulatorService = new SimulatorService(intermediaryApi);
60         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
61         simulatorService.setConfig(config);
62         acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
63         verify(intermediaryApi).updateAutomationCompositionElementState(
64             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
65             null, StateChangeResult.NO_ERROR, "Deployed");
66
67         config.setDeploySuccess(false);
68         acElementHandler.deploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
69         verify(intermediaryApi).updateAutomationCompositionElementState(
70             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
71             null, StateChangeResult.FAILED, "Deploy failed!");
72     }
73
74     @Test
75     void testUndeploy() {
76         var config = CommonTestData.createSimConfig();
77         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
78         var simulatorService = new SimulatorService(intermediaryApi);
79         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
80         simulatorService.setConfig(config);
81         acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
82         verify(intermediaryApi).updateAutomationCompositionElementState(
83             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
84             null, StateChangeResult.NO_ERROR, "Undeployed");
85
86         config.setUndeploySuccess(false);
87         acElementHandler.undeploy(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
88         verify(intermediaryApi).updateAutomationCompositionElementState(
89             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
90             null, StateChangeResult.FAILED, "Undeploy failed!");
91     }
92
93     @Test
94     void testLock() {
95         var config = CommonTestData.createSimConfig();
96         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
97         var simulatorService = new SimulatorService(intermediaryApi);
98         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
99         simulatorService.setConfig(config);
100         acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
101         verify(intermediaryApi).updateAutomationCompositionElementState(
102             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED,
103             StateChangeResult.NO_ERROR, "Locked");
104
105         config.setLockSuccess(false);
106         acElementHandler.lock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
107         verify(intermediaryApi).updateAutomationCompositionElementState(
108             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED,
109             StateChangeResult.FAILED, "Lock failed!");
110     }
111
112     @Test
113     void testUnlock() {
114         var config = CommonTestData.createSimConfig();
115         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
116         var simulatorService = new SimulatorService(intermediaryApi);
117         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
118         simulatorService.setConfig(config);
119         acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
120         verify(intermediaryApi).updateAutomationCompositionElementState(
121             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.UNLOCKED,
122             StateChangeResult.NO_ERROR, "Unlocked");
123
124         config.setUnlockSuccess(false);
125         acElementHandler.unlock(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
126         verify(intermediaryApi).updateAutomationCompositionElementState(
127             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), null, LockState.LOCKED,
128             StateChangeResult.FAILED, "Unlock failed!");
129     }
130
131     @Test
132     void testUpdate() {
133         var config = CommonTestData.createSimConfig();
134         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
135         var simulatorService = new SimulatorService(intermediaryApi);
136         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
137         simulatorService.setConfig(config);
138         var instanceElementUpdated = new InstanceElementDto(
139             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
140             Map.of("key", "value"), Map.of());
141         acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
142         verify(intermediaryApi).updateAutomationCompositionElementState(
143             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
144             DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated");
145
146         config.setUpdateSuccess(false);
147         acElementHandler.update(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, instanceElementUpdated);
148         verify(intermediaryApi).updateAutomationCompositionElementState(
149             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
150             DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!");
151     }
152
153     @Test
154     void testDelete() {
155         var config = CommonTestData.createSimConfig();
156         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
157         var simulatorService = new SimulatorService(intermediaryApi);
158         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
159         simulatorService.setConfig(config);
160         acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
161         verify(intermediaryApi).updateAutomationCompositionElementState(
162             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DELETED,
163             null, StateChangeResult.NO_ERROR, "Deleted");
164
165         config.setDeleteSuccess(false);
166         acElementHandler.delete(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
167         verify(intermediaryApi).updateAutomationCompositionElementState(
168             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
169             null, StateChangeResult.FAILED, "Delete failed!");
170     }
171
172     @Test
173     void testPrime() {
174         var config = CommonTestData.createSimConfig();
175         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
176         var simulatorService = new SimulatorService(intermediaryApi);
177         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
178         simulatorService.setConfig(config);
179         acElementHandler.prime(COMPOSITION);
180         verify(intermediaryApi).updateCompositionState(
181             COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
182
183         config.setPrimeSuccess(false);
184         acElementHandler.prime(COMPOSITION);
185         verify(intermediaryApi).updateCompositionState(
186             COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.FAILED, "Prime failed!");
187     }
188
189     @Test
190     void testDeprime() {
191         var config = CommonTestData.createSimConfig();
192         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
193         var simulatorService = new SimulatorService(intermediaryApi);
194         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
195         simulatorService.setConfig(config);
196         acElementHandler.deprime(COMPOSITION);
197         verify(intermediaryApi).updateCompositionState(
198             COMPOSITION.compositionId(), AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, "Deprimed");
199
200         config.setDeprimeSuccess(false);
201         acElementHandler.deprime(COMPOSITION);
202         verify(intermediaryApi).updateCompositionState(
203             COMPOSITION.compositionId(), AcTypeState.PRIMED, StateChangeResult.FAILED, "Deprime failed!");
204     }
205
206     @Test
207     void testMigrate() {
208         var config = CommonTestData.createSimConfig();
209         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
210         var simulatorService = new SimulatorService(intermediaryApi);
211         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
212         simulatorService.setConfig(config);
213         var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
214             Map.of(), Map.of());
215         var instanceElementMigrated = new InstanceElementDto(
216             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
217             Map.of("key", "value"), new HashMap<>());
218         acElementHandler
219             .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated, 0);
220         verify(intermediaryApi).updateAutomationCompositionElementState(
221             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
222             DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
223
224         config.setMigrateSuccess(false);
225         acElementHandler
226             .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated, 0);
227         verify(intermediaryApi).updateAutomationCompositionElementState(
228             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
229             DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Migrate failed!");
230     }
231
232     @Test
233     void testMigrateStage() {
234         var config = CommonTestData.createSimConfig();
235         var intermediaryApi = spy(new ParticipantIntermediaryApiImpl(mock(), mock()));
236         var simulatorService = new SimulatorService(intermediaryApi);
237         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
238         simulatorService.setConfig(config);
239         var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
240             Map.of("stage", List.of(1, 2)), Map.of());
241         var instanceElementMigrated = new InstanceElementDto(INSTANCE_ELEMENT.instanceId(),
242             INSTANCE_ELEMENT.elementId(), Map.of(), new HashMap<>());
243         acElementHandler
244             .migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated, 1);
245         verify(intermediaryApi).updateAutomationCompositionElementStage(
246             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
247             StateChangeResult.NO_ERROR, 2, "stage 1 Migrated");
248     }
249
250     @Test
251     void testMigrateAdd() {
252         var config = CommonTestData.createSimConfig();
253         var intermediaryApi = spy(new ParticipantIntermediaryApiImpl(mock(), mock()));
254         var simulatorService = new SimulatorService(intermediaryApi);
255         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
256         simulatorService.setConfig(config);
257         var compositionElement = new CompositionElementDto(
258             UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of(), ElementState.NOT_PRESENT);
259
260         var instanceElement = new InstanceElementDto(
261             UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of(), ElementState.NOT_PRESENT);
262
263         var compoElTargetAdd = new CompositionElementDto(
264             UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of(), ElementState.NEW);
265         var inElMigratedAdd = new InstanceElementDto(instanceElement.instanceId(), instanceElement.elementId(),
266             Map.of(), new HashMap<>(), ElementState.NEW);
267         acElementHandler
268             .migrate(compositionElement, compoElTargetAdd, instanceElement, inElMigratedAdd, 0);
269         verify(intermediaryApi).updateAutomationCompositionElementState(
270             instanceElement.instanceId(), instanceElement.elementId(),
271             DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
272     }
273
274     @Test
275     void testMigrateRemove() {
276         var config = CommonTestData.createSimConfig();
277         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
278         var simulatorService = new SimulatorService(intermediaryApi);
279         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
280         simulatorService.setConfig(config);
281
282         var compoElTargetRemove = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
283             Map.of(), Map.of(), ElementState.REMOVED);
284         var inElMigratedRemove = new InstanceElementDto(
285             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
286             Map.of("key", "value"), Map.of(), ElementState.REMOVED);
287         acElementHandler
288             .migrate(COMPOSITION_ELEMENT, compoElTargetRemove, INSTANCE_ELEMENT, inElMigratedRemove, 0);
289         verify(intermediaryApi).updateAutomationCompositionElementState(
290             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
291             DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Migration - Deleted");
292     }
293
294     @Test
295     void testMigratePrecheck() {
296         var config = CommonTestData.createSimConfig();
297         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
298         var simulatorService = new SimulatorService(intermediaryApi);
299         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
300         simulatorService.setConfig(config);
301         var compositionElementTarget = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
302             Map.of(), Map.of());
303         var instanceElementMigrated = new InstanceElementDto(
304             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
305             Map.of("key", "value"), Map.of());
306         acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
307             INSTANCE_ELEMENT, instanceElementMigrated);
308         verify(intermediaryApi).updateAutomationCompositionElementState(
309             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
310             DeployState.DEPLOYED, null,
311             StateChangeResult.NO_ERROR, "Migration precheck completed");
312
313         config.setMigratePrecheck(false);
314         acElementHandler.migratePrecheck(COMPOSITION_ELEMENT, compositionElementTarget,
315             INSTANCE_ELEMENT, instanceElementMigrated);
316         verify(intermediaryApi).updateAutomationCompositionElementState(
317             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
318             DeployState.DEPLOYED, null,
319             StateChangeResult.FAILED, "Migration precheck failed");
320     }
321
322     @Test
323     void testPrepare() {
324         var config = CommonTestData.createSimConfig();
325         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
326         var simulatorService = new SimulatorService(intermediaryApi);
327         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
328         simulatorService.setConfig(config);
329         acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, 0);
330         verify(intermediaryApi).updateAutomationCompositionElementState(
331             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
332             null, StateChangeResult.NO_ERROR, "Prepare completed");
333
334         config.setPrepare(false);
335         acElementHandler.prepare(COMPOSITION_ELEMENT, INSTANCE_ELEMENT, 0);
336         verify(intermediaryApi).updateAutomationCompositionElementState(
337             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.UNDEPLOYED,
338             null, StateChangeResult.FAILED, "Prepare failed");
339     }
340
341     @Test
342     void testReview() {
343         var config = CommonTestData.createSimConfig();
344         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
345         var simulatorService = new SimulatorService(intermediaryApi);
346         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
347         simulatorService.setConfig(config);
348         acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
349         verify(intermediaryApi).updateAutomationCompositionElementState(
350             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
351             null, StateChangeResult.NO_ERROR, "Review completed");
352
353         config.setReview(false);
354         acElementHandler.review(COMPOSITION_ELEMENT, INSTANCE_ELEMENT);
355         verify(intermediaryApi).updateAutomationCompositionElementState(
356             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
357             null, StateChangeResult.FAILED, "Review failed");
358     }
359
360     @Test
361     void testRollback() {
362         var config = CommonTestData.createSimConfig();
363         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
364         var simulatorService = new SimulatorService(intermediaryApi);
365         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
366         simulatorService.setConfig(config);
367         var compositionElementRollback = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
368                 Map.of(), Map.of());
369         var instanceElementRollback = new InstanceElementDto(
370                 INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
371                 Map.of("key", "value"), new HashMap<>());
372         acElementHandler.rollbackMigration(COMPOSITION_ELEMENT, compositionElementRollback, INSTANCE_ELEMENT,
373                 instanceElementRollback, 0);
374         verify(intermediaryApi).updateAutomationCompositionElementState(
375                 INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
376                 null, StateChangeResult.NO_ERROR, "Migration rollback done");
377
378         config.setRollback(false);
379         acElementHandler.rollbackMigration(COMPOSITION_ELEMENT, compositionElementRollback, INSTANCE_ELEMENT,
380                 instanceElementRollback, 0);
381         verify(intermediaryApi).updateAutomationCompositionElementState(
382             INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(), DeployState.DEPLOYED,
383             null, StateChangeResult.FAILED, "Migration rollback failed");
384     }
385
386     @Test
387     void testRollbackStage() {
388         var config = CommonTestData.createSimConfig();
389         var intermediaryApi = spy(new ParticipantIntermediaryApiImpl(mock(), mock()));
390         var simulatorService = new SimulatorService(intermediaryApi);
391         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
392         simulatorService.setConfig(config);
393         var compositionElementRollback = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
394                 Map.of("stage", List.of(1, 2)), Map.of());
395         var instanceElementRollback = new InstanceElementDto(INSTANCE_ELEMENT.instanceId(),
396                 INSTANCE_ELEMENT.elementId(), Map.of(), new HashMap<>());
397         acElementHandler.rollbackMigration(COMPOSITION_ELEMENT, compositionElementRollback, INSTANCE_ELEMENT,
398                 instanceElementRollback, 1);
399         verify(intermediaryApi).updateAutomationCompositionElementStage(
400                 INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
401                 StateChangeResult.NO_ERROR, 2, "stage 1 Migration rollback");
402     }
403
404     @Test
405     void testRollbackAdd() {
406         var config = CommonTestData.createSimConfig();
407         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
408         var simulatorService = new SimulatorService(intermediaryApi);
409         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
410         simulatorService.setConfig(config);
411         var compositionElement = new CompositionElementDto(
412                 UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of(), ElementState.NOT_PRESENT);
413
414         var instanceElement = new InstanceElementDto(
415                 UUID.randomUUID(), UUID.randomUUID(), Map.of(), Map.of(), ElementState.NOT_PRESENT);
416
417         var compoElRollbackAdd = new CompositionElementDto(
418                 UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of(), ElementState.NEW);
419         var inElRollbackAdd = new InstanceElementDto(instanceElement.instanceId(), instanceElement.elementId(),
420                 Map.of(), new HashMap<>(), ElementState.NEW);
421         acElementHandler
422                 .rollbackMigration(compositionElement, compoElRollbackAdd, instanceElement, inElRollbackAdd, 0);
423         verify(intermediaryApi).updateAutomationCompositionElementState(
424                 instanceElement.instanceId(), instanceElement.elementId(),
425                 DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migration rollback done");
426     }
427
428     @Test
429     void testRollbackRemove() {
430         var config = CommonTestData.createSimConfig();
431         var intermediaryApi = mock(ParticipantIntermediaryApi.class);
432         var simulatorService = new SimulatorService(intermediaryApi);
433         var acElementHandler = new AutomationCompositionElementHandler(intermediaryApi, simulatorService);
434         simulatorService.setConfig(config);
435
436         var compoElRollbackRemove = new CompositionElementDto(UUID.randomUUID(), new ToscaConceptIdentifier(),
437                 Map.of(), Map.of(), ElementState.REMOVED);
438         var inElRollbackRemove = new InstanceElementDto(
439                 INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
440                 Map.of("key", "value"), Map.of(), ElementState.REMOVED);
441         acElementHandler
442                 .rollbackMigration(COMPOSITION_ELEMENT, compoElRollbackRemove, INSTANCE_ELEMENT, inElRollbackRemove, 0);
443         verify(intermediaryApi).updateAutomationCompositionElementState(
444                 INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
445                 DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Rollback - Deleted");
446     }
447 }