Upgrade SDC from Titan to Janus Graph
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / merge / instance / ComponentInstanceRelationMergeTest.java
1 package org.openecomp.sdc.be.components.merge.instance;
2
3 import fj.data.Either;
4 import org.junit.Before;
5 import org.junit.Test;
6 import org.junit.runner.RunWith;
7 import org.mockito.ArgumentCaptor;
8 import org.mockito.Captor;
9 import org.mockito.Mock;
10 import org.mockito.Mockito;
11 import org.mockito.junit.MockitoJUnitRunner;
12 import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
13 import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
14 import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
15 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
16 import org.openecomp.sdc.be.dao.api.ActionStatus;
17 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
18 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
19 import org.openecomp.sdc.be.impl.ComponentsUtils;
20 import org.openecomp.sdc.be.model.*;
21 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
22 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
23 import org.openecomp.sdc.exception.ResponseFormat;
24
25 import java.util.*;
26 import java.util.stream.IntStream;
27
28 import static org.assertj.core.api.Assertions.assertThat;
29 import static org.assertj.core.api.Assertions.tuple;
30 import static org.junit.Assert.*;
31 import static org.mockito.Mockito.verify;
32 import static org.mockito.Mockito.when;
33
34 @RunWith(MockitoJUnitRunner.class)
35 public class ComponentInstanceRelationMergeTest {
36     private ComponentInstanceRelationMerge compInstanceRelationMerge;
37     @Mock
38     private DataForMergeHolder dataHolder;
39     private Component containerComponent;
40     private Component updatedContainerComponent;
41     private ComponentInstance currentResourceInstance;
42
43     private RequirementCapabilityRelDef requirementDef1;
44     private RequirementCapabilityRelDef requirementDef2;
45     private RequirementCapabilityRelDef capabilityDef1;
46     private RequirementCapabilityRelDef capabilityDef2;
47     private RequirementCapabilityRelDef capabilityDef3;
48     
49     @Mock
50     private ComponentsUtils componentsUtils;
51     
52     @Mock
53     private ToscaOperationFacade toscaOperationFacade;
54
55     @Mock
56     private User user;
57
58     @Mock
59     private ExceptionUtils exceptionUtils;
60     
61     @Captor
62     private ArgumentCaptor<ContainerRelationsMergeInfo> argumentCaptor;
63     
64     
65     @Before
66     public void startUp() {
67         MergeInstanceUtils mergeInstanceUtils = new MergeInstanceUtils(toscaOperationFacade, exceptionUtils);
68         compInstanceRelationMerge = new ComponentInstanceRelationMerge(componentsUtils, mergeInstanceUtils, toscaOperationFacade);
69         
70         containerComponent = new Service();
71         List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
72
73         requirementDef1 = createRequirementDef("SRV1.VF1.VFI_1", "SRV1.VF2.VFI_1", "SRV1.VF1.VFC_1.VFCI_1", "Requirement1");
74         resourceInstancesRelations.add(requirementDef1);
75         requirementDef2 = createRequirementDef("SRV1.VF1.VFI_1", "SRV1.VF3.VFI_1", "SRV1.VF1.VFC_2.VFCI_2", "Requirement2");
76         resourceInstancesRelations.add(requirementDef2);
77         
78         
79         capabilityDef1 = createCapabilityDef("SRV1.VF4.VFI_1", "SRV1.VF1.VFI_1", "SRV1.VF1.VFC_3.VFCI_3", "Capability3");
80         resourceInstancesRelations.add(capabilityDef1);
81         capabilityDef2 = createCapabilityDef("SRV1.VF5.VFI_1", "SRV1.VF1.VFI_1", "SRV1.VF1.VFC_4.VFCI_1", "Capability4");
82         resourceInstancesRelations.add(capabilityDef2);
83
84
85         capabilityDef3 = createCapabilityDef("SRV1.VF5.VFI_1", "SRV1.VF1.VFI_1", "grp1Id", "Capability5");
86         resourceInstancesRelations.add(capabilityDef3);
87
88         containerComponent.setComponentInstancesRelations(resourceInstancesRelations );
89         
90         currentResourceInstance = new ComponentInstance();
91         currentResourceInstance.setUniqueId("SRV1.VF1.VFI_1");
92         currentResourceInstance.setComponentUid("SRV1.VF1");
93         currentResourceInstance.setIsProxy(false);
94         
95         updatedContainerComponent = new Service();
96         updatedContainerComponent.setUniqueId("123123123123123123");
97     }
98     
99     @Test
100     public void testSaveDataBeforeMerge() {
101         Resource vf = new ResourceBuilder()
102                 .setResourceType(ResourceTypeEnum.VF)
103                 .setComponentType(ComponentTypeEnum.RESOURCE)
104                 .addComponentInstance(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true))
105                 .addComponentInstance(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true))
106                 .addComponentInstance(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false))
107                 .addComponentInstance(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true))
108                 .addGroup(createGroup("grp1", "grp1Id"))
109                 .build();
110
111         compInstanceRelationMerge.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, vf);
112         
113         verify(dataHolder).setVfRelationsInfo(argumentCaptor.capture());
114         ContainerRelationsMergeInfo relationsMergeInfo = argumentCaptor.getValue();
115         List<RelationMergeInfo> fromRelationsMergeInfo = relationsMergeInfo.getFromRelationsInfo();
116         List<RelationMergeInfo> toRelationsMergeInfo = relationsMergeInfo.getToRelationsInfo();
117         
118         assertNotNull("Expected not null list of relations merge info", fromRelationsMergeInfo);
119         assertNotNull("Expected not null list of relations merge info", toRelationsMergeInfo);
120         
121         assertEquals("Expected 2 elements", 2, fromRelationsMergeInfo.size());
122         assertEquals("Expected 2 elements", 2, toRelationsMergeInfo.size());
123     }
124     
125     @Test
126     public void testSaveDataBeforeMerge_RelationsNull() {
127         Resource vf = new Resource();
128
129         List<ComponentInstance> vfcInstances = new ArrayList<>();
130         vfcInstances.add(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true));
131         vfcInstances.add(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true));
132         vfcInstances.add(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false));
133         vfcInstances.add(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true));
134         vf.setComponentInstances(vfcInstances);
135         vf.setComponentType(ComponentTypeEnum.RESOURCE);
136         vf.setResourceType(ResourceTypeEnum.VF);
137         
138         containerComponent.setComponentInstancesRelations(null);
139         compInstanceRelationMerge.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, vf);
140         
141         verify(dataHolder, Mockito.never()).setVfRelationsInfo(Mockito.any());
142     }
143     
144     @Test
145     public void testSaveDataBeforeMerge_RelationsEmptyList() {
146         Resource vf = new Resource();
147
148         List<ComponentInstance> vfcInstances = new ArrayList<>();
149         vfcInstances.add(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true));
150         vfcInstances.add(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true));
151         vfcInstances.add(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false));
152         vfcInstances.add(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true));
153         vf.setComponentInstances(vfcInstances);
154         vf.setComponentType(ComponentTypeEnum.RESOURCE);
155         vf.setResourceType(ResourceTypeEnum.VF);
156         
157         containerComponent.setComponentInstancesRelations(Collections.emptyList());
158         compInstanceRelationMerge.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, vf);
159         
160         verify(dataHolder, Mockito.never()).setVfRelationsInfo(Mockito.any());
161     }
162     
163     @Test
164     public void testMergeDataAfterCreate_NoSavedData() {
165         when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(null);
166         compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
167         List<RequirementCapabilityRelDef> relations = updatedContainerComponent.getComponentInstancesRelations();
168         assertNull("Expected no relations", relations);
169     }
170
171     @Test
172     public void testMergeDataAfterCreate() {
173         Resource newInstanceOriginVf = new ResourceBuilder()
174                 .setResourceType(ResourceTypeEnum.VF)
175                 .setComponentType(ComponentTypeEnum.RESOURCE)
176                 .addComponentInstance(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true))
177                 .addComponentInstance(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true))
178                 .addComponentInstance(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false))
179                 .addComponentInstance(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true))
180                 .addGroup(createGroup("grp1", "grp1Id"))
181                 .build();
182
183
184         List<ComponentInstance> componentInstances = new ArrayList<>();
185         componentInstances.add(createVfi("SRV1.VF1", "SRV1.VF1.VFI_2"));
186         updatedContainerComponent.setComponentInstances(componentInstances);
187
188         List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
189         updatedContainerComponent.setComponentInstancesRelations(resourceInstancesRelations);
190
191         List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
192         List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
193         
194         RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
195         fromRelationsMergeInfo.add(relationMergeInfo1);
196         RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
197         toRelationsMergeInfo.add(relationMergeInfo2);
198
199         RelationMergeInfo relationMergeInfo3 = new RelationMergeInfo("CapabilityType5", "capabilityE", "grp1", capabilityDef3);
200         toRelationsMergeInfo.add(relationMergeInfo3);
201         
202         ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
203
204         when(toscaOperationFacade.getToscaElement("SRV1.VF1")).thenReturn(Either.left(newInstanceOriginVf));
205         when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
206         when(toscaOperationFacade.associateResourceInstances(Mockito.anyString(), Mockito.anyList())).thenReturn(StorageOperationStatus.OK);
207         Either<Component, ResponseFormat> mergeResult = compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
208         assertTrue(mergeResult.isLeft());
209         List<RequirementCapabilityRelDef> relations = updatedContainerComponent.getComponentInstancesRelations();
210         assertThat(relations)
211                 .containsExactlyInAnyOrder(requirementDef1, capabilityDef2, capabilityDef3)
212                 .extracting(relation -> relation.resolveSingleRelationship().getRelation().getCapabilityOwnerId(),
213                             relation -> relation.resolveSingleRelationship().getRelation().getRequirementOwnerId())
214                 .containsExactlyInAnyOrder(tuple("SRV1.VF1.VFC_4.VFCI_1", null),
215                                            tuple("grp1Id", null),
216                                            tuple(null, "SRV1.VF1.VFC_1.VFCI_1"));
217     }
218     
219     
220     @Test
221     public void testMergeDataAfterCreate_FailedToAssociateResourceInstances() {
222         Resource vf = new Resource();
223
224         List<ComponentInstance> vfcInstances = new ArrayList<>();
225         vfcInstances.add(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true));
226         vfcInstances.add(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true));
227         vfcInstances.add(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false));
228         vfcInstances.add(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true));
229         vf.setComponentInstances(vfcInstances);
230         vf.setComponentType(ComponentTypeEnum.RESOURCE);
231         vf.setResourceType(ResourceTypeEnum.VF);
232         
233         Either<Component, StorageOperationStatus> eitherVF = Either.left(vf);
234         when(toscaOperationFacade.getToscaElement("SRV1.VF1")).thenReturn(eitherVF);
235         
236         
237         List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
238         List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
239         
240         RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
241         fromRelationsMergeInfo.add(relationMergeInfo1);
242         RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
243         toRelationsMergeInfo.add(relationMergeInfo2);
244         
245         ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
246         
247         when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
248         
249         List<ComponentInstance> componentInstances = new ArrayList<>();
250         componentInstances.add(createVfi("SRV1.VF1", "SRV1.VF1.VFI_2"));
251         componentInstances.add(createVfi("SRV1.VF2", "SRV1.VF2.VFI_1"));
252         componentInstances.add(createVfi("SRV1.VF3", "SRV1.VF3.VFI_1"));
253         componentInstances.add(createVfi("SRV1.VF4", "SRV1.VF4.VFI_1"));
254         componentInstances.add(createVfi("SRV1.VF5", "SRV1.VF5.VFI_1"));
255         updatedContainerComponent.setComponentInstances(componentInstances);
256         
257         List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
258         updatedContainerComponent.setComponentInstancesRelations(resourceInstancesRelations);
259         
260         when(toscaOperationFacade.associateResourceInstances(Mockito.anyString(), Mockito.anyList())).thenReturn(StorageOperationStatus.GENERAL_ERROR);
261         when(componentsUtils.convertFromStorageResponse(Mockito.any())).thenReturn(ActionStatus.GENERAL_ERROR);
262         
263         ResponseFormat expectedRresponseFormat = new ResponseFormat();
264         when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, updatedContainerComponent.getUniqueId())).thenReturn(expectedRresponseFormat );
265
266         Either<Component, ResponseFormat> result = compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
267         assertTrue(result.isRight());
268         assertEquals(expectedRresponseFormat, result.right().value());
269     }
270     
271     @Test
272     public void testMergeDataAfterCreate_UpdatedContainerEmpty() {
273         List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
274         List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
275         
276         RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
277         fromRelationsMergeInfo.add(relationMergeInfo1);
278         RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
279         toRelationsMergeInfo.add(relationMergeInfo2);
280         
281         ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
282         
283         when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
284         
285         Either<Component, ResponseFormat> result = compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
286         assertTrue(result.isLeft());
287         assertEquals(updatedContainerComponent, result.left().value());
288     }
289     
290     @Test
291     public void testMergeDataAfterCreate_OwnerChanged() {
292         Resource vf = new Resource();
293
294         List<ComponentInstance> vfcInstances = new ArrayList<>();
295         vfcInstances.add(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_2", "SRV1.VF1.VFC_1", true));
296         vfcInstances.add(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true));
297         vfcInstances.add(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false));
298         vfcInstances.add(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_2", "SRV1.VF1.VFC_4", true));
299         vf.setComponentInstances(vfcInstances);
300         vf.setComponentType(ComponentTypeEnum.RESOURCE);
301         vf.setResourceType(ResourceTypeEnum.VF);
302         
303         Either<Component, StorageOperationStatus> eitherVF = Either.left(vf);
304         when(toscaOperationFacade.getToscaElement("SRV1.VF1")).thenReturn(eitherVF);
305         
306         
307         List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
308         List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
309         
310         RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
311         fromRelationsMergeInfo.add(relationMergeInfo1);
312         RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
313         toRelationsMergeInfo.add(relationMergeInfo2);
314         
315         ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
316         
317         when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
318         
319         List<ComponentInstance> componentInstances = new ArrayList<>();
320         componentInstances.add(createVfi("SRV1.VF1", "SRV1.VF1.VFI_2"));
321         componentInstances.add(createVfi("SRV1.VF2", "SRV1.VF2.VFI_1"));
322         componentInstances.add(createVfi("SRV1.VF3", "SRV1.VF3.VFI_1"));
323         componentInstances.add(createVfi("SRV1.VF4", "SRV1.VF4.VFI_1"));
324         componentInstances.add(createVfi("SRV1.VF5", "SRV1.VF5.VFI_1"));
325         updatedContainerComponent.setComponentInstances(componentInstances);
326         
327         List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
328         updatedContainerComponent.setComponentInstancesRelations(resourceInstancesRelations);
329         
330         when(toscaOperationFacade.associateResourceInstances(Mockito.anyString(), Mockito.anyList())).thenReturn(StorageOperationStatus.OK);
331         
332         compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
333         
334         verify(dataHolder).getContainerRelationsMergeInfo();
335         verify(toscaOperationFacade).associateResourceInstances(Mockito.anyString(), Mockito.anyList());
336         
337         List<RequirementCapabilityRelDef> relations = updatedContainerComponent.getComponentInstancesRelations();
338         assertEquals("Expected 2 relations", 2, relations.size());
339         
340         
341         RequirementCapabilityRelDef capabilityRelDef = relations.get(0);
342         assertEquals("SRV1.VF1.VFC_4.VFCI_2", capabilityRelDef.resolveSingleRelationship().getRelation().getCapabilityOwnerId());
343         assertEquals("SRV1.VF5.VFI_1", capabilityRelDef.getFromNode());
344         assertEquals("SRV1.VF1.VFI_2", capabilityRelDef.getToNode());
345         
346         RequirementCapabilityRelDef requirementRelDef = relations.get(1);
347         assertEquals("SRV1.VF1.VFC_1.VFCI_2", requirementRelDef.resolveSingleRelationship().getRelation().getRequirementOwnerId());
348         assertEquals("SRV1.VF1.VFI_2", requirementRelDef.getFromNode());
349         assertEquals("SRV1.VF2.VFI_1", requirementRelDef.getToNode());
350     }
351
352
353     /**
354      * @param vfId
355      * @param vfiUniqueId
356      * @return
357      */
358     private ComponentInstance createVfi(String vfId, String vfiUniqueId) {
359         ComponentInstance vfi = new ComponentInstance();
360         vfi.setUniqueId(vfiUniqueId);
361         vfi.setComponentUid(vfId);
362         
363         Resource vf = new Resource();
364         vf.setUniqueId(vfId);
365         return vfi;
366     }
367     
368     private ComponentInstance createVfci(String name, String uniqueId, String componentUid, boolean foundVfc) {
369         ComponentInstance compInst = new ComponentInstance();
370         compInst.setName(name);
371         compInst.setUniqueId(uniqueId);
372         compInst.setComponentUid(componentUid);
373         
374         if(foundVfc) {
375             createVfc(componentUid);
376         }
377         else {
378             failLoadVfc(componentUid);
379         }
380         return compInst;
381     }
382
383     public GroupDefinition createGroup(String name, String id) {
384         return GroupDefinitionBuilder.create()
385                 .setUniqueId(id)
386                 .setInvariantName(name)
387                 .build();
388
389     }
390     
391     private void failLoadVfc(String uid) {
392         Either<Component, StorageOperationStatus> eitherVFC = Either.right(StorageOperationStatus.NOT_FOUND);
393         when(toscaOperationFacade.getToscaElement(uid)).thenReturn(eitherVFC);
394     }
395
396     private Component createVfc(String uid) {
397         Resource vfc = new Resource();
398         vfc.setComponentType(ComponentTypeEnum.RESOURCE);
399         vfc.setUniqueId(uid);
400         
401         Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
402         Map<String, List<RequirementDefinition>> requirements = new HashMap<>();;
403         IntStream.range(0, 5).forEach(i -> {
404             
405             List<CapabilityDefinition> capList = new LinkedList<>();
406             capList.add(null);
407             CapabilityDefinition capDef = new CapabilityDefinition();
408             capDef.setName("CapabilityName" + i);
409             capDef.setUniqueId("Capability" + i);
410             capDef.setType("CapabilityType" + i);
411             capList.add(capDef);
412             capabilities.put("Key" + i, capList);
413             
414             List<RequirementDefinition> reqList = new LinkedList<>();
415             reqList.add(null);
416             RequirementDefinition reqDef = new RequirementDefinition();
417             reqDef.setName("RequirementName" + i);
418             reqDef.setUniqueId("Requirement" + i);
419             reqDef.setCapability("CapabilityType" + i);
420             reqList.add(reqDef);
421             requirements.put("Key" + i, reqList);
422             
423         });
424         vfc.setCapabilities(capabilities );
425         vfc.setRequirements(requirements);
426         
427         Either<Component, StorageOperationStatus> eitherVFC = Either.left(vfc);
428         when(toscaOperationFacade.getToscaElement(uid)).thenReturn(eitherVFC);
429         
430         return vfc;
431     }
432     
433     private RequirementCapabilityRelDef createRequirementCapabilityDef(String fromNode, String toNode) {
434         RequirementCapabilityRelDef reqCapDef = new RequirementCapabilityRelDef();
435         
436         reqCapDef.setFromNode(fromNode);
437         reqCapDef.setToNode(toNode);
438         
439         List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
440         CapabilityRequirementRelationship capabilityRequirementRelationship = new CapabilityRequirementRelationship();
441         relationships.add(capabilityRequirementRelationship);
442         reqCapDef.setRelationships(relationships);
443         
444         return reqCapDef;
445     }
446
447     private RequirementCapabilityRelDef createRequirementDef(String fromNode, String toNode, String ownerId, String requirementUid) {
448         RequirementCapabilityRelDef reqCapDef = createRequirementCapabilityDef(fromNode, toNode);
449         CapabilityRequirementRelationship capabilityRequirementRelationship = reqCapDef.resolveSingleRelationship();
450         
451         RelationshipInfo relationshipInfo = new RelationshipInfo();
452         relationshipInfo.setRequirementOwnerId(ownerId);
453         relationshipInfo.setRequirementUid(requirementUid);
454         relationshipInfo.setRelationships(new RelationshipImpl());
455         capabilityRequirementRelationship.setRelation(relationshipInfo );
456         
457         
458         
459         return reqCapDef;
460     }
461     
462     private RequirementCapabilityRelDef createCapabilityDef(String fromNode, String toNode, String ownerId, String capabilityUid) {
463         RequirementCapabilityRelDef reqCapDef = createRequirementCapabilityDef(fromNode, toNode);
464         CapabilityRequirementRelationship capabilityRequirementRelationship = reqCapDef.resolveSingleRelationship();
465         
466         RelationshipInfo relationshipInfo = new RelationshipInfo();
467         relationshipInfo.setCapabilityOwnerId(ownerId);
468         relationshipInfo.setCapabilityUid(capabilityUid);
469         relationshipInfo.setRelationships(new RelationshipImpl());
470         capabilityRequirementRelationship.setRelation(relationshipInfo );
471         
472         return reqCapDef;
473     }
474
475     
476
477 }