Fix 'Substitution Node not updated during import'-bug
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / PropertyBusinessLogicTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  * Modifications copyright (c) 2019 Nokia
20  * ================================================================================
21  */
22
23 package org.openecomp.sdc.be.components;
24
25 import static org.hamcrest.MatcherAssert.assertThat;
26 import static org.hamcrest.Matchers.equalTo;
27 import static org.hamcrest.Matchers.hasItems;
28 import static org.hamcrest.Matchers.hasSize;
29 import static org.hamcrest.Matchers.instanceOf;
30 import static org.hamcrest.Matchers.is;
31 import static org.hamcrest.Matchers.notNullValue;
32 import static org.hamcrest.Matchers.nullValue;
33 import static org.junit.jupiter.api.Assertions.assertEquals;
34 import static org.junit.jupiter.api.Assertions.assertFalse;
35 import static org.junit.jupiter.api.Assertions.assertThrows;
36 import static org.junit.jupiter.api.Assertions.assertTrue;
37 import static org.mockito.ArgumentMatchers.any;
38 import static org.mockito.ArgumentMatchers.anyString;
39 import static org.mockito.ArgumentMatchers.eq;
40 import static org.mockito.Mockito.when;
41
42 import fj.data.Either;
43 import java.lang.reflect.Field;
44 import java.util.ArrayList;
45 import java.util.Arrays;
46 import java.util.HashMap;
47 import java.util.List;
48 import java.util.Map;
49 import javax.servlet.ServletContext;
50 import org.junit.jupiter.api.BeforeEach;
51 import org.junit.jupiter.api.Test;
52 import org.mockito.InjectMocks;
53 import org.mockito.Mock;
54 import org.mockito.Mockito;
55 import org.mockito.MockitoAnnotations;
56 import org.openecomp.sdc.be.components.impl.BaseBusinessLogicMock;
57 import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
58 import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
59 import org.openecomp.sdc.be.components.validation.UserValidations;
60 import org.openecomp.sdc.be.dao.api.ActionStatus;
61 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
62 import org.openecomp.sdc.be.impl.ComponentsUtils;
63 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
64 import org.openecomp.sdc.be.model.Component;
65 import org.openecomp.sdc.be.model.ComponentInstanceInterface;
66 import org.openecomp.sdc.be.model.InterfaceDefinition;
67 import org.openecomp.sdc.be.model.LifecycleStateEnum;
68 import org.openecomp.sdc.be.model.PropertyConstraint;
69 import org.openecomp.sdc.be.model.PropertyDefinition;
70 import org.openecomp.sdc.be.model.Resource;
71 import org.openecomp.sdc.be.model.Service;
72 import org.openecomp.sdc.be.model.User;
73 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
74 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ToscaOperationException;
75 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
76 import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
77 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
78 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
79 import org.openecomp.sdc.be.user.Role;
80 import org.openecomp.sdc.be.user.UserBusinessLogic;
81 import org.openecomp.sdc.common.api.Constants;
82 import org.openecomp.sdc.common.impl.ExternalConfiguration;
83 import org.openecomp.sdc.exception.ResponseFormat;
84 import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
85 import org.springframework.web.context.WebApplicationContext;
86
87 class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
88
89     @Mock
90     private ServletContext servletContext;
91     @Mock
92     private IPropertyOperation propertyOperation;
93     @Mock
94     private WebAppContextWrapper webAppContextWrapper;
95     @Mock
96     private UserBusinessLogic mockUserAdmin;
97     @Mock
98     private WebApplicationContext webAppContext;
99     @Mock
100     private ComponentsUtils componentsUtils;
101     @Mock
102     private ToscaOperationFacade toscaOperationFacade;
103     @Mock
104     private UserValidations userValidations;
105     @Mock
106     private IGraphLockOperation graphLockOperation;
107     @Mock
108     private JanusGraphDao janusGraphDao;
109
110     @InjectMocks
111     private PropertyBusinessLogic propertyBusinessLogic = new PropertyBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
112         groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
113     private User user = null;
114     private String resourceId = "resourceforproperty.0.1";
115     private String serviceId = "serviceForProperty.0.1";
116     private static final String interfaceType = "interfaceType";
117     private static final String operationType = "operationType";
118     private static final String operationId = "operationId";
119
120     @BeforeEach
121     public void setup() {
122         MockitoAnnotations.openMocks(this);
123         ExternalConfiguration.setAppName("catalog-be");
124
125         // User data and management
126         user = new User();
127         user.setUserId("jh003");
128         user.setFirstName("Jimmi");
129         user.setLastName("Hendrix");
130         user.setRole(Role.ADMIN.name());
131
132         when(mockUserAdmin.getUser("jh003", false)).thenReturn(user);
133         when(userValidations.validateUserExists("jh003")).thenReturn(user);
134
135         // Servlet Context attributes
136         when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
137         when(servletContext.getAttribute(Constants.PROPERTY_OPERATION_MANAGER)).thenReturn(propertyOperation);
138         when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
139         when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
140     }
141
142     @Test
143     void getProperty_propertyNotFound() throws Exception {
144         Resource resource = new Resource();
145         PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
146         PropertyDefinition property2 = createPropertyObject("someProperty2", "myResource");
147         resource.setProperties(Arrays.asList(property1, property2));
148         String resourceId = "myResource";
149         resource.setUniqueId(resourceId);
150
151         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
152         Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> nonExistingProperty = propertyBusinessLogic
153             .getComponentProperty(resourceId, "NonExistingProperty", user.getUserId());
154         assertTrue(nonExistingProperty.isRight());
155         Mockito.verify(componentsUtils).getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, "");
156     }
157
158     @Test
159     void getProperty_propertyNotBelongsToResource() throws Exception {
160         Resource resource = new Resource();
161         PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
162         resource.setProperties(Arrays.asList(property1));
163         String resourceId = "myResource";
164         resource.setUniqueId(resourceId);
165
166         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
167         Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> notFoundProperty = propertyBusinessLogic
168             .getComponentProperty(resourceId, "invalidId", user.getUserId());
169         assertTrue(notFoundProperty.isRight());
170         Mockito.verify(componentsUtils).getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, "");
171     }
172
173     @Test
174     void getProperty() throws Exception {
175         Resource resource = new Resource();
176         resource.setUniqueId(resourceId);
177         PropertyDefinition property1 = createPropertyObject("someProperty", null);
178         resource.setProperties(Arrays.asList(property1));
179
180         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
181         Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> foundProperty = propertyBusinessLogic
182             .getComponentProperty(resourceId, property1.getUniqueId(), user.getUserId());
183         assertTrue(foundProperty.isLeft());
184         assertEquals(foundProperty.left().value().getValue().getUniqueId(), property1.getUniqueId());
185     }
186
187     @Test
188     void testGetPropertyFromService() {
189         Service service = new Service();
190         service.setUniqueId(serviceId);
191
192         PropertyDefinition property1 = createPropertyObject("someProperty", null);
193         service.setProperties(Arrays.asList(property1));
194
195         Mockito.when(toscaOperationFacade.getToscaElement(serviceId)).thenReturn(Either.left(service));
196         Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> serviceProperty =
197             propertyBusinessLogic.getComponentProperty(serviceId, property1.getUniqueId(), user.getUserId());
198
199         assertTrue(serviceProperty.isLeft());
200         assertEquals(serviceProperty.left().value().getValue().getUniqueId(), property1.getUniqueId());
201     }
202
203     @Test
204     void testPropertyNotFoundOnService() {
205         Service service = new Service();
206         service.setUniqueId(serviceId);
207
208         PropertyDefinition property1 = createPropertyObject("someProperty", null);
209         service.setProperties(Arrays.asList(property1));
210
211         Mockito.when(toscaOperationFacade.getToscaElement(serviceId)).thenReturn(Either.left(service));
212         Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> serviceProperty =
213             propertyBusinessLogic.getComponentProperty(serviceId, "notExistingPropId", user.getUserId());
214
215         assertTrue(serviceProperty.isRight());
216     }
217
218     @Test
219     void isPropertyUsedByComponentInterface() {
220         Service service = new Service();
221         service.setUniqueId(serviceId);
222         service.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType, operationId, operationType));
223
224         PropertyDefinition propDef1 = new PropertyDefinition();
225         propDef1.setUniqueId("ComponentInput1_uniqueId");
226         assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef1));
227
228         PropertyDefinition propDef2 = new PropertyDefinition();
229         propDef1.setUniqueId("inputId2");
230         Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
231         assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef2));
232     }
233
234     @Test
235     void isPropertyUsedByComponentInstanceInterface() {
236         Map<String, InterfaceDefinition> newInterfaceDefinition = InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType,
237             operationId, operationType);
238         ComponentInstanceInterface componentInstanceInterface = new ComponentInstanceInterface(interfaceType,
239             newInterfaceDefinition.get(interfaceType));
240
241         Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces = new HashMap<>();
242         componentInstanceInterfaces.put("Test", Arrays.asList(componentInstanceInterface));
243
244         Service service = new Service();
245         service.setUniqueId(serviceId);
246         service.setComponentInstancesInterfaces(componentInstanceInterfaces);
247
248         PropertyDefinition propDef1 = new PropertyDefinition();
249         propDef1.setUniqueId("ComponentInput1_uniqueId");
250         assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef1));
251
252         PropertyDefinition propDef2 = new PropertyDefinition();
253         propDef1.setUniqueId("inputId2");
254         Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
255         assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef2));
256     }
257
258     @Test
259     void isPropertyUsedByComponentParentComponentInstanceInterface() {
260         Map<String, InterfaceDefinition> newInterfaceDefinition = InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType,
261             operationId, operationType);
262         ComponentInstanceInterface componentInstanceInterface = new ComponentInstanceInterface(interfaceType,
263             newInterfaceDefinition.get(interfaceType));
264
265         Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces = new HashMap<>();
266         componentInstanceInterfaces.put("Test", Arrays.asList(componentInstanceInterface));
267
268         Service parentService = new Service();
269         parentService.setComponentInstancesInterfaces(componentInstanceInterfaces);
270         Service childService = new Service();
271         childService.setUniqueId(serviceId);
272
273         PropertyDefinition propDef1 = new PropertyDefinition();
274         propDef1.setUniqueId("ComponentInput1_uniqueId");
275         Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(Arrays.asList(parentService)));
276         assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(childService, propDef1));
277
278         PropertyDefinition propDef2 = new PropertyDefinition();
279         propDef1.setUniqueId("inputId2");
280         Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
281         assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(childService, propDef2));
282     }
283
284     private PropertyDefinition createPropertyObject(final String propertyName, final String resourceId) {
285         final PropertyDefinition pd = new PropertyDefinition();
286         List<PropertyConstraint> constraints = new ArrayList<>();
287         pd.setConstraints(null);
288         pd.setDefaultValue("100");
289         pd.setDescription("Size of thasdasdasdasde local disk, in Gigabytes (GB), available to applications running on the Compute node");
290         pd.setPassword(false);
291         pd.setRequired(true);
292         pd.setType("Integer");
293         pd.setOwnerId(resourceId);
294         pd.setName(propertyName);
295         pd.setUniqueId(resourceId + "." + propertyName);
296         return pd;
297     }
298
299     @Test
300     void deleteProperty_CONNECTION_FAILURE() {
301         StorageOperationStatus lockResult = StorageOperationStatus.CONNECTION_FAILURE;
302         when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
303         when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(new Resource()));
304         assertTrue(propertyBusinessLogic.deletePropertyFromComponent("resourceforproperty.0.1", "someProperty", "i726").isRight());
305     }
306
307     @Test
308     void deleteProperty_RESOURCE_NOT_FOUND() throws Exception {
309
310         Resource resource = new Resource();
311         PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
312
313         resource.setProperties(Arrays.asList(property1));
314         String resourceId = "myResource";
315         resource.setUniqueId(resourceId);
316
317         Field baseBusinessLogic3;
318         baseBusinessLogic3 = propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
319         baseBusinessLogic3.setAccessible(true);
320         baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
321
322         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
323
324         StorageOperationStatus lockResult = StorageOperationStatus.OK;
325         when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
326
327         Component resourcereturn = new Resource();
328         resourcereturn.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
329         resourcereturn.setIsDeleted(false);
330         resourcereturn.setLastUpdaterUserId("USR01");
331
332         Either<Component, StorageOperationStatus> toscastatus = Either.left(resource);
333         when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
334
335         assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty", "i726").isRight());
336     }
337
338     @Test
339     void deleteProperty_RESTRICTED_OPERATION() throws Exception {
340         Resource resource = new Resource();
341         PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
342
343         resource.setProperties(Arrays.asList(property1));
344         String resourceId = "myResource";
345         resource.setUniqueId(resourceId);
346
347         Field baseBusinessLogic3;
348         baseBusinessLogic3 = propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
349         baseBusinessLogic3.setAccessible(true);
350         baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
351
352         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
353
354         StorageOperationStatus lockResult = StorageOperationStatus.OK;
355         when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
356
357         resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
358         resource.setIsDeleted(false);
359         resource.setLastUpdaterUserId("USR01");
360
361         Either<Component, StorageOperationStatus> toscastatus = Either.left(resource);
362         when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
363
364         assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty", "i726").isRight());
365     }
366
367     @Test
368     void deleteProperty_RESTRICTED_() throws Exception {
369         final PropertyDefinition property1 = createPropertyObject("PROP", "RES01");
370         final Resource resource = new Resource();
371         final String resourceId = "myResource";
372         resource.setUniqueId(resourceId);
373         resource.setProperties(Arrays.asList(property1));
374
375         final Field baseBusinessLogic3 =
376             propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
377         baseBusinessLogic3.setAccessible(true);
378         baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
379
380         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
381
382         when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
383
384         resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
385         resource.setIsDeleted(false);
386         resource.setLastUpdaterUserId("USR01");
387
388         when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(Either.left(resource));
389         when(toscaOperationFacade.deletePropertyOfComponent(any(), anyString())).thenReturn(StorageOperationStatus.OK);
390         when(toscaOperationFacade.getParentComponents(anyString())).thenReturn(Either.left(new ArrayList<>()));
391
392         assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "PROP", "USR01").isRight());
393     }
394
395     @Test
396     void findComponentByIdTest() throws BusinessLogicException {
397         //give
398         final Resource resource = new Resource();
399         resource.setUniqueId(resourceId);
400         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
401         //when
402         final Component actualResource = propertyBusinessLogic.findComponentById(resourceId).orElse(null);
403         //then
404         assertThat("Actual resource should not be null", actualResource, is(notNullValue()));
405         assertThat("Actual resource must have the expected id",
406             actualResource.getUniqueId(), is(equalTo(resource.getUniqueId())));
407     }
408
409     @Test
410     void findComponentById_resourceNotFoundTest() throws BusinessLogicException {
411         //given
412         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.right(null));
413         Mockito.when(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, "")).thenReturn(new ResponseFormat());
414         //when
415         assertThrows(BusinessLogicException.class, () -> {
416             propertyBusinessLogic.findComponentById(resourceId);
417         });
418     }
419
420     @Test
421     void updateComponentPropertyTest() throws BusinessLogicException {
422         //given
423         final Resource resource = new Resource();
424         resource.setUniqueId(resourceId);
425         final PropertyDefinition propertyDefinition = createPropertyObject("testProperty", resourceId);
426         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
427         when(toscaOperationFacade.updatePropertyOfComponent(resource, propertyDefinition)).thenReturn(Either.left(propertyDefinition));
428         //when
429         final PropertyDefinition actualPropertyDefinition = propertyBusinessLogic
430             .updateComponentProperty(resourceId, propertyDefinition);
431         //then
432         assertThat("Actual property definition should not be null", actualPropertyDefinition, is(notNullValue()));
433         assertThat("Actual property definition must have the expected id",
434             actualPropertyDefinition.getOwnerId(), is(equalTo(resource.getUniqueId())));
435         assertThat("Actual property definition must have the expected id",
436             actualPropertyDefinition.getName(), is(equalTo(propertyDefinition.getName())));
437     }
438
439     @Test
440     void updateComponentProperty_updateFailedTest() throws BusinessLogicException {
441         //given
442         final Resource resource = new Resource();
443         resource.setUniqueId(resourceId);
444         final PropertyDefinition propertyDefinition = createPropertyObject("testProperty", resourceId);
445         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
446         when(toscaOperationFacade.updatePropertyOfComponent(resource, propertyDefinition)).thenReturn(Either.right(null));
447         when(componentsUtils.getResponseFormatByResource(Mockito.any(), Mockito.anyString())).thenReturn(new ResponseFormat());
448         when(componentsUtils.convertFromStorageResponse(Mockito.any())).thenReturn(null);
449         //when
450         assertThrows(BusinessLogicException.class, () -> {
451             propertyBusinessLogic.updateComponentProperty(resourceId, propertyDefinition);
452         });
453     }
454
455     @Test
456     void copyPropertyToComponentTest() throws ToscaOperationException {
457         //given
458         final Resource expectedResource = new Resource();
459         expectedResource.setUniqueId(resourceId);
460         final List<PropertyDefinition> propertiesToCopyList = new ArrayList<>();
461         final PropertyDefinition property1 = createPropertyObject("property1", resourceId);
462         propertiesToCopyList.add(property1);
463         final PropertyDefinition property2 = createPropertyObject("property2", resourceId);
464         propertiesToCopyList.add(property2);
465
466         final PropertyDefinition copiedProperty1 = new PropertyDefinition(property1);
467         copiedProperty1.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, copiedProperty1.getName()));
468         expectedResource.addProperty(copiedProperty1);
469         final PropertyDefinition copiedProperty2 = new PropertyDefinition(property2);
470         copiedProperty2.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, copiedProperty2.getName()));
471         expectedResource.addProperty(copiedProperty2);
472
473         Mockito.when(toscaOperationFacade
474                 .addPropertyToComponent(Mockito.any(PropertyDefinition.class), eq(expectedResource)))
475             .thenReturn(Either.left(copiedProperty1));
476         Mockito.when(toscaOperationFacade
477                 .addPropertyToComponent(Mockito.any(PropertyDefinition.class), eq(expectedResource)))
478             .thenReturn(Either.left(copiedProperty2));
479         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(expectedResource));
480         //when
481         final Component actualComponent = propertyBusinessLogic.copyPropertyToComponent(expectedResource, propertiesToCopyList, true);
482         //then
483         assertThat("Actual component should not be null", actualComponent, is(notNullValue()));
484         assertThat("Actual component should be an instance of Resource", actualComponent, is(instanceOf(Resource.class)));
485         assertThat("Actual component should have the expected id", actualComponent.getUniqueId(), is(equalTo(expectedResource.getUniqueId())));
486         assertThat("Actual component should have 2 properties", actualComponent.getProperties(), hasSize(2));
487         assertThat("Actual component should have the expected properties", actualComponent.getProperties(),
488             hasItems(copiedProperty1, copiedProperty2));
489     }
490
491     @Test
492     void copyPropertyToComponent1() throws ToscaOperationException {
493         //given
494         final Resource expectedResource = new Resource();
495         expectedResource.setUniqueId(resourceId);
496         //when
497         final Component actualComponent = propertyBusinessLogic.copyPropertyToComponent(expectedResource, null);
498         //then
499         assertThat("Actual component should not be null", actualComponent, is(notNullValue()));
500         assertThat("Actual component should be an instance of Resource", actualComponent, is(instanceOf(Resource.class)));
501         assertThat("Actual component should have the expected id", actualComponent.getUniqueId(), is(equalTo(expectedResource.getUniqueId())));
502         assertThat("Actual component should have no properties", actualComponent.getProperties(), is(nullValue()));
503     }
504
505     @Test
506     void copyPropertyToComponent_copyFailed() throws ToscaOperationException {
507         //given
508         final Resource expectedResource = new Resource();
509         expectedResource.setUniqueId(resourceId);
510         final List<PropertyDefinition> propertiesToCopyList = new ArrayList<>();
511         final PropertyDefinition property1 = createPropertyObject("property1", resourceId);
512         propertiesToCopyList.add(property1);
513         Mockito.when(toscaOperationFacade
514                 .addPropertyToComponent(Mockito.any(PropertyDefinition.class), eq(expectedResource)))
515             .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
516         Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(expectedResource));
517         //when
518         assertThrows(ToscaOperationException.class, () -> {
519             propertyBusinessLogic.copyPropertyToComponent(expectedResource, propertiesToCopyList, true);
520         });
521     }
522 }