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