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.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;
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;
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;
74 @RunWith(MockitoJUnitRunner.class)
75 public class InterfaceOperationBusinessLogicTest {
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";
87 private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
89 private UserValidations userValidations;
91 private ToscaOperationFacade toscaOperationFacade;
93 private ComponentsUtils componentsUtils;
95 private IGraphLockOperation graphLockOperation;
97 private JanusGraphDao janusGraphDao;
99 private InterfaceLifecycleOperation interfaceLifecycleOperation;
101 private InterfaceOperationValidation interfaceOperationValidation;
103 private InterfaceOperation interfaceOperation;
105 private ArtifactCassandraDao artifactCassandraDao;
107 protected ArtifactsOperations artifactToscaOperation;
109 private Resource resource;
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,
122 resource.setInputs(createInputsForResource());
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"));
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);
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)),
159 Assert.assertTrue(interfaceOperationEither.isLeft());
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))));
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");
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));
188 resource.setCapabilities(capabilityMap);
189 when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
191 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
192 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
193 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
194 operationId, operationName)),
196 Assert.assertTrue(interfaceOperationEither.isLeft());
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)),
214 Assert.assertTrue(interfaceOperationEither.isLeft());
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)),
229 Assert.assertTrue(interfaceOperationEither.isRight());
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());
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)),
258 Assert.assertTrue(interfaceOperation.isLeft());
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)),
273 Assert.assertTrue(interfaceOperation.isRight());
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)),
288 Assert.assertTrue(interfaceOperation.isLeft());
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)),
300 Assert.assertTrue(interfaceOperation.isRight());
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)),
313 Assert.assertTrue(interfaceOperationEither.isRight());
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)),
325 Assert.assertTrue(interfaceOperationEither.isRight());
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)),
340 Assert.assertTrue(interfaceOperationEither.isRight());
344 public void deleteInterfaceOperationTestInterfaceDoesntExist() {
345 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId1,
346 Collections.singletonList(operationId), user, true).isRight());
350 public void deleteInterfaceOperationTestOperationDoesntExist() {
351 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
352 Collections.singletonList(operationId1), user, true).isRight());
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());
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());
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);
386 interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
387 Collections.singletonList(operationId), user, true);
388 } catch (ByActionStatusComponentException e){
389 Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
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);
401 interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
402 Collections.singletonList(operationId), user, true);
403 } catch (ByActionStatusComponentException e){
404 Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
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);
416 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
417 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)),
419 } catch (ByActionStatusComponentException e){
420 Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
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());
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());
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());
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());
474 public void getInterfaceOperationTestInterfaceDoesntExist() {
475 Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId1,
476 Collections.singletonList(operationId), user, true).isRight());
480 public void getInterfaceOperationTestOperationDoesntExist() {
481 Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
482 Collections.singletonList(operationId1), user, true).isRight());
486 public void getInterfaceOperationTest() {
487 Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
488 Collections.singletonList(operationId), user, true).isLeft());
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());
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());
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());
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());