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