1 package org.openecomp.sdc.be.components.impl;
3 import static org.junit.Assert.assertSame;
4 import static org.assertj.core.api.Assertions.assertThat;
9 import mockit.Deencapsulation;
10 import org.apache.commons.lang3.tuple.ImmutablePair;
11 import org.assertj.core.util.Lists;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Ignore;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.InjectMocks;
18 import org.mockito.Mock;
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.types.JsonParseFlagEnum;
24 import org.openecomp.sdc.be.datatypes.elements.*;
25 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
26 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
27 import org.openecomp.sdc.be.impl.ComponentsUtils;
28 import org.openecomp.sdc.be.impl.ServletUtils;
29 import org.openecomp.sdc.be.info.CreateAndAssotiateInfo;
30 import org.openecomp.sdc.be.model.*;
31 import org.openecomp.sdc.be.model.LifecycleStateEnum;
32 import org.openecomp.sdc.be.model.jsontitan.operations.ForwardingPathOperation;
33 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
34 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
35 import org.openecomp.sdc.be.user.UserBusinessLogic;
36 import org.openecomp.sdc.exception.ResponseFormat;
38 import java.util.function.BiPredicate;
40 import static org.junit.Assert.assertTrue;
41 import static org.mockito.ArgumentMatchers.any;
42 import static org.mockito.ArgumentMatchers.anySet;
43 import static org.mockito.ArgumentMatchers.anyString;
44 import static org.mockito.ArgumentMatchers.eq;
45 import static org.mockito.Mockito.when;
47 import static org.junit.Assert.assertTrue;
48 import static org.mockito.ArgumentMatchers.*;
49 import static org.mockito.Mockito.when;
52 * The test suite designed for test functionality of ComponentInstanceBusinessLogic class
55 @RunWith(MockitoJUnitRunner.class)
56 public class ComponentInstanceBusinessLogicTest {
58 private final static String USER_ID = "jh0003";
59 private final static String COMPONENT_ID = "componentId";
60 private final static String TO_INSTANCE_ID = "toInstanceId";
61 private final static String FROM_INSTANCE_ID = "fromInstanceId";
62 private final static String RELATION_ID = "relationId";
63 private final static String CAPABILITY_OWNER_ID = "capabilityOwnerId";
64 private final static String CAPABILITY_UID = "capabilityUid";
65 private final static String CAPABILITY_NAME = "capabilityName";
66 private final static String REQUIREMENT_OWNER_ID = "requirementOwnerId";
67 private final static String REQUIREMENT_UID = "requirementUid";
68 private final static String REQUIREMENT_NAME = "requirementName";
69 private final static String RELATIONSHIP_TYPE = "relationshipType";
72 private static ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
74 private ComponentsUtils componentsUtils;
76 private ServletUtils servletUtils;
78 private ResponseFormat responseFormat;
80 private ToscaOperationFacade toscaOperationFacade;
82 private UserBusinessLogic userAdmin;
84 private ForwardingPathOperation forwardingPathOperation;
88 private UserValidations userValidations;
89 private Component service;
90 private Component resource;
91 private ComponentInstance toInstance;
92 private ComponentInstance fromInstance;
93 private CapabilityDataDefinition capability;
94 private RequirementDataDefinition requirement;
95 private RequirementCapabilityRelDef relation;
105 public void testGetRelationByIdSuccess(){
106 getServiceRelationByIdSuccess(service);
107 getServiceRelationByIdSuccess(resource);
111 public void testGetRelationByIdUserValidationFailure(){
112 getServiceRelationByIdUserValidationFailure(service);
113 getServiceRelationByIdUserValidationFailure(resource);
117 public void testGetRelationByIdComponentNotFoundFailure(){
118 getRelationByIdComponentNotFoundFailure(service);
119 getRelationByIdComponentNotFoundFailure(resource);
123 public void testForwardingPathOnVersionChange(){
124 getforwardingPathOnVersionChange();
127 private void getforwardingPathOnVersionChange(){
128 String containerComponentParam="services";
129 String containerComponentID="121-cont";
130 String componentInstanceID="121-cont-1-comp";
131 Service component=new Service();
132 Map<String, ForwardingPathDataDefinition> forwardingPaths = generateForwardingPath(componentInstanceID);
134 //Add existing componentInstance to component
135 List<ComponentInstance> componentInstanceList=new ArrayList<>();
136 ComponentInstance oldComponentInstance=new ComponentInstance();
137 oldComponentInstance.setName("OLD_COMP_INSTANCE");
138 oldComponentInstance.setUniqueId(componentInstanceID);
139 oldComponentInstance.setName(componentInstanceID);
140 oldComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,"1-comp");
141 componentInstanceList.add(oldComponentInstance);
142 component.setComponentInstances(componentInstanceList);
143 component.setForwardingPaths(forwardingPaths);
145 List<ComponentInstance> componentInstanceListNew=new ArrayList<>();
146 ComponentInstance newComponentInstance=new ComponentInstance();
147 String new_Comp_UID="2-comp";
148 newComponentInstance.setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID,new_Comp_UID);
149 newComponentInstance.setUniqueId(new_Comp_UID);
150 componentInstanceListNew.add(newComponentInstance);
151 Component component2=new Service();
152 component2.setComponentInstances(componentInstanceListNew);
154 //Mock for getting component
155 when(toscaOperationFacade.getToscaElement(eq(containerComponentID),any(ComponentParametersView.class))).thenReturn(Either.left(component));
156 when(toscaOperationFacade.validateComponentExists(any(String.class))).thenReturn(Either.left(Boolean.TRUE));
157 when(toscaOperationFacade.getToscaFullElement(eq(new_Comp_UID))).thenReturn(Either.left(component2));
159 Either<Set<String>, ResponseFormat> resultOp = componentInstanceBusinessLogic.forwardingPathOnVersionChange
160 (containerComponentParam,containerComponentID,componentInstanceID,newComponentInstance);
161 Assert.assertEquals(1,resultOp.left().value().size());
162 Assert.assertEquals("FP-ID-1",resultOp.left().value().iterator().next());
168 public void testDeleteForwardingPathsWhenComponentinstanceDeleted(){
170 ComponentTypeEnum containerComponentType = ComponentTypeEnum.findByParamName("services");
171 String containerComponentID = "Service-comp";
172 String componentInstanceID = "NodeA1";
173 Service component = new Service();
174 component.setComponentInstances(Arrays.asList(createComponentIstance("NodeA2"),createComponentIstance("NodeB2"),
175 createComponentIstance(componentInstanceID)));
177 component.addForwardingPath(createPath("path1", componentInstanceID, "NodeB1", "1"));
178 component.addForwardingPath(createPath("Path2", "NodeA2","NodeB2", "2"));
179 when(toscaOperationFacade.getToscaElement(eq(containerComponentID),any(ComponentParametersView.class))).thenReturn(Either.left(component));
180 when(toscaOperationFacade.getToscaElement(eq(containerComponentID))).thenReturn(Either.left(component));
181 when(forwardingPathOperation.deleteForwardingPath(any(Service.class), anySet())).thenReturn(Either.left(new HashSet<>()));
182 final ComponentInstance ci = new ComponentInstance();
183 ci.setName(componentInstanceID);
184 Either<ComponentInstance, ResponseFormat> responseFormatEither = componentInstanceBusinessLogic.deleteForwardingPathsRelatedTobeDeletedComponentInstance(
185 containerComponentID, containerComponentType, Either.left(ci));
186 assertThat(responseFormatEither.isLeft()).isEqualTo(true);
190 private ComponentInstance createComponentIstance(String path1) {
191 ComponentInstance componentInstance = new ComponentInstance();
192 componentInstance.setName(path1);
193 return componentInstance;
196 private ForwardingPathDataDefinition createPath(String pathName, String fromNode, String toNode , String uniqueId){
197 ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition(pathName);
198 forwardingPath.setProtocol("protocol");
199 forwardingPath.setDestinationPortNumber("port");
200 forwardingPath.setUniqueId(uniqueId);
201 ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition = new ListDataDefinition<>();
202 forwardingPathElementListDataDefinition.add(new ForwardingPathElementDataDefinition(fromNode, toNode,
203 "nodeAcpType", "nodeBcpType", "nodeDcpName", "nodeBcpName"));
204 forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
206 return forwardingPath;
211 private Map<String, ForwardingPathDataDefinition> generateForwardingPath(String componentInstanceID) {
212 ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition("fpName");
213 String protocol = "protocol";
214 forwardingPath.setProtocol(protocol);
215 forwardingPath.setDestinationPortNumber("DestinationPortNumber");
216 forwardingPath.setUniqueId("FP-ID-1");
217 ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition =
218 new ListDataDefinition<>();
219 forwardingPathElementListDataDefinition.add(
220 new ForwardingPathElementDataDefinition(componentInstanceID, "nodeB", "nodeA_FORWARDER_CAPABILITY",
221 "nodeBcpType" , "nodeDcpName",
223 forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
224 Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
225 forwardingPaths.put("1122", forwardingPath);
226 return forwardingPaths;
229 @SuppressWarnings("unchecked")
230 private void getServiceRelationByIdSuccess(Component component){
231 Either<Component, StorageOperationStatus> getComponentRes = Either.left(component);
232 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(getComponentRes);
233 Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic.getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
234 assertTrue(response.isLeft());
237 private void getServiceRelationByIdUserValidationFailure(Component component){
238 when(userValidations.validateUserExists(eq(USER_ID), eq("get relation by Id"), eq(false))).thenThrow(new ComponentException(ActionStatus.USER_NOT_FOUND));
240 componentInstanceBusinessLogic.getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
241 } catch(ComponentException e){
242 assertSame(e.getActionStatus(), ActionStatus.USER_NOT_FOUND);
246 private void getRelationByIdComponentNotFoundFailure(Component component){
247 Either<User, ActionStatus> eitherCreator = Either.left(user);
248 Either<Component, StorageOperationStatus> getComponentRes = Either.right(StorageOperationStatus.NOT_FOUND);
249 when(toscaOperationFacade.getToscaElement(eq(COMPONENT_ID), any(ComponentParametersView.class))).thenReturn(getComponentRes);
251 Either<RequirementCapabilityRelDef, ResponseFormat> response = componentInstanceBusinessLogic.getRelationById(COMPONENT_ID, RELATION_ID, USER_ID, component.getComponentType());
252 assertTrue(response.isRight());
255 private void stubMethods() {
256 when(userValidations.validateUserExists(eq(USER_ID), eq("get relation by Id"), eq(false))).thenReturn(user);
259 private void createComponents() {
266 private void createResource() {
267 resource = new Resource();
268 resource.setUniqueId(COMPONENT_ID);
269 resource.setComponentInstancesRelations(Lists.newArrayList(relation));
270 resource.setComponentInstances(Lists.newArrayList(toInstance,fromInstance));
271 resource.setCapabilities(toInstance.getCapabilities());
272 resource.setRequirements(fromInstance.getRequirements());
273 resource.setComponentType(ComponentTypeEnum.RESOURCE);
274 resource.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
278 private void createService() {
279 service = new Service();
280 service.setUniqueId(COMPONENT_ID);
281 service.setComponentInstancesRelations(Lists.newArrayList(relation));
282 service.setComponentInstances(Lists.newArrayList(toInstance,fromInstance));
283 service.setCapabilities(toInstance.getCapabilities());
284 service.setRequirements(fromInstance.getRequirements());
285 service.setComponentType(ComponentTypeEnum.SERVICE);
286 service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
290 private void createInstances() {
291 toInstance = new ComponentInstance();
292 toInstance.setUniqueId(TO_INSTANCE_ID);
294 fromInstance = new ComponentInstance();
295 fromInstance.setUniqueId(FROM_INSTANCE_ID);
297 capability = new CapabilityDataDefinition();
298 capability.setOwnerId(CAPABILITY_OWNER_ID);
299 capability.setUniqueId(CAPABILITY_UID);
300 capability.setName(CAPABILITY_NAME);
302 Map<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
303 capabilities.put(capability.getName(), Lists.newArrayList(new CapabilityDefinition(capability)));
305 requirement = new RequirementDataDefinition();
306 requirement.setOwnerId(REQUIREMENT_OWNER_ID);
307 requirement.setUniqueId(REQUIREMENT_UID);
308 requirement.setName(REQUIREMENT_NAME);
309 requirement.setRelationship(RELATIONSHIP_TYPE);
312 Map<String, List<RequirementDefinition>> requirements = new HashMap<>();
313 requirements.put(requirement.getCapability(), Lists.newArrayList(new RequirementDefinition(requirement)));
315 toInstance.setCapabilities(capabilities);
316 fromInstance.setRequirements(requirements);
320 private void createRelation() {
322 relation = new RequirementCapabilityRelDef();
323 CapabilityRequirementRelationship relationship = new CapabilityRequirementRelationship();
324 RelationshipInfo relationInfo = new RelationshipInfo();
325 relationInfo.setId(RELATION_ID);
326 relationship.setRelation(relationInfo);
328 relation.setRelationships(Lists.newArrayList(relationship));
329 relation.setToNode(TO_INSTANCE_ID);
330 relation.setFromNode(FROM_INSTANCE_ID);
332 relationInfo.setCapabilityOwnerId(CAPABILITY_OWNER_ID);
333 relationInfo.setCapabilityUid(CAPABILITY_UID);
334 relationInfo.setCapability(CAPABILITY_NAME);
335 relationInfo.setRequirementOwnerId(REQUIREMENT_OWNER_ID);
336 relationInfo.setRequirementUid(REQUIREMENT_UID);
337 relationInfo.setRequirement(REQUIREMENT_NAME);
338 RelationshipImpl relationshipImpl = new RelationshipImpl();
339 relationshipImpl.setType(RELATIONSHIP_TYPE);
340 relationInfo.setRelationships(relationshipImpl);
343 private ComponentInstanceBusinessLogic createTestSubject() {
344 return componentInstanceBusinessLogic;
352 public void testChangeServiceProxyVersion(){
353 ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
355 Either<ComponentInstance, ResponseFormat> result;
358 componentInstanceBusinessLogic = createTestSubject();
359 result = componentInstanceBusinessLogic.changeServiceProxyVersion();
369 public void testCreateServiceProxy() {
370 ComponentInstanceBusinessLogic testSubject;
371 Either<ComponentInstance, ResponseFormat> result;
374 testSubject = createTestSubject();
375 result = testSubject.createServiceProxy();
383 public void testDeleteForwardingPathsRelatedTobeDeletedComponentInstance() {
384 ComponentInstanceBusinessLogic testSubject;
385 String containerComponentId = "";
386 String componentInstanceId = "";
387 ComponentTypeEnum containerComponentType = ComponentTypeEnum.RESOURCE;
388 Either<ComponentInstance, ResponseFormat> resultOp = null;
389 Either<ComponentInstance, ResponseFormat> result;
392 testSubject = createTestSubject();
393 result = testSubject.deleteForwardingPathsRelatedTobeDeletedComponentInstance(containerComponentId,
394 containerComponentType, resultOp);
399 public void testDeleteServiceProxy() {
400 ComponentInstanceBusinessLogic testSubject;
402 Either<ComponentInstance, ResponseFormat> result;
405 testSubject = createTestSubject();
406 result = testSubject.deleteServiceProxy();
415 public void testGetComponentInstanceInputsByInputId() {
416 ComponentInstanceBusinessLogic testSubject;
417 Component component = new Service();
419 List<ComponentInstanceInput> result;
422 testSubject = createTestSubject();
423 result = testSubject.getComponentInstanceInputsByInputId(component, inputId);
429 public void testGetComponentInstancePropertiesByInputId() {
430 ComponentInstanceBusinessLogic testSubject;
431 Component component = new Service();
433 List<ComponentInstanceProperty> result;
436 testSubject = createTestSubject();
437 result = testSubject.getComponentInstancePropertiesByInputId(component, inputId);
442 public void testGetRelationById() {
443 ComponentInstanceBusinessLogic testSubject;
444 String componentId = "";
445 String relationId = "";
446 String userId = user.getUserId();
447 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE_INSTANCE;
448 Either<RequirementCapabilityRelDef, ResponseFormat> result;
451 testSubject = createTestSubject();
452 result = testSubject.getRelationById(componentId, relationId, userId, componentTypeEnum);
460 public void testCreateComponentInstance_1() {
461 ComponentInstanceBusinessLogic testSubject;String containerComponentParam = "";
462 String containerComponentId = "";
463 String userId = user.getUserId();
464 ComponentInstance resourceInstance = null;
465 boolean inTransaction = false;
466 boolean needLock = false;
467 Either<ComponentInstance,ResponseFormat> result;
470 testSubject=createTestSubject();result=testSubject.createComponentInstance(containerComponentParam, containerComponentId, userId, resourceInstance, inTransaction, needLock);
478 public void testCreateAndAssociateRIToRI() {
479 ComponentInstanceBusinessLogic testSubject;
481 String containerComponentParam = "";
482 String containerComponentId = "";
483 String userId = user.getUserId();
484 CreateAndAssotiateInfo createAndAssotiateInfo = new CreateAndAssotiateInfo(null, null);
485 Either<CreateAndAssotiateInfo,ResponseFormat> result;
488 testSubject=createTestSubject();
489 result=testSubject.createAndAssociateRIToRI(containerComponentParam, containerComponentId, userId, createAndAssotiateInfo);
493 public void testGetOriginComponentFromComponentInstance_1() {
494 ComponentInstanceBusinessLogic testSubject;
496 String componentInstanceName = "";
497 String origComponetId = resource.getUniqueId();
498 Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resource);
499 when(toscaOperationFacade.getToscaFullElement(resource.getUniqueId())).thenReturn(oldResourceRes);
500 Either<Component,ResponseFormat> result;
503 testSubject=createTestSubject();
504 result=Deencapsulation.invoke(testSubject, "getOriginComponentFromComponentInstance", new Object[]{componentInstanceName, origComponetId});
509 public void testCreateComponentInstanceOnGraph() {
510 ComponentInstanceBusinessLogic testSubject;
513 Either<ComponentInstance,ResponseFormat> result;
515 Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND);
516 when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource,toInstance, false, user)).thenReturn(result2);
519 testSubject=createTestSubject();
520 result=Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph", new Object[]{resource, resource, toInstance, user});
523 @Ignore("test failing skipping for now")
525 public void testCreateComponentInstanceOnGraph2() {
526 ComponentInstanceBusinessLogic testSubject;
528 resource.setName("name");
530 Either<ComponentInstance,ResponseFormat> result;
531 ImmutablePair<Component, String> pair = new ImmutablePair<>(resource,"");
536 Either<ImmutablePair<Component, String>, StorageOperationStatus> result2 = Either.left(pair);
537 when(toscaOperationFacade.addComponentInstanceToTopologyTemplate(resource, resource,toInstance, false, user)).thenReturn(result2);
540 testSubject=createTestSubject();
541 result=Deencapsulation.invoke(testSubject, "createComponentInstanceOnGraph", new Object[]{resource, resource, toInstance, user});
545 public void testUpdateComponentInstanceMetadata() {
546 ComponentInstanceBusinessLogic testSubject;
547 String containerComponentParam = "";
548 String containerComponentId = "";
549 String componentInstanceId = "";
550 String userId = user.getUserId();
552 Either<ComponentInstance,ResponseFormat> result;
555 testSubject=createTestSubject();
556 result=testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId, componentInstanceId, userId, toInstance);
561 public void testUpdateComponentInstanceMetadata_1() {
562 ComponentInstanceBusinessLogic testSubject;
563 String containerComponentParam = "";
564 String containerComponentId = "";
565 String componentInstanceId = "";
566 String userId = user.getUserId();
568 boolean inTransaction = false;
569 boolean needLock = false;
570 boolean createNewTransaction = false;
571 Either<ComponentInstance,ResponseFormat> result;
574 testSubject=createTestSubject();
575 result=testSubject.updateComponentInstanceMetadata(containerComponentParam, containerComponentId, componentInstanceId, userId, toInstance, inTransaction, needLock, createNewTransaction);
583 public void testValidateParent() {
584 ComponentInstanceBusinessLogic testSubject;
586 String nodeTemplateId = "";
590 testSubject=createTestSubject();
591 result=Deencapsulation.invoke(testSubject, "validateParent", new Object[]{resource, nodeTemplateId});
596 public void testGetComponentType() {
597 ComponentInstanceBusinessLogic testSubject;
598 ComponentTypeEnum result;
601 testSubject=createTestSubject();
602 result=Deencapsulation.invoke(testSubject, "getComponentType", new Object[]{ComponentTypeEnum.class});
608 public void testGetNewGroupName() {
609 ComponentInstanceBusinessLogic testSubject;String oldPrefix = "";
610 String newNormailzedPrefix = "";
611 String qualifiedGroupInstanceName = "";
615 testSubject=createTestSubject();
616 result=Deencapsulation.invoke(testSubject, "getNewGroupName", new Object[]{oldPrefix, newNormailzedPrefix, qualifiedGroupInstanceName});
621 public void testUpdateComponentInstanceMetadata_3() {
622 ComponentInstanceBusinessLogic testSubject;
624 ComponentInstance newComponentInstance = null;
625 ComponentInstance result;
628 testSubject=createTestSubject();
629 result=Deencapsulation.invoke(testSubject, "updateComponentInstanceMetadata", new Object[]{toInstance, toInstance});
634 public void testDeleteComponentInstance() {
635 ComponentInstanceBusinessLogic testSubject;String containerComponentParam = "";
636 String containerComponentId = "";
637 String componentInstanceId = "";
638 String userId = user.getUserId();
639 Either<ComponentInstance,ResponseFormat> result;
642 testSubject=createTestSubject();
643 result=testSubject.deleteComponentInstance(containerComponentParam, containerComponentId, componentInstanceId, userId);
648 public void testDeleteForwardingPaths() {
649 ComponentInstanceBusinessLogic testSubject;
651 String serviceId = service.getUniqueId();
652 List<String> pathIdsToDelete = new ArrayList<>();
653 Either<Set<String>,ResponseFormat> result;
655 // Either<Service, StorageOperationStatus> storageStatus = toscaOperationFacade.getToscaElement(serviceId);
656 when(toscaOperationFacade.getToscaElement(serviceId)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
659 testSubject=createTestSubject();
660 result=Deencapsulation.invoke(testSubject, "deleteForwardingPaths", new Object[]{serviceId, pathIdsToDelete});
665 public void testAssociateRIToRIOnGraph() throws Exception {
666 ComponentInstanceBusinessLogic testSubject;
668 RequirementCapabilityRelDef requirementDef = new RequirementCapabilityRelDef();
669 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
670 boolean inTransaction = false;
671 Either<RequirementCapabilityRelDef,ResponseFormat> result;
675 Either<RequirementCapabilityRelDef, StorageOperationStatus> getResourceResult = Either.left(requirementDef);
676 when(toscaOperationFacade.associateResourceInstances(resource.getUniqueId(), requirementDef)).thenReturn(getResourceResult);
679 testSubject=createTestSubject();
680 result=testSubject.associateRIToRIOnGraph(resource, requirementDef, componentTypeEnum, inTransaction);
686 public void testFindRelation() throws Exception {
687 ComponentInstanceBusinessLogic testSubject;
688 String relationId = "";
689 List<RequirementCapabilityRelDef> requirementCapabilityRelations = new ArrayList<>();
690 RequirementCapabilityRelDef result;
693 testSubject=createTestSubject();
694 result=Deencapsulation.invoke(testSubject, "findRelation", new Object[]{relationId, requirementCapabilityRelations});
699 public void testIsNetworkRoleServiceProperty() throws Exception {
700 ComponentInstanceBusinessLogic testSubject;
701 ComponentInstanceProperty property = new ComponentInstanceProperty();
702 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
706 testSubject=createTestSubject();
707 result=Deencapsulation.invoke(testSubject, "isNetworkRoleServiceProperty", new Object[]{property, componentTypeEnum});
712 public void testConcatServiceNameToVLINetworkRolePropertiesValues() throws Exception {
713 ComponentInstanceBusinessLogic testSubject;
714 ToscaOperationFacade toscaOperationFacade = new ToscaOperationFacade();
715 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
716 String componentId = "";
717 String resourceInstanceId = "";
718 List<ComponentInstanceProperty> properties = new ArrayList<>();
719 StorageOperationStatus result;
722 testSubject=createTestSubject();
723 result=Deencapsulation.invoke(testSubject, "concatServiceNameToVLINetworkRolePropertiesValues", new Object[]{toscaOperationFacade, componentTypeEnum, componentId, resourceInstanceId, properties});
728 public void testCreateOrUpdatePropertiesValues() throws Exception {
729 ComponentInstanceBusinessLogic testSubject;
730 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
732 String componentId = resource.getUniqueId();
733 String resourceInstanceId = "";
734 List<ComponentInstanceProperty> properties = new ArrayList<>();
735 String userId = user.getUserId();
736 Either<List<ComponentInstanceProperty>,ResponseFormat> result;
739 when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(resource));
742 testSubject=createTestSubject();
743 result=testSubject.createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties, userId);
745 componentTypeEnum =null;
746 result=testSubject.createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties, userId);
748 // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
749 result=testSubject.createOrUpdatePropertiesValues(componentTypeEnum, componentId, resourceInstanceId, properties, userId);
755 public void testUpdateCapabilityPropertyOnContainerComponent() throws Exception {
756 ComponentInstanceBusinessLogic testSubject;
757 ComponentInstanceProperty property = new ComponentInstanceProperty();
758 String newValue = "";
761 String capabilityType = "";
762 String capabilityName = "";
763 ResponseFormat result;
766 testSubject=createTestSubject();
767 result=Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent", new Object[]{property, newValue, resource, toInstance, capabilityType, capabilityName});
773 public void testCreateOrUpdateInstanceInputValues() throws Exception {
774 ComponentInstanceBusinessLogic testSubject;
775 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
777 String componentId = resource.getUniqueId();
778 String resourceInstanceId = "";
779 List<ComponentInstanceInput> inputs = new ArrayList<>();
780 String userId = user.getUserId();
781 Either<List<ComponentInstanceInput>,ResponseFormat> result;
783 when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.left(resource));
786 testSubject=createTestSubject();
787 result=testSubject.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs, userId);
788 componentTypeEnum =null;
789 result=testSubject.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs, userId);
792 // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseAll)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
793 result=testSubject.createOrUpdateInstanceInputValues(componentTypeEnum, componentId, resourceInstanceId, inputs, userId);
799 public void testCreateOrUpdateGroupInstancePropertyValue() throws Exception {
800 ComponentInstanceBusinessLogic testSubject;
801 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
803 String componentId = resource.getUniqueId();
804 String resourceInstanceId = "";
805 String groupInstanceId = "";
806 ComponentInstanceProperty property = new ComponentInstanceProperty();
807 String userId = user.getUserId();
808 Either<ComponentInstanceProperty,ResponseFormat> result;
811 when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.left(resource));
814 testSubject=createTestSubject();
815 result=testSubject.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId, groupInstanceId, property, userId);
816 componentTypeEnum = null;
817 result=testSubject.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId, groupInstanceId, property, userId);
819 // when(toscaOperationFacade.getToscaElement(componentId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
820 result=testSubject.createOrUpdateGroupInstancePropertyValue(componentTypeEnum, componentId, resourceInstanceId, groupInstanceId, property, userId);
825 public void testCreateOrUpdateInputValue() throws Exception {
826 ComponentInstanceBusinessLogic testSubject;
828 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
829 String componentId = resource.getUniqueId();
830 String resourceInstanceId = resource.getUniqueId();
831 ComponentInstanceInput inputProperty = new ComponentInstanceInput();
832 String userId = user.getUserId();
833 Either<ComponentInstanceInput,ResponseFormat> result;
836 Either<Component, StorageOperationStatus> getResourceResult = Either.left(resource);
837 when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata)).thenReturn(getResourceResult);
840 testSubject=createTestSubject();
841 result=testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty, userId);
843 componentTypeEnum = null;
844 result=testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty, userId);
846 // when(toscaOperationFacade.getToscaElement(resource.getUniqueId(), JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
847 result=testSubject.createOrUpdateInputValue(componentTypeEnum, componentId, resourceInstanceId, inputProperty, userId);
852 public void testDeletePropertyValue() throws Exception {
853 ComponentInstanceBusinessLogic testSubject;
854 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
856 String serviceId = service.getUniqueId();
857 String resourceInstanceId = "";
858 String propertyValueId = "";
859 String userId = user.getUserId();
860 Either<ComponentInstanceProperty,ResponseFormat> result;
862 when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.left(service));
865 testSubject=createTestSubject();
866 result=testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId, userId);
867 componentTypeEnum= null;
868 result=testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId, userId);
870 // when(toscaOperationFacade.getToscaElement(serviceId, JsonParseFlagEnum.ParseMetadata)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
871 result=testSubject.deletePropertyValue(componentTypeEnum, serviceId, resourceInstanceId, propertyValueId, userId);
876 public void testGetAndValidateOriginComponentOfComponentInstance() throws Exception {
877 ComponentInstanceBusinessLogic testSubject;
878 ComponentTypeEnum containerComponentType = ComponentTypeEnum.RESOURCE;
881 Either<Component,ResponseFormat> result;
883 when(toscaOperationFacade.getToscaFullElement(toInstance.getComponentUid())).thenReturn(Either.left(resource));
886 testSubject=createTestSubject();
887 result=Deencapsulation.invoke(testSubject, "getAndValidateOriginComponentOfComponentInstance", new Object[]{containerComponentType, toInstance});
895 public void testGetComponentParametersViewForForwardingPath() throws Exception {
896 ComponentInstanceBusinessLogic testSubject;
897 ComponentParametersView result;
900 testSubject=createTestSubject();
901 result=Deencapsulation.invoke(testSubject, "getComponentParametersViewForForwardingPath");
906 public void testChangeComponentInstanceVersion() throws Exception {
907 ComponentInstanceBusinessLogic testSubject;
908 String containerComponentParam = "";
909 String containerComponentId = "";
910 String componentInstanceId = "";
911 String userId = user.getUserId();
913 ComponentInstance newComponentInstance =toInstance;
914 Either<ComponentInstance,ResponseFormat> result;
917 testSubject=createTestSubject();
918 result=testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId, componentInstanceId, userId, newComponentInstance);
919 newComponentInstance = null;
920 testSubject=createTestSubject();
921 result=testSubject.changeComponentInstanceVersion(containerComponentParam, containerComponentId, componentInstanceId, userId, newComponentInstance);
925 @Ignore("test failing skipping for now")
927 public void testValidateInstanceNameUniquenessUponUpdate() throws Exception {
928 ComponentInstanceBusinessLogic testSubject;
931 String newInstanceName = toInstance.getName();
935 testSubject=createTestSubject();
936 result=Deencapsulation.invoke(testSubject, "validateInstanceNameUniquenessUponUpdate", new Object[]{resource, toInstance, newInstanceName});
941 public void testGetResourceInstanceById() throws Exception {
942 ComponentInstanceBusinessLogic testSubject;
944 String instanceId = "";
945 Either<ComponentInstance,StorageOperationStatus> result;
948 testSubject=createTestSubject();
949 result=Deencapsulation.invoke(testSubject, "getResourceInstanceById", new Object[]{resource, instanceId});
952 @Ignore("test failing skipping for now")
954 public void testBuildComponentInstance() throws Exception {
955 ComponentInstanceBusinessLogic testSubject;
957 ComponentInstance origInstanceForUpdate = null;
958 ComponentInstance result;
961 testSubject=createTestSubject();
962 result=Deencapsulation.invoke(testSubject, "buildComponentInstance", new Object[]{toInstance, toInstance});
970 public void testFindCapabilityOfInstance() throws Exception {
971 ComponentInstanceBusinessLogic testSubject;String componentId = "";
972 String instanceId = "";
973 String capabilityType = "";
974 String capabilityName = "";
976 Map<String,List<CapabilityDefinition>> instanceCapabilities = new HashMap<>();
977 Either<List<ComponentInstanceProperty>,ResponseFormat> result;
980 testSubject=createTestSubject();
981 result=Deencapsulation.invoke(testSubject, "findCapabilityOfInstance", new Object[]{componentId, instanceId, capabilityType, capabilityName, ownerId, instanceCapabilities});
986 public void testFetchComponentInstanceCapabilityProperties() throws Exception {
987 ComponentInstanceBusinessLogic testSubject;String componentId = "";
988 String instanceId = "";
989 String capabilityType = "";
990 String capabilityName = "";
992 Either<List<ComponentInstanceProperty>,ResponseFormat> result;
995 testSubject=createTestSubject();
996 result=Deencapsulation.invoke(testSubject, "fetchComponentInstanceCapabilityProperties", new Object[]{componentId, instanceId, capabilityType, capabilityName, ownerId});
1001 public void testUpdateCapabilityPropertyOnContainerComponent_1() throws Exception {
1002 ComponentInstanceBusinessLogic testSubject;
1003 ComponentInstanceProperty property = new ComponentInstanceProperty();
1004 String newValue = "";
1007 String capabilityType = "";
1008 String capabilityName = "";
1009 String ownerId = "";
1010 ResponseFormat result;
1013 testSubject=createTestSubject();
1014 result=Deencapsulation.invoke(testSubject, "updateCapabilityPropertyOnContainerComponent", new Object[]{property, newValue, resource, toInstance, capabilityType, capabilityName, ownerId});
1019 public void testUpdateInstanceCapabilityProperties() throws Exception {
1020 ComponentInstanceBusinessLogic testSubject;
1021 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1023 String containerComponentId = resource.getUniqueId();
1024 String componentInstanceUniqueId = "";
1025 String capabilityType = "";
1026 String capabilityName = "";
1027 String ownerId = "";
1028 List<ComponentInstanceProperty> properties = new ArrayList<>();
1029 String userId = user.getUserId();
1030 Either<List<ComponentInstanceProperty>,ResponseFormat> result;
1033 when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
1038 testSubject=createTestSubject();
1039 result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
1040 when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.right(StorageOperationStatus.ARTIFACT_NOT_FOUND));
1041 result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
1042 componentTypeEnum = null;
1043 result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, ownerId, properties, userId);
1050 public void testUpdateInstanceCapabilityProperties_1() throws Exception {
1051 ComponentInstanceBusinessLogic testSubject;
1052 ComponentTypeEnum componentTypeEnum = ComponentTypeEnum.RESOURCE;
1054 String containerComponentId = resource.getUniqueId();
1055 String componentInstanceUniqueId = "";
1056 String capabilityType = "";
1057 String capabilityName = "";
1058 List<ComponentInstanceProperty> properties = new ArrayList<>();
1059 String userId = user.getUserId();
1060 Either<List<ComponentInstanceProperty>,ResponseFormat> result;
1063 when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
1065 testSubject=createTestSubject();
1066 result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);
1067 when(toscaOperationFacade.getToscaFullElement(containerComponentId)).thenReturn(Either.left(resource));
1068 result=testSubject.updateInstanceCapabilityProperties(componentTypeEnum, containerComponentId, componentInstanceUniqueId, capabilityType, capabilityName, properties, userId);