2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
23 package org.openecomp.sdc.be.components;
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;
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;
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;
87 class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
90 private ServletContext servletContext;
92 private IPropertyOperation propertyOperation;
94 private WebAppContextWrapper webAppContextWrapper;
96 private UserBusinessLogic mockUserAdmin;
98 private WebApplicationContext webAppContext;
100 private ComponentsUtils componentsUtils;
102 private ToscaOperationFacade toscaOperationFacade;
104 private UserValidations userValidations;
106 private IGraphLockOperation graphLockOperation;
108 private JanusGraphDao janusGraphDao;
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";
121 public void setup() {
122 MockitoAnnotations.openMocks(this);
123 ExternalConfiguration.setAppName("catalog-be");
125 // User data and management
127 user.setUserId("jh003");
128 user.setFirstName("Jimmi");
129 user.setLastName("Hendrix");
130 user.setRole(Role.ADMIN.name());
132 when(mockUserAdmin.getUser("jh003", false)).thenReturn(user);
133 when(userValidations.validateUserExists("jh003")).thenReturn(user);
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);
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);
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, "");
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);
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, "");
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));
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());
188 void testGetPropertyFromService() {
189 Service service = new Service();
190 service.setUniqueId(serviceId);
192 PropertyDefinition property1 = createPropertyObject("someProperty", null);
193 service.setProperties(Arrays.asList(property1));
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());
199 assertTrue(serviceProperty.isLeft());
200 assertEquals(serviceProperty.left().value().getValue().getUniqueId(), property1.getUniqueId());
204 void testPropertyNotFoundOnService() {
205 Service service = new Service();
206 service.setUniqueId(serviceId);
208 PropertyDefinition property1 = createPropertyObject("someProperty", null);
209 service.setProperties(Arrays.asList(property1));
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());
215 assertTrue(serviceProperty.isRight());
219 void isPropertyUsedByComponentInterface() {
220 Service service = new Service();
221 service.setUniqueId(serviceId);
222 service.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType, operationId, operationType));
224 PropertyDefinition propDef1 = new PropertyDefinition();
225 propDef1.setUniqueId("ComponentInput1_uniqueId");
226 assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef1));
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));
235 void isPropertyUsedByComponentInstanceInterface() {
236 Map<String, InterfaceDefinition> newInterfaceDefinition = InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType,
237 operationId, operationType);
238 ComponentInstanceInterface componentInstanceInterface = new ComponentInstanceInterface(interfaceType,
239 newInterfaceDefinition.get(interfaceType));
241 Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces = new HashMap<>();
242 componentInstanceInterfaces.put("Test", Arrays.asList(componentInstanceInterface));
244 Service service = new Service();
245 service.setUniqueId(serviceId);
246 service.setComponentInstancesInterfaces(componentInstanceInterfaces);
248 PropertyDefinition propDef1 = new PropertyDefinition();
249 propDef1.setUniqueId("ComponentInput1_uniqueId");
250 assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef1));
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));
259 void isPropertyUsedByComponentParentComponentInstanceInterface() {
260 Map<String, InterfaceDefinition> newInterfaceDefinition = InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType,
261 operationId, operationType);
262 ComponentInstanceInterface componentInstanceInterface = new ComponentInstanceInterface(interfaceType,
263 newInterfaceDefinition.get(interfaceType));
265 Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces = new HashMap<>();
266 componentInstanceInterfaces.put("Test", Arrays.asList(componentInstanceInterface));
268 Service parentService = new Service();
269 parentService.setComponentInstancesInterfaces(componentInstanceInterfaces);
270 Service childService = new Service();
271 childService.setUniqueId(serviceId);
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));
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));
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);
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());
308 void deleteProperty_RESOURCE_NOT_FOUND() throws Exception {
310 Resource resource = new Resource();
311 PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
313 resource.setProperties(Arrays.asList(property1));
314 String resourceId = "myResource";
315 resource.setUniqueId(resourceId);
317 Field baseBusinessLogic3;
318 baseBusinessLogic3 = propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
319 baseBusinessLogic3.setAccessible(true);
320 baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
322 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
324 StorageOperationStatus lockResult = StorageOperationStatus.OK;
325 when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
327 Component resourcereturn = new Resource();
328 resourcereturn.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
329 resourcereturn.setIsDeleted(false);
330 resourcereturn.setLastUpdaterUserId("USR01");
332 Either<Component, StorageOperationStatus> toscastatus = Either.left(resource);
333 when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
335 assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty", "i726").isRight());
339 void deleteProperty_RESTRICTED_OPERATION() throws Exception {
340 Resource resource = new Resource();
341 PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
343 resource.setProperties(Arrays.asList(property1));
344 String resourceId = "myResource";
345 resource.setUniqueId(resourceId);
347 Field baseBusinessLogic3;
348 baseBusinessLogic3 = propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
349 baseBusinessLogic3.setAccessible(true);
350 baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
352 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
354 StorageOperationStatus lockResult = StorageOperationStatus.OK;
355 when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
357 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
358 resource.setIsDeleted(false);
359 resource.setLastUpdaterUserId("USR01");
361 Either<Component, StorageOperationStatus> toscastatus = Either.left(resource);
362 when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
364 assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty", "i726").isRight());
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));
375 final Field baseBusinessLogic3 =
376 propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
377 baseBusinessLogic3.setAccessible(true);
378 baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
380 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
382 when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
384 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
385 resource.setIsDeleted(false);
386 resource.setLastUpdaterUserId("USR01");
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<>()));
392 assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "PROP", "USR01").isRight());
396 void findComponentByIdTest() throws BusinessLogicException {
398 final Resource resource = new Resource();
399 resource.setUniqueId(resourceId);
400 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
402 final Component actualResource = propertyBusinessLogic.findComponentById(resourceId).orElse(null);
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())));
410 void findComponentById_resourceNotFoundTest() throws BusinessLogicException {
412 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.right(null));
413 Mockito.when(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, "")).thenReturn(new ResponseFormat());
415 assertThrows(BusinessLogicException.class, () -> {
416 propertyBusinessLogic.findComponentById(resourceId);
421 void updateComponentPropertyTest() throws BusinessLogicException {
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));
429 final PropertyDefinition actualPropertyDefinition = propertyBusinessLogic
430 .updateComponentProperty(resourceId, propertyDefinition);
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())));
440 void updateComponentProperty_updateFailedTest() throws BusinessLogicException {
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);
450 assertThrows(BusinessLogicException.class, () -> {
451 propertyBusinessLogic.updateComponentProperty(resourceId, propertyDefinition);
456 void copyPropertyToComponentTest() throws ToscaOperationException {
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);
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);
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));
481 final Component actualComponent = propertyBusinessLogic.copyPropertyToComponent(expectedResource, propertiesToCopyList, true);
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));
492 void copyPropertyToComponent1() throws ToscaOperationException {
494 final Resource expectedResource = new Resource();
495 expectedResource.setUniqueId(resourceId);
497 final Component actualComponent = propertyBusinessLogic.copyPropertyToComponent(expectedResource, null);
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()));
506 void copyPropertyToComponent_copyFailed() throws ToscaOperationException {
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));
518 assertThrows(ToscaOperationException.class, () -> {
519 propertyBusinessLogic.copyPropertyToComponent(expectedResource, propertiesToCopyList, true);