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