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