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 fj.data.Either;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.InjectMocks;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.mockito.MockitoAnnotations;
32 import org.openecomp.sdc.be.components.impl.BaseBusinessLogicMock;
33 import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
34 import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
35 import org.openecomp.sdc.be.components.validation.UserValidations;
36 import org.openecomp.sdc.be.config.ConfigurationManager;
37 import org.openecomp.sdc.be.dao.api.ActionStatus;
38 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
39 import org.openecomp.sdc.be.impl.ComponentsUtils;
40 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
41 import org.openecomp.sdc.be.model.Component;
42 import org.openecomp.sdc.be.model.ComponentInstanceInterface;
43 import org.openecomp.sdc.be.model.InterfaceDefinition;
44 import org.openecomp.sdc.be.model.LifecycleStateEnum;
45 import org.openecomp.sdc.be.model.PropertyConstraint;
46 import org.openecomp.sdc.be.model.PropertyDefinition;
47 import org.openecomp.sdc.be.model.Resource;
48 import org.openecomp.sdc.be.model.Service;
49 import org.openecomp.sdc.be.model.User;
50 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
51 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ToscaOperationException;
52 import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation;
53 import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
54 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
55 import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder;
56 import org.openecomp.sdc.be.user.Role;
57 import org.openecomp.sdc.be.user.UserBusinessLogic;
58 import org.openecomp.sdc.common.api.ConfigurationSource;
59 import org.openecomp.sdc.common.api.Constants;
60 import org.openecomp.sdc.common.impl.ExternalConfiguration;
61 import org.openecomp.sdc.common.impl.FSConfigurationSource;
62 import org.openecomp.sdc.exception.ResponseFormat;
63 import org.openecomp.sdc.test.utils.InterfaceOperationTestUtils;
64 import org.springframework.web.context.WebApplicationContext;
66 import javax.servlet.ServletContext;
67 import java.lang.reflect.Field;
68 import java.util.ArrayList;
69 import java.util.Arrays;
70 import java.util.HashMap;
71 import java.util.List;
74 import static org.hamcrest.Matchers.equalTo;
75 import static org.hamcrest.Matchers.hasItems;
76 import static org.hamcrest.Matchers.hasSize;
77 import static org.hamcrest.Matchers.instanceOf;
78 import static org.hamcrest.Matchers.is;
79 import static org.hamcrest.Matchers.notNullValue;
80 import static org.hamcrest.Matchers.nullValue;
81 import static org.junit.Assert.assertEquals;
82 import static org.junit.Assert.assertFalse;
83 import static org.junit.Assert.assertThat;
84 import static org.junit.Assert.assertTrue;
85 import static org.mockito.ArgumentMatchers.any;
86 import static org.mockito.ArgumentMatchers.anyObject;
87 import static org.mockito.ArgumentMatchers.anyString;
88 import static org.mockito.ArgumentMatchers.eq;
89 import static org.mockito.Mockito.when;
91 public class PropertyBusinessLogicTest extends BaseBusinessLogicMock {
94 private ServletContext servletContext;
96 private IPropertyOperation propertyOperation;
98 private WebAppContextWrapper webAppContextWrapper;
100 private UserBusinessLogic mockUserAdmin;
102 private WebApplicationContext webAppContext;
104 private ComponentsUtils componentsUtils;
106 private ToscaOperationFacade toscaOperationFacade;
108 private UserValidations userValidations;
110 IGraphLockOperation graphLockOperation;
112 JanusGraphDao janusGraphDao;
115 private PropertyBusinessLogic propertyBusinessLogic = new PropertyBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
116 groupTypeOperation, interfaceOperation, interfaceLifecycleTypeOperation, artifactToscaOperation);
117 private User user = null;
118 private String resourceId = "resourceforproperty.0.1";
119 private String serviceId = "serviceForProperty.0.1";
120 private static final String interfaceType = "interfaceType";
121 private static final String operationType = "operationType";
122 private static final String operationId = "operationId";
125 public void setup() {
126 MockitoAnnotations.initMocks(this);
127 ExternalConfiguration.setAppName("catalog-be");
129 // init Configuration
130 String appConfigDir = "src/test/resources/config/catalog-be";
131 ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
132 ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
134 // User data and management
136 user.setUserId("jh003");
137 user.setFirstName("Jimmi");
138 user.setLastName("Hendrix");
139 user.setRole(Role.ADMIN.name());
141 when(mockUserAdmin.getUser("jh003", false)).thenReturn(user);
142 when(userValidations.validateUserExists(eq("jh003"))).thenReturn(user);
144 // Servlet Context attributes
145 when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
146 when(servletContext.getAttribute(Constants.PROPERTY_OPERATION_MANAGER)).thenReturn(propertyOperation);
147 when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
148 // when(servletContext.getAttribute(Constants.RESOURCE_OPERATION_MANAGER)).thenReturn(resourceOperation);
149 when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
153 public void getProperty_propertyNotFound() throws Exception {
154 Resource resource = new Resource();
155 PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
156 PropertyDefinition property2 = createPropertyObject("someProperty2", "myResource");
157 resource.setProperties(Arrays.asList(property1, property2));
158 String resourceId = "myResource";
159 resource.setUniqueId(resourceId);
161 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
162 Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> nonExistingProperty = propertyBusinessLogic
163 .getComponentProperty(resourceId, "NonExistingProperty", user.getUserId());
164 assertTrue(nonExistingProperty.isRight());
165 Mockito.verify(componentsUtils).getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, "");
169 public void getProperty_propertyNotBelongsToResource() throws Exception {
170 Resource resource = new Resource();
171 PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
172 resource.setProperties(Arrays.asList(property1));
173 String resourceId = "myResource";
174 resource.setUniqueId(resourceId);
176 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
177 Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> notFoundProperty = propertyBusinessLogic
178 .getComponentProperty(resourceId, "invalidId", user.getUserId());
179 assertTrue(notFoundProperty.isRight());
180 Mockito.verify(componentsUtils).getResponseFormat(ActionStatus.PROPERTY_NOT_FOUND, "");
184 public void getProperty() throws Exception {
185 Resource resource = new Resource();
186 resource.setUniqueId(resourceId);
187 PropertyDefinition property1 = createPropertyObject("someProperty", null);
188 resource.setProperties(Arrays.asList(property1));
190 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
191 Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> foundProperty = propertyBusinessLogic
192 .getComponentProperty(resourceId, property1.getUniqueId(), user.getUserId());
193 assertTrue(foundProperty.isLeft());
194 assertEquals(foundProperty.left().value().getValue().getUniqueId(), property1.getUniqueId());
198 public void testGetPropertyFromService() {
199 Service service = new Service();
200 service.setUniqueId(serviceId);
202 PropertyDefinition property1 = createPropertyObject("someProperty", null);
203 service.setProperties(Arrays.asList(property1));
205 Mockito.when(toscaOperationFacade.getToscaElement(serviceId)).thenReturn(Either.left(service));
206 Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> serviceProperty =
207 propertyBusinessLogic.getComponentProperty(serviceId, property1.getUniqueId(), user.getUserId());
209 assertTrue(serviceProperty.isLeft());
210 assertEquals(serviceProperty.left().value().getValue().getUniqueId(), property1.getUniqueId());
214 public void testPropertyNotFoundOnService() {
215 Service service = new Service();
216 service.setUniqueId(serviceId);
218 PropertyDefinition property1 = createPropertyObject("someProperty", null);
219 service.setProperties(Arrays.asList(property1));
221 Mockito.when(toscaOperationFacade.getToscaElement(serviceId)).thenReturn(Either.left(service));
222 Either<Map.Entry<String, PropertyDefinition>, ResponseFormat> serviceProperty =
223 propertyBusinessLogic.getComponentProperty(serviceId, "notExistingPropId", user.getUserId());
225 assertTrue(serviceProperty.isRight());
229 public void isPropertyUsedByComponentInterface(){
230 Service service = new Service();
231 service.setUniqueId(serviceId);
232 service.setInterfaces(InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType, operationId, operationType));
234 PropertyDefinition propDef1 = new PropertyDefinition();
235 propDef1.setUniqueId("ComponentInput1_uniqueId");
236 assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef1));
238 PropertyDefinition propDef2 = new PropertyDefinition();
239 propDef1.setUniqueId("inputId2");
240 Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
241 assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef2));
245 public void isPropertyUsedByComponentInstanceInterface(){
246 Map<String, InterfaceDefinition> newInterfaceDefinition = InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType, operationId, operationType);
247 ComponentInstanceInterface componentInstanceInterface = new ComponentInstanceInterface(interfaceType, newInterfaceDefinition.get(interfaceType));
249 Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces = new HashMap<>();
250 componentInstanceInterfaces.put("Test", Arrays.asList(componentInstanceInterface));
252 Service service = new Service();
253 service.setUniqueId(serviceId);
254 service.setComponentInstancesInterfaces(componentInstanceInterfaces);
256 PropertyDefinition propDef1 = new PropertyDefinition();
257 propDef1.setUniqueId("ComponentInput1_uniqueId");
258 assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef1));
260 PropertyDefinition propDef2 = new PropertyDefinition();
261 propDef1.setUniqueId("inputId2");
262 Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
263 assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(service, propDef2));
267 public void isPropertyUsedByComponentParentComponentInstanceInterface(){
268 Map<String, InterfaceDefinition> newInterfaceDefinition = InterfaceOperationTestUtils.createMockInterfaceDefinitionMap(interfaceType, operationId, operationType);
269 ComponentInstanceInterface componentInstanceInterface = new ComponentInstanceInterface(interfaceType, newInterfaceDefinition.get(interfaceType));
271 Map<String, List<ComponentInstanceInterface>> componentInstanceInterfaces = new HashMap<>();
272 componentInstanceInterfaces.put("Test", Arrays.asList(componentInstanceInterface));
274 Service parentService = new Service();
275 parentService.setComponentInstancesInterfaces(componentInstanceInterfaces);
276 Service childService = new Service();
277 childService.setUniqueId(serviceId);
279 PropertyDefinition propDef1 = new PropertyDefinition();
280 propDef1.setUniqueId("ComponentInput1_uniqueId");
281 Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(Arrays.asList(parentService)));
282 assertTrue(propertyBusinessLogic.isPropertyUsedByOperation(childService, propDef1));
284 PropertyDefinition propDef2 = new PropertyDefinition();
285 propDef1.setUniqueId("inputId2");
286 Mockito.when(toscaOperationFacade.getParentComponents(serviceId)).thenReturn(Either.left(new ArrayList<>()));
287 assertFalse(propertyBusinessLogic.isPropertyUsedByOperation(childService, propDef2));
290 private PropertyDefinition createPropertyObject(final String propertyName, final String resourceId) {
291 final PropertyDefinition pd = new PropertyDefinition();
292 List<PropertyConstraint> constraints = new ArrayList<>();
293 pd.setConstraints(null);
294 pd.setDefaultValue("100");
295 pd.setDescription("Size of thasdasdasdasde local disk, in Gigabytes (GB), available to applications running on the Compute node");
296 pd.setPassword(false);
297 pd.setRequired(true);
298 pd.setType("Integer");
299 pd.setOwnerId(resourceId);
300 pd.setName(propertyName);
301 pd.setUniqueId(resourceId + "." + propertyName);
306 public void deleteProperty_CONNECTION_FAILURE() {
307 StorageOperationStatus lockResult = StorageOperationStatus.CONNECTION_FAILURE;
308 when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
309 when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(new Resource()));
310 assertTrue(propertyBusinessLogic.deletePropertyFromComponent("resourceforproperty.0.1", "someProperty","i726").isRight());
314 public void deleteProperty_RESOURCE_NOT_FOUND() throws Exception {
316 Resource resource = new Resource();
317 PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
319 resource.setProperties(Arrays.asList(property1));
320 String resourceId = "myResource";
321 resource.setUniqueId(resourceId);
323 Field baseBusinessLogic3;
324 baseBusinessLogic3 = propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
325 baseBusinessLogic3.setAccessible(true);
326 baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
328 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
330 StorageOperationStatus lockResult = StorageOperationStatus.OK;
331 when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
333 Component resourcereturn= new Resource();
334 resourcereturn.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
335 resourcereturn.setIsDeleted(false);
336 resourcereturn.setLastUpdaterUserId("USR01");
338 Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
339 when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
341 assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
345 public void deleteProperty_RESTRICTED_OPERATION() throws Exception {
346 Resource resource = new Resource();
347 PropertyDefinition property1 = createPropertyObject("someProperty", "someResource");
349 resource.setProperties(Arrays.asList(property1));
350 String resourceId = "myResource";
351 resource.setUniqueId(resourceId);
353 Field baseBusinessLogic3;
354 baseBusinessLogic3 = propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
355 baseBusinessLogic3.setAccessible(true);
356 baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
358 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
360 StorageOperationStatus lockResult = StorageOperationStatus.OK;
361 when(graphLockOperation.lockComponent(any(), any())).thenReturn(lockResult);
363 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
364 resource.setIsDeleted(false);
365 resource.setLastUpdaterUserId("USR01");
367 Either<Component, StorageOperationStatus> toscastatus=Either.left(resource);
368 when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(toscastatus);
371 assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "someProperty","i726").isRight());
375 public void deleteProperty_RESTRICTED_() throws Exception {
376 final PropertyDefinition property1 = createPropertyObject("PROP", "RES01");
377 final Resource resource = new Resource();
378 final String resourceId = "myResource";
379 resource.setUniqueId(resourceId);
380 resource.setProperties(Arrays.asList(property1));
382 final Field baseBusinessLogic3 =
383 propertyBusinessLogic.getClass().getSuperclass().getDeclaredField("janusGraphDao");
384 baseBusinessLogic3.setAccessible(true);
385 baseBusinessLogic3.set(propertyBusinessLogic, janusGraphDao);
387 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
389 when(graphLockOperation.lockComponent(any(), any())).thenReturn(StorageOperationStatus.OK);
391 resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
392 resource.setIsDeleted(false);
393 resource.setLastUpdaterUserId("USR01");
395 when(toscaOperationFacade.getToscaElement("RES01")).thenReturn(Either.left(resource));
396 when(toscaOperationFacade.deletePropertyOfComponent(anyObject(), anyString())).thenReturn(StorageOperationStatus.OK);
397 when(toscaOperationFacade.getParentComponents(anyString())).thenReturn(Either.left(new ArrayList<>()));
399 assertTrue(propertyBusinessLogic.deletePropertyFromComponent("RES01", "PROP","USR01").isRight());
403 public void findComponentByIdTest() throws BusinessLogicException {
405 final Resource resource = new Resource();
406 resource.setUniqueId(resourceId);
407 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
409 final Component actualResource = propertyBusinessLogic.findComponentById(resourceId).orElse(null);
411 assertThat("Actual resource should not be null", actualResource, is(notNullValue()));
412 assertThat("Actual resource must have the expected id",
413 actualResource.getUniqueId(), is(equalTo(resource.getUniqueId())));
416 @Test(expected = BusinessLogicException.class)
417 public void findComponentById_resourceNotFoundTest() throws BusinessLogicException {
419 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.right(null));
420 Mockito.when(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_NOT_FOUND, "")).thenReturn(new ResponseFormat());
422 propertyBusinessLogic.findComponentById(resourceId);
426 public void updateComponentPropertyTest() throws BusinessLogicException {
428 final Resource resource = new Resource();
429 resource.setUniqueId(resourceId);
430 final PropertyDefinition propertyDefinition = createPropertyObject("testProperty", resourceId);
431 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
432 when(toscaOperationFacade.updatePropertyOfComponent(resource, propertyDefinition)).thenReturn(Either.left(propertyDefinition));
434 final PropertyDefinition actualPropertyDefinition = propertyBusinessLogic
435 .updateComponentProperty(resourceId, propertyDefinition);
437 assertThat("Actual property definition should not be null", actualPropertyDefinition, is(notNullValue()));
438 assertThat("Actual property definition must have the expected id",
439 actualPropertyDefinition.getOwnerId(), is(equalTo(resource.getUniqueId())));
440 assertThat("Actual property definition must have the expected id",
441 actualPropertyDefinition.getName(), is(equalTo(propertyDefinition.getName())));
444 @Test(expected = BusinessLogicException.class)
445 public void updateComponentProperty_updateFailedTest() throws BusinessLogicException {
447 final Resource resource = new Resource();
448 resource.setUniqueId(resourceId);
449 final PropertyDefinition propertyDefinition = createPropertyObject("testProperty", resourceId);
450 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(resource));
451 when(toscaOperationFacade.updatePropertyOfComponent(resource, propertyDefinition)).thenReturn(Either.right(null));
452 when(componentsUtils.getResponseFormatByResource(Mockito.any(), Mockito.anyString())).thenReturn(new ResponseFormat());
453 when(componentsUtils.convertFromStorageResponse(Mockito.any())).thenReturn(null);
455 propertyBusinessLogic.updateComponentProperty(resourceId, propertyDefinition);
459 public void copyPropertyToComponentTest() throws ToscaOperationException {
461 final Resource expectedResource = new Resource();
462 expectedResource.setUniqueId(resourceId);
463 final List<PropertyDefinition> propertiesToCopyList = new ArrayList<>();
464 final PropertyDefinition property1 = createPropertyObject("property1", resourceId);
465 propertiesToCopyList.add(property1);
466 final PropertyDefinition property2 = createPropertyObject("property2", resourceId);
467 propertiesToCopyList.add(property2);
469 final PropertyDefinition copiedProperty1 = new PropertyDefinition(property1);
470 copiedProperty1.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, copiedProperty1.getName()));
471 expectedResource.addProperty(copiedProperty1);
472 final PropertyDefinition copiedProperty2 = new PropertyDefinition(property2);
473 copiedProperty2.setUniqueId(UniqueIdBuilder.buildPropertyUniqueId(resourceId, copiedProperty2.getName()));
474 expectedResource.addProperty(copiedProperty2);
476 Mockito.when(toscaOperationFacade
477 .addPropertyToComponent(eq(property1.getName()), Mockito.any(PropertyDefinition.class), eq(expectedResource)))
478 .thenReturn(Either.left(copiedProperty1));
479 Mockito.when(toscaOperationFacade
480 .addPropertyToComponent(eq(property2.getName()), Mockito.any(PropertyDefinition.class), eq(expectedResource)))
481 .thenReturn(Either.left(copiedProperty2));
482 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(expectedResource));
484 final Component actualComponent = propertyBusinessLogic.copyPropertyToComponent(expectedResource, propertiesToCopyList, true);
486 assertThat("Actual component should not be null", actualComponent, is(notNullValue()));
487 assertThat("Actual component should be an instance of Resource", actualComponent, is(instanceOf(Resource.class)));
488 assertThat("Actual component should have the expected id", actualComponent.getUniqueId(), is(equalTo(expectedResource.getUniqueId())));
489 assertThat("Actual component should have 2 properties", actualComponent.getProperties(), hasSize(2));
490 assertThat("Actual component should have the expected properties", actualComponent.getProperties(), hasItems(copiedProperty1, copiedProperty2));
494 public void copyPropertyToComponent1() throws ToscaOperationException {
496 final Resource expectedResource = new Resource();
497 expectedResource.setUniqueId(resourceId);
499 final Component actualComponent = propertyBusinessLogic.copyPropertyToComponent(expectedResource, null);
501 assertThat("Actual component should not be null", actualComponent, is(notNullValue()));
502 assertThat("Actual component should be an instance of Resource", actualComponent, is(instanceOf(Resource.class)));
503 assertThat("Actual component should have the expected id", actualComponent.getUniqueId(), is(equalTo(expectedResource.getUniqueId())));
504 assertThat("Actual component should have no properties", actualComponent.getProperties(), is(nullValue()));
507 @Test(expected = ToscaOperationException.class)
508 public void copyPropertyToComponent_copyFailed() throws ToscaOperationException {
510 final Resource expectedResource = new Resource();
511 expectedResource.setUniqueId(resourceId);
512 final List<PropertyDefinition> propertiesToCopyList = new ArrayList<>();
513 final PropertyDefinition property1 = createPropertyObject("property1", resourceId);
514 propertiesToCopyList.add(property1);
515 Mockito.when(toscaOperationFacade
516 .addPropertyToComponent(eq(property1.getName()), Mockito.any(PropertyDefinition.class), eq(expectedResource)))
517 .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
518 Mockito.when(toscaOperationFacade.getToscaElement(resourceId)).thenReturn(Either.left(expectedResource));
520 propertyBusinessLogic.copyPropertyToComponent(expectedResource, propertiesToCopyList, true);