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 static org.junit.Assert.fail;
20 import static org.mockito.ArgumentMatchers.any;
21 import static org.mockito.ArgumentMatchers.anyBoolean;
22 import static org.mockito.ArgumentMatchers.anyMap;
23 import static org.mockito.ArgumentMatchers.eq;
24 import static org.mockito.Mockito.when;
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;
33 import org.apache.commons.lang3.StringUtils;
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.impl.exceptions.ByActionStatusComponentException;
43 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
44 import org.openecomp.sdc.be.components.validation.InterfaceOperationValidation;
45 import org.openecomp.sdc.be.components.validation.UserValidations;
46 import org.openecomp.sdc.be.config.ConfigurationManager;
47 import org.openecomp.sdc.be.dao.api.ActionStatus;
48 import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
49 import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
50 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
51 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
52 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
53 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
54 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
55 import org.openecomp.sdc.be.impl.ComponentsUtils;
56 import org.openecomp.sdc.be.model.ArtifactDefinition;
57 import org.openecomp.sdc.be.model.CapabilityDefinition;
58 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
59 import org.openecomp.sdc.be.model.InputDefinition;
60 import org.openecomp.sdc.be.model.InterfaceDefinition;
61 import org.openecomp.sdc.be.model.Resource;
62 import org.openecomp.sdc.be.model.User;
63 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ArtifactsOperations;
64 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.InterfaceOperation;
65 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
66 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
67 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
68 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
69 import org.openecomp.sdc.common.impl.ExternalConfiguration;
70 import org.openecomp.sdc.common.impl.FSConfigurationSource;
71 import org.openecomp.sdc.exception.ResponseFormat;
72 import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
74 import fj.data.Either;
76 @RunWith(MockitoJUnitRunner.class)
77 public class InterfaceOperationBusinessLogicTest {
79 private static final String resourceId = "resourceId";
80 private static final String interfaceId = "interfaceId";
81 private static final String operationId = "operationId";
82 private static final String inputId = "inputId";
83 private static final String RESOURCE_NAME = "Resource1";
84 private static final String operationId1 = "operationId1";
85 private static final String interfaceId1 = "interfaceId1";
86 private static final String operationName = "createOperation";
89 private InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
91 private UserValidations userValidations;
93 private ToscaOperationFacade toscaOperationFacade;
95 private ComponentsUtils componentsUtils;
97 private IGraphLockOperation graphLockOperation;
99 private JanusGraphDao janusGraphDao;
101 private InterfaceLifecycleOperation interfaceLifecycleOperation;
103 private InterfaceOperationValidation interfaceOperationValidation;
105 private InterfaceOperation interfaceOperation;
107 private ArtifactCassandraDao artifactCassandraDao;
109 protected ArtifactsOperations artifactToscaOperation;
111 private Resource resource;
114 public void setup() {
115 interfaceOperationBusinessLogic.setUserValidations(userValidations);
116 interfaceOperationBusinessLogic.setToscaOperationFacade(toscaOperationFacade);
117 interfaceOperationBusinessLogic.setGraphLockOperation(graphLockOperation);
118 interfaceOperationBusinessLogic.setJanusGraphDao(janusGraphDao);
119 interfaceOperationBusinessLogic.setComponentsUtils(componentsUtils);
120 resource = new ResourceBuilder().setComponentType(ComponentTypeEnum.RESOURCE).setUniqueId(resourceId)
121 .setName(RESOURCE_NAME).build();
122 resource.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceId, operationId,
124 resource.setInputs(createInputsForResource());
127 when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
128 when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
129 .thenReturn(StorageOperationStatus.OK);
130 when(interfaceOperationValidation
131 .validateInterfaceOperations(any(), any(), any(), anyMap(), anyBoolean()))
132 .thenReturn(Either.left(true));
133 when(interfaceOperationValidation
134 .validateDeleteOperationContainsNoMappedOutput(any(), any(), any()))
135 .thenReturn(Either.left(true));
136 when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
137 new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
140 private List<InputDefinition> createInputsForResource() {
141 InputDefinition inputDefinition = new InputDefinition();
142 inputDefinition.setName(inputId);
143 inputDefinition.setInputId(inputId);
144 inputDefinition.setUniqueId(inputId);
145 inputDefinition.setValue(inputId);
146 inputDefinition.setDefaultValue(inputId);
147 return Arrays.asList(inputDefinition);
151 public void createInterfaceOperationTestOnExistingInterface() {
152 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
153 .thenReturn(Either.left(Collections.emptyMap()));
154 when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
155 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
156 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
157 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
158 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
159 operationId, operationName)),
161 Assert.assertTrue(interfaceOperationEither.isLeft());
165 public void createInterfaceOperationTestOnExistingInterfaceInputsFromCapProp() {
166 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
167 .thenReturn(Either.left(Collections.emptyMap()));
168 when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
169 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
171 CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
172 capabilityDefinition.setName("cap" + Math.random());
173 capabilityDefinition.setType("tosca.capabilities.network.Bindable");
174 capabilityDefinition.setOwnerId(resourceId);
175 capabilityDefinition.setUniqueId("capUniqueId");
177 List<ComponentInstanceProperty> properties = new ArrayList<>();
178 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
179 instanceProperty.setUniqueId("ComponentInput1_uniqueId");
180 instanceProperty.setType("Integer");
181 instanceProperty.setName("prop_name");
182 instanceProperty.setDescription("prop_description_prop_desc");
183 instanceProperty.setOwnerId("capUniqueId");
184 instanceProperty.setSchema(new SchemaDefinition());
185 properties.add(instanceProperty);
186 capabilityDefinition.setProperties(properties);
187 Map<String, List<CapabilityDefinition>> capabilityMap = new HashMap<>();
188 capabilityMap.put(capabilityDefinition.getType(), Collections.singletonList(capabilityDefinition));
190 resource.setCapabilities(capabilityMap);
191 when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
193 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
194 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
195 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
196 operationId, operationName)),
198 Assert.assertTrue(interfaceOperationEither.isLeft());
203 public void createInterfaceOperationWithoutInterfaceTest() {
204 resource.getInterfaces().clear();
205 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
206 .thenReturn(Either.left(Collections.emptyMap()));
207 when(interfaceOperation.addInterfaces(any(), any())).thenReturn(Either.left(
208 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
209 when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
210 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
211 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
212 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
213 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
214 operationId, operationName)),
216 Assert.assertTrue(interfaceOperationEither.isLeft());
220 public void createInterfaceOperationWithoutInterfaceTestFail() {
221 resource.getInterfaces().clear();
222 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
223 .thenReturn(Either.left(Collections.emptyMap()));
224 when(interfaceOperation.addInterfaces(any(), any()))
225 .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
226 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
227 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
228 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
229 operationId, operationName)),
231 Assert.assertTrue(interfaceOperationEither.isRight());
235 public void shouldFailWhenCreateInterfaceOperationFailedTest() {
236 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
237 .thenReturn(Either.left(Collections.emptyMap()));
238 when(interfaceOperation.updateInterfaces(any(), any()))
239 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
240 Assert.assertTrue(interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
241 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)),
242 user, true).isRight());
246 public void updateInterfaceOperationTestWithArtifactSuccess() {
247 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
248 .thenReturn(Either.left(Collections.emptyMap()));
249 when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
250 .thenReturn(Either.left(new ArtifactDefinition()));
251 when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
252 when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
253 when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
254 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
255 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
256 interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
257 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
258 operationId, operationName)),
260 Assert.assertTrue(interfaceOperation.isLeft());
264 public void updateInterfaceOperationTestWithArtifactFailure() {
265 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
266 .thenReturn(Either.left(Collections.emptyMap()));
267 when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
268 when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
269 .thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
270 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
271 interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
272 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
273 operationId, operationName)),
275 Assert.assertTrue(interfaceOperation.isRight());
279 public void updateInterfaceOperationTestWithoutArtifact() {
280 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
281 .thenReturn(Either.left(Collections.emptyMap()));
282 when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
283 when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(
284 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName))));
285 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
286 interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
287 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
288 operationId, operationName)),
290 Assert.assertTrue(interfaceOperation.isLeft());
294 public void updateInterfaceOperationTestDoesntExist() {
295 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
296 .thenReturn(Either.left(Collections.emptyMap()));
297 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperation =
298 interfaceOperationBusinessLogic.updateInterfaceOperation(resourceId,
299 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
300 operationId, operationName)),
302 Assert.assertTrue(interfaceOperation.isRight());
306 public void createInterfaceOperationTestFailOnException() {
307 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
308 .thenReturn(Either.left(Collections.emptyMap()));
309 when(interfaceOperation.updateInterfaces(any(), any())).thenThrow(new RuntimeException());
310 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
311 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
312 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
313 operationId, operationName)),
315 Assert.assertTrue(interfaceOperationEither.isRight());
319 public void createInterfaceOperationTestFailOnFetchinGlobalTypes() {
320 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
321 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
322 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
323 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
324 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
325 operationId, operationName)),
327 Assert.assertTrue(interfaceOperationEither.isRight());
331 public void createInterfaceOperationTestFailOnValidation() {
332 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
333 .thenReturn(Either.left(Collections.emptyMap()));
334 when(interfaceOperationValidation
335 .validateInterfaceOperations(any(), any(), any(), anyMap(), anyBoolean()))
336 .thenReturn(Either.right(new ResponseFormat()));
337 Either<List<InterfaceDefinition>, ResponseFormat> interfaceOperationEither =
338 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
339 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId,
340 operationId, operationName)),
342 Assert.assertTrue(interfaceOperationEither.isRight());
346 public void deleteInterfaceOperationTestInterfaceDoesntExist() {
347 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId1,
348 Collections.singletonList(operationId), user, true).isRight());
352 public void deleteInterfaceOperationTestOperationDoesntExist() {
353 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
354 Collections.singletonList(operationId1), user, true).isRight());
358 public void deleteInterfaceOperationTestSuccess() {
359 resource.getInterfaces().get(interfaceId).getOperations()
360 .putAll(InterfaceOperationTestUtils.createMockOperationMap(operationId1, operationName));
361 when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
362 when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
363 .thenReturn(Either.left(new ArtifactDefinition()));
364 when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
365 when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
366 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
367 Collections.singletonList(operationId), user, true).isLeft());
371 public void shouldFailWhenDeleteInterfaceOperationFailedTest() {
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.OK);
376 when(interfaceOperation.updateInterfaces(any(), any()))
377 .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
378 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
379 Collections.singletonList(operationId), user, true).isRight());
383 public void shouldFailOnDeleteInterfaceWhenLockComponentFailedTest() {
384 when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
385 .thenReturn(StorageOperationStatus.NOT_FOUND);
386 when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
388 interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
389 Collections.singletonList(operationId), user, true);
390 } catch (ByActionStatusComponentException e){
391 Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
398 public void shouldFailOnGetInterfaceWhenLockComponentFailedTest() {
399 when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
400 .thenReturn(StorageOperationStatus.NOT_FOUND);
401 when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
403 interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
404 Collections.singletonList(operationId), user, true);
405 } catch (ByActionStatusComponentException e){
406 Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
413 public void shouldFailOnCreateInterfaceWhenLockComponentFailedTest() {
414 when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
415 .thenReturn(StorageOperationStatus.NOT_FOUND);
416 when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE)).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
418 interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
419 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId, operationName)),
421 } catch (ByActionStatusComponentException e){
422 Assert.assertEquals(ActionStatus.RESOURCE_NOT_FOUND, e.getActionStatus());
431 public void deleteInterfaceOperationTestFailOnArtifactDeletion() {
432 when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
433 when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
434 .thenReturn(Either.left(new ArtifactDefinition()));
435 when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.GENERAL_ERROR);
436 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
437 Collections.singletonList(operationId), user, true).isRight());
441 public void deleteInterfaceOperationTestFailOnException() {
442 when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
443 when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
444 .thenReturn(Either.left(new ArtifactDefinition()));
445 when(artifactCassandraDao.deleteArtifact(any(String.class))).thenThrow(new RuntimeException());
446 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
447 Collections.singletonList(operationId), user, true).isRight());
451 public void deleteInterfaceTestSuccess() {
452 when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
453 when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
454 .thenReturn(Either.left(new ArtifactDefinition()));
455 when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
456 when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
457 when(interfaceOperation.deleteInterface(any(), any())).thenReturn(Either.left(interfaceId));
458 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
459 Collections.singletonList(operationId), user, true).isLeft());
463 public void deleteInterfaceTestFailure() {
464 when(artifactToscaOperation.getArtifactById(any(), any())).thenReturn(Either.left(new ArtifactDefinition()));
465 when(artifactToscaOperation.removeArifactFromResource(any(), any(), any(), anyBoolean()))
466 .thenReturn(Either.left(new ArtifactDefinition()));
467 when(artifactCassandraDao.deleteArtifact(any(String.class))).thenReturn(CassandraOperationStatus.OK);
468 when(interfaceOperation.updateInterfaces(any(), any())).thenReturn(Either.left(Collections.emptyList()));
469 when(interfaceOperation.deleteInterface(any(), any()))
470 .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
471 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
472 Collections.singletonList(operationId), user, true).isRight());
476 public void getInterfaceOperationTestInterfaceDoesntExist() {
477 Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId1,
478 Collections.singletonList(operationId), user, true).isRight());
482 public void getInterfaceOperationTestOperationDoesntExist() {
483 Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
484 Collections.singletonList(operationId1), user, true).isRight());
488 public void getInterfaceOperationTest() {
489 Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
490 Collections.singletonList(operationId), user, true).isLeft());
494 public void getInterfaceOperationTestFailOnException() {
495 when(janusGraphDao.commit()).thenThrow(new RuntimeException());
496 Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
497 Collections.singletonList(operationId), user, true).isRight());
501 public void shouldFailWhenGetComponentFailedTest() {
502 when(toscaOperationFacade.getToscaElement(resourceId))
503 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
504 Assert.assertTrue(interfaceOperationBusinessLogic.deleteInterfaceOperation(resourceId, interfaceId,
505 Collections.singletonList(operationId), user, true).isRight());
506 Assert.assertTrue(interfaceOperationBusinessLogic.getInterfaceOperation(resourceId, interfaceId,
507 Collections.singletonList(operationId), user, true).isRight());
508 Assert.assertTrue(interfaceOperationBusinessLogic.createInterfaceOperation(resourceId,
509 Collections.singletonList(InterfaceOperationTestUtils.createMockInterface(interfaceId, operationId,
510 operationName)), user, true).isRight());
514 public void testGetAllInterfaceLifecycleTypes_TypesNotFound() {
515 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
516 .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
517 Either<Map<String, InterfaceDefinition>, ResponseFormat> response =
518 interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(any());
519 Assert.assertTrue(response.isRight());
523 public void testGetAllInterfaceLifecycleTypes_Success() {
524 InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
525 interfaceDefinition.setUniqueId(interfaceId);
526 interfaceDefinition.setType(interfaceId);
527 Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
528 interfaceDefinitionMap.put(interfaceDefinition.getUniqueId(), interfaceDefinition);
529 when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(any()))
530 .thenReturn(Either.left(interfaceDefinitionMap));
531 Either<Map<String, InterfaceDefinition>, ResponseFormat> response =
532 interfaceOperationBusinessLogic.getAllInterfaceLifecycleTypes(StringUtils.EMPTY);
533 Assert.assertEquals(1, response.left().value().size());