4408b3c1ceac759b390750d8b71a512cf33d088f
[sdc.git] /
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  */
20
21 package org.openecomp.sdc.be.components.impl;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertSame;
27 import static org.junit.Assert.fail;
28 import static org.mockito.ArgumentMatchers.any;
29 import static org.mockito.ArgumentMatchers.anySet;
30 import static org.mockito.ArgumentMatchers.eq;
31 import static org.mockito.Mockito.when;
32
33 import fj.data.Either;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.Collections;
37 import java.util.HashMap;
38 import java.util.HashSet;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.Optional;
42 import java.util.Set;
43 import mockit.Deencapsulation;
44 import org.apache.commons.lang3.tuple.ImmutablePair;
45 import org.assertj.core.util.Lists;
46 import org.junit.Assert;
47 import org.junit.Before;
48 import org.junit.Test;
49 import org.junit.runner.RunWith;
50 import org.mockito.InjectMocks;
51 import org.mockito.Mock;
52 import org.mockito.Mockito;
53 import org.mockito.MockitoAnnotations;
54 import org.mockito.junit.MockitoJUnitRunner;
55 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
56 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
57 import org.openecomp.sdc.be.components.validation.UserValidations;
58 import org.openecomp.sdc.be.config.ConfigurationManager;
59 import org.openecomp.sdc.be.dao.api.ActionStatus;
60 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
61 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
62 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
63 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
64 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
65 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition;
66 import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
67 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
68 import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
69 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
70 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
71 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
72 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
73 import org.openecomp.sdc.be.impl.ComponentsUtils;
74 import org.openecomp.sdc.be.impl.ServletUtils;
75 import org.openecomp.sdc.be.model.ArtifactDefinition;
76 import org.openecomp.sdc.be.model.CapabilityDefinition;
77 import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
78 import org.openecomp.sdc.be.model.Component;
79 import org.openecomp.sdc.be.model.ComponentInstance;
80 import org.openecomp.sdc.be.model.ComponentInstanceInput;
81 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
82 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
83 import org.openecomp.sdc.be.model.ComponentParametersView;
84 import org.openecomp.sdc.be.model.DataTypeDefinition;
85 import org.openecomp.sdc.be.model.InputDefinition;
86 import org.openecomp.sdc.be.model.LifecycleStateEnum;
87 import org.openecomp.sdc.be.model.PolicyDefinition;
88 import org.openecomp.sdc.be.model.RelationshipImpl;
89 import org.openecomp.sdc.be.model.RelationshipInfo;
90 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
91 import org.openecomp.sdc.be.model.RequirementDefinition;
92 import org.openecomp.sdc.be.model.Resource;
93 import org.openecomp.sdc.be.model.Service;
94 import org.openecomp.sdc.be.model.User;
95 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
96 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ForwardingPathOperation;
97 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
98 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
99 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
100 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
101 import org.openecomp.sdc.be.user.UserBusinessLogic;
102 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
103 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
104 import org.openecomp.sdc.common.api.ConfigurationSource;
105 import org.openecomp.sdc.common.impl.ExternalConfiguration;
106 import org.openecomp.sdc.common.impl.FSConfigurationSource;
107 import org.openecomp.sdc.exception.ResponseFormat;
108
109 /**
110  * The test suite designed for test functionality of ComponentInstanceBusinessLogic class
111  */
112
113 @RunWith(MockitoJUnitRunner.class)
114 public class ComponentInstanceBusinessLogicTest {
115
116     private final static String USER_ID = "jh0003";
117     private final static String COMPONENT_ID = "componentId";
118     private final static String ORIGIN_COMPONENT_ID = "originComponentId";
119     private final static String COMPONENT_INST_ID = "componentInstId";
120     private final static String TO_INSTANCE_ID = "toInstanceId";
121     private final static String TO_INSTANCE_NAME = "toInstanceName";
122     private final static String COMPONENT_INSTANCE_ID = "componentInstanceId";
123     private final static String FROM_INSTANCE_ID = "fromInstanceId";
124     private final static String RELATION_ID = "relationId";
125     private final static String CAPABILITY_OWNER_ID = "capabilityOwnerId";
126     private final static String CAPABILITY_UID = "capabilityUid";
127     private final static String CAPABILITY_NAME = "capabilityName";
128     private final static String REQUIREMENT_OWNER_ID = "requirementOwnerId";
129     private final static String REQUIREMENT_UID = "requirementUid";
130     private final static String REQUIREMENT_NAME = "requirementName";
131     private final static String RELATIONSHIP_TYPE = "relationshipType";
132     private final static String ARTIFACT_1 = "cloudtech_k8s_charts.zip";
133     private final static String ARTIFACT_2 = "cloudtech_azure_day0.zip";
134     private final static String ARTIFACT_3 = "cloudtech_aws_configtemplate.zip";
135     private final static String ARTIFACT_4 = "k8s_charts.zip";
136     private final static String ARTIFACT_5 = "cloudtech_openstack_configtemplate.zip";
137     private final static String PROP_NAME = "propName";
138     private final static String NON_EXIST_NAME = "nonExistName";
139
140     static ConfigurationSource configurationSource = new FSConfigurationSource(
141         ExternalConfiguration.getChangeListener(),
142         "src/test/resources/config/catalog-be");
143     static ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
144
145     @InjectMocks
146     private static ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
147     @Mock
148     private ComponentInstancePropInput componentInstancePropInput;
149     @Mock
150     ArtifactsBusinessLogic artifactsBusinessLogic;
151     @Mock
152     private ComponentsUtils componentsUtils;
153     @Mock
154     private ServletUtils servletUtils;
155     @Mock
156     private ResponseFormat responseFormat;
157     @Mock
158     private ToscaOperationFacade toscaOperationFacade;
159     @Mock
160     private UserBusinessLogic userAdmin;
161     @Mock
162     private ForwardingPathOperation forwardingPathOperation;
163     @Mock
164     private User user;
165     @Mock
166     private UserValidations userValidations;
167     @Mock
168     GraphLockOperation graphLockOperation;
169     @Mock
170     private JanusGraphDao janusGraphDao;
171     @Mock
172     ApplicationDataTypeCache dataTypeCache;
173     @Mock
174     PropertyOperation propertyOperation;
175     @Mock
176     ApplicationDataTypeCache applicationDataTypeCache;
177
178     private Component service;
179     private Component resource;
180     private ComponentInstance toInstance;
181     private ComponentInstance fromInstance;
182     private CapabilityDataDefinition capability;
183     private RequirementDataDefinition requirement;
184     private RequirementCapabilityRelDef relation;
185
186     @Before
187     public void init() {
188         MockitoAnnotations.initMocks(componentInstanceBusinessLogic);
189         stubMethods();
190         createComponents();
191     }
192
193     @Test
194     public void testGetRelationByIdSuccess() {
195         getServiceRelationByIdSuccess(service);
196         getServiceRelationByIdSuccess(resource);
197     }
198
199     @Test
200     public void testGetRelationByIdUserValidationFailure() {
201         getServiceRelationByIdUserValidationFailure(service);
202         getServiceRelationByIdUserValidationFailure(resource);
203     }
204
205     @Test
206     public void testGetRelationByIdComponentNotFoundFailure() {
207         getRelationByIdComponentNotFoundFailure(service);
208         getRelationByIdComponentNotFoundFailure(resource);
209     }
210
211     @Test
212     public void testForwardingPathOnVersionChange() {
213         getforwardingPathOnVersionChange();
214     }
215
216     @Test
217     public void testIsCloudSpecificArtifact() {
218         assertThat(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_1)).isTrue();
219         assertThat(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_2)).isTrue();
220         assertThat(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_3)).isTrue();
221         assertThat(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_4)).isFalse();
222         assertThat(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_5)).isFalse();
223     }
224
225     private void getforwardingPathOnVersionChange() {
226         String containerComponentParam = "services";
227         String containerComponentID = "121-cont";
228         String componentInstanceID = "121-cont-1-comp";
229         Service component = new Service();
230         Map<String, ForwardingPathDataDefinition> forwardingPaths = generateForwardingPath(componentInstanceID);
231
232         //Add existing componentInstance to component
233         List<ComponentInstance> componentInstanceList = new ArrayList<>();
234         ComponentInstance oldComponentInstance = new ComponentInstance();
235         oldComponentInstance.setName("OLD_COMP_INSTANCE");
236         oldComponentInstance.setUniqueId(componentInstanceID);
237         oldComponentInstance.setName(componentInstanceID);
238         oldComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID, "1-comp");
239         componentInstanceList.add(oldComponentInstance);
240         component.setComponentInstances(componentInstanceList);
241         component.setForwardingPaths(forwardingPaths);
242
243         List<ComponentInstance> componentInstanceListNew = new ArrayList<>();
244         ComponentInstance newComponentInstance = new ComponentInstance();
245         String new_Comp_UID = "2-comp";
246         newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID, new_Comp_UID);
247         newComponentInstance.setUniqueId(new_Comp_UID);
248         componentInstanceListNew.add(newComponentInstance);
249         Component component2 = new Service();
250         component2.setComponentInstances(componentInstanceListNew);
251
252         //Mock for getting component
253         when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
254             .thenReturn(Either.left(component));
255         when(toscaOperationFacade.validateComponentExists(any(String.class))).thenReturn(Either.left(Boolean.TRUE));
256         when(toscaOperationFacade.getToscaFullElement(eq(new_Comp_UID))).thenReturn(Either.left(component2));
257
258         Either<Set<String>, ResponseFormat> resultOp = componentInstanceBusinessLogic
259             .forwardingPathOnVersionChange(containerComponentParam,
260                 containerComponentID, componentInstanceID,
261                 newComponentInstance);
262         assertEquals(1, resultOp.left().value().size());
263         assertEquals("FP-ID-1", resultOp.left().value().iterator().next());
264
265     }
266
267     @Test
268     public void testCreateOrUpdatePropertiesValues2() {
269         String containerComponentID = "containerId";
270         String resourceInstanceId = "resourceId";
271         String componentInstanceID = "componentInstance";
272         List<ComponentInstanceProperty> properties = new ArrayList<>();
273         ComponentInstanceProperty property = new ComponentInstanceProperty();
274         property.setName("property");
275         property.setValue("newVal");
276         property.setType("string");
277         properties.add(property);
278
279         List<ComponentInstanceProperty> origProperties = new ArrayList<>();
280         ComponentInstanceProperty origProperty = new ComponentInstanceProperty();
281         origProperty.setName("property");
282         origProperty.setValue("value");
283         origProperty.setType("string");
284         origProperties.add(origProperty);
285
286         Map<String, DataTypeDefinition> types = new HashMap<>();
287         DataTypeDefinition dataTypeDef = new DataTypeDefinition();
288         types.put("string", dataTypeDef);
289
290         Component component = new Service();
291         component.setLastUpdaterUserId("userId");
292         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
293         Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
294         componentInstanceProps.put("resourceId", origProperties);
295         component.setComponentInstancesProperties(componentInstanceProps);
296         ComponentInstance ci = createComponentInstance("ci1");
297         ci.setUniqueId("resourceId");
298         component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
299             createComponentInstance(componentInstanceID)));
300         HashMap<String, DataTypeDefinition> dataTypeDefinitionHashMap = new HashMap<>();
301         DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
302         dataTypeDefinition.setName("string");
303         dataTypeDefinitionHashMap.put("string", dataTypeDefinition);
304
305         //when(userValidations.validateUserExists(user.getUserId(), false)).thenReturn(user);
306         when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
307             .thenReturn(Either.left(component));
308         when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
309             .thenReturn(StorageOperationStatus.OK);
310         when(dataTypeCache.getAll()).thenReturn(Either.left(types));
311         when(propertyOperation.validateAndUpdatePropertyValue(property.getType(), "newVal", true, null, types))
312             .thenReturn(Either.left("newVal"));
313         when(propertyOperation.validateAndUpdateRules("string", property.getRules(),
314             null, types, true)).thenReturn(ImmutablePair.of("string", null));
315         when(toscaOperationFacade.updateComponentInstanceProperty(component, ci.getUniqueId(),
316             origProperty)).thenReturn(StorageOperationStatus.OK);
317         origProperties.get(0).setValue("newVal");
318         when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(component))
319             .thenReturn(Either.left(component));
320         when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
321         when(graphLockOperation.unlockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
322             .thenReturn(StorageOperationStatus.OK);
323
324         Either<List<ComponentInstanceProperty>, ResponseFormat> responseFormatEither = componentInstanceBusinessLogic
325             .createOrUpdatePropertiesValues(
326                 ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
327         assertThat(responseFormatEither.left().value()).isEqualTo(properties);
328     }
329
330     @Test
331     public void testCreateOrUpdatePropertiesValuesPropertyNotExists() {
332         String containerComponentID = "containerId";
333         String resourceInstanceId = "resourceId";
334         String componentInstanceID = "componentInstance";
335         List<ComponentInstanceProperty> properties = new ArrayList<>();
336         ComponentInstanceProperty property = new ComponentInstanceProperty();
337         property.setName("property");
338         property.setValue("newVal");
339         property.setType("string");
340         properties.add(property);
341
342         List<ComponentInstanceProperty> origProperties = new ArrayList<>();
343
344         Map<String, DataTypeDefinition> types = new HashMap<>();
345         DataTypeDefinition dataTypeDef = new DataTypeDefinition();
346         types.put("string", dataTypeDef);
347
348         Component component = new Service();
349         component.setLastUpdaterUserId("userId");
350         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
351         Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
352         componentInstanceProps.put("resourceId", origProperties);
353         component.setComponentInstancesProperties(componentInstanceProps);
354         ComponentInstance ci = createComponentInstance("ci1");
355         ci.setUniqueId("resourceId");
356         component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
357             createComponentInstance(componentInstanceID)));
358         HashMap<String, DataTypeDefinition> dataTypeDefinitionHashMap = new HashMap<>();
359         DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
360         dataTypeDefinition.setName("string");
361         dataTypeDefinitionHashMap.put("string", dataTypeDefinition);
362
363         //when(userValidations.validateUserExists(user.getUserId(), false)).thenReturn(user);
364         when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
365             .thenReturn(Either.left(component));
366         when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
367             .thenReturn(StorageOperationStatus.OK);
368         //when(dataTypeCache.getAll()).thenReturn(Either.left(types));
369         //when (janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
370         when(graphLockOperation.unlockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
371             .thenReturn(StorageOperationStatus.OK);
372
373         try {
374             componentInstanceBusinessLogic.createOrUpdatePropertiesValues(
375                 ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
376         } catch (ComponentException e) {
377             assertThat(e.getActionStatus()).isEqualTo(ActionStatus.PROPERTY_NOT_FOUND);
378         }
379
380     }
381
382     @Test
383     public void testCreateOrUpdatePropertiesValuesValidationFailure() {
384         String containerComponentID = "containerId";
385         String resourceInstanceId = "resourceId";
386         String componentInstanceID = "componentInstance";
387         List<ComponentInstanceProperty> properties = new ArrayList<>();
388         ComponentInstanceProperty property = new ComponentInstanceProperty();
389         property.setName("property");
390         property.setValue("newVal");
391         property.setType("string");
392         properties.add(property);
393
394         List<ComponentInstanceProperty> origProperties = new ArrayList<>();
395         ComponentInstanceProperty origProperty = new ComponentInstanceProperty();
396         origProperty.setName("property");
397         origProperty.setValue("value");
398         origProperty.setType("string");
399         origProperties.add(origProperty);
400
401         Map<String, DataTypeDefinition> types = new HashMap<>();
402         DataTypeDefinition dataTypeDef = new DataTypeDefinition();
403         types.put("string", dataTypeDef);
404
405         Component component = new Service();
406         component.setLastUpdaterUserId("userId");
407         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
408         Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
409         componentInstanceProps.put("resourceId", origProperties);
410         component.setComponentInstancesProperties(componentInstanceProps);
411         ComponentInstance ci = createComponentInstance("ci1");
412         ci.setUniqueId("resourceId");
413         component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
414             createComponentInstance(componentInstanceID)));
415         HashMap<String, DataTypeDefinition> dataTypeDefinitionHashMap = new HashMap<>();
416         DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
417         dataTypeDefinition.setName("string");
418         dataTypeDefinitionHashMap.put("string", dataTypeDefinition);
419
420         //when(userValidations.validateUserExists(user.getUserId(), false)).thenReturn(user);
421         when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
422             .thenReturn(Either.left(component));
423         when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
424             .thenReturn(StorageOperationStatus.OK);
425         when(dataTypeCache.getAll()).thenReturn(Either.left(types));
426         when(propertyOperation.validateAndUpdatePropertyValue(property.getType(), "newVal", true, null, types))
427             .thenReturn(Either.right(false));
428         when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST))
429             .thenReturn(ActionStatus.INVALID_CONTENT);
430
431         try {
432             componentInstanceBusinessLogic.createOrUpdatePropertiesValues(
433                 ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
434         } catch (ComponentException e) {
435             assertThat(e.getActionStatus()).isEqualTo(ActionStatus.INVALID_CONTENT);
436             return;
437         }
438         fail();
439     }
440
441     @Test
442     public void testCreateOrUpdatePropertiesValuesMissingFieldFailure() {
443         String containerComponentID = "containerId";
444         String resourceInstanceId = "resourceId";
445         String componentInstanceID = "componentInstance";
446         List<ComponentInstanceProperty> properties = new ArrayList<>();
447         ComponentInstanceProperty property = new ComponentInstanceProperty();
448         property.setValue("newVal");
449         property.setType("string");
450         properties.add(property);
451
452         List<ComponentInstanceProperty> origProperties = new ArrayList<>();
453         ComponentInstanceProperty origProperty = new ComponentInstanceProperty();
454         origProperty.setName("property");
455         origProperty.setValue("value");
456         origProperty.setType("string");
457         origProperties.add(origProperty);
458
459         Component component = new Service();
460         component.setLastUpdaterUserId("userId");
461         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
462         Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
463         componentInstanceProps.put("resourceId", origProperties);
464         component.setComponentInstancesProperties(componentInstanceProps);
465         ComponentInstance ci = createComponentInstance("ci1");
466         ci.setUniqueId("resourceId");
467         component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
468             createComponentInstance(componentInstanceID)));
469
470         HashMap<String, DataTypeDefinition> dataTypeDefinitionHashMap = new HashMap<>();
471         DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
472         dataTypeDefinition.setName("string");
473         dataTypeDefinitionHashMap.put("string", dataTypeDefinition);
474
475         //when(userValidations.validateUserExists(user.getUserId(), false)).thenReturn(user);
476         when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
477             .thenReturn(Either.left(component));
478         when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
479             .thenReturn(StorageOperationStatus.OK);
480
481         try {
482             componentInstanceBusinessLogic.createOrUpdatePropertiesValues(
483                 ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
484         } catch (ComponentException e) {
485             assertThat(e.getActionStatus()).isEqualTo(ActionStatus.MISSING_PROPERTY_NAME);
486         }
487     }
488
489     @Test
490     public void testDeleteForwardingPathsWhenComponentinstanceDeleted() {
491
492         ComponentTypeEnum containerComponentType = ComponentTypeEnum.findByParamName("services");
493         String containerComponentID = "Service-comp";
494         String componentInstanceID = "NodeA1";
495         Service component = new Service();
496         component
497             .setComponentInstances(Arrays.asList(createComponentInstance("NodeA2"), createComponentInstance("NodeB2"),
498                 createComponentInstance(componentInstanceID)));
499
500         component.addForwardingPath(createPath("path1", componentInstanceID, "NodeB1", "1"));
501         component.addForwardingPath(createPath("Path2", "NodeA2", "NodeB2", "2"));
502         when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
503             .thenReturn(Either.left(component));
504         when(toscaOperationFacade.getToscaElement(eq(containerComponentID))).thenReturn(Either.left(component));
505         when(forwardingPathOperation.deleteForwardingPath(any(Service.class), anySet()))
506             .thenReturn(Either.left(new HashSet<>()));
507         final ComponentInstance ci = new ComponentInstance();
508         ci.setName(componentInstanceID);
509         ComponentInstance responseFormatEither = componentInstanceBusinessLogic
510             .deleteForwardingPathsRelatedTobeDeletedComponentInstance(
511                 containerComponentID, containerComponentType, ci);
512         assertThat(!responseFormatEither.isEmpty()).isEqualTo(true);
513
514     }
515
516     @Test
517     public void testAddComponentInstanceDeploymentArtifacts() {
518
519         Component containerComponent = new Service();
520         ComponentInstance componentInstance = new ComponentInstance();
521         componentInstance.setUniqueId(COMPONENT_INSTANCE_ID);
522         Component originComponent = fillOriginComponent(new Resource());
523
524         Map<String, ArtifactDefinition> artifacts = new HashMap<>();
525         ArtifactDefinition deploymentArtifact1 = getArtifact("deploymentArtifact1", ArtifactTypeEnum.HEAT.getType());
526         artifacts.put(deploymentArtifact1.getArtifactLabel(), deploymentArtifact1);
527         ArtifactDefinition deploymentArtifact2 = getArtifact("deploymentArtifact2",
528             ArtifactTypeEnum.HEAT_ENV.getType());
529         artifacts.put(deploymentArtifact2.getArtifactLabel(), deploymentArtifact2);
530         ArtifactDefinition deploymentArtifact3 = getArtifact("deploymentArtifact3",
531             ArtifactTypeEnum.HEAT_VOL.getType());
532         artifacts.put(deploymentArtifact3.getArtifactLabel(), deploymentArtifact3);
533         ArtifactDefinition heatEnvPlaceHolder = getArtifact("deploymentArtifact4", ArtifactTypeEnum.HEAT_ENV.getType());
534         ArtifactDefinition heatEnvPlaceHolder2 = getArtifact("deploymentArtifact5",
535             ArtifactTypeEnum.HEAT_ENV.getType());
536
537         Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = Either
538             .left(artifacts);
539
540         Map<String, ArtifactDefinition> finalDeploymentArtifacts = new HashMap<>();
541         finalDeploymentArtifacts.put(deploymentArtifact1.getArtifactLabel(), deploymentArtifact1);
542         finalDeploymentArtifacts.put(deploymentArtifact3.getArtifactLabel(), deploymentArtifact3);
543         finalDeploymentArtifacts.put(heatEnvPlaceHolder.getArtifactLabel(), heatEnvPlaceHolder);
544         finalDeploymentArtifacts.put(heatEnvPlaceHolder2.getArtifactLabel(), heatEnvPlaceHolder2);
545
546         when(artifactsBusinessLogic.getArtifacts(componentInstance.getComponentUid(), NodeTypeEnum.Resource,
547             ArtifactGroupTypeEnum.DEPLOYMENT, null)).thenReturn(getResourceDeploymentArtifacts);
548         when(artifactsBusinessLogic.createHeatEnvPlaceHolder(new ArrayList<>(),
549             deploymentArtifact1, ArtifactsBusinessLogic.HEAT_ENV_NAME, componentInstance.getUniqueId(),
550             NodeTypeEnum.ResourceInstance, componentInstance.getName(), user, containerComponent,
551             null)).thenReturn(heatEnvPlaceHolder);
552         when(artifactsBusinessLogic.createHeatEnvPlaceHolder(new ArrayList<>(),
553             deploymentArtifact3, ArtifactsBusinessLogic.HEAT_ENV_NAME, componentInstance.getUniqueId(),
554             NodeTypeEnum.ResourceInstance, componentInstance.getName(), user, containerComponent,
555             null)).thenReturn(heatEnvPlaceHolder2);
556
557         when(toscaOperationFacade.addDeploymentArtifactsToInstance(containerComponent.getUniqueId(), componentInstance,
558             finalDeploymentArtifacts)).thenReturn(StorageOperationStatus.OK);
559         when(toscaOperationFacade
560             .addGroupInstancesToComponentInstance(containerComponent, componentInstance, null, new HashMap<>()))
561             .thenReturn(StorageOperationStatus.OK);
562         when(toscaOperationFacade
563             .addInformationalArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, null))
564             .thenReturn(StorageOperationStatus.OK);
565
566         ActionStatus status = componentInstanceBusinessLogic.addComponentInstanceArtifacts(containerComponent,
567             componentInstance, originComponent, user, null);
568
569         assertThat(status).isEqualTo(ActionStatus.OK);
570
571     }
572
573     private Component fillOriginComponent(Resource originComponent) {
574         originComponent.setUniqueId("resourceId");
575         originComponent.setUniqueId(ORIGIN_COMPONENT_ID);
576         originComponent.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
577         originComponent.setComponentType(ComponentTypeEnum.RESOURCE);
578         originComponent.setState(LifecycleStateEnum.CERTIFIED);
579         return originComponent;
580     }
581
582     private ArtifactDefinition getArtifact(String artifactLabel, String artifactType) {
583         ArtifactDefinition artifactDefinition = new ArtifactDefinition();
584         artifactDefinition.setArtifactLabel(artifactLabel);
585         artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
586         artifactDefinition.setEsId("esId" + artifactLabel);
587         artifactDefinition.setArtifactType(artifactType);
588         return artifactDefinition;
589     }
590
591     private ComponentInstance createComponentInstance(String path1) {
592         ComponentInstance componentInstance = new ComponentInstance();
593         componentInstance.setName(path1);
594         return componentInstance;
595     }
596
597     private ForwardingPathDataDefinition createPath(String pathName, String fromNode, String toNode, String uniqueId) {
598         ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition(pathName);
599         forwardingPath.setProtocol("protocol");
600         forwardingPath.setDestinationPortNumber("port");
601         forwardingPath.setUniqueId(uniqueId);
602         ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
603             new ListDataDefinition<>();
604         forwardingPathElementListDataDefinition
605             .add(new ForwardingPathElementDataDefinition(fromNode, toNode, "nodeAcpType", "nodeBcpType",
606                 "nodeDcpName", "nodeBcpName"));
607         forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
608
609         return forwardingPath;
610     }
611
612     private Map<String, ForwardingPathDataDefinition> generateForwardingPath(String componentInstanceID) {
613         ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition("fpName");
614         String protocol = "protocol";
615         forwardingPath.setProtocol(protocol);
616         forwardingPath.setDestinationPortNumber("DestinationPortNumber");
617         forwardingPath.setUniqueId("FP-ID-1");
618         ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
619             new ListDataDefinition<>();
620         forwardingPathElementListDataDefinition
621             .add(new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY",
622                 "nodeBcpType", "nodeDcpName", "nodeBcpName"));
623         forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
624         Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
625         forwardingPaths.put("1122", forwardingPath);
626         return forwardingPaths;
627     }
628
629     @SuppressWarnings("unchecked")
630     private void getServiceRelationByIdSuccess(Component component) {
631         Either<Component, StorageOperationStatus> getComponentRes = Either.left(component);
632         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
633             .thenReturn(getComponentRes);
634         Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
635             .getRelationById(COMPONENT_ID,
636                 RELATION_ID, USER_ID,
637                 component.getComponentType());
638         assertThat(response.isLeft()).isTrue();
639     }
640
641     private void getServiceRelationByIdUserValidationFailure(Component component) {
642         when(userValidations.validateUserExists(eq(USER_ID)))
643             .thenThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND));
644         try {
645             componentInstanceBusinessLogic
646                 .getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
647         } catch (ByActionStatusComponentException e) {
648             assertSame(e.getActionStatus(), ActionStatus.USER_NOT_FOUND);
649         }
650     }
651
652     private void getRelationByIdComponentNotFoundFailure(Component component) {
653         Either<User, ActionStatus> eitherCreator = Either.left(user);
654         Either<Component, StorageOperationStatus> getComponentRes = Either.right(StorageOperationStatus.NOT_FOUND);
655         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
656             .thenReturn(getComponentRes);
657
658         Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
659             .getRelationById(COMPONENT_ID,
660                 RELATION_ID, USER_ID,
661                 component.getComponentType());
662         assertThat(response.isRight()).isTrue();
663     }
664
665     private void stubMethods() {
666         when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
667         when(componentsUtils
668             .convertFromStorageResponse(eq(StorageOperationStatus.GENERAL_ERROR), any(ComponentTypeEnum.class)))
669             .thenReturn(ActionStatus.GENERAL_ERROR);
670     }
671
672     private void createComponents() {
673         createRelation();
674         createInstances();
675         createService();
676         createResource();
677     }
678
679     private void createResource() {
680         resource = new Resource();
681         resource.setUniqueId(COMPONENT_ID);
682         resource.setComponentInstancesRelations(Lists.newArrayList(relation));
683         resource.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
684         resource.setCapabilities(toInstance.getCapabilities());
685         resource.setRequirements(fromInstance.getRequirements());
686         resource.setComponentType(ComponentTypeEnum.RESOURCE);
687         resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
688     }
689
690     private void createService() {
691         service = new Service();
692         service.setUniqueId(COMPONENT_ID);
693         service.setComponentInstancesRelations(Lists.newArrayList(relation));
694         service.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
695         service.setCapabilities(toInstance.getCapabilities());
696         service.setRequirements(fromInstance.getRequirements());
697         service.setComponentType(ComponentTypeEnum.SERVICE);
698         service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
699     }
700
701     private void createInstances() {
702         toInstance = new ComponentInstance();
703         toInstance.setUniqueId(TO_INSTANCE_ID);
704         toInstance.setName(TO_INSTANCE_NAME);
705
706         fromInstance = new ComponentInstance();
707         fromInstance.setUniqueId(FROM_INSTANCE_ID);
708
709         capability = new CapabilityDataDefinition();
710         capability.setOwnerId(CAPABILITY_OWNER_ID);
711         capability.setUniqueId(CAPABILITY_UID);
712         capability.setName(CAPABILITY_NAME);
713
714         Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
715         final CapabilityDefinition capabilityDefinition = new CapabilityDefinition(capability);
716         final ArrayList<ComponentInstanceProperty> properties = new ArrayList<>();
717         properties.add(componentInstancePropInput);
718         capabilityDefinition.setProperties(properties);
719         capabilities.put(capability.getName(), Lists.newArrayList(capabilityDefinition));
720
721         requirement = new RequirementDataDefinition();
722         requirement.setOwnerId(REQUIREMENT_OWNER_ID);
723         requirement.setUniqueId(REQUIREMENT_UID);
724         requirement.setName(REQUIREMENT_NAME);
725         requirement.setRelationship(RELATIONSHIP_TYPE);
726
727         Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
728         requirements.put(requirement.getCapability(), Lists.newArrayList(new RequirementDefinition(requirement)));
729
730         toInstance.setCapabilities(capabilities);
731         fromInstance.setRequirements(requirements);
732     }
733
734     private void createRelation() {
735
736         relation = new RequirementCapabilityRelDef();
737         CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
738         RelationshipInfo relationInfo = new RelationshipInfo();
739         relationInfo.setId(RELATION_ID);
740         relationship.setRelation(relationInfo);
741
742         relation.setRelationships(Lists.newArrayList(relationship));
743         relation.setToNode(TO_INSTANCE_ID);
744         relation.setFromNode(FROM_INSTANCE_ID);
745
746         relationInfo.setCapabilityOwnerId(CAPABILITY_OWNER_ID);
747         relationInfo.setCapabilityUid(CAPABILITY_UID);
748         relationInfo.setCapability(CAPABILITY_NAME);
749         relationInfo.setRequirementOwnerId(REQUIREMENT_OWNER_ID);
750         relationInfo.setRequirementUid(REQUIREMENT_UID);
751         relationInfo.setRequirement(REQUIREMENT_NAME);
752         RelationshipImpl relationshipImpl = new RelationshipImpl();
753         relationshipImpl.setType(RELATIONSHIP_TYPE);
754         relationInfo.setRelationships(relationshipImpl);
755     }
756
757     private ComponentInstanceBusinessLogic createTestSubject() {
758         return componentInstanceBusinessLogic;
759     }
760
761     @Test
762     public void testChangeServiceProxyVersion() {
763         ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
764
765         Either<ComponentInstance, ResponseFormat> result;
766
767         // default test
768         componentInstanceBusinessLogic = createTestSubject();
769         result = componentInstanceBusinessLogic.changeServiceProxyVersion();
770         assertNotNull(result);
771     }
772
773     @Test
774     public void testCreateServiceProxy() {
775         ComponentInstanceBusinessLogic testSubject;
776         Either<ComponentInstance, ResponseFormat> result;
777
778         // default test
779         testSubject = createTestSubject();
780         result = testSubject.createServiceProxy();
781         assertNotNull(result);
782     }
783
784     @Test
785     public void testDeleteServiceProxy() {
786         ComponentInstanceBusinessLogic testSubject;
787
788         Either<ComponentInstance, ResponseFormat> result;
789
790         // default test
791         testSubject = createTestSubject();
792         result = testSubject.deleteServiceProxy();
793         assertNotNull(result);
794     }
795
796     @Test
797     public void testGetComponentInstanceInputsByInputId() {
798         ComponentInstanceBusinessLogic testSubject;
799         Component component = new Service();
800         String inputId = "";
801         List<ComponentInstanceInput> result;
802
803         // default test
804         testSubject = createTestSubject();
805         result = testSubject.getComponentInstanceInputsByInputId(component, inputId);
806         assertNotNull(result);
807     }
808
809     @Test
810     public void testGetComponentInstancePropertiesByInputId() {
811         ComponentInstanceBusinessLogic testSubject;
812         Component component = new Service();
813         String inputId = "";
814         List<ComponentInstanceProperty> result;
815
816         // default test
817         testSubject = createTestSubject();
818         result = testSubject.getComponentInstancePropertiesByInputId(component, inputId);
819         assertNotNull(result);
820     }
821
822     @Test
823     public void testGetRelationById() {
824         ComponentInstanceBusinessLogic testSubject;
825         String componentId = "";
826         String relationId = "";
827         String userId = user.getUserId();
828         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE_INSTANCE;
829         Either<RequirementCapabilityRelDef, ResponseFormat> result;
830
831         // default test
832         testSubject = createTestSubject();
833         result = testSubject.getRelationById(componentId, relationId, userId, componentTypeEnum);
834         assertNotNull(result);
835     }
836
837     @Test
838     public void testValidateParent() {
839         ComponentInstanceBusinessLogic testSubject;
840         createResource();
841         String nodeTemplateId = "";
842         boolean result;
843
844         // default test
845         testSubject = createTestSubject();
846         result = Deencapsulation.invoke(testSubject, "validateParent", new Object[]{resource, nodeTemplateId});
847         assertNotNull(result);
848     }
849
850     @Test
851     public void testGetComponentType() {
852         ComponentInstanceBusinessLogic testSubject;
853         ComponentTypeEnum result;
854
855         // default test
856         testSubject = createTestSubject();
857         result = Deencapsulation.invoke(testSubject, "getComponentType", new Object[]{ComponentTypeEnum.class});
858         assertNotNull(result);
859     }
860
861     @Test
862     public void testGetNewGroupName() {
863         ComponentInstanceBusinessLogic testSubject;
864         String oldPrefix = "";
865         String newNormailzedPrefix = "";
866         String qualifiedGroupInstanceName = "";
867         String result;
868
869         // test 1
870         testSubject = createTestSubject();
871         result = Deencapsulation.invoke(testSubject, "getNewGroupName",
872             new Object[]{oldPrefix, newNormailzedPrefix, qualifiedGroupInstanceName});
873         assertNotNull(result);
874     }
875
876     @Test
877     public void testUpdateComponentInstanceMetadata_3() {
878         ComponentInstanceBusinessLogic testSubject;
879         createInstances();
880         ComponentInstance newComponentInstance = null;
881         ComponentInstance result;
882
883         // default test
884         testSubject = createTestSubject();
885         result = Deencapsulation
886             .invoke(testSubject, "updateComponentInstanceMetadata", new Object[]{toInstance, toInstance});
887         assertNotNull(result);
888     }
889
890     @Test
891     public void testFindRelation() throws Exception {
892         ComponentInstanceBusinessLogic testSubject;
893         String relationId = "";
894         List<RequirementCapabilityRelDef> requirementCapabilityRelations = new ArrayList<>();
895         RequirementCapabilityRelDef result;
896
897         // default test
898         testSubject = createTestSubject();
899         result = Deencapsulation.invoke(testSubject, "findRelation",
900             new Object[]{relationId, requirementCapabilityRelations});
901     }
902
903     @Test
904     public void testCreateOrUpdatePropertiesValues() throws Exception {
905         ComponentInstanceBusinessLogic testSubject;
906         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
907         createResource();
908         String componentId = resource.getUniqueId();
909         String resourceInstanceId = "";
910         List<ComponentInstanceProperty> properties = new ArrayList<>();
911         String userId = user.getUserId();
912         Either<List<ComponentInstanceProperty>, ResponseFormat> result;
913
914         when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
915             .thenReturn(Either.left(resource));
916
917         // test 1
918         testSubject = createTestSubject();
919         result = testSubject
920             .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
921                 userId);
922         assertNotNull(result);
923
924         componentTypeEnum = null;
925         result = testSubject
926             .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
927                 userId);
928         assertNotNull(result);
929
930         result = testSubject
931             .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
932                 userId);
933         assertNotNull(result);
934     }
935
936     @Test
937     public void testUpdateCapabilityPropertyOnContainerComponent() throws Exception {
938         ComponentInstanceBusinessLogic testSubject;
939         ComponentInstanceProperty property = new ComponentInstanceProperty();
940         String newValue = "";
941         createResource();
942         createInstances();
943         String capabilityType = "";
944         String capabilityName = "";
945         ResponseFormat result;
946
947         // default test
948         testSubject = createTestSubject();
949         result = Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent",
950             new Object[]{property, newValue, resource, toInstance, capabilityType, capabilityName});
951     }
952
953     @Test
954     public void testCreateOrUpdateInstanceInputValues() throws Exception {
955         ComponentInstanceBusinessLogic testSubject;
956         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
957         createResource();
958         String componentId = resource.getUniqueId();
959         String resourceInstanceId = "";
960         List<ComponentInstanceInput> inputs = new ArrayList<>();
961         String userId = user.getUserId();
962         Either<List<ComponentInstanceInput>, ResponseFormat> result;
963
964         when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
965             .thenReturn(Either.left(resource));
966
967         // test 1
968         testSubject = createTestSubject();
969         result = testSubject
970             .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
971                 userId);
972         assertNotNull(result);
973         componentTypeEnum = null;
974         result = testSubject
975             .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
976                 userId);
977         assertNotNull(result);
978
979         result = testSubject
980             .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
981                 userId);
982         assertNotNull(result);
983     }
984
985     @Test
986     public void testCreateOrUpdateGroupInstancePropertyValue() throws Exception {
987         ComponentInstanceBusinessLogic testSubject;
988         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
989         createResource();
990         String componentId = resource.getUniqueId();
991         String resourceInstanceId = "";
992         String groupInstanceId = "";
993         ComponentInstanceProperty property = new ComponentInstanceProperty();
994         String userId = user.getUserId();
995         Either<ComponentInstanceProperty, ResponseFormat> result;
996
997         when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata))
998             .thenReturn(Either.left(resource));
999
1000         // test 1
1001         testSubject = createTestSubject();
1002         result = testSubject
1003             .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
1004                 groupInstanceId, property, userId);
1005         assertNotNull(result);
1006         componentTypeEnum = null;
1007         result = testSubject
1008             .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
1009                 groupInstanceId, property, userId);
1010         assertNotNull(result);
1011
1012         result = testSubject
1013             .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
1014                 groupInstanceId, property, userId);
1015         assertNotNull(result);
1016     }
1017
1018     @Test
1019     public void testDeletePropertyValue() throws Exception {
1020         ComponentInstanceBusinessLogic testSubject;
1021         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1022         createService();
1023         String serviceId = service.getUniqueId();
1024         String resourceInstanceId = "";
1025         String propertyValueId = "";
1026         String userId = user.getUserId();
1027         Either<ComponentInstanceProperty, ResponseFormat> result;
1028
1029         when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata))
1030             .thenReturn(Either.left(service));
1031
1032         // test 1
1033         testSubject = createTestSubject();
1034         result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
1035             userId);
1036         assertNotNull(result);
1037         componentTypeEnum = null;
1038         result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
1039             userId);
1040         assertNotNull(result);
1041
1042         result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
1043             userId);
1044         assertNotNull(result);
1045     }
1046
1047     @Test
1048     public void testGetComponentParametersViewForForwardingPath() throws Exception {
1049         ComponentInstanceBusinessLogic testSubject;
1050         ComponentParametersView result;
1051
1052         // default test
1053         testSubject = createTestSubject();
1054         result = Deencapsulation.invoke(testSubject, "getComponentParametersViewForForwardingPath");
1055         assertNotNull(result);
1056     }
1057
1058     @Test
1059     public void testGetResourceInstanceById() throws Exception {
1060         ComponentInstanceBusinessLogic testSubject;
1061         createResource();
1062         String instanceId = "";
1063         Either<ComponentInstance, StorageOperationStatus> result;
1064
1065         // default test
1066         testSubject = createTestSubject();
1067         result = Deencapsulation.invoke(testSubject, "getResourceInstanceById", new Object[]{resource, instanceId});
1068         assertNotNull(result);
1069     }
1070
1071     @Test
1072     public void testUpdateInstanceCapabilityProperties_1() throws Exception {
1073         ComponentInstanceBusinessLogic testSubject;
1074         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1075         createResource();
1076         String containerComponentId = resource.getUniqueId();
1077         String componentInstanceUniqueId = "";
1078         String capabilityType = "";
1079         String capabilityName = "";
1080         List<ComponentInstanceProperty> properties = new ArrayList<>();
1081         String userId = user.getUserId();
1082         Either<List<ComponentInstanceProperty>, ResponseFormat> result;
1083
1084         when(toscaOperationFacade.getToscaFullElement(containerComponentId))
1085             .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
1086         // test 1
1087         testSubject = createTestSubject();
1088         result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
1089             componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
1090         assertNotNull(result);
1091         when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
1092         result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
1093             componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
1094         assertNotNull(result);
1095     }
1096
1097     @Test
1098     public void testCopyComponentInstanceWrongUserId() {
1099
1100         Either<Map<String, ComponentInstance>, ResponseFormat> result;
1101         ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource);
1102         String containerComponentId = service.getUniqueId();
1103         String componentInstanceId = resource.getUniqueId();
1104         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1105         service.setLastUpdaterUserId("wrong user id");
1106
1107         Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
1108         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
1109         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1110             .thenReturn(leftServiceOp);
1111         when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
1112         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1113             .thenReturn(StorageOperationStatus.OK);
1114         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1115             .thenReturn(StorageOperationStatus.OK);
1116
1117         result = componentInstanceBusinessLogic
1118             .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
1119                 USER_ID);
1120         assertNotNull(result);
1121
1122         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1123         assertThat(result.isRight()).isTrue();
1124     }
1125
1126     @Test
1127     public void testCopyComponentInstanceComponentWrongState() {
1128         Either<Map<String, ComponentInstance>, ResponseFormat> result;
1129         ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource);
1130         String containerComponentId = service.getUniqueId();
1131         String componentInstanceId = resource.getUniqueId();
1132         String oldServiceLastUpdatedUserId = service.getLastUpdaterUserId();
1133         service.setLastUpdaterUserId(USER_ID);
1134
1135         Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
1136         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
1137         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1138             .thenReturn(leftServiceOp);
1139         when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
1140         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1141             .thenReturn(StorageOperationStatus.OK);
1142         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1143             .thenReturn(StorageOperationStatus.OK);
1144         Either<Component, StorageOperationStatus> getComponentRes = Either.left(resource);
1145         result = componentInstanceBusinessLogic
1146             .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID);
1147         assertNotNull(result);
1148         service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
1149         assertThat(result.isRight()).isTrue();
1150     }
1151
1152     @Test
1153     public void testCopyComponentInstance() {
1154         Either<Map<String, ComponentInstance>, ResponseFormat> result;
1155         ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource);
1156         String containerComponentId = service.getUniqueId();
1157         String componentInstanceId = resource.getUniqueId();
1158         String oldServiceLastUpdatedUserId = service.getLastUpdaterUserId();
1159         service.setLastUpdaterUserId(USER_ID);
1160         LifecycleStateEnum oldResourceLifeCycle = resource.getLifecycleState();
1161         resource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
1162
1163         Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
1164         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
1165         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1166             .thenReturn(leftServiceOp);
1167         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1168             .thenReturn(StorageOperationStatus.OK);
1169         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1170             .thenReturn(StorageOperationStatus.OK);
1171         Either<Component, StorageOperationStatus> getComponentRes = Either.left(resource);
1172         ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, TO_INSTANCE_ID);
1173         Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
1174         Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = Either
1175             .left(new HashMap<String, ArtifactDefinition>());
1176         StorageOperationStatus artStatus = StorageOperationStatus.OK;
1177
1178         result = componentInstanceBusinessLogic
1179             .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
1180                 USER_ID);
1181         assertNotNull(result);
1182
1183         service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
1184         resource.setLifecycleState(oldResourceLifeCycle);
1185
1186         assertThat(result.isLeft());
1187     }
1188
1189     @Test
1190     public void testCreateOrUpdateAttributeValueForCopyPaste() {
1191         ComponentInstance serviceComponentInstance = createComponetInstanceFromComponent(service);
1192         ComponentInstanceProperty attribute = new ComponentInstanceProperty();
1193         attribute.setType("string");
1194         attribute.setUniqueId("testCreateOrUpdateAttributeValueForCopyPaste");
1195         SchemaDefinition def = Mockito.mock(SchemaDefinition.class);
1196         attribute.setSchema(def);
1197         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1198         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1199         service.setLastUpdaterUserId(USER_ID);
1200         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1201
1202         Map<String, List<ComponentInstanceProperty>> instAttrsMap =
1203             new HashMap<String, List<ComponentInstanceProperty>>();
1204         List<ComponentInstanceProperty> instAttrsList = new ArrayList<ComponentInstanceProperty>();
1205         ComponentInstanceProperty prop = new ComponentInstanceProperty();
1206         prop.setUniqueId(attribute.getUniqueId());
1207         instAttrsList.add(prop);
1208         instAttrsMap.put(toInstance.getUniqueId(), instAttrsList);
1209         service.setComponentInstancesAttributes(instAttrsMap);
1210
1211         Either<Component, StorageOperationStatus> serviceEitherLeft = Either.left(service);
1212         when(toscaOperationFacade.getToscaElement(serviceComponentInstance.getUniqueId(), JsonParseFlagEnum.ParseAll))
1213             .thenReturn(serviceEitherLeft);
1214         when(toscaOperationFacade.updateComponentInstanceAttribute(service, toInstance.getUniqueId(), attribute))
1215             .thenReturn(StorageOperationStatus.OK);
1216         when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
1217             .thenReturn(serviceEitherLeft);
1218
1219         Either<ComponentInstanceProperty, ResponseFormat> result = Deencapsulation
1220             .invoke(componentInstanceBusinessLogic,
1221                 "createOrUpdateAttributeValueForCopyPaste",
1222                 ComponentTypeEnum.SERVICE,
1223                 serviceComponentInstance
1224                     .getUniqueId(),
1225                 toInstance.getUniqueId(), attribute,
1226                 USER_ID);
1227         assertNotNull(result);
1228
1229         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1230         service.setLifecycleState(oldLifeCycleState);
1231
1232         assertThat(result.isLeft()).isTrue();
1233         ComponentInstanceProperty resultProp = result.left().value();
1234         assertEquals(resultProp.getPath().size(), 1);
1235         assertEquals(resultProp.getPath().get(0), toInstance.getUniqueId());
1236     }
1237
1238     @Test
1239     public void testUpdateComponentInstanceProperty() {
1240
1241         String containerComponentId = service.getUniqueId();
1242         String componentInstanceId = "dummy_id";
1243         ComponentInstanceProperty property = Mockito.mock(ComponentInstanceProperty.class);
1244
1245         Either<Component, StorageOperationStatus> getComponent = Either.left(service);
1246         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(getComponent);
1247         StorageOperationStatus status = StorageOperationStatus.OK;
1248         when(toscaOperationFacade.updateComponentInstanceProperty(service, componentInstanceId, property))
1249             .thenReturn(status);
1250         Either<Component, StorageOperationStatus> updateContainerRes = Either.left(service);
1251         when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
1252             .thenReturn(updateContainerRes);
1253
1254         Either<String, ResponseFormat> result = Deencapsulation.invoke(componentInstanceBusinessLogic,
1255             "updateComponentInstanceProperty", containerComponentId, componentInstanceId, property);
1256         assertNotNull(result);
1257         assertThat(result.isLeft()).isTrue();
1258     }
1259
1260     @Test
1261     public void testGetInputListDefaultValue() {
1262         Component component = service;
1263         String inputId = "dummy_id";
1264         String defaultValue = "dummy_default_value";
1265         List<InputDefinition> newInputs = new ArrayList<InputDefinition>();
1266         InputDefinition in = new InputDefinition();
1267         in.setUniqueId(inputId);
1268         in.setDefaultValue(defaultValue);
1269         newInputs.add(in);
1270         List<InputDefinition> oldInputs = service.getInputs();
1271         service.setInputs(newInputs);
1272
1273         Either<String, ResponseFormat> result =
1274             Deencapsulation.invoke(componentInstanceBusinessLogic, "getInputListDefaultValue", component, inputId);
1275
1276         service.setInputs(oldInputs);
1277
1278         assertEquals(result.left().value(), defaultValue);
1279     }
1280
1281     @Test
1282     public void testBatchDeleteComponentInstanceFailureWrongType() {
1283         Map<String, List<String>> result;
1284         List<String> componentInstanceIdList = new ArrayList<>();
1285         String containerComponentParam = "WRONG_TYPE";
1286         String containerComponentId = "containerComponentId";
1287         String componentInstanceId = "componentInstanceId";
1288         componentInstanceIdList.add(componentInstanceId);
1289         String userId = USER_ID;
1290         Map<String, List<String>> deleteErrorMap = new HashMap<>();
1291         List<String> deleteErrorIds = new ArrayList<>();
1292         deleteErrorIds.add(componentInstanceId);
1293         deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
1294         Either<Component, StorageOperationStatus> cont = Either.left(service);
1295         when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.NOT_FOUND), eq(null)))
1296             .thenReturn(ActionStatus.GENERAL_ERROR);
1297         when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
1298             .thenReturn(cont);
1299
1300         try {
1301             result = componentInstanceBusinessLogic
1302                 .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList,
1303                     userId);
1304             assertNotNull(result);
1305             assertEquals(deleteErrorMap, result);
1306         } catch (ComponentException e) {
1307             assertEquals(e.getActionStatus().toString(), StorageOperationStatus.GENERAL_ERROR.toString());
1308         }
1309     }
1310
1311     @Test
1312     public void testBatchDeleteComponentInstanceFailureCompIds() {
1313         Map<String, List<String>> result = new HashMap<>();
1314         String containerComponentParam = ComponentTypeEnum.SERVICE_PARAM_NAME;
1315         String containerComponentId = "containerComponentId";
1316         String componentInstanceId = "componentInstanceId";
1317         List<String> componentInstanceIdList = new ArrayList<>();
1318         componentInstanceIdList.add(componentInstanceId);
1319         String userId = USER_ID;
1320         Map<String, List<String>> deleteErrorMap = new HashMap<>();
1321         List<String> deleteErrorIds = new ArrayList<>();
1322         deleteErrorIds.add(componentInstanceId);
1323         deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
1324
1325         Either<Component, StorageOperationStatus> err = Either.right(StorageOperationStatus.GENERAL_ERROR);
1326         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1327             .thenReturn(err);
1328
1329         try {
1330             result = componentInstanceBusinessLogic
1331                 .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList,
1332                     userId);
1333             assertNotNull(result);
1334             assertEquals(deleteErrorMap, result);
1335         } catch (ComponentException e) {
1336             assertEquals(e.getActionStatus().toString(), StorageOperationStatus.GENERAL_ERROR.toString());
1337         }
1338     }
1339
1340     @Test
1341     public void testBatchDeleteComponentInstanceSuccess() {
1342         Map<String, List<String>> result;
1343         String containerComponentParam = ComponentTypeEnum.SERVICE_PARAM_NAME;
1344         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1345         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1346         service.setLastUpdaterUserId(USER_ID);
1347         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1348         String containerComponentId = service.getUniqueId();
1349         String componentInstanceId = TO_INSTANCE_ID;
1350         String userId = USER_ID;
1351         List<String> componentInstanceIdList = new ArrayList<>();
1352         componentInstanceIdList.add(componentInstanceId);
1353         Map<String, List<String>> deleteErrorMap = new HashMap<>();
1354         List<String> deleteErrorIds = new ArrayList<>();
1355         deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
1356
1357         Either<Component, StorageOperationStatus> cont = Either.left(service);
1358         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1359             .thenReturn(StorageOperationStatus.OK);
1360         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1361             .thenReturn(StorageOperationStatus.OK);
1362         ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, TO_INSTANCE_ID);
1363         Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
1364         when(toscaOperationFacade.deleteComponentInstanceFromTopologyTemplate(service, componentInstanceId))
1365             .thenReturn(result2);
1366         when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
1367             .thenReturn(cont);
1368         when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
1369
1370         result = componentInstanceBusinessLogic
1371             .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
1372                 componentInstanceIdList, userId);
1373         assertNotNull(result);
1374
1375         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1376         service.setLifecycleState(oldLifeCycleState);
1377         assertEquals(deleteErrorMap, result);
1378     }
1379
1380     @Test
1381     public void testDissociateRIFromRIFailDissociate() {
1382
1383         List<RequirementCapabilityRelDef> result;
1384         RequirementCapabilityRelDef ref = new RequirementCapabilityRelDef();
1385         ref.setFromNode(FROM_INSTANCE_ID);
1386         ref.setToNode(TO_INSTANCE_ID);
1387         List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
1388         CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
1389         RelationshipInfo ri = new RelationshipInfo();
1390         ri.setRequirement(REQUIREMENT_NAME);
1391         relationship.setRelation(ri);
1392         relationships.add(relationship);
1393         ref.setRelationships(relationships);
1394         List<RequirementCapabilityRelDef> requirementDefList = new ArrayList<>();
1395         requirementDefList.add(ref);
1396         ComponentTypeEnum componentTypeEnum = service.getComponentType();
1397         String componentId = service.getUniqueId();
1398         String userId = USER_ID;
1399         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1400         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1401         service.setLastUpdaterUserId(USER_ID);
1402         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1403
1404         Either<Component, StorageOperationStatus> cont = Either.left(service);
1405         when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
1406             .thenReturn(cont);
1407         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1408             .thenReturn(StorageOperationStatus.OK);
1409         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1410             .thenReturn(StorageOperationStatus.OK);
1411         Either<RequirementCapabilityRelDef, StorageOperationStatus> resultEither;
1412         resultEither = Either.right(StorageOperationStatus.OK);
1413         when(componentsUtils.convertFromStorageResponseForResourceInstance(eq(StorageOperationStatus.OK), eq(true)))
1414             .thenReturn(ActionStatus.GENERAL_ERROR);
1415         when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
1416
1417         try {
1418             result = componentInstanceBusinessLogic
1419                 .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
1420             assertNotNull(result);
1421             assertEquals(new ArrayList<>(), result);
1422         } catch (ComponentException e) {
1423             assertEquals(e.getActionStatus().toString(), StorageOperationStatus.GENERAL_ERROR.toString());
1424         }
1425
1426         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1427         service.setLifecycleState(oldLifeCycleState);
1428
1429     }
1430
1431     @Test
1432     public void testDissociateRIFromRISuccess() {
1433
1434         List<RequirementCapabilityRelDef> result;
1435         RequirementCapabilityRelDef ref = new RequirementCapabilityRelDef();
1436         List<RequirementCapabilityRelDef> requirementDefList = new ArrayList<>();
1437         requirementDefList.add(ref);
1438         ComponentTypeEnum componentTypeEnum = service.getComponentType();
1439         String componentId = service.getUniqueId();
1440         String userId = USER_ID;
1441         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1442         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1443         service.setLastUpdaterUserId(USER_ID);
1444         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1445
1446         Either<Component, StorageOperationStatus> cont = Either.left(service);
1447         when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
1448             .thenReturn(cont);
1449         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1450             .thenReturn(StorageOperationStatus.OK);
1451         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1452             .thenReturn(StorageOperationStatus.OK);
1453         Either<RequirementCapabilityRelDef, StorageOperationStatus> resultEither;
1454         resultEither = Either.left(ref);
1455         when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
1456
1457         result = componentInstanceBusinessLogic
1458             .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
1459         assertNotNull(result);
1460
1461         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1462         service.setLifecycleState(oldLifeCycleState);
1463
1464         assertEquals(requirementDefList, result);
1465     }
1466
1467     @Test
1468     public void testGetComponentInstancePropertyByPolicyId_success() {
1469         Optional<ComponentInstanceProperty> propertyCandidate =
1470             getComponentInstanceProperty(PROP_NAME);
1471
1472         assertThat(propertyCandidate.isPresent()).isTrue();
1473         assertEquals(propertyCandidate.get().getName(), PROP_NAME);
1474     }
1475
1476     @Test
1477     public void testGetComponentInstancePropertyByPolicyId_failure() {
1478         Optional<ComponentInstanceProperty> propertyCandidate =
1479             getComponentInstanceProperty(NON_EXIST_NAME);
1480
1481         assertEquals(propertyCandidate, Optional.empty());
1482     }
1483
1484     private Optional<ComponentInstanceProperty> getComponentInstanceProperty(String propertyName) {
1485         ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
1486         componentInstanceProperty.setName(propertyName);
1487
1488         PolicyDefinition policyDefinition = getPolicyDefinition();
1489         componentInstanceProperty.setGetPolicyValues(policyDefinition.getGetPolicyValues());
1490
1491         service.setComponentInstancesProperties(
1492             Collections.singletonMap(COMPONENT_INST_ID, Collections.singletonList(componentInstanceProperty)));
1493
1494         return componentInstanceBusinessLogic.getComponentInstancePropertyByPolicyId(service, policyDefinition);
1495     }
1496
1497     private PolicyDefinition getPolicyDefinition() {
1498         PolicyDefinition policyDefinition = new PolicyDefinition();
1499         policyDefinition.setInstanceUniqueId(COMPONENT_INST_ID);
1500         policyDefinition.setName(PROP_NAME);
1501
1502         GetPolicyValueDataDefinition getPolicy = new GetPolicyValueDataDefinition();
1503         getPolicy.setPropertyName(PROP_NAME);
1504
1505         List<GetPolicyValueDataDefinition> getPolicies = new ArrayList<>();
1506         getPolicies.add(getPolicy);
1507         policyDefinition.setGetPolicyValues(getPolicies);
1508
1509         return policyDefinition;
1510     }
1511
1512     private ComponentInstance createComponetInstanceFromComponent(Component component) {
1513         ComponentInstance componentInst = new ComponentInstance();
1514         componentInst.setUniqueId(component.getUniqueId());
1515         componentInst.setComponentUid(component.getUniqueId() + "_test");
1516         componentInst.setPosX("10");
1517         componentInst.setPosY("10");
1518         componentInst.setCapabilities(component.getCapabilities());
1519         componentInst.setRequirements(component.getRequirements());
1520         componentInst.setArtifacts(component.getArtifacts());
1521         componentInst.setDeploymentArtifacts(component.getDeploymentArtifacts());
1522         return componentInst;
1523     }
1524 }