ad5ddafe0e133007000f8c329888bec76746ec3a
[sdc.git] /
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 fj.data.Either;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.Optional;
33 import java.util.Set;
34 import mockit.Deencapsulation;
35 import org.apache.commons.lang3.tuple.ImmutablePair;
36 import org.assertj.core.util.Lists;
37 import org.junit.Assert;
38 import org.junit.Before;
39 import org.junit.Ignore;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.mockito.InjectMocks;
43 import org.mockito.Mock;
44 import org.mockito.Mockito;
45 import org.mockito.junit.MockitoJUnitRunner;
46 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
47 import org.openecomp.sdc.be.components.validation.UserValidations;
48 import org.openecomp.sdc.be.dao.api.ActionStatus;
49 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
50 import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
51 import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
52 import org.openecomp.sdc.be.datatypes.elements.*;
53 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
54 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
55 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
56 import org.openecomp.sdc.be.impl.ComponentsUtils;
57 import org.openecomp.sdc.be.impl.ServletUtils;
58 import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
59 import org.openecomp.sdc.be.model.ArtifactDefinition;
60 import org.openecomp.sdc.be.model.CapabilityDefinition;
61 import org.openecomp.sdc.be.model.CapabilityRequirementRelationship;
62 import org.openecomp.sdc.be.model.Component;
63 import org.openecomp.sdc.be.model.ComponentInstance;
64 import org.openecomp.sdc.be.model.ComponentInstanceInput;
65 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
66 import org.openecomp.sdc.be.model.ComponentParametersView;
67 import org.openecomp.sdc.be.model.InputDefinition;
68 import org.openecomp.sdc.be.model.LifecycleStateEnum;
69 import org.openecomp.sdc.be.model.PolicyDefinition;
70 import org.openecomp.sdc.be.model.RelationshipImpl;
71 import org.openecomp.sdc.be.model.RelationshipInfo;
72 import org.openecomp.sdc.be.model.RequirementCapabilityRelDef;
73 import org.openecomp.sdc.be.model.RequirementDefinition;
74 import org.openecomp.sdc.be.model.Resource;
75 import org.openecomp.sdc.be.model.Service;
76 import org.openecomp.sdc.be.model.User;
77 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ForwardingPathOperation;
78 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
79 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
80 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
81 import org.openecomp.sdc.be.user.UserBusinessLogic;
82 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
83 import org.openecomp.sdc.exception.ResponseFormat;
84
85 import static org.junit.Assert.assertTrue;
86 import static org.junit.Assert.assertFalse;
87 import static org.junit.Assert.assertSame;
88 import static org.junit.Assert.assertEquals;
89 import static org.mockito.ArgumentMatchers.any;
90 import static org.mockito.ArgumentMatchers.anySet;
91 import static org.mockito.ArgumentMatchers.eq;
92 import static org.mockito.Mockito.when;
93
94 import static org.mockito.ArgumentMatchers.*;
95
96 /**
97  * The test suite designed for test functionality of ComponentInstanceBusinessLogic class
98  */
99
100 @RunWith(MockitoJUnitRunner.class)
101 public class ComponentInstanceBusinessLogicTest {
102
103     private final static String USER_ID = "jh0003";
104     private final static String COMPONENT_ID = "componentId";
105     private final static String COMPONENT_INST_ID = "componentInstId";
106     private final static String TO_INSTANCE_ID = "toInstanceId";
107     private final static String FROM_INSTANCE_ID = "fromInstanceId";
108     private final static String RELATION_ID = "relationId";
109     private final static String CAPABILITY_OWNER_ID = "capabilityOwnerId";
110     private final static String CAPABILITY_UID = "capabilityUid";
111     private final static String CAPABILITY_NAME = "capabilityName";
112     private final static String REQUIREMENT_OWNER_ID = "requirementOwnerId";
113     private final static String REQUIREMENT_UID = "requirementUid";
114     private final static String REQUIREMENT_NAME = "requirementName";
115     private final static String RELATIONSHIP_TYPE = "relationshipType";
116     private final static String ARTIFACT_1 = "cloudtech_k8s_charts.zip";
117     private final static String ARTIFACT_2 = "cloudtech_azure_day0.zip";
118     private final static String ARTIFACT_3 = "cloudtech_aws_configtemplate.zip";
119     private final static String ARTIFACT_4 = "k8s_charts.zip";
120     private final static String ARTIFACT_5 = "cloudtech_openstack_configtemplate.zip";
121     private final static String PROP_NAME = "propName";
122     private final static String NON_EXIST_NAME = "nonExistName";
123
124     @InjectMocks
125     private static ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
126     @Mock
127     private ComponentsUtils componentsUtils;
128     @Mock
129     private ServletUtils servletUtils;
130     @Mock
131     private ResponseFormat responseFormat;
132     @Mock
133     private ToscaOperationFacade toscaOperationFacade;
134     @Mock
135     private UserBusinessLogic userAdmin;
136     @Mock
137     private ForwardingPathOperation forwardingPathOperation;
138     @Mock
139     private User user;
140     @Mock
141     private UserValidations userValidations;
142     @Mock
143     private JanusGraphDao janusGraphDao;
144     @Mock
145     private ArtifactsBusinessLogic artifactBusinessLogic;
146     @Mock
147     private GraphLockOperation graphLockOperation;
148
149     private Component service;
150     private Component resource;
151     private ComponentInstance toInstance;
152     private ComponentInstance fromInstance;
153     private CapabilityDataDefinition capability;
154     private RequirementDataDefinition requirement;
155     private RequirementCapabilityRelDef relation;
156
157
158     @Before
159     public void init() {
160         stubMethods();
161         createComponents();
162     }
163
164     @Test
165     public void testGetRelationByIdSuccess() {
166         getServiceRelationByIdSuccess(service);
167         getServiceRelationByIdSuccess(resource);
168     }
169
170     @Test
171     public void testGetRelationByIdUserValidationFailure() {
172         getServiceRelationByIdUserValidationFailure(service);
173         getServiceRelationByIdUserValidationFailure(resource);
174     }
175
176     @Test
177     public void testGetRelationByIdComponentNotFoundFailure() {
178         getRelationByIdComponentNotFoundFailure(service);
179         getRelationByIdComponentNotFoundFailure(resource);
180     }
181
182     @Test
183     public void testForwardingPathOnVersionChange() {
184         getforwardingPathOnVersionChange();
185     }
186
187     @Test
188     public void testIsCloudSpecificArtifact() {
189         assertTrue(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_1));
190         assertTrue(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_2));
191         assertTrue(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_3));
192         assertFalse(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_4));
193         assertFalse(componentInstanceBusinessLogic.isCloudSpecificArtifact(ARTIFACT_5));
194     }
195
196     private void getforwardingPathOnVersionChange(){
197         String containerComponentParam = "services";
198         String containerComponentID = "121-cont";
199         String componentInstanceID = "121-cont-1-comp";
200         Service component = new Service();
201         Map<String, ForwardingPathDataDefinition> forwardingPaths = generateForwardingPath(componentInstanceID);
202
203         //Add existing componentInstance to component
204         List<ComponentInstance> componentInstanceList = new ArrayList<>();
205         ComponentInstance oldComponentInstance = new ComponentInstance();
206         oldComponentInstance.setName("OLD_COMP_INSTANCE");
207         oldComponentInstance.setUniqueId(componentInstanceID);
208         oldComponentInstance.setName(componentInstanceID);
209         oldComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID, "1-comp");
210         componentInstanceList.add(oldComponentInstance);
211         component.setComponentInstances(componentInstanceList);
212         component.setForwardingPaths(forwardingPaths);
213
214         List<ComponentInstance> componentInstanceListNew = new ArrayList<>();
215         ComponentInstance newComponentInstance = new ComponentInstance();
216         String new_Comp_UID = "2-comp";
217         newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID, new_Comp_UID);
218         newComponentInstance.setUniqueId(new_Comp_UID);
219         componentInstanceListNew.add(newComponentInstance);
220         Component component2 = new Service();
221         component2.setComponentInstances(componentInstanceListNew);
222
223         //Mock for getting component
224         when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
225                 .thenReturn(Either.left(component));
226         when(toscaOperationFacade.validateComponentExists(any(String.class))).thenReturn(Either.left(Boolean.TRUE));
227         when(toscaOperationFacade.getToscaFullElement(eq(new_Comp_UID))).thenReturn(Either.left(component2));
228
229         Either<Set<String>, ResponseFormat> resultOp = componentInstanceBusinessLogic
230                                                                .forwardingPathOnVersionChange(containerComponentParam,
231                                                                        containerComponentID, componentInstanceID,
232                                                                        newComponentInstance);
233         assertEquals(1, resultOp.left().value().size());
234         assertEquals("FP-ID-1", resultOp.left().value().iterator().next());
235
236     }
237
238
239     @Test
240     public void testDeleteForwardingPathsWhenComponentinstanceDeleted() {
241
242         ComponentTypeEnum containerComponentType = ComponentTypeEnum.findByParamName("services");
243         String containerComponentID = "Service-comp";
244         String componentInstanceID = "NodeA1";
245         Service component = new Service();
246         component.setComponentInstances(
247                 Arrays.asList(createComponentIstance("NodeA2"), createComponentIstance("NodeB2"),
248                         createComponentIstance(componentInstanceID)));
249
250         component.addForwardingPath(createPath("path1", componentInstanceID, "NodeB1", "1"));
251         component.addForwardingPath(createPath("Path2", "NodeA2", "NodeB2", "2"));
252         when(toscaOperationFacade.getToscaElement(eq(containerComponentID), any(ComponentParametersView.class)))
253                 .thenReturn(Either.left(component));
254         when(toscaOperationFacade.getToscaElement(eq(containerComponentID))).thenReturn(Either.left(component));
255         when(forwardingPathOperation.deleteForwardingPath(any(Service.class), anySet()))
256                 .thenReturn(Either.left(new HashSet<>()));
257         final ComponentInstance ci = new ComponentInstance();
258         ci.setName(componentInstanceID);
259         Either<ComponentInstance, ResponseFormat> responseFormatEither = componentInstanceBusinessLogic.deleteForwardingPathsRelatedTobeDeletedComponentInstance(
260                 containerComponentID, containerComponentType, Either.left(ci));
261         assertThat(responseFormatEither.isLeft()).isEqualTo(true);
262
263     }
264
265     private ComponentInstance createComponentIstance(String path1) {
266         ComponentInstance componentInstance = new ComponentInstance();
267         componentInstance.setName(path1);
268         return componentInstance;
269     }
270
271     private ForwardingPathDataDefinition createPath(String pathName, String fromNode, String toNode, String uniqueId) {
272         ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition(pathName);
273         forwardingPath.setProtocol("protocol");
274         forwardingPath.setDestinationPortNumber("port");
275         forwardingPath.setUniqueId(uniqueId);
276         ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
277                 new ListDataDefinition<>();
278         forwardingPathElementListDataDefinition
279                 .add(new ForwardingPathElementDataDefinition(fromNode, toNode, "nodeAcpType", "nodeBcpType",
280                         "nodeDcpName", "nodeBcpName"));
281         forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
282
283         return forwardingPath;
284     }
285
286
287     private Map<String, ForwardingPathDataDefinition> generateForwardingPath(String componentInstanceID) {
288         ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition("fpName");
289         String protocol = "protocol";
290         forwardingPath.setProtocol(protocol);
291         forwardingPath.setDestinationPortNumber("DestinationPortNumber");
292         forwardingPath.setUniqueId("FP-ID-1");
293         ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
294                 new ListDataDefinition<>();
295         forwardingPathElementListDataDefinition
296                 .add(new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY",
297                         "nodeBcpType", "nodeDcpName", "nodeBcpName"));
298         forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
299         Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
300         forwardingPaths.put("1122", forwardingPath);
301         return forwardingPaths;
302     }
303
304     @SuppressWarnings("unchecked")
305     private void getServiceRelationByIdSuccess(Component component) {
306         Either<Component, StorageOperationStatus> getComponentRes = Either.left(component);
307         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
308                 .thenReturn(getComponentRes);
309         Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
310                                                                                .getRelationById(COMPONENT_ID,
311                                                                                        RELATION_ID, USER_ID,
312                                                                                        component.getComponentType());
313         assertTrue(response.isLeft());
314     }
315
316     private void getServiceRelationByIdUserValidationFailure(Component component) {
317         when(userValidations.validateUserExists(eq(USER_ID), eq("get relation by Id"), eq(false)))
318                 .thenThrow(new ByActionStatusComponentException(ActionStatus.USER_NOT_FOUND));
319         try {
320             componentInstanceBusinessLogic
321                     .getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
322         } catch (ByActionStatusComponentException e) {
323             assertSame(e.getActionStatus(), ActionStatus.USER_NOT_FOUND);
324         }
325     }
326
327     private void getRelationByIdComponentNotFoundFailure(Component component) {
328         Either<User, ActionStatus> eitherCreator = Either.left(user);
329         Either<Component, StorageOperationStatus> getComponentRes = Either.right(StorageOperationStatus.NOT_FOUND);
330         when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class)))
331                 .thenReturn(getComponentRes);
332
333         Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic
334                                                                                .getRelationById(COMPONENT_ID,
335                                                                                        RELATION_ID, USER_ID,
336                                                                                        component.getComponentType());
337         assertTrue(response.isRight());
338     }
339
340     private void stubMethods() {
341         when(userValidations.validateUserExists(eq(USER_ID), eq("get relation by Id"), eq(false))).thenReturn(user);
342     }
343
344     private void createComponents() {
345         createRelation();
346         createInstances();
347         createService();
348         createResource();
349     }
350
351     private void createResource() {
352         resource = new Resource();
353         resource.setUniqueId(COMPONENT_ID);
354         resource.setComponentInstancesRelations(Lists.newArrayList(relation));
355         resource.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
356         resource.setCapabilities(toInstance.getCapabilities());
357         resource.setRequirements(fromInstance.getRequirements());
358         resource.setComponentType(ComponentTypeEnum.RESOURCE);
359         resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
360     }
361
362
363     private void createService() {
364         service = new Service();
365         service.setUniqueId(COMPONENT_ID);
366         service.setComponentInstancesRelations(Lists.newArrayList(relation));
367         service.setComponentInstances(Lists.newArrayList(toInstance, fromInstance));
368         service.setCapabilities(toInstance.getCapabilities());
369         service.setRequirements(fromInstance.getRequirements());
370         service.setComponentType(ComponentTypeEnum.SERVICE);
371         service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
372     }
373
374
375     private void createInstances() {
376         toInstance = new ComponentInstance();
377         toInstance.setUniqueId(TO_INSTANCE_ID);
378
379         fromInstance = new ComponentInstance();
380         fromInstance.setUniqueId(FROM_INSTANCE_ID);
381
382         capability = new CapabilityDataDefinition();
383         capability.setOwnerId(CAPABILITY_OWNER_ID);
384         capability.setUniqueId(CAPABILITY_UID);
385         capability.setName(CAPABILITY_NAME);
386
387         Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
388         capabilities.put(capability.getName(), Lists.newArrayList(new CapabilityDefinition(capability)));
389
390         requirement = new RequirementDataDefinition();
391         requirement.setOwnerId(REQUIREMENT_OWNER_ID);
392         requirement.setUniqueId(REQUIREMENT_UID);
393         requirement.setName(REQUIREMENT_NAME);
394         requirement.setRelationship(RELATIONSHIP_TYPE);
395
396
397         Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
398         requirements.put(requirement.getCapability(), Lists.newArrayList(new RequirementDefinition(requirement)));
399
400         toInstance.setCapabilities(capabilities);
401         fromInstance.setRequirements(requirements);
402     }
403
404
405     private void createRelation() {
406
407         relation = new RequirementCapabilityRelDef();
408         CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
409         RelationshipInfo relationInfo = new RelationshipInfo();
410         relationInfo.setId(RELATION_ID);
411         relationship.setRelation(relationInfo);
412
413         relation.setRelationships(Lists.newArrayList(relationship));
414         relation.setToNode(TO_INSTANCE_ID);
415         relation.setFromNode(FROM_INSTANCE_ID);
416
417         relationInfo.setCapabilityOwnerId(CAPABILITY_OWNER_ID);
418         relationInfo.setCapabilityUid(CAPABILITY_UID);
419         relationInfo.setCapability(CAPABILITY_NAME);
420         relationInfo.setRequirementOwnerId(REQUIREMENT_OWNER_ID);
421         relationInfo.setRequirementUid(REQUIREMENT_UID);
422         relationInfo.setRequirement(REQUIREMENT_NAME);
423         RelationshipImpl relationshipImpl = new RelationshipImpl();
424         relationshipImpl.setType(RELATIONSHIP_TYPE);
425         relationInfo.setRelationships(relationshipImpl);
426     }
427
428     private ComponentInstanceBusinessLogic createTestSubject() {
429         return componentInstanceBusinessLogic;
430     }
431
432
433     @Test
434     public void testChangeServiceProxyVersion() {
435         ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
436
437         Either<ComponentInstance, ResponseFormat> result;
438
439         // default test
440         componentInstanceBusinessLogic = createTestSubject();
441         result = componentInstanceBusinessLogic.changeServiceProxyVersion();
442     }
443
444
445     @Test
446     public void testCreateServiceProxy() {
447         ComponentInstanceBusinessLogic testSubject;
448         Either<ComponentInstance, ResponseFormat> result;
449
450         // default test
451         testSubject = createTestSubject();
452         result = testSubject.createServiceProxy();
453     }
454
455
456     @Test
457     public void testDeleteForwardingPathsRelatedTobeDeletedComponentInstance() {
458         ComponentInstanceBusinessLogic testSubject;
459         String containerComponentId = "";
460         String componentInstanceId = "";
461         ComponentTypeEnum containerComponentType = ComponentTypeEnum.RESOURCE;
462         Either<ComponentInstance, ResponseFormat> resultOp = null;
463         Either<ComponentInstance, ResponseFormat> result;
464
465         // default test
466         testSubject = createTestSubject();
467         result = testSubject.deleteForwardingPathsRelatedTobeDeletedComponentInstance(containerComponentId,
468                 containerComponentType, resultOp);
469     }
470
471
472     @Test
473     public void testDeleteServiceProxy() {
474         ComponentInstanceBusinessLogic testSubject;
475
476         Either<ComponentInstance, ResponseFormat> result;
477
478         // default test
479         testSubject = createTestSubject();
480         result = testSubject.deleteServiceProxy();
481     }
482
483
484     @Test
485     public void testGetComponentInstanceInputsByInputId() {
486         ComponentInstanceBusinessLogic testSubject;
487         Component component = new Service();
488         String inputId = "";
489         List<ComponentInstanceInput> result;
490
491         // default test
492         testSubject = createTestSubject();
493         result = testSubject.getComponentInstanceInputsByInputId(component, inputId);
494     }
495
496
497     @Test
498     public void testGetComponentInstancePropertiesByInputId() {
499         ComponentInstanceBusinessLogic testSubject;
500         Component component = new Service();
501         String inputId = "";
502         List<ComponentInstanceProperty> result;
503
504         // default test
505         testSubject = createTestSubject();
506         result = testSubject.getComponentInstancePropertiesByInputId(component, inputId);
507     }
508
509
510     @Test
511     public void testGetRelationById() {
512         ComponentInstanceBusinessLogic testSubject;
513         String componentId = "";
514         String relationId = "";
515         String userId = user.getUserId();
516         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE_INSTANCE;
517         Either<RequirementCapabilityRelDef, ResponseFormat> result;
518
519         // default test
520         testSubject = createTestSubject();
521         result = testSubject.getRelationById(componentId, relationId, userId, componentTypeEnum);
522     }
523
524
525     @Test
526     public void testCreateComponentInstance_1() {
527         ComponentInstanceBusinessLogic testSubject;
528         String containerComponentParam = "";
529         String containerComponentId = "";
530         String userId = user.getUserId();
531         ComponentInstance resourceInstance = null;
532         boolean inTransaction = false;
533         boolean needLock = false;
534         Either<ComponentInstance, ResponseFormat> result;
535
536         // default test
537         testSubject = createTestSubject();
538         result = testSubject.createComponentInstance(containerComponentParam, containerComponentId, userId,
539                 resourceInstance, inTransaction, needLock);
540     }
541
542
543     @Test
544     public void testCreateAndAssociateRIToRI() {
545         ComponentInstanceBusinessLogic testSubject;
546
547         String containerComponentParam = "";
548         String containerComponentId = "";
549         String userId = user.getUserId();
550         CreateAndAssotiateInfo createAndAssotiateInfo = new CreateAndAssotiateInfo(null, null);
551         Either<CreateAndAssotiateInfo, ResponseFormat> result;
552
553         // default test
554         testSubject = createTestSubject();
555         result = testSubject.createAndAssociateRIToRI(containerComponentParam, containerComponentId, userId,
556                 createAndAssotiateInfo);
557     }
558
559     @Test
560     public void testGetOriginComponentFromComponentInstance_1() {
561         ComponentInstanceBusinessLogic testSubject;
562         createResource();
563         String componentInstanceName = "";
564         String origComponetId = resource.getUniqueId();
565         Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resource);
566         when(toscaOperationFacade.getToscaFullElement(resource.getUniqueId())).thenReturn(oldResourceRes);
567         Either<Component, ResponseFormat> result;
568
569         // default test
570         testSubject = createTestSubject();
571         result = Deencapsulation.invoke(testSubject, "getOriginComponentFromComponentInstance",
572                 new Object[] {componentInstanceName, origComponetId});
573     }
574
575
576     @Test
577     public void testCreateComponentInstanceOnGraph() {
578         ComponentInstanceBusinessLogic testSubject;
579         createResource();
580         createInstances();
581         Either<ComponentInstance, ResponseFormat> result;
582
583         Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 =
584                 Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND);
585         when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource, toInstance, false, user))
586                 .thenReturn(result2);
587
588         // default test
589         testSubject = createTestSubject();
590         result = Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph",
591                 new Object[] {resource, resource, toInstance, user});
592     }
593
594     @Ignore("test failing skipping for now")
595     @Test
596     public void testCreateComponentInstanceOnGraph2() {
597         ComponentInstanceBusinessLogic testSubject;
598         createResource();
599         resource.setName("name");
600         createInstances();
601         Either<ComponentInstance, ResponseFormat> result;
602         ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, "");
603
604
605         Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
606         when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource, toInstance, false, user))
607                 .thenReturn(result2);
608
609         // default test
610         testSubject = createTestSubject();
611         result = Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph",
612                 new Object[] {resource, resource, toInstance, user});
613     }
614
615     @Test
616     public void testUpdateComponentInstanceMetadata() {
617         ComponentInstanceBusinessLogic testSubject;
618         String containerComponentParam = "";
619         String containerComponentId = "";
620         String componentInstanceId = "";
621         String userId = user.getUserId();
622         createInstances();
623         Either<ComponentInstance, ResponseFormat> result;
624
625         // default test
626         testSubject = createTestSubject();
627         result = testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId,
628                 componentInstanceId, userId, toInstance);
629     }
630
631
632     @Test
633     public void testUpdateComponentInstanceMetadata_1() {
634         ComponentInstanceBusinessLogic testSubject;
635         String containerComponentParam = "";
636         String containerComponentId = "";
637         String componentInstanceId = "";
638         String userId = user.getUserId();
639         createInstances();
640         boolean inTransaction = false;
641         boolean needLock = false;
642         boolean createNewTransaction = false;
643         Either<ComponentInstance, ResponseFormat> result;
644
645         // default test
646         testSubject = createTestSubject();
647         result = testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId,
648                 componentInstanceId, userId, toInstance, inTransaction, needLock, createNewTransaction);
649     }
650
651
652     @Test
653     public void testValidateParent() {
654         ComponentInstanceBusinessLogic testSubject;
655         createResource();
656         String nodeTemplateId = "";
657         boolean result;
658
659         // default test
660         testSubject = createTestSubject();
661         result = Deencapsulation.invoke(testSubject, "validateParent", new Object[] {resource, nodeTemplateId});
662     }
663
664
665     @Test
666     public void testGetComponentType() {
667         ComponentInstanceBusinessLogic testSubject;
668         ComponentTypeEnum result;
669
670         // default test
671         testSubject = createTestSubject();
672         result = Deencapsulation.invoke(testSubject, "getComponentType", new Object[] {ComponentTypeEnum.class});
673     }
674
675
676     @Test
677     public void testGetNewGroupName() {
678         ComponentInstanceBusinessLogic testSubject;
679         String oldPrefix = "";
680         String newNormailzedPrefix = "";
681         String qualifiedGroupInstanceName = "";
682         String result;
683
684         // test 1
685         testSubject = createTestSubject();
686         result = Deencapsulation.invoke(testSubject, "getNewGroupName",
687                 new Object[] {oldPrefix, newNormailzedPrefix, qualifiedGroupInstanceName});
688     }
689
690
691     @Test
692     public void testUpdateComponentInstanceMetadata_3() {
693         ComponentInstanceBusinessLogic testSubject;
694         createInstances();
695         ComponentInstance newComponentInstance = null;
696         ComponentInstance result;
697
698         // default test
699         testSubject = createTestSubject();
700         result = Deencapsulation
701                          .invoke(testSubject, "updateComponentInstanceMetadata", new Object[] {toInstance, toInstance});
702     }
703
704
705     @Test
706     public void testDeleteComponentInstance() throws Exception {
707         ComponentInstanceBusinessLogic testSubject;
708         String containerComponentParam = "";
709         String containerComponentId = "";
710         String componentInstanceId = "";
711         String userId = user.getUserId();
712         Either<ComponentInstance, ResponseFormat> result;
713
714         // default test
715         testSubject = createTestSubject();
716         JanusGraphDao mock = Mockito.mock(JanusGraphDao.class);
717         testSubject.setJanusGraphGenericDao(mock);
718         result = testSubject.deleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceId,
719                 userId);
720     }
721
722
723     @Test
724     public void testDeleteForwardingPaths() {
725         ComponentInstanceBusinessLogic testSubject;
726         createService();
727         String serviceId = service.getUniqueId();
728         List<String> pathIdsToDelete = new ArrayList<>();
729         Either<Set<String>, ResponseFormat> result;
730
731         //      Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
732         when(toscaOperationFacade.getToscaElement(serviceId))
733                 .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
734
735         // default test
736         testSubject = createTestSubject();
737         result =
738                 Deencapsulation.invoke(testSubject, "deleteForwardingPaths", new Object[] {serviceId, pathIdsToDelete});
739     }
740
741
742     @Test
743     public void testAssociateRIToRIOnGraph() throws Exception {
744         ComponentInstanceBusinessLogic testSubject;
745         createResource();
746         RequirementCapabilityRelDef requirementDef = new RequirementCapabilityRelDef();
747         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
748         boolean inTransaction = false;
749         Either<RequirementCapabilityRelDef, ResponseFormat> result;
750
751
752         Either<RequirementCapabilityRelDef, StorageOperationStatus> getResourceResult = Either.left(requirementDef);
753         when(toscaOperationFacade.associateResourceInstances(resource.getUniqueId(), requirementDef))
754                 .thenReturn(getResourceResult);
755
756         // default test
757         testSubject = createTestSubject();
758         result = testSubject.associateRIToRIOnGraph(resource, requirementDef, componentTypeEnum, inTransaction);
759     }
760
761
762     @Test
763     public void testFindRelation() throws Exception {
764         ComponentInstanceBusinessLogic testSubject;
765         String relationId = "";
766         List<RequirementCapabilityRelDef> requirementCapabilityRelations = new ArrayList<>();
767         RequirementCapabilityRelDef result;
768
769         // default test
770         testSubject = createTestSubject();
771         result = Deencapsulation.invoke(testSubject, "findRelation",
772                 new Object[] {relationId, requirementCapabilityRelations});
773     }
774
775
776     @Test
777     public void testIsNetworkRoleServiceProperty() throws Exception {
778         ComponentInstanceBusinessLogic testSubject;
779         ComponentInstanceProperty property = new ComponentInstanceProperty();
780         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
781         boolean result;
782
783         // default test
784         testSubject = createTestSubject();
785         result = Deencapsulation.invoke(testSubject, "isNetworkRoleServiceProperty",
786                 new Object[] {property, componentTypeEnum});
787     }
788
789
790     @Test
791     public void testConcatServiceNameToVLINetworkRolePropertiesValues() throws Exception {
792         ComponentInstanceBusinessLogic testSubject;
793         ToscaOperationFacade toscaOperationFacade = new ToscaOperationFacade();
794         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
795         String componentId = "";
796         String resourceInstanceId = "";
797         List<ComponentInstanceProperty> properties = new ArrayList<>();
798         StorageOperationStatus result;
799
800         // default test
801         testSubject = createTestSubject();
802         result = Deencapsulation.invoke(testSubject, "concatServiceNameToVLINetworkRolePropertiesValues",
803                 new Object[] {toscaOperationFacade, componentTypeEnum, componentId, resourceInstanceId, properties});
804     }
805
806
807     @Test
808     public void testCreateOrUpdatePropertiesValues() throws Exception {
809         ComponentInstanceBusinessLogic testSubject;
810         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
811         createResource();
812         String componentId = resource.getUniqueId();
813         String resourceInstanceId = "";
814         List<ComponentInstanceProperty> properties = new ArrayList<>();
815         String userId = user.getUserId();
816         Either<List<ComponentInstanceProperty>, ResponseFormat> result;
817
818
819         when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
820                 .thenReturn(Either.left(resource));
821
822         // test 1
823         testSubject = createTestSubject();
824         result = testSubject
825                          .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
826                                  userId);
827
828         componentTypeEnum = null;
829         result = testSubject
830                          .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
831                                  userId);
832
833         //        when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
834         result = testSubject
835                          .createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties,
836                                  userId);
837
838     }
839
840
841     @Test
842     public void testUpdateCapabilityPropertyOnContainerComponent() throws Exception {
843         ComponentInstanceBusinessLogic testSubject;
844         ComponentInstanceProperty property = new ComponentInstanceProperty();
845         String newValue = "";
846         createResource();
847         createInstances();
848         String capabilityType = "";
849         String capabilityName = "";
850         ResponseFormat result;
851
852         // default test
853         testSubject = createTestSubject();
854         result = Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent",
855                 new Object[] {property, newValue, resource, toInstance, capabilityType, capabilityName});
856     }
857
858
859     @Test
860     public void testCreateOrUpdateInstanceInputValues() throws Exception {
861         ComponentInstanceBusinessLogic testSubject;
862         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
863         createResource();
864         String componentId = resource.getUniqueId();
865         String resourceInstanceId = "";
866         List<ComponentInstanceInput> inputs = new ArrayList<>();
867         String userId = user.getUserId();
868         Either<List<ComponentInstanceInput>, ResponseFormat> result;
869
870         when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll))
871                 .thenReturn(Either.left(resource));
872
873         // test 1
874         testSubject = createTestSubject();
875         result = testSubject
876                          .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
877                                  userId);
878         componentTypeEnum = null;
879         result = testSubject
880                          .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
881                                  userId);
882
883
884         //        when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
885         result = testSubject
886                          .createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs,
887                                  userId);
888
889     }
890
891
892     @Test
893     public void testCreateOrUpdateGroupInstancePropertyValue() throws Exception {
894         ComponentInstanceBusinessLogic testSubject;
895         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
896         createResource();
897         String componentId = resource.getUniqueId();
898         String resourceInstanceId = "";
899         String groupInstanceId = "";
900         ComponentInstanceProperty property = new ComponentInstanceProperty();
901         String userId = user.getUserId();
902         Either<ComponentInstanceProperty, ResponseFormat> result;
903
904
905         when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata))
906                 .thenReturn(Either.left(resource));
907
908         // test 1
909         testSubject = createTestSubject();
910         result = testSubject
911                          .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
912                                  groupInstanceId, property, userId);
913         componentTypeEnum = null;
914         result = testSubject
915                          .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
916                                  groupInstanceId, property, userId);
917
918         //        when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
919         result = testSubject
920                          .createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId,
921                                  groupInstanceId, property, userId);
922     }
923
924
925     @Test
926     public void testCreateOrUpdateInputValue() throws Exception {
927         ComponentInstanceBusinessLogic testSubject;
928         createResource();
929         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
930         String componentId = resource.getUniqueId();
931         String resourceInstanceId = resource.getUniqueId();
932         ComponentInstanceInput inputProperty = new ComponentInstanceInput();
933         String userId = user.getUserId();
934         Either<ComponentInstanceInput, ResponseFormat> result;
935
936
937         Either<Component, StorageOperationStatus> getResourceResult = Either.left(resource);
938         when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata))
939                 .thenReturn(getResourceResult);
940
941         // test 1
942         testSubject = createTestSubject();
943         result = testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty,
944                 userId);
945
946         componentTypeEnum = null;
947         result = testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty,
948                 userId);
949
950         //        when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
951         result = testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty,
952                 userId);
953     }
954
955
956     @Test
957     public void testDeletePropertyValue() throws Exception {
958         ComponentInstanceBusinessLogic testSubject;
959         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
960         createService();
961         String serviceId = service.getUniqueId();
962         String resourceInstanceId = "";
963         String propertyValueId = "";
964         String userId = user.getUserId();
965         Either<ComponentInstanceProperty, ResponseFormat> result;
966
967         when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata))
968                 .thenReturn(Either.left(service));
969
970         // test 1
971         testSubject = createTestSubject();
972         result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
973                 userId);
974         componentTypeEnum = null;
975         result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
976                 userId);
977
978         //        when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
979         result = testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId,
980                 userId);
981     }
982
983
984     @Test
985     public void testGetAndValidateOriginComponentOfComponentInstance() throws Exception {
986         ComponentInstanceBusinessLogic testSubject;
987         ComponentTypeEnum containerComponentType = ComponentTypeEnum.RESOURCE;
988         createResource();
989         createInstances();
990         Either<Component, ResponseFormat> result;
991
992         when(toscaOperationFacade.getToscaFullElement(toInstance.getComponentUid())).thenReturn(Either.left(resource));
993
994         // default test
995         testSubject = createTestSubject();
996         result = Deencapsulation.invoke(testSubject, "getAndValidateOriginComponentOfComponentInstance",
997                 new Object[] {containerComponentType, toInstance});
998     }
999
1000
1001     @Test
1002     public void testGetComponentParametersViewForForwardingPath() throws Exception {
1003         ComponentInstanceBusinessLogic testSubject;
1004         ComponentParametersView result;
1005
1006         // default test
1007         testSubject = createTestSubject();
1008         result = Deencapsulation.invoke(testSubject, "getComponentParametersViewForForwardingPath");
1009     }
1010
1011
1012     @Test
1013     public void testChangeComponentInstanceVersion() throws Exception {
1014         ComponentInstanceBusinessLogic testSubject;
1015         String containerComponentParam = "";
1016         String containerComponentId = "";
1017         String componentInstanceId = "";
1018         String userId = user.getUserId();
1019         createInstances();
1020         ComponentInstance newComponentInstance = toInstance;
1021         Either<ComponentInstance, ResponseFormat> result;
1022
1023         // default test
1024         testSubject = createTestSubject();
1025         result = testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId,
1026                 componentInstanceId, userId, newComponentInstance);
1027         newComponentInstance = null;
1028         testSubject = createTestSubject();
1029         result = testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId,
1030                 componentInstanceId, userId, newComponentInstance);
1031
1032     }
1033
1034     @Ignore("test failing skipping for now")
1035     @Test
1036     public void testValidateInstanceNameUniquenessUponUpdate() throws Exception {
1037         ComponentInstanceBusinessLogic testSubject;
1038         createResource();
1039         createInstances();
1040         String newInstanceName = toInstance.getName();
1041         Boolean result;
1042
1043         // default test
1044         testSubject = createTestSubject();
1045         result = Deencapsulation.invoke(testSubject, "validateInstanceNameUniquenessUponUpdate",
1046                 new Object[] {resource, toInstance, newInstanceName});
1047     }
1048
1049
1050     @Test
1051     public void testGetResourceInstanceById() throws Exception {
1052         ComponentInstanceBusinessLogic testSubject;
1053         createResource();
1054         String instanceId = "";
1055         Either<ComponentInstance, StorageOperationStatus> result;
1056
1057         // default test
1058         testSubject = createTestSubject();
1059         result = Deencapsulation.invoke(testSubject, "getResourceInstanceById", new Object[] {resource, instanceId});
1060     }
1061
1062     @Ignore("test failing skipping for now")
1063     @Test
1064     public void testBuildComponentInstance() throws Exception {
1065         ComponentInstanceBusinessLogic testSubject;
1066         createInstances();
1067         ComponentInstance origInstanceForUpdate = null;
1068         ComponentInstance result;
1069
1070         // default test
1071         testSubject = createTestSubject();
1072         result = Deencapsulation.invoke(testSubject, "buildComponentInstance", new Object[] {toInstance, toInstance});
1073     }
1074
1075
1076     @Test
1077     public void testFindCapabilityOfInstance() throws Exception {
1078         ComponentInstanceBusinessLogic testSubject;
1079         String componentId = "";
1080         String instanceId = "";
1081         String capabilityType = "";
1082         String capabilityName = "";
1083         String ownerId = "";
1084         Map<String, List<CapabilityDefinition>> instanceCapabilities = new HashMap<>();
1085         Either<List<ComponentInstanceProperty>, ResponseFormat> result;
1086
1087         // default test
1088         testSubject = createTestSubject();
1089         result = Deencapsulation.invoke(testSubject, "findCapabilityOfInstance",
1090                 new Object[] {componentId, instanceId, capabilityType, capabilityName, ownerId, instanceCapabilities});
1091     }
1092
1093
1094     @Test
1095     public void testFetchComponentInstanceCapabilityProperties() throws Exception {
1096         ComponentInstanceBusinessLogic testSubject;
1097         String componentId = "";
1098         String instanceId = "";
1099         String capabilityType = "";
1100         String capabilityName = "";
1101         String ownerId = "";
1102         Either<List<ComponentInstanceProperty>, ResponseFormat> result;
1103
1104         // default test
1105         testSubject = createTestSubject();
1106         result = Deencapsulation.invoke(testSubject, "fetchComponentInstanceCapabilityProperties",
1107                 new Object[] {componentId, instanceId, capabilityType, capabilityName, ownerId});
1108     }
1109
1110
1111     @Test
1112     public void testUpdateCapabilityPropertyOnContainerComponent_1() throws Exception {
1113         ComponentInstanceBusinessLogic testSubject;
1114         ComponentInstanceProperty property = new ComponentInstanceProperty();
1115         String newValue = "";
1116         createResource();
1117         createInstances();
1118         String capabilityType = "";
1119         String capabilityName = "";
1120         String ownerId = "";
1121         ResponseFormat result;
1122
1123         // default test
1124         testSubject = createTestSubject();
1125         result = Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent",
1126                 new Object[] {property, newValue, resource, toInstance, capabilityType, capabilityName, ownerId});
1127     }
1128
1129
1130     @Test
1131     public void testUpdateInstanceCapabilityProperties() throws Exception {
1132         ComponentInstanceBusinessLogic testSubject;
1133         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1134         createResource();
1135         String containerComponentId = resource.getUniqueId();
1136         String componentInstanceUniqueId = "";
1137         String capabilityType = "";
1138         String capabilityName = "";
1139         String ownerId = "";
1140         List<ComponentInstanceProperty> properties = new ArrayList<>();
1141         String userId = user.getUserId();
1142         Either<List<ComponentInstanceProperty>, ResponseFormat> result;
1143
1144
1145         when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
1146
1147
1148         // test 1
1149         testSubject = createTestSubject();
1150         result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
1151                 componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
1152         when(toscaOperationFacade.getToscaFullElement(containerComponentId))
1153                 .thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
1154         result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
1155                 componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
1156         componentTypeEnum = null;
1157         result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
1158                 componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
1159
1160
1161     }
1162
1163
1164     @Test
1165     public void testUpdateInstanceCapabilityProperties_1() throws Exception {
1166         ComponentInstanceBusinessLogic testSubject;
1167         ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1168         createResource();
1169         String containerComponentId = resource.getUniqueId();
1170         String componentInstanceUniqueId = "";
1171         String capabilityType = "";
1172         String capabilityName = "";
1173         List<ComponentInstanceProperty> properties = new ArrayList<>();
1174         String userId = user.getUserId();
1175         Either<List<ComponentInstanceProperty>, ResponseFormat> result;
1176
1177
1178         when(toscaOperationFacade.getToscaFullElement(containerComponentId))
1179                 .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
1180         // test 1
1181         testSubject = createTestSubject();
1182         result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
1183                 componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
1184         when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
1185         result = testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId,
1186                 componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
1187     }
1188
1189     @Test
1190     public void testCopyComponentInstanceWrongUserId() {
1191
1192         Either<Map<String, ComponentInstance>, ResponseFormat> result;
1193         ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource);
1194         String containerComponentId = service.getUniqueId();
1195         String componentInstanceId = resource.getUniqueId();
1196         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1197         service.setLastUpdaterUserId("wrong user id");
1198
1199         Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
1200         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
1201         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1202                 .thenReturn(leftServiceOp);
1203         when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
1204         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1205                 .thenReturn(StorageOperationStatus.OK);
1206         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1207                 .thenReturn(StorageOperationStatus.OK);
1208
1209         result = componentInstanceBusinessLogic
1210                          .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
1211                                  USER_ID);
1212
1213         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1214
1215         assertThat(result.isRight());
1216     }
1217
1218     @Test
1219     public void testCopyComponentInstanceComponentWrongState() {
1220         Either<Map<String, ComponentInstance>, ResponseFormat> result;
1221         ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource);
1222         String containerComponentId = service.getUniqueId();
1223         String componentInstanceId = resource.getUniqueId();
1224         String oldServiceLastUpdatedUserId = service.getLastUpdaterUserId();
1225         service.setLastUpdaterUserId(USER_ID);
1226
1227         Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
1228         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
1229         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1230                 .thenReturn(leftServiceOp);
1231         when(janusGraphDao.rollback()).thenReturn(JanusGraphOperationStatus.OK);
1232         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1233                 .thenReturn(StorageOperationStatus.OK);
1234         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1235                 .thenReturn(StorageOperationStatus.OK);
1236         Either<Component, StorageOperationStatus> getComponentRes = Either.left(resource);
1237         when(toscaOperationFacade.getToscaFullElement(inputComponentInstance.getComponentUid()))
1238                 .thenReturn(getComponentRes);
1239
1240         result = componentInstanceBusinessLogic
1241                          .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
1242                                  USER_ID);
1243
1244         service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
1245
1246         assertThat(result.isRight());
1247     }
1248
1249     @Test
1250     public void testCopyComponentInstance() {
1251         Either<Map<String, ComponentInstance>, ResponseFormat> result;
1252         ComponentInstance inputComponentInstance = createComponetInstanceFromComponent(resource);
1253         String containerComponentId = service.getUniqueId();
1254         String componentInstanceId = resource.getUniqueId();
1255         String oldServiceLastUpdatedUserId = service.getLastUpdaterUserId();
1256         service.setLastUpdaterUserId(USER_ID);
1257         LifecycleStateEnum oldResourceLifeCycle = resource.getLifecycleState();
1258         resource.setLifecycleState(LifecycleStateEnum.CERTIFIED);
1259
1260         Either<Component, StorageOperationStatus> leftServiceOp = Either.left(service);
1261         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(leftServiceOp);
1262         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1263                 .thenReturn(leftServiceOp);
1264         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1265                 .thenReturn(StorageOperationStatus.OK);
1266         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1267                 .thenReturn(StorageOperationStatus.OK);
1268         Either<Component, StorageOperationStatus> getComponentRes = Either.left(resource);
1269         when(toscaOperationFacade.getToscaFullElement(inputComponentInstance.getComponentUid()))
1270                 .thenReturn(getComponentRes);
1271         ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, TO_INSTANCE_ID);
1272         Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
1273         when(toscaOperationFacade
1274                      .addComponentInstanceToTopologyTemplate(eq(service), eq(resource), eq(inputComponentInstance),
1275                              eq(false), isNull(User.class))).thenReturn(result2);
1276         Either<Map<String, ArtifactDefinition>, StorageOperationStatus> getResourceDeploymentArtifacts =
1277                 Either.left(new HashMap<String, ArtifactDefinition>());
1278         when(artifactBusinessLogic.getArtifacts(eq(inputComponentInstance.getComponentUid()), eq(NodeTypeEnum.Resource),
1279                 eq(ArtifactGroupTypeEnum.DEPLOYMENT), isNull(String.class))).thenReturn(getResourceDeploymentArtifacts);
1280         StorageOperationStatus artStatus = StorageOperationStatus.OK;
1281         when(toscaOperationFacade
1282                      .addInformationalArtifactsToInstance(eq(resource.getUniqueId()), eq(inputComponentInstance),
1283                              isNull(Map.class))).thenReturn(artStatus);
1284
1285         result = componentInstanceBusinessLogic
1286                          .copyComponentInstance(inputComponentInstance, containerComponentId, componentInstanceId,
1287                                  USER_ID);
1288
1289         service.setLastUpdaterUserId(oldServiceLastUpdatedUserId);
1290         resource.setLifecycleState(oldResourceLifeCycle);
1291
1292         assertThat(result.isLeft());
1293     }
1294
1295     @Test
1296     public void testCreateOrUpdateAttributeValueForCopyPaste() {
1297         ComponentInstance serviceComponentInstance = createComponetInstanceFromComponent(service);
1298         ComponentInstanceProperty attribute = new ComponentInstanceProperty();
1299         attribute.setType("string");
1300         attribute.setUniqueId("testCreateOrUpdateAttributeValueForCopyPaste");
1301         SchemaDefinition def = Mockito.mock(SchemaDefinition.class);
1302         attribute.setSchema(def);
1303         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1304         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1305         service.setLastUpdaterUserId(USER_ID);
1306         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1307
1308         Map<String, List<ComponentInstanceProperty>> instAttrsMap =
1309                 new HashMap<String, List<ComponentInstanceProperty>>();
1310         List<ComponentInstanceProperty> instAttrsList = new ArrayList<ComponentInstanceProperty>();
1311         ComponentInstanceProperty prop = new ComponentInstanceProperty();
1312         prop.setUniqueId(attribute.getUniqueId());
1313         instAttrsList.add(prop);
1314         instAttrsMap.put(toInstance.getUniqueId(), instAttrsList);
1315         service.setComponentInstancesAttributes(instAttrsMap);
1316
1317         Either<Component, StorageOperationStatus> serviceEitherLeft = Either.left(service);
1318         when(toscaOperationFacade.getToscaElement(serviceComponentInstance.getUniqueId(), JsonParseFlagEnum.ParseAll))
1319                 .thenReturn(serviceEitherLeft);
1320         when(toscaOperationFacade.updateComponentInstanceAttribute(service, toInstance.getUniqueId(), attribute))
1321                 .thenReturn(StorageOperationStatus.OK);
1322         when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
1323                 .thenReturn(serviceEitherLeft);
1324
1325         Either<ComponentInstanceProperty, ResponseFormat> result = Deencapsulation
1326                                                                            .invoke(componentInstanceBusinessLogic,
1327                                                                                    "createOrUpdateAttributeValueForCopyPaste",
1328                                                                                    ComponentTypeEnum.SERVICE,
1329                                                                                    serviceComponentInstance
1330                                                                                            .getUniqueId(),
1331                                                                                    toInstance.getUniqueId(), attribute,
1332                                                                                    USER_ID);
1333
1334         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1335         service.setLifecycleState(oldLifeCycleState);
1336
1337         assertTrue(result.isLeft());
1338         ComponentInstanceProperty resultProp = result.left().value();
1339         assertEquals(resultProp.getPath().size(), 1);
1340         assertEquals(resultProp.getPath().get(0), toInstance.getUniqueId());
1341     }
1342
1343     @Test
1344     public void testUpdateComponentInstanceProperty() {
1345
1346         String containerComponentId = service.getUniqueId();
1347         String componentInstanceId = "dummy_id";
1348         ComponentInstanceProperty property = Mockito.mock(ComponentInstanceProperty.class);
1349
1350         Either<Component, StorageOperationStatus> getComponent = Either.left(service);
1351         when(toscaOperationFacade.getToscaElement(containerComponentId)).thenReturn(getComponent);
1352         StorageOperationStatus status = StorageOperationStatus.OK;
1353         when(toscaOperationFacade.updateComponentInstanceProperty(service, componentInstanceId, property))
1354                 .thenReturn(status);
1355         Either<Component, StorageOperationStatus> updateContainerRes = Either.left(service);
1356         when(toscaOperationFacade.updateComponentInstanceMetadataOfTopologyTemplate(service))
1357                 .thenReturn(updateContainerRes);
1358
1359         Either<String, ResponseFormat> result = Deencapsulation.invoke(componentInstanceBusinessLogic,
1360                 "updateComponentInstanceProperty", containerComponentId, componentInstanceId, property);
1361
1362         assertTrue(result.isLeft());
1363     }
1364
1365     @Test
1366     public void testGetInputListDefaultValue() {
1367         Component component = service;
1368         String inputId = "dummy_id";
1369         String defaultValue = "dummy_default_value";
1370         List<InputDefinition> newInputs = new ArrayList<InputDefinition>();
1371         InputDefinition in = new InputDefinition();
1372         in.setUniqueId(inputId);
1373         in.setDefaultValue(defaultValue);
1374         newInputs.add(in);
1375         List<InputDefinition> oldInputs = service.getInputs();
1376         service.setInputs(newInputs);
1377
1378         Either<String, ResponseFormat> result =
1379                 Deencapsulation.invoke(componentInstanceBusinessLogic, "getInputListDefaultValue", component, inputId);
1380
1381         service.setInputs(oldInputs);
1382
1383         assertEquals(result.left().value(), defaultValue);
1384     }
1385
1386     @Test
1387     public void testBatchDeleteComponentInstanceFailureWrongType() {
1388         Map<String, List<String>> result;
1389         List<String> componentInstanceIdList = new ArrayList<>();
1390         String containerComponentParam = "WRONG_TYPE";
1391         String containerComponentId = "containerComponentId";
1392         String componentInstanceId = "componentInstanceId";
1393         componentInstanceIdList.add(componentInstanceId);
1394         String userId = USER_ID;
1395         Map<String, List<String>> deleteErrorMap = new HashMap<>();
1396         List<String> deleteErrorIds = new ArrayList<>();
1397         deleteErrorIds.add(componentInstanceId);
1398         deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
1399
1400         result = componentInstanceBusinessLogic
1401                          .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
1402                                  componentInstanceIdList, userId);
1403
1404         assertEquals(deleteErrorMap, result);
1405     }
1406
1407     @Test
1408     public void testBatchDeleteComponentInstanceFailureCompIds() {
1409         Map<String, List<String>> result;
1410         String containerComponentParam = ComponentTypeEnum.SERVICE_PARAM_NAME;
1411         String containerComponentId = "containerComponentId";
1412         String componentInstanceId = "componentInstanceId";
1413         List<String> componentInstanceIdList = new ArrayList<>();
1414         componentInstanceIdList.add(componentInstanceId);
1415         String userId = USER_ID;
1416         Map<String, List<String>> deleteErrorMap = new HashMap<>();
1417         List<String> deleteErrorIds = new ArrayList<>();
1418         deleteErrorIds.add(componentInstanceId);
1419         deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
1420
1421         Either<Component, StorageOperationStatus> err = Either.right(StorageOperationStatus.GENERAL_ERROR);
1422         when(toscaOperationFacade.getToscaElement(eq(containerComponentId), any(ComponentParametersView.class)))
1423                 .thenReturn(err);
1424
1425         result = componentInstanceBusinessLogic
1426                          .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
1427                                  componentInstanceIdList, userId);
1428
1429         assertEquals(deleteErrorMap, result);
1430     }
1431
1432     @Test
1433     public void testBatchDeleteComponentInstanceSuccess() {
1434         Map<String, List<String>> result;
1435         String containerComponentParam = ComponentTypeEnum.SERVICE_PARAM_NAME;
1436         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1437         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1438         service.setLastUpdaterUserId(USER_ID);
1439         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1440         String containerComponentId = service.getUniqueId();
1441         String componentInstanceId = TO_INSTANCE_ID;
1442         String userId = USER_ID;
1443         List<String> componentInstanceIdList = new ArrayList<>();
1444         componentInstanceIdList.add(componentInstanceId);
1445         Map<String, List<String>> deleteErrorMap = new HashMap<>();
1446         List<String> deleteErrorIds = new ArrayList<>();
1447         deleteErrorMap.put("deleteFailedIds", deleteErrorIds);
1448
1449         Either<Component, StorageOperationStatus> cont = Either.left(service);
1450         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1451                 .thenReturn(StorageOperationStatus.OK);
1452         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1453                 .thenReturn(StorageOperationStatus.OK);
1454         ImmutablePair<Component, String> pair = new ImmutablePair<>(resource, TO_INSTANCE_ID);
1455         Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
1456         when(toscaOperationFacade.deleteComponentInstanceFromTopologyTemplate(service, componentInstanceId))
1457                 .thenReturn(result2);
1458         when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
1459                 .thenReturn(cont);
1460         when(janusGraphDao.commit()).thenReturn(JanusGraphOperationStatus.OK);
1461
1462         result = componentInstanceBusinessLogic
1463                          .batchDeleteComponentInstance(containerComponentParam, containerComponentId,
1464                                  componentInstanceIdList, userId);
1465
1466         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1467         service.setLifecycleState(oldLifeCycleState);
1468         assertEquals(deleteErrorMap, result);
1469     }
1470
1471     @Test
1472     public void testDissociateRIFromRIFailDissociate() {
1473
1474         List<RequirementCapabilityRelDef> result;
1475         RequirementCapabilityRelDef ref = new RequirementCapabilityRelDef();
1476         ref.setFromNode(FROM_INSTANCE_ID);
1477         ref.setToNode(TO_INSTANCE_ID);
1478         List<CapabilityRequirementRelationship> relationships = new ArrayList<>();
1479         CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
1480         RelationshipInfo ri = new RelationshipInfo();
1481         ri.setRequirement(REQUIREMENT_NAME);
1482         relationship.setRelation(ri);
1483         relationships.add(relationship);
1484         ref.setRelationships(relationships);
1485         List<RequirementCapabilityRelDef> requirementDefList = new ArrayList<>();
1486         requirementDefList.add(ref);
1487         ComponentTypeEnum componentTypeEnum = service.getComponentType();
1488         String componentId = service.getUniqueId();
1489         String userId = USER_ID;
1490         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1491         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1492         service.setLastUpdaterUserId(USER_ID);
1493         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1494
1495         Either<Component, StorageOperationStatus> cont = Either.left(service);
1496         when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
1497                 .thenReturn(cont);
1498         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1499                 .thenReturn(StorageOperationStatus.OK);
1500         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1501                 .thenReturn(StorageOperationStatus.OK);
1502         Either<RequirementCapabilityRelDef, StorageOperationStatus> resultEither;
1503         resultEither = Either.right(StorageOperationStatus.OK);
1504         when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
1505
1506         result = componentInstanceBusinessLogic
1507                          .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
1508
1509         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1510         service.setLifecycleState(oldLifeCycleState);
1511
1512         assertEquals(new ArrayList<>(), result);
1513     }
1514
1515     @Test
1516     public void testDissociateRIFromRISuccess() {
1517
1518         List<RequirementCapabilityRelDef> result;
1519         RequirementCapabilityRelDef ref = new RequirementCapabilityRelDef();
1520         List<RequirementCapabilityRelDef> requirementDefList = new ArrayList<>();
1521         requirementDefList.add(ref);
1522         ComponentTypeEnum componentTypeEnum = service.getComponentType();
1523         String componentId = service.getUniqueId();
1524         String userId = USER_ID;
1525         LifecycleStateEnum oldLifeCycleState = service.getLifecycleState();
1526         String oldLastUpdatedUserId = service.getLastUpdaterUserId();
1527         service.setLastUpdaterUserId(USER_ID);
1528         service.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
1529
1530         Either<Component, StorageOperationStatus> cont = Either.left(service);
1531         when(toscaOperationFacade.getToscaElement(eq(service.getUniqueId()), any(ComponentParametersView.class)))
1532                 .thenReturn(cont);
1533         when(graphLockOperation.unlockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1534                 .thenReturn(StorageOperationStatus.OK);
1535         when(graphLockOperation.lockComponent(Mockito.anyString(), eq(NodeTypeEnum.Service)))
1536                 .thenReturn(StorageOperationStatus.OK);
1537         Either<RequirementCapabilityRelDef, StorageOperationStatus> resultEither;
1538         resultEither = Either.left(ref);
1539         when(toscaOperationFacade.dissociateResourceInstances(componentId, ref)).thenReturn(resultEither);
1540
1541         result = componentInstanceBusinessLogic
1542                          .batchDissociateRIFromRI(componentId, userId, requirementDefList, componentTypeEnum);
1543
1544         service.setLastUpdaterUserId(oldLastUpdatedUserId);
1545         service.setLifecycleState(oldLifeCycleState);
1546
1547         assertEquals(requirementDefList, result);
1548     }
1549
1550     @Test
1551     public void testGetComponentInstancePropertyByPolicyId_success() {
1552         Optional<ComponentInstanceProperty> propertyCandidate =
1553                 getComponentInstanceProperty(PROP_NAME);
1554
1555         Assert.assertTrue(propertyCandidate.isPresent());
1556         Assert.assertEquals(propertyCandidate.get().getName(), PROP_NAME);
1557     }
1558
1559     @Test
1560     public void testGetComponentInstancePropertyByPolicyId_failure() {
1561         Optional<ComponentInstanceProperty> propertyCandidate =
1562                 getComponentInstanceProperty(NON_EXIST_NAME);
1563
1564         Assert.assertEquals(propertyCandidate, Optional.empty());
1565     }
1566
1567     private Optional<ComponentInstanceProperty> getComponentInstanceProperty(String propertyName) {
1568         ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
1569         componentInstanceProperty.setName(propertyName);
1570
1571         PolicyDefinition policyDefinition = getPolicyDefinition();
1572         componentInstanceProperty.setGetPolicyValues(policyDefinition.getGetPolicyValues());
1573
1574         service.setComponentInstancesProperties(
1575                 Collections.singletonMap(COMPONENT_INST_ID, Collections.singletonList(componentInstanceProperty)));
1576
1577         return componentInstanceBusinessLogic.getComponentInstancePropertyByPolicyId(service, policyDefinition);
1578     }
1579
1580     private PolicyDefinition getPolicyDefinition() {
1581         PolicyDefinition policyDefinition = new PolicyDefinition();
1582         policyDefinition.setInstanceUniqueId(COMPONENT_INST_ID);
1583         policyDefinition.setName(PROP_NAME);
1584
1585         GetPolicyValueDataDefinition getPolicy = new GetPolicyValueDataDefinition();
1586         getPolicy.setPropertyName(PROP_NAME);
1587
1588         List<GetPolicyValueDataDefinition> getPolicies = new ArrayList<>();
1589         getPolicies.add(getPolicy);
1590         policyDefinition.setGetPolicyValues(getPolicies);
1591
1592         return policyDefinition;
1593     }
1594
1595     private ComponentInstance createComponetInstanceFromComponent(Component component) {
1596         ComponentInstance componentInst = new ComponentInstance();
1597         componentInst.setUniqueId(component.getUniqueId());
1598         componentInst.setComponentUid(component.getUniqueId() + "_test");
1599         componentInst.setPosX("10");
1600         componentInst.setPosY("10");
1601         componentInst.setCapabilities(component.getCapabilities());
1602         componentInst.setRequirements(component.getRequirements());
1603         componentInst.setArtifacts(component.getArtifacts());
1604         componentInst.setDeploymentArtifacts(component.getDeploymentArtifacts());
1605         return componentInst;
1606     }
1607 }