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