2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.be.components.impl;
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;
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;
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;
71 @RunWith(MockitoJUnitRunner.class)
72 public class InterfaceOperationBusinessLogicTest {
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";
84 private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
86 private UserValidations userValidations;
88 private ToscaOperationFacade toscaOperationFacade;
90 private ComponentsUtils componentsUtils;
92 private IGraphLockOperation graphLockOperation;
94 private JanusGraphDao janusGraphDao;
96 private InterfaceLifecycleOperation interfaceLifecycleOperation;
98 private InterfaceOperationValidation interfaceOperationValidation;
100 private InterfaceOperation interfaceOperation;
102 private ArtifactCassandraDao artifactCassandraDao;
104 protected ArtifactsOperations artifactToscaOperation;
106 private Resource resource;
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,
119 resource.setInputs(createInputsForResource());
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);
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);
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)),
155 Assert.assertTrue(interfaceOperationEither.isLeft());
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))));
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");
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));
184 resource.setCapabilities(capabilityMap);
185 when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
187 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
188 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
189 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
190 operationId, operationName)),
192 Assert.assertTrue(interfaceOperationEither.isLeft());
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)),
210 Assert.assertTrue(interfaceOperationEither.isLeft());
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)),
225 Assert.assertTrue(interfaceOperationEither.isRight());
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());
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)),
254 Assert.assertTrue(interfaceOperation.isLeft());
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)),
269 Assert.assertTrue(interfaceOperation.isRight());
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)),
284 Assert.assertTrue(interfaceOperation.isLeft());
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)),
296 Assert.assertTrue(interfaceOperation.isRight());
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)),
309 Assert.assertTrue(interfaceOperationEither.isRight());
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)),
321 Assert.assertTrue(interfaceOperationEither.isRight());
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)),
336 Assert.assertTrue(interfaceOperationEither.isRight());
340 public void deleteInterfaceOperationTestInterfaceDoesntExist() {
341 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId1,
342 Collections.singletonList(operationId), user, true).isRight());
346 public void deleteInterfaceOperationTestOperationDoesntExist() {
347 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
348 Collections.singletonList(operationId1), user, true).isRight());
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());
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());
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);
382 interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
383 Collections.singletonList(operationId), user, true);
384 } catch (ByActionStatusComponentException e){
385 Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
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);
397 interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
398 Collections.singletonList(operationId), user, true);
399 } catch (ByActionStatusComponentException e){
400 Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
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);
412 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
413 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)),
415 } catch (ByActionStatusComponentException e){
416 Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
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());
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());
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());
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());
470 public void getInterfaceOperationTestInterfaceDoesntExist() {
471 Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId1,
472 Collections.singletonList(operationId), user, true).isRight());
476 public void getInterfaceOperationTestOperationDoesntExist() {
477 Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
478 Collections.singletonList(operationId1), user, true).isRight());
482 public void getInterfaceOperationTest() {
483 Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
484 Collections.singletonList(operationId), user, true).isLeft());
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());
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());
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());
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());