2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.merge.path;
23 import fj.data.Either;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.InjectMocks;
27 import org.mockito.Mock;
28 import org.mockito.MockitoAnnotations;
29 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
30 import org.openecomp.sdc.be.components.merge.instance.ComponentInstanceForwardingPathMerge;
31 import org.openecomp.sdc.be.components.path.BaseForwardingPathVersionChangeTest;
32 import org.openecomp.sdc.be.impl.ForwardingPathUtils;
33 import org.openecomp.sdc.be.model.Component;
34 import org.openecomp.sdc.be.model.Service;
35 import org.openecomp.sdc.be.model.User;
36 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
37 import org.openecomp.sdc.common.api.UserRoleEnum;
41 import static junit.framework.TestCase.assertTrue;
42 import static org.junit.Assert.assertEquals;
43 import static org.junit.Assert.assertNotNull;
44 import static org.mockito.ArgumentMatchers.any;
45 import static org.mockito.ArgumentMatchers.anyBoolean;
46 import static org.mockito.Mockito.when;
48 public class ComponentInstanceForwardingPathMergeTest extends BaseForwardingPathVersionChangeTest {
51 private ComponentInstanceForwardingPathMerge testInstance;
54 private ServiceBusinessLogic serviceBusinessLogic;
57 private ToscaOperationFacade toscaOperationFacade;
61 public void setUpData() {
62 MockitoAnnotations.initMocks(this);
65 user.setRole(UserRoleEnum.ADMIN.getName());
69 public void testIgnoreMergeSinceItIsNotService() {
71 testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
72 assertEquals(nodeACI.getName(), dataHolder.getOrigComponentInstId());
73 Component componentResponseFormatEither = testInstance
74 .mergeDataAfterCreate(user, dataHolder, newNodeAC, "3344");
75 assertNotNull(componentResponseFormatEither);
76 assertTrue(componentResponseFormatEither != null);
77 assertEquals(newNodeAC, componentResponseFormatEither);
81 public void mergeShouldDelete() {
82 Set<String> forwardingPathNamesToDeleteOnComponentInstanceDeletion = new ForwardingPathUtils()
83 .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, nodeACI.getUniqueId());
84 nodeACI.getCapabilities().clear();
85 newNodeAC.getCapabilities().clear();
86 Set<String> returnValue = forwardingPathNamesToDeleteOnComponentInstanceDeletion;
87 when(serviceBusinessLogic.deleteForwardingPaths(any(), any(), any(), anyBoolean()))
88 .thenReturn(returnValue);
89 when(toscaOperationFacade.getToscaFullElement(any())).thenReturn(Either.left(newNodeAC));
91 // Change internal ci, just like change version do
92 service.getComponentInstances().remove(nodeACI);
93 service.getComponentInstances().add(newNodeACI);
95 testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
96 assertEquals(nodeACI.getName(), dataHolder.getOrigComponentInstId());
97 Component componentResponseFormatEither = testInstance
98 .mergeDataAfterCreate(user, dataHolder, service, newNodeA);
99 assertNotNull(componentResponseFormatEither);
100 assertEquals(0, ((Service) componentResponseFormatEither).getForwardingPaths().size());
104 public void mergeShouldUpdate() {
105 when(serviceBusinessLogic.updateForwardingPath(any(), any(), any(), anyBoolean()))
106 .then(invocationOnMock -> service);
107 when(toscaOperationFacade.getToscaFullElement(any())).thenReturn(Either.left(newNodeAC));
108 testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
109 assertEquals(nodeACI.getName(), dataHolder.getOrigComponentInstId());
111 // Change internal ci, just like change version do
112 service.getComponentInstances().remove(nodeACI);
113 service.getComponentInstances().add(newNodeACI);
115 Component component = testInstance.mergeDataAfterCreate(user, dataHolder, service, newNodeA);
116 assertNotNull(component);
120 public void handleNullCapailities() {
121 nodeACI.setCapabilities(null);
122 testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);