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