f6a86ac02fe60b0443c9d3d6bf6018485d90afce
[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.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertFalse;
26 import static org.junit.jupiter.api.Assertions.assertNotEquals;
27 import static org.junit.jupiter.api.Assertions.assertNotNull;
28 import static org.junit.jupiter.api.Assertions.assertNull;
29 import static org.junit.jupiter.api.Assertions.assertSame;
30 import static org.junit.jupiter.api.Assertions.assertThrows;
31 import static org.junit.jupiter.api.Assertions.assertTrue;
32 import static org.junit.jupiter.api.DynamicTest.dynamicTest;
33 import static org.mockito.ArgumentMatchers.any;
34 import static org.mockito.ArgumentMatchers.anySet;
35 import static org.mockito.ArgumentMatchers.eq;
36 import static org.mockito.ArgumentMatchers.isNull;
37 import static org.mockito.Mockito.doReturn;
38 import static org.mockito.Mockito.doThrow;
39 import static org.mockito.Mockito.times;
40 import static org.mockito.Mockito.verify;
41 import static org.mockito.Mockito.when;
42 import static org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum.RESOURCE_PARAM_NAME;
43
44 import fj.data.Either;
45 import java.util.ArrayList;
46 import java.util.Arrays;
47 import java.util.Collections;
48 import java.util.HashMap;
49 import java.util.HashSet;
50 import java.util.List;
51 import java.util.Map;
52 import java.util.Optional;
53 import java.util.Set;
54 import lombok.SneakyThrows;
55 import mockit.Deencapsulation;
56 import org.apache.commons.lang3.tuple.ImmutablePair;
57 import org.apache.commons.lang3.tuple.Pair;
58 import org.assertj.core.util.Lists;
59 import org.junit.jupiter.api.BeforeAll;
60 import org.junit.jupiter.api.BeforeEach;
61 import org.junit.jupiter.api.DynamicTest;
62 import org.junit.jupiter.api.Test;
63 import org.junit.jupiter.api.TestFactory;
64 import org.mockito.Mock;
65 import org.mockito.Mockito;
66 import org.mockito.MockitoAnnotations;
67 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
68 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
69 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
70 import org.openecomp.sdc.be.components.validation.UserValidations;
71 import org.openecomp.sdc.be.config.ConfigurationManager;
72 import org.openecomp.sdc.be.dao.api.ActionStatus;
73 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
74 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
75 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
76 import org.openecomp.sdc.be.datamodel.utils.PropertyValueConstraintValidationUtil;
77 import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition;
78 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
79 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition;
80 import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
81 import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition;
82 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
83 import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition;
84 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
85 import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
86 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
87 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
88 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
89 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
90 import org.openecomp.sdc.be.datatypes.enums.PropertySource;
91 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
92 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
93 import org.openecomp.sdc.be.exception.BusinessException;
94 import org.openecomp.sdc.be.impl.ComponentsUtils;
95 import org.openecomp.sdc.be.model.ArtifactDefinition;
96 import org.openecomp.sdc.be.model.CapabilityDefinition;
97 import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
98 import org.openecomp.sdc.be.model.Component;
99 import org.openecomp.sdc.be.model.ComponentInstance;
100 import org.openecomp.sdc.be.model.ComponentInstanceAttribute;
101 import org.openecomp.sdc.be.model.ComponentInstanceInput;
102 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
103 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
104 import org.openecomp.sdc.be.model.ComponentParametersView;
105 import org.openecomp.sdc.be.model.DataTypeDefinition;
106 import org.openecomp.sdc.be.model.InputDefinition;
107 import org.openecomp.sdc.be.model.LifecycleStateEnum;
108 import org.openecomp.sdc.be.model.PolicyDefinition;
109 import org.openecomp.sdc.be.model.PropertyDefinition;
110 import org.openecomp.sdc.be.model.RelationshipImpl;
111 import org.openecomp.sdc.be.model.RelationshipInfo;
112 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
113 import org.openecomp.sdc.be.model.RequirementDefinition;
114 import org.openecomp.sdc.be.model.Resource;
115 import org.openecomp.sdc.be.model.Service;
116 import org.openecomp.sdc.be.model.User;
117 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
118 import org.openecomp.sdc.be.model.jsonjanusgraph.config.ContainerInstanceTypesData;
119 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ForwardingPathOperation;
120 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
121 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
122 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
123 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
124 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
125 import org.openecomp.sdc.be.model.validation.ToscaFunctionValidator;
126 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
127 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
128 import org.openecomp.sdc.common.api.ConfigurationSource;
129 import org.openecomp.sdc.common.impl.ExternalConfiguration;
130 import org.openecomp.sdc.common.impl.FSConfigurationSource;
131 import org.openecomp.sdc.common.util.ValidationUtils;
132 import org.openecomp.sdc.exception.ResponseFormat;
133
134 /**
135  * The test suite designed for test functionality of ComponentInstanceBusinessLogic class
136  */
137 class ComponentInstanceBusinessLogicTest {
138
139     private final static String USER_ID = "jh0003";
140     private final static String COMPONENT_ID = "componentId";
141     private final static String ORIGIN_COMPONENT_ID = "originComponentId";
142     private final static String ORIGIN_COMPONENT_VERSION = "1.0";
143     private final static String TO_INSTANCE_ID = "toInstanceId";
144     private final static String TO_INSTANCE_NAME = "toInstanceName";
145     private final static String COMPONENT_INSTANCE_ID = "componentInstanceId";
146     private final static String COMPONENT_INSTANCE_NAME = "componentInstanceName";
147     private final static String FROM_INSTANCE_ID = "fromInstanceId";
148     private final static String RELATION_ID = "relationId";
149     private final static String CAPABILITY_OWNER_ID = "capabilityOwnerId";
150     private final static String CAPABILITY_UID = "capabilityUid";
151     private final static String CAPABILITY_NAME = "capabilityName";
152     private final static String REQUIREMENT_OWNER_ID = "requirementOwnerId";
153     private final static String REQUIREMENT_UID = "requirementUid";
154     private final static String REQUIREMENT_NAME = "requirementName";
155     private final static String RELATIONSHIP_TYPE = "relationshipType";
156     private final static String ARTIFACT_1 = "cloudtech_k8s_charts.zip";
157     private final static String ARTIFACT_2 = "cloudtech_azure_day0.zip";
158     private final static String ARTIFACT_3 = "cloudtech_aws_configtemplate.zip";
159     private final static String ARTIFACT_4 = "k8s_charts.zip";
160     private final static String ARTIFACT_5 = "cloudtech_openstack_configtemplate.zip";
161     private final static String PROP_NAME = "propName";
162     private final static String NON_EXIST_NAME = "nonExistName";
163     private final static String INPUT_ID = "inputId";
164     private final static String ICON_NAME = "icon";
165
166     private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
167     @Mock
168     private ComponentInstancePropInput componentInstancePropInput;
169     @Mock
170     private ArtifactsBusinessLogic artifactsBusinessLogic;
171     @Mock
172     private ComponentsUtils componentsUtils;
173     @Mock
174     private ToscaOperationFacade toscaOperationFacade;
175     @Mock
176     private ForwardingPathOperation forwardingPathOperation;
177     @Mock
178     private User user;
179     @Mock
180     private UserValidations userValidations;
181     @Mock
182     private GraphLockOperation graphLockOperation;
183     @Mock
184     private JanusGraphDao janusGraphDao;
185     @Mock
186     private ApplicationDataTypeCache applicationDataTypeCache;
187     @Mock
188     private PropertyOperation propertyOperation;
189     @Mock
190     private ContainerInstanceTypesData containerInstanceTypeData;
191     @Mock
192     private CompositionBusinessLogic compositionBusinessLogic;
193     @Mock
194     private ToscaFunctionValidator toscaFunctionValidator;
195     @Mock
196     private PropertyBusinessLogic propertyBusinessLogic;
197     private Component service;
198     private Component resource;
199     private ComponentInstance toInstance;
200     private ComponentInstance fromInstance;
201     private RequirementCapabilityRelDef relation;
202     private List<ComponentInstanceProperty> ciPropertyList;
203     private List<ComponentInstanceInput> ciInputList;
204
205     @BeforeAll
206     static void beforeAll() {
207         initConfig();
208     }
209
210     private static void initConfig() {
211         final ConfigurationSource configurationSource = new FSConfigurationSource(
212             ExternalConfiguration.getChangeListener(),
213             "src/test/resources/config/catalog-be"
214         );
215         new ConfigurationManager(configurationSource);
216     }
217
218     @BeforeEach
219     void init() {
220         MockitoAnnotations.openMocks(this);
221         componentInstanceBusinessLogic = new ComponentInstanceBusinessLogic(null, null, null, null, null, null, null, artifactsBusinessLogic, null,
222             null, forwardingPathOperation, null, null, toscaFunctionValidator, propertyBusinessLogic);
223         componentInstanceBusinessLogic.setComponentsUtils(componentsUtils);
224         componentInstanceBusinessLogic.setToscaOperationFacade(toscaOperationFacade);
225         componentInstanceBusinessLogic.setUserValidations(userValidations);
226         componentInstanceBusinessLogic.setGraphLockOperation(graphLockOperation);
227         componentInstanceBusinessLogic.setJanusGraphDao(janusGraphDao);
228         componentInstanceBusinessLogic.setApplicationDataTypeCache(applicationDataTypeCache);
229         componentInstanceBusinessLogic.setPropertyOperation(propertyOperation);
230         componentInstanceBusinessLogic.setContainerInstanceTypesData(containerInstanceTypeData);
231         componentInstanceBusinessLogic.setCompositionBusinessLogic(compositionBusinessLogic);
232
233         stubMethods();
234         createComponents();
235     }
236
237     @Test
238     void testGetRelationByIdSuccess() {
239         getServiceRelationByIdSuccess(service);
240         getServiceRelationByIdSuccess(resource);
241     }
242
243     @Test
244     void testGetRelationByIdUserValidationFailure() {
245         getServiceRelationByIdUserValidationFailure(service);
246         getServiceRelationByIdUserValidationFailure(resource);
247     }
248
249     @Test
250     void testGetRelationByIdComponentNotFoundFailure() {
251         getRelationByIdComponentNotFoundFailure(service);
252         getRelationByIdComponentNotFoundFailure(resource);
253     }
254
255     @Test
256     void testForwardingPathOnVersionChange() {
257         getforwardingPathOnVersionChange();
258     }
259
260     @Test
261     void testIsCloudSpecificArtifact() {
262         assertThat(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_1)).isTrue();
263         assertThat(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_2)).isTrue();
264         assertThat(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_3)).isTrue();
265         assertThat(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_4)).isFalse();
266         assertThat(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_5)).isFalse();
267     }
268
269     private void getforwardingPathOnVersionChange() {
270         String containerComponentParam = "services";
271         String containerComponentID = "121-cont";
272         String componentInstanceID = "121-cont-1-comp";
273         Service component = new Service();
274         Map<String, ForwardingPathDataDefinition> forwardingPaths = generateForwardingPath(componentInstanceID);
275
276         //Add existing componentInstance to component
277         List<ComponentInstance> componentInstanceList = new ArrayList<>();
278         ComponentInstance oldComponentInstance = new ComponentInstance();
279         oldComponentInstance.setName("OLD_COMP_INSTANCE");
280         oldComponentInstance.setUniqueId(componentInstanceID);
281         oldComponentInstance.setName(componentInstanceID);
282         oldComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID, "1-comp");
283         componentInstanceList.add(oldComponentInstance);
284         component.setComponentInstances(componentInstanceList);
285         component.setForwardingPaths(forwardingPaths);
286
287         List<ComponentInstance> componentInstanceListNew = new ArrayList<>();
288         ComponentInstance newComponentInstance = new ComponentInstance();
289         String new_Comp_UID = "2-comp";
290         newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID, new_Comp_UID);
291         newComponentInstance.setUniqueId(new_Comp_UID);
292         componentInstanceListNew.add(newComponentInstance);
293         Component component2 = new Service();
294         component2.setComponentInstances(componentInstanceListNew);
295
296         //Mock for getting component
297         when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
298             .thenReturn(Either.left(component));
299         when(toscaOperationFacade.validateComponentExists(any(String.class))).thenReturn(Either.left(Boolean.TRUE));
300         when(toscaOperationFacade.getToscaFullElement(new_Comp_UID)).thenReturn(Either.left(component2));
301
302         Either<Set<String>, ResponseFormat> resultOp = componentInstanceBusinessLogic
303             .forwardingPathOnVersionChange(containerComponentParam,
304                 containerComponentID, componentInstanceID,
305                 newComponentInstance);
306         assertEquals(1, resultOp.left().value().size());
307         assertEquals("FP-ID-1", resultOp.left().value().iterator().next());
308
309     }
310
311     @SneakyThrows
312     @Test
313     void testCreateOrUpdatePropertiesValues2() {
314         String containerComponentID = "containerId";
315         String resourceInstanceId = "resourceId";
316         String componentInstanceID = "componentInstance";
317         List<ComponentInstanceProperty> properties = new ArrayList<>();
318         ComponentInstanceProperty property = new ComponentInstanceProperty();
319         property.setName("property");
320         property.setValue("newVal");
321         property.setType("string");
322         property.setUniqueId("propId");
323         properties.add(property);
324
325         List<ComponentInstanceProperty> origProperties = new ArrayList<>();
326         ComponentInstanceProperty origProperty = new ComponentInstanceProperty();
327         origProperty.setName("property");
328         origProperty.setValue("value");
329         origProperty.setType("string");
330         origProperties.add(origProperty);
331
332         List<PropertyDefinition> ciProperties = new ArrayList<>();
333         PropertyDefinition ciProperty = new ComponentInstanceProperty();
334         ciProperty.setName("property");
335         ciProperty.setValue("value");
336         ciProperty.setType("string");
337         ciProperty.setUniqueId("propId");
338         ciProperties.add(ciProperty);
339
340         Map<String, DataTypeDefinition> types = new HashMap<>();
341         DataTypeDefinition dataTypeDef = new DataTypeDefinition();
342         types.put("string", dataTypeDef);
343
344         Component component = new Service();
345         component.setLastUpdaterUserId("userId");
346         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
347         Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
348         componentInstanceProps.put("resourceId", origProperties);
349         component.setComponentInstancesProperties(componentInstanceProps);
350         ComponentInstance ci = createComponentInstance("ci1");
351         ci.setUniqueId("resourceId");
352         ci.setProperties(ciProperties);
353         component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
354             createComponentInstance(componentInstanceID)));
355
356         when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
357             .thenReturn(Either.left(component));
358         when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
359             .thenReturn(StorageOperationStatus.OK);
360         when(componentsUtils.getAllDataTypes(applicationDataTypeCache, component.getModel())).thenReturn(types);
361         when(propertyOperation.validateAndUpdatePropertyValue(property.getType(), "newVal", true, null, types))
362             .thenReturn(Either.left("newVal"));
363         when(propertyOperation.validateAndUpdateRules("string", property.getRules(),
364             null, types, true)).thenReturn(ImmutablePair.of("string", null));
365         when(toscaOperationFacade.updateComponentInstanceProperty(component, ci.getUniqueId(),
366             origProperty)).thenReturn(StorageOperationStatus.OK);
367         origProperties.get(0).setValue("newVal");
368         when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(component))
369             .thenReturn(Either.left(component));
370         when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
371         when(graphLockOperation.unlockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
372             .thenReturn(StorageOperationStatus.OK);
373         when(propertyBusinessLogic.getComponentModelByComponentId(any())).thenReturn(component.getModel());
374         when(applicationDataTypeCache.getAll(any())).thenReturn(Either.left(types));
375         PropertyValueConstraintValidationUtil validationUtil = Mockito.mock(PropertyValueConstraintValidationUtil.class);
376         when(validationUtil.validatePropertyConstraints(any(),any(),any())).thenReturn(Either.left(any()));
377
378         Either<List<ComponentInstanceProperty>, ResponseFormat> responseFormatEither = componentInstanceBusinessLogic
379             .createOrUpdatePropertiesValues(
380                 ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
381         assertThat(responseFormatEither.left().value()).isEqualTo(properties);
382     }
383
384
385
386     @SneakyThrows
387     @Test
388     void testCreateOrUpdatePropertiesValuesPropertyNotExists() {
389         String containerComponentID = "containerId";
390         String resourceInstanceId = "resourceId";
391         String componentInstanceID = "componentInstance";
392         List<ComponentInstanceProperty> properties = new ArrayList<>();
393         ComponentInstanceProperty property = new ComponentInstanceProperty();
394         property.setName("property");
395         property.setValue("newVal");
396         property.setType("string");
397         properties.add(property);
398
399         List<ComponentInstanceProperty> origProperties = new ArrayList<>();
400
401         Component component = new Service();
402         component.setLastUpdaterUserId("userId");
403         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
404         Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
405         componentInstanceProps.put("resourceId", origProperties);
406         component.setComponentInstancesProperties(componentInstanceProps);
407         ComponentInstance ci = createComponentInstance("ci1");
408         ci.setUniqueId("resourceId");
409         component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
410             createComponentInstance(componentInstanceID)));
411
412         when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
413             .thenReturn(Either.left(component));
414         when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
415             .thenReturn(StorageOperationStatus.OK);
416         when(graphLockOperation.unlockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
417             .thenReturn(StorageOperationStatus.OK);
418         when(propertyBusinessLogic.getComponentModelByComponentId(any())).thenReturn(component.getModel());
419         Map<String, DataTypeDefinition> dataTypeMap = new HashMap<>();
420         when(applicationDataTypeCache.getAll(any())).thenReturn(Either.left(dataTypeMap));
421         PropertyValueConstraintValidationUtil validationUtil = Mockito.mock(PropertyValueConstraintValidationUtil.class);
422         when(validationUtil.validatePropertyConstraints(any(),any(),any()))
423             .thenReturn(Either.left(any()));
424
425         try {
426             componentInstanceBusinessLogic.createOrUpdatePropertiesValues(
427                 ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
428         } catch (ComponentException e) {
429             assertThat(e.getActionStatus()).isEqualTo(ActionStatus.PROPERTY_NOT_FOUND);
430         }
431
432     }
433
434     @SneakyThrows
435     @Test
436     void testCreateOrUpdatePropertiesValuesValidationFailure() {
437         String containerComponentID = "containerId";
438         String resourceInstanceId = "resourceId";
439         String componentInstanceID = "componentInstance";
440         List<ComponentInstanceProperty> properties = new ArrayList<>();
441         ComponentInstanceProperty property = new ComponentInstanceProperty();
442         property.setName("property");
443         property.setValue("newVal");
444         property.setType("string");
445         properties.add(property);
446
447         List<ComponentInstanceProperty> origProperties = new ArrayList<>();
448         ComponentInstanceProperty origProperty = new ComponentInstanceProperty();
449         origProperty.setName("property");
450         origProperty.setValue("value");
451         origProperty.setType("string");
452         origProperties.add(origProperty);
453
454         Map<String, DataTypeDefinition> types = new HashMap<>();
455         DataTypeDefinition dataTypeDef = new DataTypeDefinition();
456         types.put("string", dataTypeDef);
457
458         Component component = new Service();
459         component.setLastUpdaterUserId("userId");
460         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
461         Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
462         componentInstanceProps.put("resourceId", origProperties);
463         component.setComponentInstancesProperties(componentInstanceProps);
464         ComponentInstance ci = createComponentInstance("ci1");
465         ci.setUniqueId("resourceId");
466         component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
467             createComponentInstance(componentInstanceID)));
468
469         when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
470             .thenReturn(Either.left(component));
471         when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
472             .thenReturn(StorageOperationStatus.OK);
473         when(componentsUtils.getAllDataTypes(applicationDataTypeCache, component.getModel())).thenReturn(types);
474         when(propertyOperation.validateAndUpdatePropertyValue(property.getType(), "newVal", true, null, types))
475             .thenReturn(Either.right(false));
476         when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST))
477             .thenReturn(ActionStatus.INVALID_CONTENT);
478         when(propertyBusinessLogic.getComponentModelByComponentId(any())).thenReturn(component.getModel());
479         Map<String, DataTypeDefinition> dataTypeMap = new HashMap<>();
480         when(applicationDataTypeCache.getAll(any())).thenReturn(Either.left(dataTypeMap));
481         PropertyValueConstraintValidationUtil validationUtil = Mockito.mock(PropertyValueConstraintValidationUtil.class);
482         when(validationUtil.validatePropertyConstraints(any(),any(),any()))
483             .thenReturn(Either.left(any()));
484
485         final Either<List<ComponentInstanceProperty>, ResponseFormat> response = componentInstanceBusinessLogic.createOrUpdatePropertiesValues(
486             ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
487         assertThat(response.isRight()).as("Response should be an error").isTrue();
488         final ResponseFormat responseFormat = response.right().value();
489         assertThat(responseFormat.getStatus()).as("Response status should be as expected").isEqualTo(400);
490         assertThat(responseFormat.getMessageId()).as("Error message id should be as expected").isEqualTo("SVC4726");
491     }
492
493     @SneakyThrows
494     @Test
495     void testCreateOrUpdatePropertiesValuesMissingFieldFailure() {
496         String containerComponentID = "containerId";
497         String resourceInstanceId = "resourceId";
498         String componentInstanceID = "componentInstance";
499         List<ComponentInstanceProperty> properties = new ArrayList<>();
500         ComponentInstanceProperty property = new ComponentInstanceProperty();
501         property.setValue("newVal");
502         property.setType("string");
503         properties.add(property);
504
505         List<ComponentInstanceProperty> origProperties = new ArrayList<>();
506         ComponentInstanceProperty origProperty = new ComponentInstanceProperty();
507         origProperty.setName("property");
508         origProperty.setValue("value");
509         origProperty.setType("string");
510         origProperties.add(origProperty);
511
512         Component component = new Service();
513         component.setLastUpdaterUserId("userId");
514         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
515         Map<String, List<ComponentInstanceProperty>> componentInstanceProps = new HashMap<>();
516         componentInstanceProps.put("resourceId", origProperties);
517         component.setComponentInstancesProperties(componentInstanceProps);
518         ComponentInstance ci = createComponentInstance("ci1");
519         ci.setUniqueId("resourceId");
520         component.setComponentInstances(Arrays.asList(ci, createComponentInstance("ci2"),
521             createComponentInstance(componentInstanceID)));
522
523         when(toscaOperationFacade.getToscaElement(containerComponentID, JsonParseFlagEnum.ParseAll))
524             .thenReturn(Either.left(component));
525         when(graphLockOperation.lockComponent(containerComponentID, NodeTypeEnum.ResourceInstance))
526             .thenReturn(StorageOperationStatus.OK);
527         when(propertyBusinessLogic.getComponentModelByComponentId(any())).thenReturn(component.getModel());
528         Map<String, DataTypeDefinition> dataTypeMap = new HashMap<>();
529         when(applicationDataTypeCache.getAll(any())).thenReturn(Either.left(dataTypeMap));
530         PropertyValueConstraintValidationUtil validationUtil = Mockito.mock(PropertyValueConstraintValidationUtil.class);
531         when(validationUtil.validatePropertyConstraints(any(),any(),any()))
532             .thenReturn(Either.left(any()));
533
534         try {
535             componentInstanceBusinessLogic.createOrUpdatePropertiesValues(
536                 ComponentTypeEnum.RESOURCE_INSTANCE, containerComponentID, resourceInstanceId, properties, "userId");
537         } catch (ComponentException e) {
538             assertThat(e.getActionStatus()).isEqualTo(ActionStatus.MISSING_PROPERTY_NAME);
539         }
540     }
541
542     @Test
543     void testDeleteForwardingPathsWhenComponentinstanceDeleted() {
544
545         ComponentTypeEnum containerComponentType = ComponentTypeEnum.findByParamName("services");
546         String containerComponentID = "Service-comp";
547         String componentInstanceID = "NodeA1";
548         Service component = new Service();
549         component
550             .setComponentInstances(Arrays.asList(createComponentInstance("NodeA2"), createComponentInstance("NodeB2"),
551                 createComponentInstance(componentInstanceID)));
552
553         component.addForwardingPath(createPath("path1", componentInstanceID, "NodeB1", "1"));
554         component.addForwardingPath(createPath("Path2", "NodeA2", "NodeB2", "2"));
555         when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
556             .thenReturn(Either.left(component));
557         when(toscaOperationFacade.getToscaElement(containerComponentID)).thenReturn(Either.left(component));
558         when(forwardingPathOperation.deleteForwardingPath(any(Service.class), anySet()))
559             .thenReturn(Either.left(new HashSet<>()));
560         final ComponentInstance ci = new ComponentInstance();
561         ci.setName(componentInstanceID);
562         ComponentInstance responseFormatEither = componentInstanceBusinessLogic
563             .deleteForwardingPathsRelatedTobeDeletedComponentInstance(
564                 containerComponentID, containerComponentType, ci);
565         assertFalse(responseFormatEither.isEmpty());
566     }
567
568     @Test
569     void testAddComponentInstanceDeploymentArtifacts() {
570
571         Component containerComponent = new Service();
572         ComponentInstance componentInstance = new ComponentInstance();
573         componentInstance.setUniqueId(COMPONENT_INSTANCE_ID);
574         Component originComponent = fillOriginComponent(new Resource());
575
576         Map<String, ArtifactDefinition> artifacts = new HashMap<>();
577         ArtifactDefinition deploymentArtifact1 = getArtifact("deploymentArtifact1", ArtifactTypeEnum.HEAT.getType());
578         artifacts.put(deploymentArtifact1.getArtifactLabel(), deploymentArtifact1);
579         ArtifactDefinition deploymentArtifact2 = getArtifact("deploymentArtifact2",
580             ArtifactTypeEnum.HEAT_ENV.getType());
581         artifacts.put(deploymentArtifact2.getArtifactLabel(), deploymentArtifact2);
582         ArtifactDefinition deploymentArtifact3 = getArtifact("deploymentArtifact3",
583             ArtifactTypeEnum.HEAT_VOL.getType());
584         artifacts.put(deploymentArtifact3.getArtifactLabel(), deploymentArtifact3);
585         ArtifactDefinition heatEnvPlaceHolder = getArtifact("deploymentArtifact4", ArtifactTypeEnum.HEAT_ENV.getType());
586         ArtifactDefinition heatEnvPlaceHolder2 = getArtifact("deploymentArtifact5",
587             ArtifactTypeEnum.HEAT_ENV.getType());
588
589         Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts = Either
590             .left(artifacts);
591
592         Map<String, ArtifactDefinition> finalDeploymentArtifacts = new HashMap<>();
593         finalDeploymentArtifacts.put(deploymentArtifact1.getArtifactLabel(), deploymentArtifact1);
594         finalDeploymentArtifacts.put(deploymentArtifact3.getArtifactLabel(), deploymentArtifact3);
595         finalDeploymentArtifacts.put(heatEnvPlaceHolder.getArtifactLabel(), heatEnvPlaceHolder);
596         finalDeploymentArtifacts.put(heatEnvPlaceHolder2.getArtifactLabel(), heatEnvPlaceHolder2);
597         when(artifactsBusinessLogic.getArtifacts(componentInstance.getComponentUid(), NodeTypeEnum.Resource,
598             ArtifactGroupTypeEnum.DEPLOYMENT, null)).thenReturn(getResourceDeploymentArtifacts);
599         when(artifactsBusinessLogic.createHeatEnvPlaceHolder(new ArrayList<>(),
600             deploymentArtifact1, ArtifactsBusinessLogic.HEAT_ENV_NAME, componentInstance.getUniqueId(),
601             NodeTypeEnum.ResourceInstance, componentInstance.getName(), user, containerComponent,
602             null)).thenReturn(heatEnvPlaceHolder);
603         when(artifactsBusinessLogic.createHeatEnvPlaceHolder(new ArrayList<>(),
604             deploymentArtifact3, ArtifactsBusinessLogic.HEAT_ENV_NAME, componentInstance.getUniqueId(),
605             NodeTypeEnum.ResourceInstance, componentInstance.getName(), user, containerComponent,
606             null)).thenReturn(heatEnvPlaceHolder2);
607
608         componentInstanceBusinessLogic.setToscaOperationFacade(toscaOperationFacade);
609         when(toscaOperationFacade.addDeploymentArtifactsToInstance(containerComponent.getUniqueId(), componentInstance,
610             finalDeploymentArtifacts)).thenReturn(StorageOperationStatus.OK);
611         when(toscaOperationFacade
612             .addGroupInstancesToComponentInstance(containerComponent, componentInstance, new ArrayList<>(),
613                 new HashMap<>()))
614             .thenReturn(StorageOperationStatus.OK);
615         when(toscaOperationFacade
616             .addInformationalArtifactsToInstance(containerComponent.getUniqueId(), componentInstance, null))
617             .thenReturn(StorageOperationStatus.OK);
618
619         ActionStatus status = componentInstanceBusinessLogic.addComponentInstanceArtifacts(containerComponent,
620             componentInstance, originComponent, user, null);
621
622         assertThat(status).isEqualTo(ActionStatus.OK);
623
624     }
625
626     private Component fillOriginComponent(Resource originComponent) {
627         originComponent.setUniqueId("resourceId");
628         originComponent.setUniqueId(ORIGIN_COMPONENT_ID);
629         originComponent.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
630         originComponent.setComponentType(ComponentTypeEnum.RESOURCE);
631         originComponent.setState(LifecycleStateEnum.CERTIFIED);
632         return originComponent;
633     }
634
635     private ArtifactDefinition getArtifact(String artifactLabel, String artifactType) {
636         ArtifactDefinition artifactDefinition = new ArtifactDefinition();
637         artifactDefinition.setArtifactLabel(artifactLabel);
638         artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
639         artifactDefinition.setEsId("esId" + artifactLabel);
640         artifactDefinition.setArtifactType(artifactType);
641         artifactDefinition.setArtifactName("artifactName");
642         return artifactDefinition;
643     }
644
645     private ComponentInstance createComponentInstance(String path1) {
646         ComponentInstance componentInstance = new ComponentInstance();
647         componentInstance.setName(path1);
648         return componentInstance;
649     }
650
651     private ForwardingPathDataDefinition createPath(String pathName, String fromNode, String toNode, String uniqueId) {
652         ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition(pathName);
653         forwardingPath.setProtocol("protocol");
654         forwardingPath.setDestinationPortNumber("port");
655         forwardingPath.setUniqueId(uniqueId);
656         ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
657             new ListDataDefinition<>();
658         forwardingPathElementListDataDefinition
659             .add(new ForwardingPathElementDataDefinition(fromNode, toNode, "nodeAcpType", "nodeBcpType",
660                 "nodeDcpName", "nodeBcpName"));
661         forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
662
663         return forwardingPath;
664     }
665
666     private Map<String, ForwardingPathDataDefinition> generateForwardingPath(String componentInstanceID) {
667         ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition("fpName");
668         String protocol = "protocol";
669         forwardingPath.setProtocol(protocol);
670         forwardingPath.setDestinationPortNumber("DestinationPortNumber");
671         forwardingPath.setUniqueId("FP-ID-1");
672         ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
673             new ListDataDefinition<>();
674         forwardingPathElementListDataDefinition
675             .add(new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY",
676                 "nodeBcpType", "nodeDcpName", "nodeBcpName"));
677         forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
678         Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
679         forwardingPaths.put("1122", forwardingPath);
680         return forwardingPaths;
681     }
682
683     private void getServiceRelationByIdSuccess(Component component) {
684         Either<Component, StorageOperationStatus> getComponentRes = Either.left(component);
685         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
686             .thenReturn(getComponentRes);
687         Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
688             .getRelationById(COMPONENT_ID,
689                 RELATION_ID, USER_ID,
690                 component.getComponentType());
691         assertThat(response.isLeft()).isTrue();
692     }
693
694     private void getServiceRelationByIdUserValidationFailure(Component component) {
695         doThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND)).when(userValidations).validateUserExists(USER_ID);
696         try {
697             componentInstanceBusinessLogic
698                 .getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
699         } catch (ByActionStatusComponentException e) {
700             assertSame(ActionStatus.USER_NOT_FOUND, e.getActionStatus());
701         }
702     }
703
704     private void getRelationByIdComponentNotFoundFailure(Component component) {
705         Either<Component, StorageOperationStatus> getComponentRes = Either.right(StorageOperationStatus.NOT_FOUND);
706         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
707             .thenReturn(getComponentRes);
708
709         Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
710             .getRelationById(COMPONENT_ID,
711                 RELATION_ID, USER_ID,
712                 component.getComponentType());
713         assertThat(response.isRight()).isTrue();
714     }
715
716     private void stubMethods() {
717         Mockito.lenient().when(userValidations.validateUserExists(eq(USER_ID))).thenReturn(user);
718         Mockito.lenient().when(componentsUtils
719             .convertFromStorageResponse(eq(StorageOperationStatus.GENERAL_ERROR), any(ComponentTypeEnum.class)))
720             .thenReturn(ActionStatus.GENERAL_ERROR);
721     }
722
723     private void createComponents() {
724         createRelation();
725         createInstances();
726         createProperties();
727         createInputs();
728         createService();
729         resource = createResource();
730     }
731
732     private Resource createResource() {
733         final Resource resource = new Resource();
734         resource.setUniqueId(COMPONENT_ID);
735         resource.setComponentInstancesRelations(Lists.newArrayList(relation));
736         resource.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
737         resource.setCapabilities(toInstance.getCapabilities());
738         resource.setRequirements(fromInstance.getRequirements());
739         resource.setComponentType(ComponentTypeEnum.RESOURCE);
740         resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
741         return resource;
742     }
743
744     private void createService() {
745         service = new Service();
746         service.setUniqueId(COMPONENT_ID);
747         service.setComponentInstancesRelations(Lists.newArrayList(relation));
748         service.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
749         service.setCapabilities(toInstance.getCapabilities());
750         service.setRequirements(fromInstance.getRequirements());
751         service.setComponentType(ComponentTypeEnum.SERVICE);
752         service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
753         service.setLastUpdaterUserId(USER_ID);
754
755         Map<String, List<ComponentInstanceProperty>> ciPropertyMap = new HashMap<>();
756         ciPropertyMap.put(TO_INSTANCE_ID, ciPropertyList);
757         service.setComponentInstancesProperties(ciPropertyMap);
758
759         Map<String, List<ComponentInstanceInput>> ciInputMap = new HashMap<>();
760         ciInputMap.put(TO_INSTANCE_ID, ciInputList);
761         service.setComponentInstancesInputs(ciInputMap);
762     }
763
764     private void createInstances() {
765         toInstance = new ComponentInstance();
766         toInstance.setUniqueId(TO_INSTANCE_ID);
767         toInstance.setName(TO_INSTANCE_NAME);
768
769         fromInstance = new ComponentInstance();
770         fromInstance.setUniqueId(FROM_INSTANCE_ID);
771
772         CapabilityDataDefinition capability = new CapabilityDataDefinition();
773         capability.setOwnerId(CAPABILITY_OWNER_ID);
774         capability.setUniqueId(CAPABILITY_UID);
775         capability.setName(CAPABILITY_NAME);
776
777         Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
778         final CapabilityDefinition capabilityDefinition = new CapabilityDefinition(capability);
779         final ArrayList<ComponentInstanceProperty> properties = new ArrayList<>();
780         properties.add(componentInstancePropInput);
781         capabilityDefinition.setProperties(properties);
782         capabilities.put(capability.getName(), Lists.newArrayList(capabilityDefinition));
783
784         RequirementDataDefinition requirement = new RequirementDataDefinition();
785         requirement.setOwnerId(REQUIREMENT_OWNER_ID);
786         requirement.setUniqueId(REQUIREMENT_UID);
787         requirement.setName(REQUIREMENT_NAME);
788         requirement.setRelationship(RELATIONSHIP_TYPE);
789
790         Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
791         requirements.put(requirement.getCapability(), Lists.newArrayList(new RequirementDefinition(requirement)));
792
793         toInstance.setCapabilities(capabilities);
794         fromInstance.setRequirements(requirements);
795
796     }
797
798     private void createRelation() {
799
800         relation = new RequirementCapabilityRelDef();
801         CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
802         RelationshipInfo relationInfo = new RelationshipInfo();
803         relationInfo.setId(RELATION_ID);
804         relationship.setRelation(relationInfo);
805
806         relation.setRelationships(Lists.newArrayList(relationship));
807         relation.setToNode(TO_INSTANCE_ID);
808         relation.setFromNode(FROM_INSTANCE_ID);
809
810         relationInfo.setCapabilityOwnerId(CAPABILITY_OWNER_ID);
811         relationInfo.setCapabilityUid(CAPABILITY_UID);
812         relationInfo.setCapability(CAPABILITY_NAME);
813         relationInfo.setRequirementOwnerId(REQUIREMENT_OWNER_ID);
814         relationInfo.setRequirementUid(REQUIREMENT_UID);
815         relationInfo.setRequirement(REQUIREMENT_NAME);
816         RelationshipImpl relationshipImpl = new RelationshipImpl();
817         relationshipImpl.setType(RELATIONSHIP_TYPE);
818         relationInfo.setRelationships(relationshipImpl);
819     }
820
821     private void createProperties() {
822         // Create GetInputValueData
823         GetInputValueDataDefinition inputValueDef = new GetInputValueDataDefinition();
824         inputValueDef.setInputId(INPUT_ID);
825         List<GetInputValueDataDefinition> inputValueDefList = new ArrayList<>();
826         inputValueDefList.add(inputValueDef);
827         // Create ComponentInstanceProperty
828         ComponentInstanceProperty ciProperty = new ComponentInstanceProperty();
829         ciProperty.setGetInputValues(inputValueDefList);
830         ciProperty.setName(PROP_NAME);
831         // Create ComponentInstanceProperty list
832         ciPropertyList = new ArrayList<>();
833         ciPropertyList.add(ciProperty);
834     }
835
836     private void createInputs() {
837         // Create GetInputValueData
838         GetInputValueDataDefinition inputValueDef = new GetInputValueDataDefinition();
839         inputValueDef.setInputId(INPUT_ID);
840         List<GetInputValueDataDefinition> inputValueDefList = new ArrayList<>();
841         inputValueDefList.add(inputValueDef);
842         // Create ComponentInstanceInput
843         ComponentInstanceInput ciInput = new ComponentInstanceInput();
844         ciInput.setUniqueId(INPUT_ID);
845         ciInput.setName(PROP_NAME);
846         ciInput.setGetInputValues(inputValueDefList);
847         // Create ComponentInstanceInput list
848         ciInputList = new ArrayList<>();
849         ciInputList.add(ciInput);
850     }
851
852     private ComponentInstanceBusinessLogic createTestSubject() {
853         return componentInstanceBusinessLogic;
854     }
855
856     @Test
857     void testChangeServiceProxyVersion() {
858         ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
859
860         Either<ComponentInstance, ResponseFormat> result;
861
862         // default test
863         componentInstanceBusinessLogic = createTestSubject();
864         result = componentInstanceBusinessLogic.changeServiceProxyVersion();
865         assertNotNull(result);
866     }
867
868     @Test
869     void testCreateServiceProxy() {
870         ComponentInstanceBusinessLogic testSubject;
871         Either<ComponentInstance, ResponseFormat> result;
872
873         // default test
874         testSubject = createTestSubject();
875         result = testSubject.createServiceProxy();
876         assertNotNull(result);
877     }
878
879     @Test
880     void testDeleteServiceProxy() {
881         ComponentInstanceBusinessLogic testSubject;
882
883         Either<ComponentInstance, ResponseFormat> result;
884
885         // default test
886         testSubject = createTestSubject();
887         result = testSubject.deleteServiceProxy();
888         assertNotNull(result);
889     }
890
891     @Test
892     void testGetComponentInstanceInputsByInputIdEmpty() {
893         Component component = new Service();
894         String inputId = "";
895         List<ComponentInstanceInput> result;
896
897         result = componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(component, inputId);
898         assertNotNull(result);
899         assertThat(result.isEmpty()).isTrue();
900     }
901
902     @Test
903     void testGetComponentInstanceInputsByInputIdPresent() {
904         List<ComponentInstanceInput> result;
905
906         result = componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(service, INPUT_ID);
907         assertNotNull(result);
908         assertThat(result.isEmpty()).isFalse();
909         assertThat(result.size()).isOne();
910         ComponentInstanceInput resultInput = result.get(0);
911         assertThat(resultInput.getComponentInstanceId()).isEqualTo(TO_INSTANCE_ID);
912         assertThat(resultInput.getComponentInstanceName()).isEqualTo(TO_INSTANCE_NAME);
913     }
914
915     @Test
916     void testGetComponentInstancePropertiesByInputIdEmpty() {
917         Component component = new Service();
918         String inputId = "";
919         List<ComponentInstanceProperty> result;
920
921         result = componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(component, inputId);
922         assertNotNull(result);
923         assertThat(result.isEmpty()).isTrue();
924     }
925
926     @Test
927     void testGetComponentInstancePropertiesByInputIdPresent() {
928         List<ComponentInstanceProperty> result;
929
930         result = componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(service, INPUT_ID);
931         assertNotNull(result);
932         assertThat(result.size()).isOne();
933         ComponentInstanceProperty resultProperty = result.get(0);
934         assertThat(resultProperty.getComponentInstanceId()).isEqualTo(TO_INSTANCE_ID);
935         assertThat(resultProperty.getComponentInstanceName()).isEqualTo(TO_INSTANCE_NAME);
936     }
937
938     @Test
939     void testGetRelationById() {
940         ComponentInstanceBusinessLogic testSubject;
941         String componentId = "";
942         String relationId = "";
943         String userId = user.getUserId();
944         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE_INSTANCE;
945         Either<RequirementCapabilityRelDef, ResponseFormat> result;
946
947         // default test
948         testSubject = createTestSubject();
949         result = testSubject.getRelationById(componentId, relationId, userId, componentTypeEnum);
950         assertNotNull(result);
951     }
952
953     @Test
954     void testValidateParent() {
955         ComponentInstanceBusinessLogic testSubject;
956         resource = createResource();
957         String nodeTemplateId = "";
958         boolean result;
959
960         // default test
961         testSubject = createTestSubject();
962         result = Deencapsulation.invoke(testSubject, "validateParent", new Object[]{resource, nodeTemplateId});
963         assertFalse(result);
964     }
965
966     @Test
967     void testGetComponentType() {
968         ComponentInstanceBusinessLogic testSubject;
969         ComponentTypeEnum result;
970
971         // default test
972         testSubject = createTestSubject();
973         result = Deencapsulation.invoke(testSubject, "getComponentType", new Object[]{ComponentTypeEnum.class});
974         assertNotNull(result);
975     }
976
977     @Test
978     void testGetNewGroupName() {
979         ComponentInstanceBusinessLogic testSubject;
980         String oldPrefix = "";
981         String newNormailzedPrefix = "";
982         String qualifiedGroupInstanceName = "";
983         String result;
984
985         // test 1
986         testSubject = createTestSubject();
987         result = Deencapsulation.invoke(testSubject, "getNewGroupName",
988             new Object[]{oldPrefix, newNormailzedPrefix, qualifiedGroupInstanceName});
989         assertNotNull(result);
990     }
991
992     @Test
993     void testUpdateComponentInstanceMetadata_3() {
994         ComponentInstanceBusinessLogic testSubject;
995         createInstances();
996         ComponentInstance result;
997
998         // default test
999         testSubject = createTestSubject();
1000         result = Deencapsulation
1001             .invoke(testSubject, "updateComponentInstanceMetadata", new Object[]{toInstance, toInstance});
1002         assertNotNull(result);
1003     }
1004
1005     @Test
1006     void testFindRelation() {
1007         ComponentInstanceBusinessLogic testSubject;
1008         String relationId = "";
1009         List<RequirementCapabilityRelDef> requirementCapabilityRelations = new ArrayList<>();
1010         RequirementCapabilityRelDef result;
1011
1012         // default test
1013         testSubject = createTestSubject();
1014         result = Deencapsulation.invoke(testSubject, "findRelation",
1015             new Object[]{relationId, requirementCapabilityRelations});
1016         assertNull(result);
1017     }
1018
1019     @Test
1020     void testCreateOrUpdatePropertiesValues() {
1021         ComponentInstanceBusinessLogic testSubject;
1022         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1023         resource = createResource();
1024         String componentId = resource.getUniqueId();
1025         String resourceInstanceId = "";
1026         List<ComponentInstanceProperty> properties = new ArrayList<>();
1027         String userId = user.getUserId();
1028         Either<List<ComponentInstanceProperty>, ResponseFormat> result;
1029
1030         when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
1031             .thenReturn(Either.left(resource));
1032
1033         // test 1
1034         testSubject = createTestSubject();
1035         result = testSubject
1036             .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
1037                 userId);
1038         assertNotNull(result);
1039
1040         componentTypeEnum = null;
1041         result = testSubject
1042             .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
1043                 userId);
1044         assertNotNull(result);
1045
1046         result = testSubject
1047             .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
1048                 userId);
1049         assertNotNull(result);
1050     }
1051
1052     @Test
1053     void testUpdateCapabilityPropertyOnContainerComponent() {
1054         ComponentInstanceBusinessLogic testSubject;
1055         ComponentInstanceProperty property = new ComponentInstanceProperty();
1056         String newValue = "";
1057         resource = createResource();
1058         createInstances();
1059         String capabilityType = "";
1060         String capabilityName = "";
1061         ResponseFormat result;
1062
1063         // default test
1064         testSubject = createTestSubject();
1065         result = Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent",
1066             new Object[]{property, newValue, resource, toInstance, capabilityType, capabilityName});
1067         assertNull(result);
1068     }
1069
1070     @Test
1071     void testCreateOrUpdateInstanceInputValues() {
1072         ComponentInstanceBusinessLogic testSubject;
1073         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1074         resource = createResource();
1075         String componentId = resource.getUniqueId();
1076         String resourceInstanceId = "";
1077         List<ComponentInstanceInput> inputs = new ArrayList<>();
1078         String userId = user.getUserId();
1079         Either<List<ComponentInstanceInput>, ResponseFormat> result;
1080
1081         when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
1082             .thenReturn(Either.left(resource));
1083
1084         // test 1
1085         testSubject = createTestSubject();
1086         result = testSubject
1087             .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
1088                 userId);
1089         assertNotNull(result);
1090         componentTypeEnum = null;
1091         result = testSubject
1092             .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
1093                 userId);
1094         assertNotNull(result);
1095
1096         result = testSubject
1097             .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
1098                 userId);
1099         assertNotNull(result);
1100     }
1101
1102     @Test
1103     void testCreateOrUpdateGroupInstancePropertyValue() {
1104         ComponentInstanceBusinessLogic testSubject;
1105         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1106         resource = createResource();
1107         String componentId = resource.getUniqueId();
1108         String resourceInstanceId = "";
1109         String groupInstanceId = "";
1110         ComponentInstanceProperty property = new ComponentInstanceProperty();
1111         String userId = user.getUserId();
1112         Either<ComponentInstanceProperty, ResponseFormat> result;
1113
1114         when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata))
1115             .thenReturn(Either.left(resource));
1116
1117         // test 1
1118         testSubject = createTestSubject();
1119         result = testSubject
1120             .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
1121                 groupInstanceId, property, userId);
1122         assertNotNull(result);
1123         componentTypeEnum = null;
1124         result = testSubject
1125             .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
1126                 groupInstanceId, property, userId);
1127         assertNotNull(result);
1128
1129         result = testSubject
1130             .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
1131                 groupInstanceId, property, userId);
1132         assertNotNull(result);
1133     }
1134
1135     @Test
1136     void testDeletePropertyValue() {
1137         ComponentInstanceBusinessLogic testSubject;
1138         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1139         createService();
1140         String serviceId = service.getUniqueId();
1141         String resourceInstanceId = "";
1142         String propertyValueId = "";
1143         String userId = user.getUserId();
1144         Either<ComponentInstanceProperty, ResponseFormat> result;
1145
1146         when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata))
1147             .thenReturn(Either.left(service));
1148
1149         // test 1
1150         testSubject = createTestSubject();
1151         result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
1152             userId);
1153         assertNotNull(result);
1154         componentTypeEnum = null;
1155         result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
1156             userId);
1157         assertNotNull(result);
1158
1159         result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
1160             userId);
1161         assertNotNull(result);
1162     }
1163
1164     @Test
1165     void testGetComponentParametersViewForForwardingPath() {
1166         ComponentInstanceBusinessLogic testSubject;
1167         ComponentParametersView result;
1168
1169         // default test
1170         testSubject = createTestSubject();
1171         result = Deencapsulation.invoke(testSubject, "getComponentParametersViewForForwardingPath");
1172         assertNotNull(result);
1173     }
1174
1175     @Test
1176     void testGetResourceInstanceById() {
1177         ComponentInstanceBusinessLogic testSubject;
1178         resource = createResource();
1179         String instanceId = "";
1180         Either<ComponentInstance, StorageOperationStatus> result;
1181
1182         // default test
1183         testSubject = createTestSubject();
1184         result = Deencapsulation.invoke(testSubject, "getResourceInstanceById", new Object[]{resource, instanceId});
1185         assertNotNull(result);
1186     }
1187
1188     @Test
1189     void testUpdateInstanceCapabilityProperties_1() {
1190         ComponentInstanceBusinessLogic testSubject;
1191         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1192         resource = createResource();
1193         String containerComponentId = resource.getUniqueId();
1194         String componentInstanceUniqueId = "";
1195         String capabilityType = "";
1196         String capabilityName = "";
1197         List<ComponentInstanceProperty> properties = new ArrayList<>();
1198         String userId = user.getUserId();
1199         Either<List<ComponentInstanceProperty>, ResponseFormat> result;
1200
1201         when(toscaOperationFacade.getToscaFullElement(containerComponentId))
1202             .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
1203         // test 1
1204         testSubject = createTestSubject();
1205         result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
1206             componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
1207         assertNotNull(result);
1208         when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
1209         result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
1210             componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
1211         assertNotNull(result);
1212     }
1213
1214     @Test
1215     void testUpdateInstanceRequirement() {
1216         ComponentInstanceBusinessLogic testSubject;
1217         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1218         createComponents();
1219         String userId = "userId";
1220         resource.setLastUpdaterUserId(userId);
1221         String containerComponentId = resource.getUniqueId();
1222         String componentInstanceUniqueId = TO_INSTANCE_ID;
1223         String capabilityType = "";
1224         String capabilityName = "";
1225         RequirementDefinition requirementDef = new RequirementDefinition();
1226
1227         Either<RequirementDefinition, ResponseFormat> result;
1228
1229         when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
1230         testSubject = createTestSubject();
1231         when(toscaOperationFacade.updateComponentInstanceRequirement(containerComponentId, TO_INSTANCE_ID, requirementDef)).thenReturn(StorageOperationStatus.OK);
1232         when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(resource)).thenReturn(Either.left(resource));
1233         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
1234             .thenReturn(StorageOperationStatus.OK);
1235         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Resource)))
1236             .thenReturn(StorageOperationStatus.OK);
1237
1238         result = testSubject.updateInstanceRequirement(componentTypeEnum, containerComponentId,
1239             componentInstanceUniqueId, requirementDef, userId);
1240         assertEquals(requirementDef, result.left().value());
1241
1242     }
1243
1244     @Test
1245     void testCopyComponentInstanceWrongUserId() {
1246
1247         Either<Map<String, ComponentInstance>, ResponseFormat> result;
1248         ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource);
1249         String containerComponentId = service.getUniqueId();
1250         String componentInstanceId = resource.getUniqueId();
1251         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1252         service.setLastUpdaterUserId("wrong user id");
1253
1254         Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
1255         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
1256         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1257             .thenReturn(leftServiceOp);
1258         when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
1259         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1260             .thenReturn(StorageOperationStatus.OK);
1261         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1262             .thenReturn(StorageOperationStatus.OK);
1263
1264         result = componentInstanceBusinessLogic
1265             .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
1266                 USER_ID);
1267         assertNotNull(result);
1268
1269         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1270         assertThat(result.isRight()).isTrue();
1271     }
1272
1273     @Test
1274     void testCopyComponentInstanceComponentWrongState() {
1275         Either<Map<String, ComponentInstance>, ResponseFormat> result;
1276         ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource);
1277         String containerComponentId = service.getUniqueId();
1278         String componentInstanceId = resource.getUniqueId();
1279         String oldServiceLastUpdatedUserId = service.getLastUpdaterUserId();
1280         service.setLastUpdaterUserId(USER_ID);
1281
1282         Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
1283         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
1284         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1285             .thenReturn(leftServiceOp);
1286         when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
1287         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1288             .thenReturn(StorageOperationStatus.OK);
1289         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1290             .thenReturn(StorageOperationStatus.OK);
1291         result = componentInstanceBusinessLogic
1292             .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId, USER_ID);
1293         assertNotNull(result);
1294         service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
1295         assertThat(result.isRight()).isTrue();
1296     }
1297
1298     @Test
1299     void testCopyComponentInstance() {
1300         Either<Map<String, ComponentInstance>, ResponseFormat> result;
1301         ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource);
1302         String containerComponentId = service.getUniqueId();
1303         String componentInstanceId = resource.getUniqueId();
1304         String oldServiceLastUpdatedUserId = service.getLastUpdaterUserId();
1305         service.setLastUpdaterUserId(USER_ID);
1306         LifecycleStateEnum oldResourceLifeCycle = resource.getLifecycleState();
1307         resource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
1308
1309         Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
1310         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
1311         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1312             .thenReturn(leftServiceOp);
1313         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1314             .thenReturn(StorageOperationStatus.OK);
1315         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1316             .thenReturn(StorageOperationStatus.OK);
1317
1318         result = componentInstanceBusinessLogic
1319             .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
1320                 USER_ID);
1321         assertNotNull(result);
1322
1323         service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
1324         resource.setLifecycleState(oldResourceLifeCycle);
1325
1326         assertThat(result.isLeft()).isFalse();
1327     }
1328
1329     @Test
1330     void testCreateOrUpdateAttributeValueForCopyPaste() {
1331         ComponentInstance serviceComponentInstance = createComponetInstanceFromComponent(service);
1332         ComponentInstanceAttribute attribute = new ComponentInstanceAttribute();
1333         attribute.setType("string");
1334         attribute.setUniqueId("testCreateOrUpdateAttributeValueForCopyPaste");
1335         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1336         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1337         service.setLastUpdaterUserId(USER_ID);
1338         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1339
1340         Map<String, List<ComponentInstanceAttribute>> instAttrsMap = new HashMap<>();
1341         List<ComponentInstanceAttribute> instAttrsList = new ArrayList<>();
1342         ComponentInstanceAttribute prop = new ComponentInstanceAttribute();
1343         prop.setUniqueId(attribute.getUniqueId());
1344         instAttrsList.add(prop);
1345         instAttrsMap.put(toInstance.getUniqueId(), instAttrsList);
1346         service.setComponentInstancesAttributes(instAttrsMap);
1347
1348         Either<Component, StorageOperationStatus> serviceEitherLeft = Either.left(service);
1349         when(toscaOperationFacade.getToscaElement(serviceComponentInstance.getUniqueId(), JsonParseFlagEnum.ParseAll))
1350             .thenReturn(serviceEitherLeft);
1351         when(toscaOperationFacade.updateComponentInstanceAttribute(service, toInstance.getUniqueId(), attribute))
1352             .thenReturn(StorageOperationStatus.OK);
1353         when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
1354             .thenReturn(serviceEitherLeft);
1355
1356         Either<ComponentInstanceAttribute, ResponseFormat> result = Deencapsulation
1357             .invoke(componentInstanceBusinessLogic,
1358                 "createOrUpdateAttributeValueForCopyPaste",
1359                 ComponentTypeEnum.SERVICE,
1360                 serviceComponentInstance
1361                     .getUniqueId(),
1362                 toInstance.getUniqueId(), attribute,
1363                 USER_ID);
1364         assertNotNull(result);
1365
1366         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1367         service.setLifecycleState(oldLifeCycleState);
1368
1369         assertThat(result.isLeft()).isTrue();
1370         ComponentInstanceAttribute resultProp = result.left().value();
1371         assertEquals(1, resultProp.getPath().size());
1372         assertEquals(resultProp.getPath().get(0), toInstance.getUniqueId());
1373     }
1374
1375     @Test
1376     void testUpdateComponentInstanceProperty() {
1377
1378         String containerComponentId = service.getUniqueId();
1379         String componentInstanceId = "dummy_id";
1380         ComponentInstanceProperty property = Mockito.mock(ComponentInstanceProperty.class);
1381
1382         Either<Component, StorageOperationStatus> getComponent = Either.left(service);
1383         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(getComponent);
1384         StorageOperationStatus status = StorageOperationStatus.OK;
1385         when(toscaOperationFacade.updateComponentInstanceProperty(service, componentInstanceId, property))
1386             .thenReturn(status);
1387         Either<Component, StorageOperationStatus> updateContainerRes = Either.left(service);
1388         when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
1389             .thenReturn(updateContainerRes);
1390
1391         Either<String, ResponseFormat> result = Deencapsulation.invoke(componentInstanceBusinessLogic,
1392             "updateComponentInstanceProperty", containerComponentId, componentInstanceId, property);
1393         assertNotNull(result);
1394         assertThat(result.isLeft()).isTrue();
1395     }
1396
1397     @Test
1398     void testGetInputListDefaultValue() {
1399         Component component = service;
1400         String inputId = "dummy_id";
1401         String defaultValue = "dummy_default_value";
1402         List<InputDefinition> newInputs = new ArrayList<>();
1403         InputDefinition in = new InputDefinition();
1404         in.setUniqueId(inputId);
1405         in.setDefaultValue(defaultValue);
1406         newInputs.add(in);
1407         List<InputDefinition> oldInputs = service.getInputs();
1408         service.setInputs(newInputs);
1409
1410         Either<String, ResponseFormat> result =
1411             Deencapsulation.invoke(componentInstanceBusinessLogic, "getInputListDefaultValue", component, inputId);
1412
1413         service.setInputs(oldInputs);
1414
1415         assertEquals(result.left().value(), defaultValue);
1416     }
1417
1418     @Test
1419     void testBatchDeleteComponentInstanceFailureWrongType() {
1420         Map<String, List<String>> result;
1421         List<String> componentInstanceIdList = new ArrayList<>();
1422         String containerComponentParam = "WRONG_TYPE";
1423         String containerComponentId = "containerComponentId";
1424         String componentInstanceId = "componentInstanceId";
1425         componentInstanceIdList.add(componentInstanceId);
1426         Map<String, List<String>> deleteErrorMap = new HashMap<>();
1427         List<String> deleteErrorIds = new ArrayList<>();
1428         deleteErrorIds.add(componentInstanceId);
1429         deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
1430         Either<Component, StorageOperationStatus> cont = Either.left(service);
1431         when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, null))
1432             .thenReturn(ActionStatus.GENERAL_ERROR);
1433         when(toscaOperationFacade.getToscaElement(any(String.class), any(ComponentParametersView.class)))
1434             .thenReturn(cont);
1435
1436         try {
1437             result = componentInstanceBusinessLogic
1438                 .batchDeleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceIdList,
1439                     USER_ID);
1440             assertNotNull(result);
1441             assertEquals(deleteErrorMap, result);
1442         } catch (ComponentException e) {
1443             assertEquals(e.getActionStatus().toString(), StorageOperationStatus.GENERAL_ERROR.toString());
1444         }
1445     }
1446
1447     @Test
1448     void testBatchDeleteComponentInstanceFailureCompIds() {
1449         String containerComponentParam = ComponentTypeEnum.SERVICE_PARAM_NAME;
1450         String containerComponentId = "containerComponentId";
1451         String componentInstanceId = "componentInstanceId";
1452         List<String> componentInstanceIdList = new ArrayList<>();
1453         componentInstanceIdList.add(componentInstanceId);
1454         Map<String, List<String>> deleteErrorMap = new HashMap<>();
1455         List<String> deleteErrorIds = new ArrayList<>();
1456         deleteErrorIds.add(componentInstanceId);
1457         deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
1458
1459         Either<Component, StorageOperationStatus> err = Either.right(StorageOperationStatus.GENERAL_ERROR);
1460         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1461             .thenReturn(err);
1462
1463         try {
1464             Map<String, List<String>> result = componentInstanceBusinessLogic.batchDeleteComponentInstance(
1465                 containerComponentParam, containerComponentId, componentInstanceIdList, USER_ID);
1466             assertNotNull(result);
1467             assertEquals(deleteErrorMap, result);
1468         } catch (ComponentException e) {
1469             assertEquals(e.getActionStatus().toString(), StorageOperationStatus.GENERAL_ERROR.toString());
1470         }
1471     }
1472
1473     @Test
1474     void testBatchDeleteComponentInstanceSuccess() {
1475         Map<String, List<String>> result;
1476         String containerComponentParam = ComponentTypeEnum.SERVICE_PARAM_NAME;
1477         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1478         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1479         service.setLastUpdaterUserId(USER_ID);
1480         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1481         String containerComponentId = service.getUniqueId();
1482         String componentInstanceId = TO_INSTANCE_ID;
1483         List<String> componentInstanceIdList = new ArrayList<>();
1484         componentInstanceIdList.add(componentInstanceId);
1485         Map<String, List<String>> deleteErrorMap = new HashMap<>();
1486         List<String> deleteErrorIds = new ArrayList<>();
1487         deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
1488
1489         Either<Component, StorageOperationStatus> cont = Either.left(service);
1490         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1491             .thenReturn(StorageOperationStatus.OK);
1492         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1493             .thenReturn(StorageOperationStatus.OK);
1494         ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, TO_INSTANCE_ID);
1495         Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
1496         when(toscaOperationFacade.deleteComponentInstanceFromTopologyTemplate(service, componentInstanceId))
1497             .thenReturn(result2);
1498         when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
1499             .thenReturn(cont);
1500         when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
1501
1502         result = componentInstanceBusinessLogic
1503             .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
1504                 componentInstanceIdList, USER_ID);
1505         assertNotNull(result);
1506
1507         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1508         service.setLifecycleState(oldLifeCycleState);
1509         assertEquals(deleteErrorMap, result);
1510     }
1511
1512     @Test
1513     void testDissociateRIFromRIFailDissociate() {
1514
1515         List<RequirementCapabilityRelDef> result;
1516         RequirementCapabilityRelDef ref = new RequirementCapabilityRelDef();
1517         ref.setFromNode(FROM_INSTANCE_ID);
1518         ref.setToNode(TO_INSTANCE_ID);
1519         List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
1520         CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
1521         RelationshipInfo ri = new RelationshipInfo();
1522         ri.setRequirement(REQUIREMENT_NAME);
1523         relationship.setRelation(ri);
1524         relationships.add(relationship);
1525         ref.setRelationships(relationships);
1526         List<RequirementCapabilityRelDef> requirementDefList = new ArrayList<>();
1527         requirementDefList.add(ref);
1528         ComponentTypeEnum componentTypeEnum = service.getComponentType();
1529         String componentId = service.getUniqueId();
1530         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1531         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1532         service.setLastUpdaterUserId(USER_ID);
1533         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1534
1535         Either<Component, StorageOperationStatus> cont = Either.left(service);
1536         when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
1537             .thenReturn(cont);
1538         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1539             .thenReturn(StorageOperationStatus.OK);
1540         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1541             .thenReturn(StorageOperationStatus.OK);
1542         Either<RequirementCapabilityRelDef, StorageOperationStatus> resultEither;
1543         resultEither = Either.right(StorageOperationStatus.OK);
1544         when(componentsUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.OK, true))
1545             .thenReturn(ActionStatus.GENERAL_ERROR);
1546         when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
1547
1548         try {
1549             result = componentInstanceBusinessLogic
1550                 .batchDissociateRIFromRI(componentId, USER_ID, requirementDefList, componentTypeEnum);
1551             assertNotNull(result);
1552             assertEquals(new ArrayList<>(), result);
1553         } catch (ComponentException e) {
1554             assertEquals(e.getActionStatus().toString(), StorageOperationStatus.GENERAL_ERROR.toString());
1555         }
1556
1557         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1558         service.setLifecycleState(oldLifeCycleState);
1559
1560     }
1561
1562     @Test
1563     void testDissociateRIFromRISuccess() {
1564
1565         List<RequirementCapabilityRelDef> result;
1566         RequirementCapabilityRelDef ref = new RequirementCapabilityRelDef();
1567         List<RequirementCapabilityRelDef> requirementDefList = new ArrayList<>();
1568         requirementDefList.add(ref);
1569         ComponentTypeEnum componentTypeEnum = service.getComponentType();
1570         String componentId = service.getUniqueId();
1571         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1572         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1573         service.setLastUpdaterUserId(USER_ID);
1574         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1575
1576         Either<Component, StorageOperationStatus> cont = Either.left(service);
1577         when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
1578             .thenReturn(cont);
1579         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1580             .thenReturn(StorageOperationStatus.OK);
1581         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1582             .thenReturn(StorageOperationStatus.OK);
1583         Either<RequirementCapabilityRelDef, StorageOperationStatus> resultEither;
1584         resultEither = Either.left(ref);
1585         when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
1586
1587         result = componentInstanceBusinessLogic
1588             .batchDissociateRIFromRI(componentId, USER_ID, requirementDefList, componentTypeEnum);
1589         assertNotNull(result);
1590
1591         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1592         service.setLifecycleState(oldLifeCycleState);
1593
1594         assertEquals(requirementDefList, result);
1595     }
1596
1597     @Test
1598     void testGetComponentInstancePropertyByPolicyId_success() {
1599         Optional<ComponentInstanceProperty> propertyCandidate =
1600             getComponentInstanceProperty(PROP_NAME);
1601
1602         assertThat(propertyCandidate).isPresent();
1603         assertEquals(PROP_NAME, propertyCandidate.get().getName());
1604     }
1605
1606     @Test
1607     void testGetComponentInstancePropertyByPolicyId_failure() {
1608         Optional<ComponentInstanceProperty> propertyCandidate =
1609             getComponentInstanceProperty(NON_EXIST_NAME);
1610
1611         assertEquals(propertyCandidate, Optional.empty());
1612     }
1613
1614     private Optional<ComponentInstanceProperty> getComponentInstanceProperty(String propertyName) {
1615         ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
1616         componentInstanceProperty.setName(propertyName);
1617
1618         PolicyDefinition policyDefinition = getPolicyDefinition();
1619         componentInstanceProperty.setGetPolicyValues(policyDefinition.getGetPolicyValues());
1620
1621         service.setComponentInstancesProperties(
1622             Collections.singletonMap(COMPONENT_INSTANCE_ID, Collections.singletonList(componentInstanceProperty)));
1623
1624         return componentInstanceBusinessLogic.getComponentInstancePropertyByPolicyId(service, policyDefinition);
1625     }
1626
1627     private PolicyDefinition getPolicyDefinition() {
1628         PolicyDefinition policyDefinition = new PolicyDefinition();
1629         policyDefinition.setInstanceUniqueId(COMPONENT_INSTANCE_ID);
1630         policyDefinition.setName(PROP_NAME);
1631
1632         GetPolicyValueDataDefinition getPolicy = new GetPolicyValueDataDefinition();
1633         getPolicy.setPropertyName(PROP_NAME);
1634
1635         List<GetPolicyValueDataDefinition> getPolicies = new ArrayList<>();
1636         getPolicies.add(getPolicy);
1637         policyDefinition.setGetPolicyValues(getPolicies);
1638
1639         return policyDefinition;
1640     }
1641
1642     private ComponentInstance createComponetInstanceFromComponent(Component component) {
1643         ComponentInstance componentInst = new ComponentInstance();
1644         componentInst.setUniqueId(component.getUniqueId());
1645         componentInst.setComponentUid(component.getUniqueId() + "_test");
1646         componentInst.setPosX("10");
1647         componentInst.setPosY("10");
1648         componentInst.setCapabilities(component.getCapabilities());
1649         componentInst.setRequirements(component.getRequirements());
1650         componentInst.setArtifacts(component.getArtifacts());
1651         componentInst.setDeploymentArtifacts(component.getDeploymentArtifacts());
1652         return componentInst;
1653     }
1654
1655     // Prepare ComponentInstance & Resource objects used in createComponentInstance() tests
1656
1657     private Pair<ComponentInstance, Resource> prepareResourcesForCreateComponentInstanceTest() {
1658         ComponentInstance instanceToBeCreated = new ComponentInstance();
1659         instanceToBeCreated.setName(COMPONENT_INSTANCE_NAME);
1660         instanceToBeCreated.setUniqueId(COMPONENT_INSTANCE_ID);
1661         instanceToBeCreated.setComponentUid(ORIGIN_COMPONENT_ID);
1662         instanceToBeCreated.setOriginType(OriginTypeEnum.VF);
1663
1664         Resource originComponent = new Resource();
1665         originComponent.setLifecycleState(LifecycleStateEnum.CERTIFIED);
1666         originComponent.setResourceType(ResourceTypeEnum.VF);
1667         originComponent.setVersion(ORIGIN_COMPONENT_VERSION);
1668         originComponent.setIcon(ICON_NAME);
1669
1670         return Pair.of(instanceToBeCreated, originComponent);
1671     }
1672     // Common part for testing component instance name validation
1673
1674     private void testCreateComponentInstanceNameValidationFailure(String ciName) {
1675         ComponentInstance ci = new ComponentInstance();
1676         ci.setName(ciName);
1677
1678         // Stub for getting component
1679         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
1680             .thenReturn(Either.left(service));
1681
1682         // Expecting ByActionStatusComponentException
1683         ByActionStatusComponentException e = assertThrows(ByActionStatusComponentException.class, () -> {
1684             componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
1685         });
1686         assertEquals(ActionStatus.INVALID_COMPONENT_NAME, e.getActionStatus());
1687     }
1688     @TestFactory
1689     Iterable<DynamicTest> testCreateComponentInstanceNameValidationFailureFactory() {
1690         String longName = String.join("", Collections.nCopies(ValidationUtils.COMPONENT_NAME_MAX_LENGTH + 1, "x"));
1691         String invalidName = "componentInstance#name";
1692         return Arrays.asList(
1693             dynamicTest("instance name is empty", () ->
1694                 testCreateComponentInstanceNameValidationFailure("")),
1695             dynamicTest("instance name is too long", () ->
1696                 testCreateComponentInstanceNameValidationFailure(longName)),
1697             dynamicTest("instance name includes invalid character", () ->
1698                 testCreateComponentInstanceNameValidationFailure(invalidName))
1699         );
1700     }
1701
1702     @Test
1703     void testCreateComponentInstanceFailToGetComponent() {
1704         ComponentInstance ci = prepareResourcesForCreateComponentInstanceTest().getLeft();
1705
1706         // Stub for getting component
1707         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
1708             .thenReturn(Either.left(service));
1709         when(toscaOperationFacade.getToscaFullElement(ORIGIN_COMPONENT_ID))
1710             .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
1711         when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND, ComponentTypeEnum.RESOURCE))
1712             .thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
1713
1714         ByActionStatusComponentException e = assertThrows(ByActionStatusComponentException.class, () -> {
1715             componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
1716         });
1717         assertThat(e.getActionStatus()).isEqualTo(ActionStatus.RESOURCE_NOT_FOUND);
1718     }
1719
1720     @Test
1721     void testCreateComponentInstanceFailureInvalidState() {
1722         Pair<ComponentInstance, Resource> p = prepareResourcesForCreateComponentInstanceTest();
1723         ComponentInstance ci = p.getLeft();
1724         Resource originComponent = p.getRight();
1725         originComponent.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1726
1727         // Stub for getting component
1728         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
1729             .thenReturn(Either.left(service));
1730         when(toscaOperationFacade.getToscaFullElement(ORIGIN_COMPONENT_ID))
1731             .thenReturn(Either.left(originComponent));
1732
1733         ByActionStatusComponentException e = assertThrows(ByActionStatusComponentException.class, () -> {
1734             componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
1735         });
1736         assertThat(e.getActionStatus()).isEqualTo(ActionStatus.CONTAINER_CANNOT_CONTAIN_COMPONENT_IN_STATE);
1737     }
1738
1739     @Test
1740     void testCreateComponentInstanceFailureArchived() {
1741         Pair<ComponentInstance, Resource> p = prepareResourcesForCreateComponentInstanceTest();
1742         ComponentInstance ci = p.getLeft();
1743         Resource originComponent = p.getRight();
1744         originComponent.setArchived(Boolean.TRUE);
1745
1746         // Stub for getting component
1747         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
1748             .thenReturn(Either.left(service));
1749         when(toscaOperationFacade.getToscaFullElement(ORIGIN_COMPONENT_ID))
1750             .thenReturn(Either.left(originComponent));
1751
1752         ByActionStatusComponentException e = assertThrows(ByActionStatusComponentException.class, () -> {
1753             componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
1754         });
1755         assertThat(e.getActionStatus()).isEqualTo(ActionStatus.COMPONENT_IS_ARCHIVED);
1756     }
1757
1758     @Test
1759     void testCreateComponentInstanceFailureInvalidOriginType() {
1760         Pair<ComponentInstance, Resource> p = prepareResourcesForCreateComponentInstanceTest();
1761         ComponentInstance ci = p.getLeft();
1762         Resource originComponent = p.getRight();
1763         ci.setOriginType(OriginTypeEnum.VFC); // Set different type from origin
1764
1765         // Stub for getting component
1766         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
1767             .thenReturn(Either.left(service));
1768         when(toscaOperationFacade.getToscaFullElement(ORIGIN_COMPONENT_ID))
1769             .thenReturn(Either.left(originComponent));
1770
1771         final ByActionStatusComponentException e = assertThrows(ByActionStatusComponentException.class, () -> {
1772             componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
1773         });
1774         assertThat(e.getActionStatus()).isEqualTo(ActionStatus.INVALID_CONTENT);
1775     }
1776
1777     @Test
1778     void testCreateComponentInstanceFailureCannotContainInstance() {
1779         final Pair<ComponentInstance, Resource> p = prepareResourcesForCreateComponentInstanceTest();
1780         final ComponentInstance ci = p.getLeft();
1781         final Resource originComponent = p.getRight();
1782
1783         // Stub for getting component
1784         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
1785             .thenReturn(Either.left(service));
1786         when(toscaOperationFacade.getToscaFullElement(ORIGIN_COMPONENT_ID))
1787             .thenReturn(Either.left(originComponent));
1788         // Assume services cannot contain VF resource
1789         when(containerInstanceTypeData.isAllowedForServiceComponent(ResourceTypeEnum.VF, null))
1790             .thenReturn(false);
1791
1792         ByActionStatusComponentException actualException = assertThrows(ByActionStatusComponentException.class, () -> {
1793             componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
1794         });
1795         assertThat(actualException.getActionStatus()).isEqualTo(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE);
1796         verify(containerInstanceTypeData, times(1)).isAllowedForServiceComponent(ResourceTypeEnum.VF, null);
1797
1798         //given
1799         final Resource resource = createResource();
1800         resource.setResourceType(ResourceTypeEnum.VF);
1801         resource.setLastUpdaterUserId(USER_ID);
1802         //when
1803         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
1804             .thenReturn(Either.left(resource));
1805         when(toscaOperationFacade.getToscaFullElement(ORIGIN_COMPONENT_ID))
1806             .thenReturn(Either.left(originComponent));
1807         when(containerInstanceTypeData.isAllowedForResourceComponent(ResourceTypeEnum.VF, ResourceTypeEnum.VF))
1808             .thenReturn(false);
1809         actualException = assertThrows(ByActionStatusComponentException.class, () -> {
1810             componentInstanceBusinessLogic.createComponentInstance(RESOURCE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
1811         });
1812         //then
1813         assertThat(actualException.getActionStatus()).isEqualTo(ActionStatus.CONTAINER_CANNOT_CONTAIN_INSTANCE);
1814     }
1815
1816     @Test
1817     void testCreateComponentInstanceFailureAddToGraph() {
1818         final Pair<ComponentInstance, Resource> p = prepareResourcesForCreateComponentInstanceTest();
1819         final ComponentInstance ci = p.getLeft();
1820         final Resource originComponent = p.getRight();
1821
1822         // TODO Refactor createComponentInstance() method and reduce these mocks
1823         //      not to target the internal details too much
1824         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
1825             .thenReturn(Either.left(service));
1826         when(toscaOperationFacade.getToscaFullElement(ORIGIN_COMPONENT_ID))
1827             .thenReturn(Either.left(originComponent));
1828         when(containerInstanceTypeData.isAllowedForServiceComponent(ResourceTypeEnum.VF, null))
1829             .thenReturn(true);
1830         Mockito.doNothing().when(compositionBusinessLogic).validateAndSetDefaultCoordinates(ci);
1831         when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service))
1832             .thenReturn(StorageOperationStatus.OK);
1833         when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(service, originComponent, ci, false, user))
1834             .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
1835         when(componentsUtils.convertFromStorageResponseForResourceInstance(StorageOperationStatus.BAD_REQUEST, true))
1836             .thenReturn(ActionStatus.INVALID_CONTENT);
1837         when(componentsUtils.getResponseFormatForResourceInstance(ActionStatus.INVALID_CONTENT, "", null))
1838             .thenReturn(new ResponseFormat());
1839         when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
1840         when(graphLockOperation.unlockComponent(COMPONENT_ID, NodeTypeEnum.Service))
1841             .thenReturn(StorageOperationStatus.OK);
1842
1843         assertThrows(ByResponseFormatComponentException.class, () -> {
1844             componentInstanceBusinessLogic.createComponentInstance(ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, ci);
1845         });
1846         verify(containerInstanceTypeData, times(1))
1847             .isAllowedForServiceComponent(ResourceTypeEnum.VF, null);
1848         verify(compositionBusinessLogic, times(1)).validateAndSetDefaultCoordinates(ci);
1849         verify(toscaOperationFacade, times(1))
1850             .addComponentInstanceToTopologyTemplate(service, originComponent, ci, false, user);
1851         verify(graphLockOperation, times(1)).unlockComponent(COMPONENT_ID, NodeTypeEnum.Service);
1852     }
1853
1854     @Test
1855     void testCreateComponentInstanceSuccess() {
1856         final Pair<ComponentInstance, Resource> p = prepareResourcesForCreateComponentInstanceTest();
1857         final ComponentInstance instanceToBeCreated = p.getLeft();
1858         final Resource originComponent = p.getRight();
1859
1860         final Service updatedService = new Service();
1861         updatedService.setComponentInstances(Collections.singletonList(instanceToBeCreated));
1862         updatedService.setUniqueId(service.getUniqueId());
1863
1864         // TODO Refactor createComponentInstance() method and reduce these mocks
1865         //      not to target the internal details too much
1866         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
1867             .thenReturn(Either.left(service));
1868         when(toscaOperationFacade.getToscaFullElement(ORIGIN_COMPONENT_ID))
1869             .thenReturn(Either.left(originComponent));
1870         when(containerInstanceTypeData.isAllowedForServiceComponent(ResourceTypeEnum.VF, null))
1871             .thenReturn(true);
1872         Mockito.doNothing().when(compositionBusinessLogic).validateAndSetDefaultCoordinates(instanceToBeCreated);
1873         when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service))
1874             .thenReturn(StorageOperationStatus.OK);
1875         when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(service, originComponent, instanceToBeCreated, false, user))
1876             .thenReturn(Either.left(new ImmutablePair<>(updatedService, COMPONENT_INSTANCE_ID)));
1877         when(artifactsBusinessLogic.getArtifacts(
1878             ORIGIN_COMPONENT_ID, NodeTypeEnum.Resource, ArtifactGroupTypeEnum.DEPLOYMENT, null))
1879             .thenReturn(Either.left(new HashMap<>()));
1880         when(toscaOperationFacade
1881             .addInformationalArtifactsToInstance(service.getUniqueId(), instanceToBeCreated, originComponent.getArtifacts()))
1882             .thenReturn(StorageOperationStatus.OK);
1883         when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
1884         when(graphLockOperation.unlockComponent(COMPONENT_ID, NodeTypeEnum.Service))
1885             .thenReturn(StorageOperationStatus.OK);
1886
1887         final ComponentInstance result = componentInstanceBusinessLogic.createComponentInstance(
1888             ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, instanceToBeCreated);
1889         assertThat(result).isEqualTo(instanceToBeCreated);
1890         assertThat(instanceToBeCreated.getComponentVersion()).isEqualTo(originComponent.getVersion());
1891         assertThat(instanceToBeCreated.getIcon()).isEqualTo(originComponent.getIcon());
1892         verify(containerInstanceTypeData, times(1))
1893             .isAllowedForServiceComponent(ResourceTypeEnum.VF, null);
1894         verify(compositionBusinessLogic, times(1)).validateAndSetDefaultCoordinates(instanceToBeCreated);
1895         verify(toscaOperationFacade, times(1))
1896             .addComponentInstanceToTopologyTemplate(service, originComponent, instanceToBeCreated, false, user);
1897         // Check graph db change was committed
1898         verify(janusGraphDao, times(1)).commit();
1899     }
1900     
1901     @Test
1902     void testCreateComponentInstanceServiceSubstitutionSuccess() {
1903         ComponentInstance instanceToBeCreated = createServiceSubstitutionComponentInstance();
1904         Service originService = createServiceSubstitutionOriginService();
1905         Component serviceBaseComponent = createServiceSubstitutionServiceDerivedFromComponent();
1906
1907         Service updatedService = new Service();
1908         updatedService.setComponentInstances(Collections.singletonList(instanceToBeCreated));
1909         updatedService.setUniqueId(service.getUniqueId());
1910         
1911         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
1912             .thenReturn(Either.left(service));
1913         when(toscaOperationFacade.getToscaFullElement(ORIGIN_COMPONENT_ID))
1914             .thenReturn(Either.left(originService));
1915         when(toscaOperationFacade.getLatestByToscaResourceName(eq(originService.getDerivedFromGenericType()), isNull()))
1916             .thenReturn(Either.left(serviceBaseComponent));
1917         when(toscaOperationFacade.getToscaElement(eq(ORIGIN_COMPONENT_ID), any(ComponentParametersView.class)))
1918             .thenReturn(Either.left(originService));
1919         Mockito.doNothing().when(compositionBusinessLogic).validateAndSetDefaultCoordinates(instanceToBeCreated);
1920         when(graphLockOperation.lockComponent(COMPONENT_ID, NodeTypeEnum.Service))
1921             .thenReturn(StorageOperationStatus.OK);
1922         when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(service, serviceBaseComponent, instanceToBeCreated, false, user))
1923             .thenReturn(Either.left(new ImmutablePair<>(updatedService, COMPONENT_INSTANCE_ID)));
1924         when(artifactsBusinessLogic.getArtifacts(
1925                 "baseComponentId", NodeTypeEnum.Resource, ArtifactGroupTypeEnum.DEPLOYMENT, null))
1926             .thenReturn(Either.left(new HashMap<>()));
1927         when(toscaOperationFacade
1928             .addInformationalArtifactsToInstance(service.getUniqueId(), instanceToBeCreated, originService.getArtifacts()))
1929             .thenReturn(StorageOperationStatus.OK);
1930         when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
1931         when(graphLockOperation.unlockComponent(COMPONENT_ID, NodeTypeEnum.Service))
1932             .thenReturn(StorageOperationStatus.OK);
1933
1934         ComponentInstance result = componentInstanceBusinessLogic.createComponentInstance(
1935             ComponentTypeEnum.SERVICE_PARAM_NAME, COMPONENT_ID, USER_ID, instanceToBeCreated);
1936         assertThat(result).isEqualTo(instanceToBeCreated);
1937         assertThat(instanceToBeCreated.getComponentVersion()).isEqualTo(originService.getVersion());
1938         assertThat(instanceToBeCreated.getIcon()).isEqualTo(originService.getIcon());
1939         verify(compositionBusinessLogic, times(1)).validateAndSetDefaultCoordinates(instanceToBeCreated);
1940         verify(toscaOperationFacade, times(1))
1941             .addComponentInstanceToTopologyTemplate(service, serviceBaseComponent, instanceToBeCreated, false, user);
1942         // Check graph db change was committed
1943         verify(janusGraphDao, times(1)).commit();
1944     }
1945
1946     @Test
1947     void testGetComponentInstanceAttributesById_success() {
1948         final ComponentInstanceAttribute componentInstanceAttribute = new ComponentInstanceAttribute();
1949         componentInstanceAttribute.setComponentInstanceId(TO_INSTANCE_ID);
1950
1951         final HashMap<String, List<ComponentInstanceAttribute>> map = new HashMap<>();
1952         map.put(TO_INSTANCE_ID, Arrays.asList(componentInstanceAttribute));
1953         resource.setComponentInstancesAttributes(map);
1954
1955         final Either<Component, StorageOperationStatus> leftServiceOp = Either.left(resource);
1956         doReturn(leftServiceOp).when(toscaOperationFacade).getToscaElement(COMPONENT_ID);
1957
1958         final List<ComponentInstanceAttribute> result = componentInstanceBusinessLogic
1959             .getComponentInstanceAttributesById(RESOURCE_PARAM_NAME, COMPONENT_ID, TO_INSTANCE_ID, USER_ID);
1960         assertThat(result).isNotNull().isNotEmpty();
1961         verify(toscaOperationFacade, times(1)).getToscaElement(COMPONENT_ID);
1962     }
1963
1964     @Test
1965     void testGetComponentInstanceAttributesById_fail_missing_ComponentInstancesAttributes() {
1966         final Either<Component, StorageOperationStatus> leftServiceOp = Either.left(resource);
1967         doReturn(leftServiceOp).when(toscaOperationFacade).getToscaElement(COMPONENT_ID);
1968
1969         final List<ComponentInstanceAttribute> result = componentInstanceBusinessLogic
1970             .getComponentInstanceAttributesById(RESOURCE_PARAM_NAME, COMPONENT_ID, TO_INSTANCE_ID, USER_ID);
1971         assertThat(result).isNotNull().isEmpty();
1972         verify(toscaOperationFacade, times(1)).getToscaElement(COMPONENT_ID);
1973     }
1974
1975     @Test
1976     void testGetComponentInstanceAttributesById_fail_getToscaElement() {
1977         final ComponentInstanceAttribute componentInstanceAttribute = new ComponentInstanceAttribute();
1978         componentInstanceAttribute.setComponentInstanceId(TO_INSTANCE_ID);
1979
1980         final HashMap<String, List<ComponentInstanceAttribute>> map = new HashMap<>();
1981         map.put(TO_INSTANCE_ID, Arrays.asList(componentInstanceAttribute));
1982         resource.setComponentInstancesAttributes(map);
1983
1984         final Either<Object, StorageOperationStatus> right = Either.right(StorageOperationStatus.BAD_REQUEST);
1985         doReturn(right).when(toscaOperationFacade).getToscaElement(COMPONENT_ID);
1986         doReturn(ActionStatus.BAD_REQUEST_MISSING_RESOURCE).when(componentsUtils).convertFromStorageResponse(StorageOperationStatus.BAD_REQUEST);
1987
1988         assertThrows(ByActionStatusComponentException.class, () -> {
1989             final List<ComponentInstanceAttribute> result = componentInstanceBusinessLogic
1990                 .getComponentInstanceAttributesById(RESOURCE_PARAM_NAME, COMPONENT_ID, TO_INSTANCE_ID, USER_ID);
1991
1992         });
1993
1994     }
1995
1996     @Test
1997     void testGetComponentInstanceAttributesById_fail_getResourceInstanceById() {
1998         final ComponentInstanceAttribute componentInstanceAttribute = new ComponentInstanceAttribute();
1999         componentInstanceAttribute.setComponentInstanceId(TO_INSTANCE_ID);
2000
2001         final HashMap<String, List<ComponentInstanceAttribute>> map = new HashMap<>();
2002         map.put(TO_INSTANCE_ID, Arrays.asList(componentInstanceAttribute));
2003         resource.setComponentInstancesAttributes(map);
2004
2005         final Either<Component, StorageOperationStatus> leftServiceOp = Either.left(resource);
2006         doReturn(leftServiceOp).when(toscaOperationFacade).getToscaElement(COMPONENT_ID);
2007         doReturn(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE).when(componentsUtils).convertFromStorageResponse(StorageOperationStatus.PARENT_RESOURCE_NOT_FOUND);
2008
2009         assertThrows(ByActionStatusComponentException.class, () -> {
2010             final List<ComponentInstanceAttribute> result = componentInstanceBusinessLogic
2011                 .getComponentInstanceAttributesById(RESOURCE_PARAM_NAME, COMPONENT_ID, "", USER_ID);
2012
2013         });
2014
2015     }
2016
2017     @Test
2018     void updateInstanceCapabilitySuccessTest() {
2019         var containerComponentId = "containerComponentId";
2020         var componentInstanceUniqueId = "componentInstanceUniqueId";
2021         var capabilityDefinition = new CapabilityDefinition();
2022         capabilityDefinition.setUniqueId("uniqueId");
2023
2024         final Component component = new Service();
2025         component.setUniqueId(containerComponentId);
2026         component.setLastUpdaterUserId(USER_ID);
2027         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
2028
2029         var componentInstance = new ComponentInstance();
2030         componentInstance.setUniqueId(componentInstanceUniqueId);
2031         component.setComponentInstances(Collections.singletonList(componentInstance));
2032
2033         when(toscaOperationFacade.getToscaFullElement(containerComponentId))
2034             .thenReturn(Either.left(component));
2035         when(toscaOperationFacade.updateComponentInstanceCapability(containerComponentId, componentInstanceUniqueId, capabilityDefinition))
2036             .thenReturn(capabilityDefinition);
2037         when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(component))
2038             .thenReturn(Either.left(component));
2039         when(graphLockOperation.lockComponent(containerComponentId, NodeTypeEnum.Service))
2040             .thenReturn(StorageOperationStatus.OK);
2041
2042         final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
2043             .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, capabilityDefinition, USER_ID);
2044         assertTrue(resultEither.isLeft());
2045         final CapabilityDefinition actualCapabilityDefinition = resultEither.left().value();
2046         assertNotEquals(capabilityDefinition, actualCapabilityDefinition);
2047         assertEquals(capabilityDefinition.getUniqueId(), actualCapabilityDefinition.getUniqueId());
2048     }
2049
2050     @Test
2051     void updateInstanceCapabilityNoContainerComponentTypeTest() {
2052         var responseFormat = new ResponseFormat();
2053         when(componentsUtils.getResponseFormat(ActionStatus.NOT_ALLOWED)).thenReturn(responseFormat);
2054         final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
2055             .updateInstanceCapability(null, "containerComponentId", "componentInstanceUniqueId", new CapabilityDefinition(), USER_ID);
2056         assertTrue(resultEither.isRight(), "Either return should be right");
2057         final ResponseFormat actualResponseFormat = resultEither.right().value();
2058         assertEquals(responseFormat, actualResponseFormat);
2059     }
2060
2061     @Test
2062     void updateInstanceCapabilityContainerComponentNotFoundTest() {
2063         var containerComponentId = "containerComponentId";
2064         when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.right(null));
2065         var responseFormat = new ResponseFormat();
2066         when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_NOT_FOUND, containerComponentId)).thenReturn(responseFormat);
2067         final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
2068             .updateInstanceCapability(ComponentTypeEnum.SERVICE, "containerComponentId", "componentInstanceUniqueId", new CapabilityDefinition(), USER_ID);
2069         assertTrue(resultEither.isRight(), "Either return should be right");
2070         final ResponseFormat actualResponseFormat = resultEither.right().value();
2071         assertEquals(responseFormat, actualResponseFormat);
2072     }
2073
2074     @Test
2075     void updateInstanceCapabilityCannotWorkOnComponentTest() {
2076         var containerComponentId = "containerComponentId";
2077         var componentInstanceUniqueId = "componentInstanceUniqueId";
2078
2079         final Component component = new Service();
2080         component.setUniqueId(containerComponentId);
2081         component.setLastUpdaterUserId("anotherUse");
2082         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
2083
2084         var expectedResponseFormat = new ResponseFormat();
2085
2086         when(toscaOperationFacade.getToscaFullElement(containerComponentId))
2087             .thenReturn(Either.left(component));
2088         when(componentsUtils.getResponseFormat(ActionStatus.RESTRICTED_OPERATION))
2089             .thenReturn(expectedResponseFormat);
2090
2091         final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
2092             .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, new CapabilityDefinition(), USER_ID);
2093         assertTrue(resultEither.isRight(), "Either return should be right");
2094         final ResponseFormat actualResponseFormat = resultEither.right().value();
2095         assertEquals(expectedResponseFormat, actualResponseFormat);
2096     }
2097
2098     @Test
2099     void updateInstanceCapabilityResourceInstanceNotFoundTest() {
2100         var containerComponentId = "containerComponentId";
2101         var componentInstanceUniqueId = "componentInstanceUniqueId";
2102
2103         final Component component = new Service();
2104         component.setUniqueId(containerComponentId);
2105         component.setLastUpdaterUserId(USER_ID);
2106         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
2107
2108         var expectedResponseFormat = new ResponseFormat();
2109
2110         when(toscaOperationFacade.getToscaFullElement(containerComponentId))
2111             .thenReturn(Either.left(component));
2112         when(componentsUtils.getResponseFormat(ActionStatus.RESOURCE_INSTANCE_NOT_FOUND_ON_SERVICE, componentInstanceUniqueId, containerComponentId))
2113             .thenReturn(expectedResponseFormat);
2114
2115         final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
2116             .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, new CapabilityDefinition(), USER_ID);
2117         assertTrue(resultEither.isRight(), "Either return should be right");
2118         final ResponseFormat actualResponseFormat = resultEither.right().value();
2119         assertEquals(expectedResponseFormat, actualResponseFormat);
2120     }
2121
2122     @Test
2123     void updateInstanceCapabilityUpdateMetadataFailTest() {
2124         var containerComponentId = "containerComponentId";
2125         var componentInstanceUniqueId = "componentInstanceUniqueId";
2126         var capabilityDefinition = new CapabilityDefinition();
2127         capabilityDefinition.setUniqueId("uniqueId");
2128
2129         final Component component = new Service();
2130         component.setUniqueId(containerComponentId);
2131         component.setLastUpdaterUserId(USER_ID);
2132         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
2133
2134         var componentInstance = new ComponentInstance();
2135         componentInstance.setUniqueId(componentInstanceUniqueId);
2136         component.setComponentInstances(Collections.singletonList(componentInstance));
2137
2138         var expectedResponseFormat = new ResponseFormat();
2139
2140         when(toscaOperationFacade.getToscaFullElement(containerComponentId))
2141             .thenReturn(Either.left(component));
2142         when(graphLockOperation.lockComponent(containerComponentId, NodeTypeEnum.Service))
2143             .thenReturn(StorageOperationStatus.OK);
2144         when(toscaOperationFacade.updateComponentInstanceCapability(containerComponentId, componentInstanceUniqueId, capabilityDefinition))
2145             .thenReturn(capabilityDefinition);
2146         when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(component))
2147             .thenReturn(Either.right(StorageOperationStatus.GENERAL_ERROR));
2148         when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.GENERAL_ERROR, ComponentTypeEnum.SERVICE))
2149             .thenReturn(ActionStatus.GENERAL_ERROR);
2150         when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR))
2151             .thenReturn(expectedResponseFormat);
2152
2153         final Either<CapabilityDefinition, ResponseFormat> resultEither = componentInstanceBusinessLogic
2154             .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, capabilityDefinition, USER_ID);
2155         assertTrue(resultEither.isRight(), "Either return should be right");
2156         final ResponseFormat actualResponseFormat = resultEither.right().value();
2157         assertEquals(expectedResponseFormat, actualResponseFormat);
2158     }
2159
2160     @Test
2161     void updateInstanceCapabilityBusinessExceptionHandlingTest() {
2162         var containerComponentId = "containerComponentId";
2163         var componentInstanceUniqueId = "componentInstanceUniqueId";
2164         var capabilityDefinition = new CapabilityDefinition();
2165         capabilityDefinition.setUniqueId("uniqueId");
2166
2167         final Component component = new Service();
2168         component.setUniqueId(containerComponentId);
2169         component.setLastUpdaterUserId(USER_ID);
2170         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
2171
2172         var componentInstance = new ComponentInstance();
2173         componentInstance.setUniqueId(componentInstanceUniqueId);
2174         component.setComponentInstances(Collections.singletonList(componentInstance));
2175
2176
2177         when(toscaOperationFacade.getToscaFullElement(containerComponentId))
2178             .thenReturn(Either.left(component));
2179         when(graphLockOperation.lockComponent(containerComponentId, NodeTypeEnum.Service))
2180             .thenReturn(StorageOperationStatus.OK);
2181         when(toscaOperationFacade.updateComponentInstanceCapability(containerComponentId, componentInstanceUniqueId, capabilityDefinition))
2182             .thenThrow(new OperationException(ActionStatus.GENERAL_ERROR));
2183
2184         final BusinessException businessException = assertThrows(BusinessException.class, () -> {
2185             componentInstanceBusinessLogic
2186                 .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, capabilityDefinition, USER_ID);
2187         });
2188         assertTrue(businessException instanceof OperationException);
2189         assertEquals(ActionStatus.GENERAL_ERROR, ((OperationException) businessException).getActionStatus());
2190     }
2191
2192     @Test
2193     void updateInstanceCapabilityUnknownExceptionHandlingTest() {
2194         var containerComponentId = "containerComponentId";
2195         var componentInstanceUniqueId = "componentInstanceUniqueId";
2196         var capabilityDefinition = new CapabilityDefinition();
2197         capabilityDefinition.setUniqueId("uniqueId");
2198
2199         final Component component = new Service();
2200         component.setUniqueId(containerComponentId);
2201         component.setLastUpdaterUserId(USER_ID);
2202         component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
2203
2204         var componentInstance = new ComponentInstance();
2205         componentInstance.setUniqueId(componentInstanceUniqueId);
2206         component.setComponentInstances(Collections.singletonList(componentInstance));
2207
2208         var expectedResponseFormat = new ResponseFormat();
2209
2210         when(toscaOperationFacade.getToscaFullElement(containerComponentId))
2211             .thenReturn(Either.left(component));
2212         when(graphLockOperation.lockComponent(containerComponentId, NodeTypeEnum.Service))
2213             .thenReturn(StorageOperationStatus.OK);
2214         when(toscaOperationFacade.updateComponentInstanceCapability(containerComponentId, componentInstanceUniqueId, capabilityDefinition))
2215             .thenThrow(new RuntimeException());
2216         when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR))
2217             .thenReturn(expectedResponseFormat);
2218
2219         final Exception exception = assertThrows(BusinessException.class, () ->
2220             componentInstanceBusinessLogic
2221                 .updateInstanceCapability(ComponentTypeEnum.SERVICE, containerComponentId, componentInstanceUniqueId, capabilityDefinition, USER_ID));
2222         assertTrue(exception instanceof ByResponseFormatComponentException);
2223         final ByResponseFormatComponentException actualException = (ByResponseFormatComponentException) exception;
2224         assertEquals(expectedResponseFormat, actualException.getResponseFormat());
2225     }
2226
2227     private ComponentInstance createServiceSubstitutionComponentInstance() {
2228         final ComponentInstance instanceToBeCreated = new ComponentInstance();
2229         instanceToBeCreated.setName(COMPONENT_INSTANCE_NAME);
2230         instanceToBeCreated.setUniqueId(COMPONENT_INSTANCE_ID);
2231         instanceToBeCreated.setComponentUid(ORIGIN_COMPONENT_ID);
2232         instanceToBeCreated.setOriginType(OriginTypeEnum.ServiceSubstitution);
2233
2234         return instanceToBeCreated;
2235     }
2236     
2237     private Service createServiceSubstitutionOriginService() {
2238         final Service originComponent = new Service();
2239         originComponent.setLifecycleState(LifecycleStateEnum.CERTIFIED);
2240         originComponent.setVersion(ORIGIN_COMPONENT_VERSION);
2241         originComponent.setIcon(ICON_NAME);
2242         originComponent.setDerivedFromGenericType("org.openecomp.resource.abstract.nodes.service");
2243         originComponent.setName("myService");
2244         return originComponent;
2245     }
2246     
2247     private Component createServiceSubstitutionServiceDerivedFromComponent() {
2248         final Resource component = new Resource();
2249         component.setLifecycleState(LifecycleStateEnum.CERTIFIED);
2250         component.setVersion(ORIGIN_COMPONENT_VERSION);
2251         component.setIcon(ICON_NAME);
2252         component.setToscaResourceName("org.openecomp.resource.abstract.nodes.service");
2253         component.setUniqueId("baseComponentId");
2254         return component;
2255     }
2256
2257 }
2258