1 package org.openecomp.sdc.be.components.merge.path;
3 import static groovy.util.GroovyTestCase.assertEquals;
4 import static junit.framework.Assert.assertNotNull;
5 import static junit.framework.TestCase.assertEquals;
6 import static junit.framework.TestCase.assertTrue;
7 import static org.mockito.ArgumentMatchers.any;
8 import static org.mockito.ArgumentMatchers.anyBoolean;
9 import static org.mockito.Mockito.when;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.InjectMocks;
16 import org.mockito.Mock;
17 import org.mockito.MockitoAnnotations;
18 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
19 import org.openecomp.sdc.be.components.merge.instance.ComponentInstanceForwardingPathMerge;
20 import org.openecomp.sdc.be.components.path.BaseForwardingPathVersionChangeTest;
21 import org.openecomp.sdc.be.impl.ForwardingPathUtils;
22 import org.openecomp.sdc.be.model.Component;
23 import org.openecomp.sdc.be.model.Service;
24 import org.openecomp.sdc.be.model.User;
25 import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
26 import org.openecomp.sdc.common.api.UserRoleEnum;
27 import org.openecomp.sdc.exception.ResponseFormat;
29 import fj.data.Either;
31 public class ComponentInstanceForwardingPathMergeTest extends BaseForwardingPathVersionChangeTest {
34 private ComponentInstanceForwardingPathMerge testInstance;
37 private ServiceBusinessLogic serviceBusinessLogic;
40 private ToscaOperationFacade toscaOperationFacade;
44 public void setUpData() {
45 MockitoAnnotations.initMocks(this);
48 user.setRole(UserRoleEnum.ADMIN.getName());
52 public void testIgnoreMergeSinceItIsNotService() {
54 testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
55 assertEquals(nodeACI.getUniqueId(), dataHolder.getOrigComponentInstId());
56 Either<Component, ResponseFormat> componentResponseFormatEither = testInstance
57 .mergeDataAfterCreate(user, dataHolder, newNodeAC, "3344");
58 assertNotNull(componentResponseFormatEither);
59 assertTrue(componentResponseFormatEither.isLeft());
60 assertEquals(newNodeAC, componentResponseFormatEither.left().value());
64 public void mergeShouldDelete() {
65 Set<String> forwardingPathNamesToDeleteOnComponentInstanceDeletion = new ForwardingPathUtils()
66 .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, nodeACI.getUniqueId());
67 nodeACI.getCapabilities().clear();
68 newNodeAC.getCapabilities().clear();
69 when(serviceBusinessLogic.deleteForwardingPaths(any(), any(), any(), anyBoolean()))
70 .thenReturn(Either.left(forwardingPathNamesToDeleteOnComponentInstanceDeletion));
71 when(toscaOperationFacade.getToscaFullElement(any())).thenReturn(Either.left(newNodeAC));
73 // Change internal ci, just like change version do
74 service.getComponentInstances().remove(nodeACI);
75 service.getComponentInstances().add(newNodeACI);
77 testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
78 assertEquals(nodeACI.getUniqueId(), dataHolder.getOrigComponentInstId());
79 Either<Component, ResponseFormat> componentResponseFormatEither = testInstance
80 .mergeDataAfterCreate(user, dataHolder, service, newNodeA);
81 assertNotNull(componentResponseFormatEither);
82 assertTrue(componentResponseFormatEither.isLeft());
83 assertEquals(0, ((Service) componentResponseFormatEither.left().value()).getForwardingPaths().size());
87 public void mergeShouldUpdate() {
88 when(serviceBusinessLogic.updateForwardingPath(any(), any(), any(), anyBoolean()))
89 .thenReturn(Either.left(service));
90 when(toscaOperationFacade.getToscaFullElement(any())).thenReturn(Either.left(newNodeAC));
91 testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
92 assertEquals(nodeACI.getUniqueId(), dataHolder.getOrigComponentInstId());
94 // Change internal ci, just like change version do
95 service.getComponentInstances().remove(nodeACI);
96 service.getComponentInstances().add(newNodeACI);
98 Either<Component, ResponseFormat> componentResponseFormatEither = testInstance
99 .mergeDataAfterCreate(user, dataHolder, service, newNodeA);
100 assertNotNull(componentResponseFormatEither);
101 assertTrue(componentResponseFormatEither.isLeft());