2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.components.merge.instance;
23 import fj.data.Either;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.ArgumentCaptor;
28 import org.mockito.Captor;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.mockito.junit.MockitoJUnitRunner;
32 import org.openecomp.sdc.be.components.impl.utils.ExceptionUtils;
33 import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils;
34 import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder;
35 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
36 import org.openecomp.sdc.be.dao.api.ActionStatus;
37 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
38 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
39 import org.openecomp.sdc.be.impl.ComponentsUtils;
40 import org.openecomp.sdc.be.model.*;
41 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
42 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
43 import org.openecomp.sdc.exception.ResponseFormat;
46 import java.util.stream.IntStream;
48 import static org.assertj.core.api.Assertions.assertThat;
49 import static org.assertj.core.api.Assertions.tuple;
50 import static org.junit.Assert.*;
51 import static org.mockito.Mockito.verify;
52 import static org.mockito.Mockito.when;
54 @RunWith(MockitoJUnitRunner.class)
55 public class ComponentInstanceRelationMergeTest {
56 private ComponentInstanceRelationMerge compInstanceRelationMerge;
58 private DataForMergeHolder dataHolder;
59 private Component containerComponent;
60 private Component updatedContainerComponent;
61 private ComponentInstance currentResourceInstance;
63 private RequirementCapabilityRelDef requirementDef1;
64 private RequirementCapabilityRelDef requirementDef2;
65 private RequirementCapabilityRelDef capabilityDef1;
66 private RequirementCapabilityRelDef capabilityDef2;
67 private RequirementCapabilityRelDef capabilityDef3;
70 private ComponentsUtils componentsUtils;
73 private ToscaOperationFacade toscaOperationFacade;
79 private ExceptionUtils exceptionUtils;
82 private ArgumentCaptor<ContainerRelationsMergeInfo> argumentCaptor;
86 public void startUp() {
87 MergeInstanceUtils mergeInstanceUtils = new MergeInstanceUtils(toscaOperationFacade, exceptionUtils);
88 compInstanceRelationMerge = new ComponentInstanceRelationMerge(componentsUtils, mergeInstanceUtils, toscaOperationFacade);
90 containerComponent = new Service();
91 List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
93 requirementDef1 = createRequirementDef("SRV1.VF1.VFI_1", "SRV1.VF2.VFI_1", "SRV1.VF1.VFC_1.VFCI_1", "Requirement1");
94 resourceInstancesRelations.add(requirementDef1);
95 requirementDef2 = createRequirementDef("SRV1.VF1.VFI_1", "SRV1.VF3.VFI_1", "SRV1.VF1.VFC_2.VFCI_2", "Requirement2");
96 resourceInstancesRelations.add(requirementDef2);
99 capabilityDef1 = createCapabilityDef("SRV1.VF4.VFI_1", "SRV1.VF1.VFI_1", "SRV1.VF1.VFC_3.VFCI_3", "Capability3");
100 resourceInstancesRelations.add(capabilityDef1);
101 capabilityDef2 = createCapabilityDef("SRV1.VF5.VFI_1", "SRV1.VF1.VFI_1", "SRV1.VF1.VFC_4.VFCI_1", "Capability4");
102 resourceInstancesRelations.add(capabilityDef2);
105 capabilityDef3 = createCapabilityDef("SRV1.VF5.VFI_1", "SRV1.VF1.VFI_1", "grp1Id", "Capability5");
106 resourceInstancesRelations.add(capabilityDef3);
108 containerComponent.setComponentInstancesRelations(resourceInstancesRelations );
110 currentResourceInstance = new ComponentInstance();
111 currentResourceInstance.setUniqueId("SRV1.VF1.VFI_1");
112 currentResourceInstance.setComponentUid("SRV1.VF1");
113 currentResourceInstance.setIsProxy(false);
115 updatedContainerComponent = new Service();
116 updatedContainerComponent.setUniqueId("123123123123123123");
120 public void testSaveDataBeforeMerge() {
121 Resource vf = new ResourceBuilder()
122 .setResourceType(ResourceTypeEnum.VF)
123 .setComponentType(ComponentTypeEnum.RESOURCE)
124 .addComponentInstance(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true))
125 .addComponentInstance(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true))
126 .addComponentInstance(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false))
127 .addComponentInstance(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true))
128 .addGroup(createGroup("grp1", "grp1Id"))
131 compInstanceRelationMerge.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, vf);
133 verify(dataHolder).setVfRelationsInfo(argumentCaptor.capture());
134 ContainerRelationsMergeInfo relationsMergeInfo = argumentCaptor.getValue();
135 List<RelationMergeInfo> fromRelationsMergeInfo = relationsMergeInfo.getFromRelationsInfo();
136 List<RelationMergeInfo> toRelationsMergeInfo = relationsMergeInfo.getToRelationsInfo();
138 assertNotNull("Expected not null list of relations merge info", fromRelationsMergeInfo);
139 assertNotNull("Expected not null list of relations merge info", toRelationsMergeInfo);
141 assertEquals("Expected 2 elements", 2, fromRelationsMergeInfo.size());
142 assertEquals("Expected 2 elements", 2, toRelationsMergeInfo.size());
146 public void testSaveDataBeforeMerge_RelationsNull() {
147 Resource vf = new Resource();
149 List<ComponentInstance> vfcInstances = new ArrayList<>();
150 vfcInstances.add(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true));
151 vfcInstances.add(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true));
152 vfcInstances.add(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false));
153 vfcInstances.add(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true));
154 vf.setComponentInstances(vfcInstances);
155 vf.setComponentType(ComponentTypeEnum.RESOURCE);
156 vf.setResourceType(ResourceTypeEnum.VF);
158 containerComponent.setComponentInstancesRelations(null);
159 compInstanceRelationMerge.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, vf);
161 verify(dataHolder, Mockito.never()).setVfRelationsInfo(Mockito.any());
165 public void testSaveDataBeforeMerge_RelationsEmptyList() {
166 Resource vf = new Resource();
168 List<ComponentInstance> vfcInstances = new ArrayList<>();
169 vfcInstances.add(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true));
170 vfcInstances.add(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true));
171 vfcInstances.add(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false));
172 vfcInstances.add(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true));
173 vf.setComponentInstances(vfcInstances);
174 vf.setComponentType(ComponentTypeEnum.RESOURCE);
175 vf.setResourceType(ResourceTypeEnum.VF);
177 containerComponent.setComponentInstancesRelations(Collections.emptyList());
178 compInstanceRelationMerge.saveDataBeforeMerge(dataHolder, containerComponent, currentResourceInstance, vf);
180 verify(dataHolder, Mockito.never()).setVfRelationsInfo(Mockito.any());
184 public void testMergeDataAfterCreate_NoSavedData() {
185 when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(null);
186 compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
187 List<RequirementCapabilityRelDef> relations = updatedContainerComponent.getComponentInstancesRelations();
188 assertNull("Expected no relations", relations);
192 public void testMergeDataAfterCreate() {
193 Resource newInstanceOriginVf = new ResourceBuilder()
194 .setResourceType(ResourceTypeEnum.VF)
195 .setComponentType(ComponentTypeEnum.RESOURCE)
196 .addComponentInstance(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true))
197 .addComponentInstance(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true))
198 .addComponentInstance(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false))
199 .addComponentInstance(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true))
200 .addGroup(createGroup("grp1", "grp1Id"))
204 List<ComponentInstance> componentInstances = new ArrayList<>();
205 componentInstances.add(createVfi("SRV1.VF1", "SRV1.VF1.VFI_2"));
206 updatedContainerComponent.setComponentInstances(componentInstances);
208 List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
209 updatedContainerComponent.setComponentInstancesRelations(resourceInstancesRelations);
211 List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
212 List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
214 RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
215 fromRelationsMergeInfo.add(relationMergeInfo1);
216 RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
217 toRelationsMergeInfo.add(relationMergeInfo2);
219 RelationMergeInfo relationMergeInfo3 = new RelationMergeInfo("CapabilityType5", "capabilityE", "grp1", capabilityDef3);
220 toRelationsMergeInfo.add(relationMergeInfo3);
222 ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
224 when(toscaOperationFacade.getToscaElement("SRV1.VF1")).thenReturn(Either.left(newInstanceOriginVf));
225 when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
226 when(toscaOperationFacade.associateResourceInstances(Mockito.anyString(), Mockito.anyList())).thenReturn(StorageOperationStatus.OK);
227 Either<Component, ResponseFormat> mergeResult = compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
228 assertTrue(mergeResult.isLeft());
229 List<RequirementCapabilityRelDef> relations = updatedContainerComponent.getComponentInstancesRelations();
230 assertThat(relations)
231 .containsExactlyInAnyOrder(requirementDef1, capabilityDef2, capabilityDef3)
232 .extracting(relation -> relation.resolveSingleRelationship().getRelation().getCapabilityOwnerId(),
233 relation -> relation.resolveSingleRelationship().getRelation().getRequirementOwnerId())
234 .containsExactlyInAnyOrder(tuple("SRV1.VF1.VFC_4.VFCI_1", null),
235 tuple("grp1Id", null),
236 tuple(null, "SRV1.VF1.VFC_1.VFCI_1"));
241 public void testMergeDataAfterCreate_FailedToAssociateResourceInstances() {
242 Resource vf = new Resource();
244 List<ComponentInstance> vfcInstances = new ArrayList<>();
245 vfcInstances.add(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_1", "SRV1.VF1.VFC_1", true));
246 vfcInstances.add(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true));
247 vfcInstances.add(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false));
248 vfcInstances.add(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_1", "SRV1.VF1.VFC_4", true));
249 vf.setComponentInstances(vfcInstances);
250 vf.setComponentType(ComponentTypeEnum.RESOURCE);
251 vf.setResourceType(ResourceTypeEnum.VF);
253 Either<Component, StorageOperationStatus> eitherVF = Either.left(vf);
254 when(toscaOperationFacade.getToscaElement("SRV1.VF1")).thenReturn(eitherVF);
257 List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
258 List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
260 RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
261 fromRelationsMergeInfo.add(relationMergeInfo1);
262 RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
263 toRelationsMergeInfo.add(relationMergeInfo2);
265 ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
267 when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
269 List<ComponentInstance> componentInstances = new ArrayList<>();
270 componentInstances.add(createVfi("SRV1.VF1", "SRV1.VF1.VFI_2"));
271 componentInstances.add(createVfi("SRV1.VF2", "SRV1.VF2.VFI_1"));
272 componentInstances.add(createVfi("SRV1.VF3", "SRV1.VF3.VFI_1"));
273 componentInstances.add(createVfi("SRV1.VF4", "SRV1.VF4.VFI_1"));
274 componentInstances.add(createVfi("SRV1.VF5", "SRV1.VF5.VFI_1"));
275 updatedContainerComponent.setComponentInstances(componentInstances);
277 List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
278 updatedContainerComponent.setComponentInstancesRelations(resourceInstancesRelations);
280 when(toscaOperationFacade.associateResourceInstances(Mockito.anyString(), Mockito.anyList())).thenReturn(StorageOperationStatus.GENERAL_ERROR);
281 when(componentsUtils.convertFromStorageResponse(Mockito.any())).thenReturn(ActionStatus.GENERAL_ERROR);
283 ResponseFormat expectedRresponseFormat = new ResponseFormat();
284 when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR, updatedContainerComponent.getUniqueId())).thenReturn(expectedRresponseFormat );
286 Either<Component, ResponseFormat> result = compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
287 assertTrue(result.isRight());
288 assertEquals(expectedRresponseFormat, result.right().value());
292 public void testMergeDataAfterCreate_UpdatedContainerEmpty() {
293 List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
294 List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
296 RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
297 fromRelationsMergeInfo.add(relationMergeInfo1);
298 RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
299 toRelationsMergeInfo.add(relationMergeInfo2);
301 ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
303 when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
305 Either<Component, ResponseFormat> result = compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
306 assertTrue(result.isLeft());
307 assertEquals(updatedContainerComponent, result.left().value());
311 public void testMergeDataAfterCreate_OwnerChanged() {
312 Resource vf = new Resource();
314 List<ComponentInstance> vfcInstances = new ArrayList<>();
315 vfcInstances.add(createVfci("vfc_A", "SRV1.VF1.VFC_1.VFCI_2", "SRV1.VF1.VFC_1", true));
316 vfcInstances.add(createVfci("vfc_B", "SRV1.VF1.VFC_2.VFCI_2", "SRV1.VF1.VFC_2", true));
317 vfcInstances.add(createVfci("vfc_C", "SRV1.VF1.VFC_3.VFCI_3", "SRV1.VF1.VFC_3", false));
318 vfcInstances.add(createVfci("vfc_D", "SRV1.VF1.VFC_4.VFCI_2", "SRV1.VF1.VFC_4", true));
319 vf.setComponentInstances(vfcInstances);
320 vf.setComponentType(ComponentTypeEnum.RESOURCE);
321 vf.setResourceType(ResourceTypeEnum.VF);
323 Either<Component, StorageOperationStatus> eitherVF = Either.left(vf);
324 when(toscaOperationFacade.getToscaElement("SRV1.VF1")).thenReturn(eitherVF);
327 List<RelationMergeInfo> fromRelationsMergeInfo = new ArrayList<>();
328 List<RelationMergeInfo> toRelationsMergeInfo = new ArrayList<>();
330 RelationMergeInfo relationMergeInfo1 = new RelationMergeInfo("CapabilityType1", "capabilityA", "vfc_A", requirementDef1);
331 fromRelationsMergeInfo.add(relationMergeInfo1);
332 RelationMergeInfo relationMergeInfo2 = new RelationMergeInfo("CapabilityType4", "capabilityD", "vfc_D", capabilityDef2);
333 toRelationsMergeInfo.add(relationMergeInfo2);
335 ContainerRelationsMergeInfo relationsMergeInfo = new ContainerRelationsMergeInfo(fromRelationsMergeInfo, toRelationsMergeInfo);
337 when(dataHolder.getContainerRelationsMergeInfo()).thenReturn(relationsMergeInfo);
339 List<ComponentInstance> componentInstances = new ArrayList<>();
340 componentInstances.add(createVfi("SRV1.VF1", "SRV1.VF1.VFI_2"));
341 componentInstances.add(createVfi("SRV1.VF2", "SRV1.VF2.VFI_1"));
342 componentInstances.add(createVfi("SRV1.VF3", "SRV1.VF3.VFI_1"));
343 componentInstances.add(createVfi("SRV1.VF4", "SRV1.VF4.VFI_1"));
344 componentInstances.add(createVfi("SRV1.VF5", "SRV1.VF5.VFI_1"));
345 updatedContainerComponent.setComponentInstances(componentInstances);
347 List<RequirementCapabilityRelDef> resourceInstancesRelations = new ArrayList<>();
348 updatedContainerComponent.setComponentInstancesRelations(resourceInstancesRelations);
350 when(toscaOperationFacade.associateResourceInstances(Mockito.anyString(), Mockito.anyList())).thenReturn(StorageOperationStatus.OK);
352 compInstanceRelationMerge.mergeDataAfterCreate(user, dataHolder, updatedContainerComponent, "SRV1.VF1.VFI_2");
354 verify(dataHolder).getContainerRelationsMergeInfo();
355 verify(toscaOperationFacade).associateResourceInstances(Mockito.anyString(), Mockito.anyList());
357 List<RequirementCapabilityRelDef> relations = updatedContainerComponent.getComponentInstancesRelations();
358 assertEquals("Expected 2 relations", 2, relations.size());
361 RequirementCapabilityRelDef capabilityRelDef = relations.get(0);
362 assertEquals("SRV1.VF1.VFC_4.VFCI_2", capabilityRelDef.resolveSingleRelationship().getRelation().getCapabilityOwnerId());
363 assertEquals("SRV1.VF5.VFI_1", capabilityRelDef.getFromNode());
364 assertEquals("SRV1.VF1.VFI_2", capabilityRelDef.getToNode());
366 RequirementCapabilityRelDef requirementRelDef = relations.get(1);
367 assertEquals("SRV1.VF1.VFC_1.VFCI_2", requirementRelDef.resolveSingleRelationship().getRelation().getRequirementOwnerId());
368 assertEquals("SRV1.VF1.VFI_2", requirementRelDef.getFromNode());
369 assertEquals("SRV1.VF2.VFI_1", requirementRelDef.getToNode());
378 private ComponentInstance createVfi(String vfId, String vfiUniqueId) {
379 ComponentInstance vfi = new ComponentInstance();
380 vfi.setUniqueId(vfiUniqueId);
381 vfi.setComponentUid(vfId);
383 Resource vf = new Resource();
384 vf.setUniqueId(vfId);
388 private ComponentInstance createVfci(String name, String uniqueId, String componentUid, boolean foundVfc) {
389 ComponentInstance compInst = new ComponentInstance();
390 compInst.setName(name);
391 compInst.setUniqueId(uniqueId);
392 compInst.setComponentUid(componentUid);
395 createVfc(componentUid);
398 failLoadVfc(componentUid);
403 public GroupDefinition createGroup(String name, String id) {
404 return GroupDefinitionBuilder.create()
406 .setInvariantName(name)
411 private void failLoadVfc(String uid) {
412 Either<Component, StorageOperationStatus> eitherVFC = Either.right(StorageOperationStatus.NOT_FOUND);
413 when(toscaOperationFacade.getToscaElement(uid)).thenReturn(eitherVFC);
416 private Component createVfc(String uid) {
417 Resource vfc = new Resource();
418 vfc.setComponentType(ComponentTypeEnum.RESOURCE);
419 vfc.setUniqueId(uid);
421 Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
422 Map<String, List<RequirementDefinition>> requirements = new HashMap<>();;
423 IntStream.range(0, 5).forEach(i -> {
425 List<CapabilityDefinition> capList = new LinkedList<>();
427 CapabilityDefinition capDef = new CapabilityDefinition();
428 capDef.setName("CapabilityName" + i);
429 capDef.setUniqueId("Capability" + i);
430 capDef.setType("CapabilityType" + i);
432 capabilities.put("Key" + i, capList);
434 List<RequirementDefinition> reqList = new LinkedList<>();
436 RequirementDefinition reqDef = new RequirementDefinition();
437 reqDef.setName("RequirementName" + i);
438 reqDef.setUniqueId("Requirement" + i);
439 reqDef.setCapability("CapabilityType" + i);
441 requirements.put("Key" + i, reqList);
444 vfc.setCapabilities(capabilities );
445 vfc.setRequirements(requirements);
447 Either<Component, StorageOperationStatus> eitherVFC = Either.left(vfc);
448 when(toscaOperationFacade.getToscaElement(uid)).thenReturn(eitherVFC);
453 private RequirementCapabilityRelDef createRequirementCapabilityDef(String fromNode, String toNode) {
454 RequirementCapabilityRelDef reqCapDef = new RequirementCapabilityRelDef();
456 reqCapDef.setFromNode(fromNode);
457 reqCapDef.setToNode(toNode);
459 List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
460 CapabilityRequirementRelationship capabilityRequirementRelationship = new CapabilityRequirementRelationship();
461 relationships.add(capabilityRequirementRelationship);
462 reqCapDef.setRelationships(relationships);
467 private RequirementCapabilityRelDef createRequirementDef(String fromNode, String toNode, String ownerId, String requirementUid) {
468 RequirementCapabilityRelDef reqCapDef = createRequirementCapabilityDef(fromNode, toNode);
469 CapabilityRequirementRelationship capabilityRequirementRelationship = reqCapDef.resolveSingleRelationship();
471 RelationshipInfo relationshipInfo = new RelationshipInfo();
472 relationshipInfo.setRequirementOwnerId(ownerId);
473 relationshipInfo.setRequirementUid(requirementUid);
474 relationshipInfo.setRelationships(new RelationshipImpl());
475 capabilityRequirementRelationship.setRelation(relationshipInfo );
482 private RequirementCapabilityRelDef createCapabilityDef(String fromNode, String toNode, String ownerId, String capabilityUid) {
483 RequirementCapabilityRelDef reqCapDef = createRequirementCapabilityDef(fromNode, toNode);
484 CapabilityRequirementRelationship capabilityRequirementRelationship = reqCapDef.resolveSingleRelationship();
486 RelationshipInfo relationshipInfo = new RelationshipInfo();
487 relationshipInfo.setCapabilityOwnerId(ownerId);
488 relationshipInfo.setCapabilityUid(capabilityUid);
489 relationshipInfo.setRelationships(new RelationshipImpl());
490 capabilityRequirementRelationship.setRelation(relationshipInfo );