db4cfa3211ad67591937cfce0a44aeeb52731ad5
[sdc/sdc-workflow-designer.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.sdc.workflow.services.impl;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.mockito.ArgumentMatchers.any;
21 import static org.mockito.ArgumentMatchers.anyString;
22 import static org.mockito.ArgumentMatchers.argThat;
23 import static org.mockito.ArgumentMatchers.eq;
24 import static org.mockito.Mockito.doNothing;
25 import static org.mockito.Mockito.doReturn;
26 import static org.mockito.Mockito.doThrow;
27 import static org.mockito.Mockito.times;
28 import static org.mockito.Mockito.verify;
29 import static org.onap.sdc.workflow.services.types.WorkflowVersionState.CERTIFIED;
30 import static org.onap.sdc.workflow.services.types.WorkflowVersionState.DRAFT;
31
32 import java.io.IOException;
33 import java.io.InputStream;
34 import java.util.Arrays;
35 import java.util.Collection;
36 import java.util.Collections;
37 import java.util.List;
38 import java.util.Optional;
39
40 import org.apache.commons.io.IOUtils;
41 import org.junit.Rule;
42 import org.junit.Test;
43 import org.junit.rules.ExpectedException;
44 import org.junit.runner.RunWith;
45 import org.mockito.ArgumentCaptor;
46 import org.mockito.InjectMocks;
47 import org.mockito.Mock;
48 import org.mockito.Spy;
49 import org.mockito.junit.MockitoJUnitRunner;
50 import org.onap.sdc.workflow.persistence.ArtifactRepository;
51 import org.onap.sdc.workflow.persistence.ParameterRepository;
52 import org.onap.sdc.workflow.persistence.types.ArtifactEntity;
53 import org.onap.sdc.workflow.persistence.types.ParameterEntity;
54 import org.onap.sdc.workflow.persistence.types.ParameterRole;
55 import org.onap.sdc.workflow.services.exceptions.EntityNotFoundException;
56 import org.onap.sdc.workflow.services.exceptions.VersionCreationException;
57 import org.onap.sdc.workflow.services.exceptions.VersionModificationException;
58 import org.onap.sdc.workflow.services.exceptions.VersionStateModificationException;
59 import org.onap.sdc.workflow.services.exceptions.VersionStateModificationMissingArtifactException;
60 import org.onap.sdc.workflow.services.exceptions.WorkflowModificationException;
61 import org.onap.sdc.workflow.services.impl.mappers.VersionMapper;
62 import org.onap.sdc.workflow.services.impl.mappers.VersionStateMapper;
63 import org.onap.sdc.workflow.services.types.WorkflowVersion;
64 import org.onap.sdc.workflow.services.types.WorkflowVersionState;
65 import org.openecomp.sdc.versioning.ItemManager;
66 import org.openecomp.sdc.versioning.VersioningManager;
67 import org.openecomp.sdc.versioning.dao.types.Version;
68 import org.openecomp.sdc.versioning.dao.types.VersionState;
69 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
70 import org.openecomp.sdc.versioning.types.Item;
71 import org.openecomp.sdc.versioning.types.ItemStatus;
72 import org.openecomp.sdc.versioning.types.VersionCreationMethod;
73 import org.springframework.mock.web.MockMultipartFile;
74
75 @RunWith(MockitoJUnitRunner.class)
76 public class WorkflowVersionManagerImplTest {
77
78     private static final String ITEM1_ID = "item_id_1";
79     private static final String VERSION1_ID = "version_id_1";
80     private static final String VERSION2_ID = "version_id_2";
81
82     @Mock
83     private ItemManager itemManagerMock;
84     @Mock
85     private VersioningManager versioningManagerMock;
86     @Mock
87     private ParameterRepository parameterRepositoryMock;
88     @Mock
89     private ArtifactRepository artifactRepositoryMock;
90     @Mock
91     private VersionMapper versionMapperMock;
92     @Mock
93     private VersionStateMapper versionStateMapperMock;
94     @Rule
95     public ExpectedException exceptionRule = ExpectedException.none();
96     @Spy
97     @InjectMocks
98     private WorkflowVersionManagerImpl workflowVersionManager;
99
100     @Test(expected = EntityNotFoundException.class)
101     public void shouldThrowExceptionWhenVersionDontExist() {
102         Version nonExistingVersion = new Version(VERSION1_ID);
103         doThrow(new RuntimeException()).when(versioningManagerMock).get(ITEM1_ID, nonExistingVersion);
104         workflowVersionManager.get(ITEM1_ID, VERSION1_ID);
105     }
106
107     @Test(expected = WorkflowModificationException.class)
108     public void shouldThrowExceptionWhenCreatingVersionForArchivedWorkflow() {
109         Item mockItem = new Item();
110         mockItem.setId(ITEM1_ID);
111         mockItem.setStatus(ItemStatus.ARCHIVED);
112         doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID);
113         workflowVersionManager.create(ITEM1_ID, null, new WorkflowVersion(VERSION1_ID));
114     }
115
116     @Test(expected = WorkflowModificationException.class)
117     public void shouldThrowExceptionWhenUpdatingVersionForArchivedWorkflow() {
118         Item mockItem = new Item();
119         mockItem.setId(ITEM1_ID);
120         mockItem.setStatus(ItemStatus.ARCHIVED);
121         doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID);
122         workflowVersionManager.update(ITEM1_ID, new WorkflowVersion(VERSION1_ID));
123     }
124
125     @Test(expected = WorkflowModificationException.class)
126     public void shouldThrowExceptionWhenUploadingArtifactForArchivedWorkflow() {
127         Item mockItem = new Item();
128         mockItem.setId(ITEM1_ID);
129         mockItem.setStatus(ItemStatus.ARCHIVED);
130         doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID);
131         MockMultipartFile mockFile = new MockMultipartFile("data", "filename.txt", "text/plain", "some xml".getBytes());
132         workflowVersionManager.uploadArtifact(ITEM1_ID, VERSION1_ID, mockFile);
133     }
134
135     @Test(expected = WorkflowModificationException.class)
136     public void shouldThrowExceptionWhenDeletingArtifactForArchivedWorkflow() {
137         Item mockItem = new Item();
138         mockItem.setId(ITEM1_ID);
139         mockItem.setStatus(ItemStatus.ARCHIVED);
140         doReturn(mockItem).when(itemManagerMock).get(ITEM1_ID);
141         workflowVersionManager.deleteArtifact(ITEM1_ID, VERSION1_ID);
142     }
143
144     @Test
145     public void shouldReturnWorkflowVersionWhenExist() {
146         Version version = new Version(VERSION1_ID);
147         WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
148         doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(any(Version.class));
149         doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), any(Version.class));
150         doReturn(Collections.emptyList()).when(parameterRepositoryMock)
151                 .list(eq(ITEM1_ID), eq(VERSION1_ID), any(ParameterRole.class));
152         workflowVersionManager.get(ITEM1_ID, VERSION1_ID);
153         verify(versioningManagerMock).get(ITEM1_ID, version);
154     }
155
156     @Test
157     public void shouldReturnWorkflowVersionList() {
158         Version version1 = new Version(VERSION1_ID);
159         Version version2 = new Version(VERSION2_ID);
160         List<Version> versionList = Arrays.asList(version1, version2);
161         doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID);
162         WorkflowVersion workflowVersion1 = new WorkflowVersion();
163         workflowVersion1.setId(VERSION1_ID);
164         workflowVersion1.setName(VERSION1_ID);
165         WorkflowVersion workflowVersion2 = new WorkflowVersion();
166         workflowVersion2.setId(VERSION2_ID);
167         workflowVersion2.setName(VERSION2_ID);
168         doReturn(workflowVersion2).when(versionMapperMock).versionToWorkflowVersion(version2);
169         doReturn(Collections.emptyList()).when(parameterRepositoryMock)
170                 .list(eq(ITEM1_ID), anyString(), eq(ParameterRole.INPUT));
171         doReturn(Collections.emptyList()).when(parameterRepositoryMock)
172                 .list(eq(ITEM1_ID), anyString(), eq(ParameterRole.OUTPUT));
173         workflowVersionManager.list(ITEM1_ID, null);
174         verify(versioningManagerMock).list(ITEM1_ID);
175         verify(versionMapperMock, times(2)).versionToWorkflowVersion(any(Version.class));
176     }
177
178     @Test
179     public void shouldReturnCertifiedWorkflowVersionList() {
180         Version version1 = new Version(VERSION1_ID);
181         version1.setStatus(VersionStatus.Certified);
182         Version version2 = new Version(VERSION2_ID);
183         version2.setStatus(VersionStatus.Draft);
184         List<Version> versionList = Arrays.asList(version1, version2);
185         doReturn(versionList).when(versioningManagerMock).list(ITEM1_ID);
186         WorkflowVersion workflowVersion1 = new WorkflowVersion();
187         workflowVersion1.setId(VERSION1_ID);
188         workflowVersion1.setName(VERSION1_ID);
189         WorkflowVersion workflowVersion2 = new WorkflowVersion();
190         workflowVersion2.setId(VERSION2_ID);
191         workflowVersion2.setName(VERSION2_ID);
192         doReturn(workflowVersion1).when(versionMapperMock).versionToWorkflowVersion(version1);
193         doReturn(Collections.emptyList()).when(parameterRepositoryMock)
194                 .list(eq(ITEM1_ID), anyString(), eq(ParameterRole.INPUT));
195         doReturn(Collections.emptyList()).when(parameterRepositoryMock)
196                 .list(eq(ITEM1_ID), anyString(), eq(ParameterRole.OUTPUT));
197         doReturn(VersionStatus.Certified).when(versionStateMapperMock)
198                 .workflowVersionStateToVersionStatus(
199                         WorkflowVersionState.CERTIFIED);
200
201         assertEquals(1,
202                 workflowVersionManager.list(ITEM1_ID, Collections.singleton(WorkflowVersionState.CERTIFIED)).size());
203         verify(versioningManagerMock).list(ITEM1_ID);
204         verify(versionMapperMock, times(1)).versionToWorkflowVersion(any(Version.class));
205
206     }
207
208     @Test
209     public void shouldUpdateWorkflowVersion() {
210         doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
211         String updatedDescription = "WorkflowVersion description updated";
212         Version retrievedVersion = new Version(VERSION1_ID);
213         retrievedVersion.setName("1.0");
214         retrievedVersion.setDescription("WorkflowVersion description");
215         retrievedVersion.setStatus(VersionStatus.Draft);
216         VersionState versionState = new VersionState();
217         versionState.setDirty(true);
218         retrievedVersion.setState(versionState);
219         doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
220         doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(retrievedVersion.getStatus());
221
222         WorkflowVersion inputVersion = new WorkflowVersion(VERSION1_ID);
223         inputVersion.setName("1.0");
224         inputVersion.setDescription(updatedDescription);
225         ParameterEntity toBeCreated = new ParameterEntity("Input1");
226         inputVersion.setInputs(Collections.singleton(toBeCreated));
227         ParameterEntity toBeUpdated = new ParameterEntity("Output1");
228         inputVersion.setOutputs(Collections.singleton(toBeUpdated));
229         doReturn(Collections.emptyList()).when(parameterRepositoryMock)
230                 .list(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT);
231         ParameterEntity toBeDeleted = new ParameterEntity("Output2");
232         toBeDeleted.setId("parameter_id_1");
233         Collection<ParameterEntity> currentOutputs = Arrays.asList(toBeDeleted, toBeUpdated);
234         doReturn(currentOutputs).when(parameterRepositoryMock).list(ITEM1_ID, VERSION1_ID, ParameterRole.OUTPUT);
235
236         Version mappedInputVersion = new Version(VERSION1_ID);
237         mappedInputVersion.setName("1.0");
238         mappedInputVersion.setDescription(updatedDescription);
239         doReturn(mappedInputVersion).when(versionMapperMock).workflowVersionToVersion(inputVersion);
240
241         ArgumentCaptor<Version> versionArgCaptor = ArgumentCaptor.forClass(Version.class);
242         workflowVersionManager.update(ITEM1_ID, inputVersion);
243
244         verify(versioningManagerMock).updateVersion(eq(ITEM1_ID), versionArgCaptor.capture());
245         Version captorVersion = versionArgCaptor.getValue();
246         assertEquals("1.0", captorVersion.getName());
247         assertEquals(updatedDescription, captorVersion.getDescription());
248         assertEquals(VersionStatus.Draft, captorVersion.getStatus());
249         verify(versioningManagerMock).publish(ITEM1_ID, mappedInputVersion, "Update version");
250
251         verify(parameterRepositoryMock).delete(ITEM1_ID, VERSION1_ID, "parameter_id_1");
252         verify(parameterRepositoryMock).create(ITEM1_ID, VERSION1_ID, ParameterRole.INPUT, toBeCreated);
253         verify(parameterRepositoryMock).update(ITEM1_ID, VERSION1_ID, ParameterRole.OUTPUT, toBeUpdated);
254
255     }
256
257
258     @Test
259     public void shouldCreateWorkflowVersion() {
260         doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
261         Version version = new Version(VERSION1_ID);
262         version.setDescription("version desc");
263         doReturn(version).when(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major);
264         WorkflowVersion versionRequest = new WorkflowVersion();
265         versionRequest.setDescription("version desc");
266         versionRequest.setInputs(Collections.emptyList());
267         versionRequest.setOutputs(Collections.emptyList());
268         WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
269         doReturn(workflowVersion).when(workflowVersionManager).get(ITEM1_ID, VERSION1_ID);
270         workflowVersionManager.create(ITEM1_ID, null, versionRequest);
271         verify(versioningManagerMock).create(ITEM1_ID, version, VersionCreationMethod.major);
272     }
273
274     @Test(expected = VersionCreationException.class)
275     public void shouldTrowExceptionWhenDraftVersionExists() {
276         doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
277         WorkflowVersion versionRequestDto = new WorkflowVersion();
278
279         Version baseVersion = new Version(VERSION2_ID);
280         baseVersion.setStatus(VersionStatus.Draft);
281         List<Version> versions = Collections.singletonList(baseVersion);
282         doReturn(versions).when(versioningManagerMock).list(ITEM1_ID);
283
284         workflowVersionManager.create(ITEM1_ID, VERSION2_ID, versionRequestDto);
285     }
286
287     @Test(expected = VersionCreationException.class)
288     public void shouldTrowExceptionWhenInputsSupplied() {
289         doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
290         WorkflowVersion versionRequestDto = new WorkflowVersion();
291         versionRequestDto.setInputs(Collections.singleton(new ParameterEntity()));
292         Version baseVersion = new Version(VERSION2_ID);
293         baseVersion.setStatus(VersionStatus.Draft);
294         List<Version> versions = Collections.singletonList(baseVersion);
295         doReturn(versions).when(versioningManagerMock).list(ITEM1_ID);
296
297         workflowVersionManager.create(ITEM1_ID, VERSION2_ID, versionRequestDto);
298     }
299
300     @Test(expected = EntityNotFoundException.class)
301     public void getStateOfNonExisting() {
302         doThrow(new RuntimeException()).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
303         workflowVersionManager.getState(ITEM1_ID, VERSION1_ID);
304     }
305
306     @Test
307     public void getState() {
308         Version version = new Version(VERSION1_ID);
309         version.setStatus(VersionStatus.Certified);
310         doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
311         doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus());
312
313         WorkflowVersionState state = workflowVersionManager.getState(ITEM1_ID, VERSION1_ID);
314         assertEquals(CERTIFIED, state);
315     }
316
317     @Test(expected = EntityNotFoundException.class)
318     public void updateStateOfNonExisting() {
319         doThrow(new RuntimeException()).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
320         workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED);
321     }
322
323     @Test(expected = VersionStateModificationException.class)
324     public void updateStateToCurrentState() {
325         Version version = new Version(VERSION1_ID);
326         version.setStatus(VersionStatus.Draft);
327         doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
328         doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus());
329
330         workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, DRAFT);
331     }
332
333     @Test(expected = VersionStateModificationMissingArtifactException.class)
334     public void updateStateWhenCertified() {
335         Version version = new Version(VERSION1_ID);
336         version.setStatus(VersionStatus.Certified);
337         doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
338         doReturn(CERTIFIED).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus());
339
340         workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED);
341     }
342
343     @Test
344     public void shouldFailUpdateStateWhenNoArtifact() {
345         Version retrievedVersion = new Version(VERSION1_ID);
346         retrievedVersion.setStatus(VersionStatus.Draft);
347         doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
348         doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(VersionStatus.Draft);
349
350         exceptionRule.expect(VersionStateModificationMissingArtifactException.class);
351         exceptionRule.expectMessage(String.format(
352                 VersionStateModificationMissingArtifactException.WORKFLOW_MODIFICATION_STATE_MISSING_ARTIFACT_TEMPLATE,
353                 ITEM1_ID, VERSION1_ID, DRAFT, CERTIFIED));
354         workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED);
355
356         verify(versioningManagerMock).submit(eq(ITEM1_ID), eqVersion(VERSION1_ID), anyString());
357     }
358
359     @Test
360     public void shouldSuccessUpdateStateWhenArtifactExist() {
361         Version retrievedVersion = new Version(VERSION1_ID);
362         retrievedVersion.setStatus(VersionStatus.Draft);
363         doReturn(retrievedVersion).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
364         doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(VersionStatus.Draft);
365         doReturn(true).when(artifactRepositoryMock).isExist(ITEM1_ID, VERSION1_ID);
366         workflowVersionManager.updateState(ITEM1_ID, VERSION1_ID, CERTIFIED);
367         verify(versioningManagerMock).submit(eq(ITEM1_ID), eqVersion(VERSION1_ID), anyString());
368     }
369
370     @Test
371     public void shouldUploadArtifact() {
372         doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
373         Version version = new Version(VERSION1_ID);
374         version.setStatus(VersionStatus.Draft);
375         VersionState versionState = new VersionState();
376         versionState.setDirty(false);
377         version.setState(versionState);
378         doReturn(version).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
379         doReturn(DRAFT).when(versionStateMapperMock).versionStatusToWorkflowVersionState(version.getStatus());
380
381         MockMultipartFile mockFile = new MockMultipartFile("data", "filename.txt", "text/plain", "some xml".getBytes());
382         workflowVersionManager.uploadArtifact(ITEM1_ID, VERSION1_ID, mockFile);
383
384         verify(artifactRepositoryMock).update(eq(ITEM1_ID), eq(VERSION1_ID), any(ArtifactEntity.class));
385     }
386
387     @Test(expected = EntityNotFoundException.class)
388     public void shouldThrowExceptionWhenArtifactNotFound() {
389         doReturn(new Version(VERSION1_ID)).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
390
391         doReturn(Optional.empty()).when(artifactRepositoryMock).get(ITEM1_ID, VERSION1_ID);
392         workflowVersionManager.getArtifact(ITEM1_ID, VERSION1_ID);
393     }
394
395     @Test
396     public void shouldReturnArtifact() throws IOException {
397         doReturn(new Version(VERSION1_ID)).when(versioningManagerMock).get(eq(ITEM1_ID), eqVersion(VERSION1_ID));
398
399         InputStream inputStreamMock = IOUtils.toInputStream("some test data for my input stream", "UTF-8");
400         ArtifactEntity artifactMock = new ArtifactEntity("fileName.txt", inputStreamMock);
401         doReturn(Optional.of(artifactMock)).when(artifactRepositoryMock).get(ITEM1_ID, VERSION1_ID);
402         ArtifactEntity returnedArtifact = workflowVersionManager.getArtifact(ITEM1_ID, VERSION1_ID);
403         assertEquals(artifactMock, returnedArtifact);
404     }
405
406     @Test(expected = VersionModificationException.class)
407     public void shouldThrowExceptionInDeleteArtifactWhenVersionIsCertified() {
408         doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
409         Version version = new Version(VERSION1_ID);
410         doReturn(version).when(versioningManagerMock).get(ITEM1_ID, version);
411         WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
412         workflowVersion.setState(WorkflowVersionState.CERTIFIED);
413         doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(version);
414         workflowVersionManager.deleteArtifact(ITEM1_ID, VERSION1_ID);
415     }
416
417     @Test
418     public void shouldNotDeleteArtifactIfNotExist() {
419         doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
420         Version version = new Version(VERSION1_ID);
421         doReturn(version).when(versioningManagerMock).get(ITEM1_ID, version);
422         WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
423         doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(version);
424         workflowVersionManager.deleteArtifact(ITEM1_ID, VERSION1_ID);
425         verify(artifactRepositoryMock, times(0)).delete(ITEM1_ID, VERSION1_ID);
426         verify(versioningManagerMock, times(0)).publish(ITEM1_ID, version, "Delete Artifact");
427     }
428
429     @Test
430     public void shouldDeleteArtifactIfExist() {
431         doNothing().when(workflowVersionManager).validateWorkflowStatus(ITEM1_ID);
432         Version version = new Version(VERSION1_ID);
433         doReturn(version).when(versioningManagerMock).get(ITEM1_ID, version);
434         WorkflowVersion workflowVersion = new WorkflowVersion(VERSION1_ID);
435         doReturn(true).when(artifactRepositoryMock).isExist(ITEM1_ID, VERSION1_ID);
436         doReturn(workflowVersion).when(versionMapperMock).versionToWorkflowVersion(version);
437         workflowVersionManager.deleteArtifact(ITEM1_ID, VERSION1_ID);
438         verify(artifactRepositoryMock, times(1)).delete(ITEM1_ID, VERSION1_ID);
439         verify(versioningManagerMock, times(1)).publish(ITEM1_ID, version, "Delete Artifact");
440     }
441
442     private static Version eqVersion(String versionId) {
443         return argThat(version -> versionId.equals(version.getId()));
444     }
445 }