Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / InterfaceOperationBusinessLogicTest.java
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.openecomp.sdc.be.components.impl;
18
19 import fj.data.Either;
20 import org.junit.Assert;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.mockito.Mockito;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
29 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
30 import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
31 import org.openecomp.sdc.be.components.validation.UserValidations;
32 import org.openecomp.sdc.be.dao.api.ActionStatus;
33 import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
34 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
35 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
36 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
37 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
38 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
39 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
40 import org.openecomp.sdc.be.impl.ComponentsUtils;
41 import org.openecomp.sdc.be.model.ArtifactDefinition;
42 import org.openecomp.sdc.be.model.CapabilityDefinition;
43 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
44 import org.openecomp.sdc.be.model.InputDefinition;
45 import org.openecomp.sdc.be.model.InterfaceDefinition;
46 import org.openecomp.sdc.be.model.Resource;
47 import org.openecomp.sdc.be.model.User;
48 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
49 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
50 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
51 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
52 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
53 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
54 import org.openecomp.sdc.exception.ResponseFormat;
55 import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
56
57 import java.util.ArrayList;
58 import java.util.Arrays;
59 import java.util.Collections;
60 import java.util.HashMap;
61 import java.util.List;
62 import java.util.Map;
63
64 import static org.junit.Assert.fail;
65 import static org.mockito.ArgumentMatchers.any;
66 import static org.mockito.ArgumentMatchers.anyBoolean;
67 import static org.mockito.ArgumentMatchers.anyMap;
68 import static org.mockito.ArgumentMatchers.eq;
69 import static org.mockito.Mockito.when;
70
71 @RunWith(MockitoJUnitRunner.class)
72 public class InterfaceOperationBusinessLogicTest {
73
74     private static final String resourceId = "resourceId";
75     private static final String interfaceId = "interfaceId";
76     private static final String operationId = "operationId";
77     private static final String inputId = "inputId";
78     private static final String RESOURCE_NAME = "Resource1";
79     private static final String operationId1 = "operationId1";
80     private static final String interfaceId1 = "interfaceId1";
81     private static final String operationName = "createOperation";
82
83     @InjectMocks
84     private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
85     @Mock
86     private UserValidations userValidations;
87     @Mock
88     private ToscaOperationFacade toscaOperationFacade;
89     @Mock
90     private ComponentsUtils componentsUtils;
91     @Mock
92     private IGraphLockOperation graphLockOperation;
93     @Mock
94     private JanusGraphDao janusGraphDao;
95     @Mock
96     private InterfaceLifecycleOperation interfaceLifecycleOperation;
97     @Mock
98     private InterfaceOperationValidation interfaceOperationValidation;
99     @Mock
100     private InterfaceOperation interfaceOperation;
101     @Mock
102     private ArtifactCassandraDao artifactCassandraDao;
103     @Mock
104     protected ArtifactsOperations artifactToscaOperation;
105     private User user;
106     private Resource resource;
107
108     @Before
109     public void setup() {
110         interfaceOperationBusinessLogic.setUserValidations(userValidations);
111         interfaceOperationBusinessLogic.setToscaOperationFacade(toscaOperationFacade);
112         interfaceOperationBusinessLogic.setGraphLockOperation(graphLockOperation);
113         interfaceOperationBusinessLogic.setJanusGraphDao(janusGraphDao);
114         interfaceOperationBusinessLogic.setComponentsUtils(componentsUtils);
115         resource = new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setUniqueId(resourceId)
116                            .setName(RESOURCE_NAME).build();
117         resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId,
118                 operationName));
119         resource.setInputs(createInputsForResource());
120
121         user = new User();
122         when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
123         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
124                 .thenReturn(StorageOperationStatus.OK);
125         when(interfaceOperationValidation
126                      .validateInterfaceOperations(any(), any(), any(), anyMap(), anyBoolean()))
127                 .thenReturn(Either.left(true));
128         when(interfaceOperationValidation
129                 .validateDeleteOperationContainsNoMappedOutput(any(), any(), any()))
130                 .thenReturn(Either.left(true));
131         when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
132     }
133
134     private List<InputDefinition> createInputsForResource() {
135         InputDefinition inputDefinition = new InputDefinition();
136         inputDefinition.setName(inputId);
137         inputDefinition.setInputId(inputId);
138         inputDefinition.setUniqueId(inputId);
139         inputDefinition.setValue(inputId);
140         inputDefinition.setDefaultValue(inputId);
141         return Arrays.asList(inputDefinition);
142     }
143
144     @Test
145     public void createInterfaceOperationTestOnExistingInterface() {
146         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
147                 .thenReturn(Either.left(Collections.emptyMap()));
148         when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
149                 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
150         Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
151                 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
152                     Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
153                             operationId, operationName)),
154                         user, true);
155         Assert.assertTrue(interfaceOperationEither.isLeft());
156     }
157
158     @Test
159     public void createInterfaceOperationTestOnExistingInterfaceInputsFromCapProp() {
160         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
161                 .thenReturn(Either.left(Collections.emptyMap()));
162         when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
163                 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
164
165         CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
166         capabilityDefinition.setName("cap" + Math.random());
167         capabilityDefinition.setType("tosca.capabilities.network.Bindable");
168         capabilityDefinition.setOwnerId(resourceId);
169         capabilityDefinition.setUniqueId("capUniqueId");
170
171         List<ComponentInstanceProperty> properties = new ArrayList<>();
172         ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
173         instanceProperty.setUniqueId("ComponentInput1_uniqueId");
174         instanceProperty.setType("Integer");
175         instanceProperty.setName("prop_name");
176         instanceProperty.setDescription("prop_description_prop_desc");
177         instanceProperty.setOwnerId("capUniqueId");
178         instanceProperty.setSchema(new SchemaDefinition());
179         properties.add(instanceProperty);
180         capabilityDefinition.setProperties(properties);
181         Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>();
182         capabilityMap.put(capabilityDefinition.getType(), Collections.singletonList(capabilityDefinition));
183
184         resource.setCapabilities(capabilityMap);
185         when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
186
187         Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
188                 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
189                         Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
190                                 operationId, operationName)),
191                         user, true);
192         Assert.assertTrue(interfaceOperationEither.isLeft());
193     }
194
195
196     @Test
197     public void createInterfaceOperationWithoutInterfaceTest() {
198         resource.getInterfaces().clear();
199         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
200                 .thenReturn(Either.left(Collections.emptyMap()));
201         when(interfaceOperation.addInterfaces(any(), any())).thenReturn(Either.left(
202                 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
203         when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
204                 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
205         Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
206                 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
207                         Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
208                                 operationId, operationName)),
209                         user, true);
210         Assert.assertTrue(interfaceOperationEither.isLeft());
211     }
212
213     @Test
214     public void createInterfaceOperationWithoutInterfaceTestFail() {
215         resource.getInterfaces().clear();
216         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
217                 .thenReturn(Either.left(Collections.emptyMap()));
218         when(interfaceOperation.addInterfaces(any(), any()))
219                 .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
220         Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
221                 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
222                         Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
223                                 operationId, operationName)),
224                         user, true);
225         Assert.assertTrue(interfaceOperationEither.isRight());
226     }
227
228     @Test
229     public void shouldFailWhenCreateInterfaceOperationFailedTest() {
230         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
231                 .thenReturn(Either.left(Collections.emptyMap()));
232         when(interfaceOperation.updateInterfaces(any(), any()))
233                 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
234         Assert.assertTrue(interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
235                 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)),
236                 user, true).isRight());
237     }
238
239     @Test
240     public void updateInterfaceOperationTestWithArtifactSuccess() {
241         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
242                 .thenReturn(Either.left(Collections.emptyMap()));
243         when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
244                 .thenReturn(Either.left(new ArtifactDefinition()));
245         when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
246         when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
247         when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
248                 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
249         Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
250                 interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
251                         Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
252                                 operationId, operationName)),
253                         user, true);
254         Assert.assertTrue(interfaceOperation.isLeft());
255     }
256
257     @Test
258     public void updateInterfaceOperationTestWithArtifactFailure() {
259         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
260                 .thenReturn(Either.left(Collections.emptyMap()));
261         when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
262         when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
263                 .thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
264         Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
265                 interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
266                         Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
267                                 operationId, operationName)),
268                         user, true);
269         Assert.assertTrue(interfaceOperation.isRight());
270     }
271
272     @Test
273     public void updateInterfaceOperationTestWithoutArtifact() {
274         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
275                 .thenReturn(Either.left(Collections.emptyMap()));
276         when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
277         when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
278                 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
279         Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
280                 interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
281                         Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
282                                 operationId, operationName)),
283                         user, true);
284         Assert.assertTrue(interfaceOperation.isLeft());
285     }
286
287     @Test
288     public void updateInterfaceOperationTestDoesntExist() {
289         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
290                 .thenReturn(Either.left(Collections.emptyMap()));
291         Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
292                 interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
293                         Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
294                                 operationId, operationName)),
295                         user, true);
296         Assert.assertTrue(interfaceOperation.isRight());
297     }
298
299     @Test
300     public void createInterfaceOperationTestFailOnException() {
301         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
302                 .thenReturn(Either.left(Collections.emptyMap()));
303         when(interfaceOperation.updateInterfaces(any(), any())).thenThrow(new RuntimeException());
304         Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
305                 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
306                         Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
307                                 operationId, operationName)),
308                         user, true);
309         Assert.assertTrue(interfaceOperationEither.isRight());
310     }
311
312     @Test
313     public void createInterfaceOperationTestFailOnFetchinGlobalTypes() {
314         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
315                 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
316         Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
317                 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
318                         Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
319                                 operationId, operationName)),
320                         user, true);
321         Assert.assertTrue(interfaceOperationEither.isRight());
322     }
323
324     @Test
325     public void createInterfaceOperationTestFailOnValidation() {
326         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
327                 .thenReturn(Either.left(Collections.emptyMap()));
328         when(interfaceOperationValidation
329                      .validateInterfaceOperations(any(), any(), any(), anyMap(), anyBoolean()))
330                 .thenReturn(Either.right(new ResponseFormat()));
331         Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
332                 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
333                         Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
334                                 operationId, operationName)),
335                         user, true);
336         Assert.assertTrue(interfaceOperationEither.isRight());
337     }
338
339     @Test
340     public void deleteInterfaceOperationTestInterfaceDoesntExist() {
341         Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId1,
342                 Collections.singletonList(operationId), user, true).isRight());
343     }
344
345     @Test
346     public void deleteInterfaceOperationTestOperationDoesntExist() {
347         Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
348                 Collections.singletonList(operationId1), user, true).isRight());
349     }
350
351     @Test
352     public void deleteInterfaceOperationTestSuccess() {
353         resource.getInterfaces().get(interfaceId).getOperations()
354                 .putAll(InterfaceOperationTestUtils.createMockOperationMap(operationId1, operationName));
355         when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
356         when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
357                 .thenReturn(Either.left(new ArtifactDefinition()));
358         when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
359         when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
360         Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
361                 Collections.singletonList(operationId), user, true).isLeft());
362     }
363
364     @Test
365     public void shouldFailWhenDeleteInterfaceOperationFailedTest() {
366         when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
367         when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
368                 .thenReturn(Either.left(new ArtifactDefinition()));
369         when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
370         when(interfaceOperation.updateInterfaces(any(), any()))
371                 .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
372         Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
373                 Collections.singletonList(operationId), user, true).isRight());
374     }
375
376     @Test
377     public void shouldFailOnDeleteInterfaceWhenLockComponentFailedTest() {
378         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
379                 .thenReturn(StorageOperationStatus.NOT_FOUND);
380         when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
381         try{
382             interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
383                     Collections.singletonList(operationId), user, true);
384         } catch (ByActionStatusComponentException e){
385             Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
386             return;
387         }
388         fail();
389     }
390
391     @Test
392     public void shouldFailOnGetInterfaceWhenLockComponentFailedTest() {
393         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
394                 .thenReturn(StorageOperationStatus.NOT_FOUND);
395         when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
396         try{
397             interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
398                     Collections.singletonList(operationId), user, true);
399         } catch (ByActionStatusComponentException e){
400             Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
401             return;
402         }
403         fail();
404     }
405
406     @Test
407     public void shouldFailOnCreateInterfaceWhenLockComponentFailedTest() {
408         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
409                 .thenReturn(StorageOperationStatus.NOT_FOUND);
410         when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
411         try{
412             interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
413                     Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)),
414                     user, true);
415         } catch (ByActionStatusComponentException e){
416             Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
417             return;
418         }
419         fail();
420
421     }
422
423
424     @Test
425     public void deleteInterfaceOperationTestFailOnArtifactDeletion() {
426         when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
427         when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
428                 .thenReturn(Either.left(new ArtifactDefinition()));
429         when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.GENERAL_ERROR);
430         Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
431                 Collections.singletonList(operationId), user, true).isRight());
432     }
433
434     @Test
435     public void deleteInterfaceOperationTestFailOnException() {
436         when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
437         when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
438                 .thenReturn(Either.left(new ArtifactDefinition()));
439         when(artifactCassandraDao.deleteArtifact(any(String.class))).thenThrow(new RuntimeException());
440         Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
441                 Collections.singletonList(operationId), user, true).isRight());
442     }
443
444     @Test
445     public void deleteInterfaceTestSuccess() {
446         when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
447         when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
448                 .thenReturn(Either.left(new ArtifactDefinition()));
449         when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
450         when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
451         when(interfaceOperation.deleteInterface(any(), any())).thenReturn(Either.left(interfaceId));
452         Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
453                 Collections.singletonList(operationId), user, true).isLeft());
454     }
455
456     @Test
457     public void deleteInterfaceTestFailure() {
458         when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
459         when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
460                 .thenReturn(Either.left(new ArtifactDefinition()));
461         when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
462         when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
463         when(interfaceOperation.deleteInterface(any(), any()))
464                 .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
465         Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
466                 Collections.singletonList(operationId), user, true).isRight());
467     }
468
469     @Test
470     public void getInterfaceOperationTestInterfaceDoesntExist() {
471         Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId1,
472                 Collections.singletonList(operationId), user, true).isRight());
473     }
474
475     @Test
476     public void getInterfaceOperationTestOperationDoesntExist() {
477         Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
478                 Collections.singletonList(operationId1), user, true).isRight());
479     }
480
481     @Test
482     public void getInterfaceOperationTest() {
483         Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
484                 Collections.singletonList(operationId), user, true).isLeft());
485     }
486
487     @Test
488     public void getInterfaceOperationTestFailOnException() {
489         when(janusGraphDao.commit()).thenThrow(new RuntimeException());
490         Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
491                 Collections.singletonList(operationId), user, true).isRight());
492     }
493
494     @Test
495     public void shouldFailWhenGetComponentFailedTest() {
496         when(toscaOperationFacade.getToscaElement(resourceId))
497                 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
498         Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
499                 Collections.singletonList(operationId), user, true).isRight());
500         Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
501                 Collections.singletonList(operationId), user, true).isRight());
502         Assert.assertTrue(interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
503                 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId,
504                         operationName)), user, true).isRight());
505     }
506
507     @Test
508     public void testGetAllInterfaceLifecycleTypes_TypesNotFound() {
509         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
510                 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
511         Either<Map<String, InterfaceDefinition>, ResponseFormat> response =
512                 interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes();
513         Assert.assertTrue(response.isRight());
514     }
515
516     @Test
517     public void testGetAllInterfaceLifecycleTypes_Success() {
518         InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
519         interfaceDefinition.setUniqueId(interfaceId);
520         interfaceDefinition.setType(interfaceId);
521         Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
522         interfaceDefinitionMap.put(interfaceDefinition.getUniqueId(), interfaceDefinition);
523         when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes())
524                 .thenReturn(Either.left(interfaceDefinitionMap));
525         Either<Map<String, InterfaceDefinition>, ResponseFormat> response =
526                 interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes();
527         Assert.assertEquals(1, response.left().value().size());
528     }
529
530
531
532 }