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 static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.ArgumentMatchers.anyBoolean;
27 import static org.mockito.Mockito.when;
29 import fj.data.Either;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.MockitoAnnotations;
36 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
37 import org.openecomp.sdc.be.components.merge.instance.ComponentInstanceForwardingPathMerge;
38 import org.openecomp.sdc.be.components.path.BaseForwardingPathVersionChangeTest;
39 import org.openecomp.sdc.be.impl.ForwardingPathUtils;
40 import org.openecomp.sdc.be.model.Component;
41 import org.openecomp.sdc.be.model.Service;
42 import org.openecomp.sdc.be.model.User;
43 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
44 import org.openecomp.sdc.common.api.UserRoleEnum;
46 public class ComponentInstanceForwardingPathMergeTest extends BaseForwardingPathVersionChangeTest {
49 private ComponentInstanceForwardingPathMerge testInstance;
52 private ServiceBusinessLogic serviceBusinessLogic;
55 private ToscaOperationFacade toscaOperationFacade;
59 public void setUpData() {
60 MockitoAnnotations.initMocks(this);
63 user.setRole(UserRoleEnum.ADMIN.getName());
67 public void testIgnoreMergeSinceItIsNotService() {
69 testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
70 assertEquals(nodeACI.getName(), dataHolder.getOrigComponentInstId());
71 Component componentResponseFormatEither = testInstance
72 .mergeDataAfterCreate(user, dataHolder, newNodeAC, "3344");
73 assertNotNull(componentResponseFormatEither);
74 assertEquals(newNodeAC, componentResponseFormatEither);
78 public void mergeShouldDelete() {
79 Set<String> forwardingPathNamesToDeleteOnComponentInstanceDeletion = new ForwardingPathUtils()
80 .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, nodeACI.getUniqueId());
81 nodeACI.getCapabilities().clear();
82 newNodeAC.getCapabilities().clear();
83 Set<String> returnValue = forwardingPathNamesToDeleteOnComponentInstanceDeletion;
84 when(serviceBusinessLogic.deleteForwardingPaths(any(), any(), any(), anyBoolean()))
85 .thenReturn(returnValue);
86 when(toscaOperationFacade.getToscaFullElement(any())).thenReturn(Either.left(newNodeAC));
88 // Change internal ci, just like change version do
89 service.getComponentInstances().remove(nodeACI);
90 service.getComponentInstances().add(newNodeACI);
92 testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
93 assertEquals(nodeACI.getName(), dataHolder.getOrigComponentInstId());
94 Component componentResponseFormatEither = testInstance
95 .mergeDataAfterCreate(user, dataHolder, service, newNodeA);
96 assertNotNull(componentResponseFormatEither);
97 assertEquals(0, ((Service) componentResponseFormatEither).getForwardingPaths().size());
101 public void mergeShouldUpdate() {
102 when(serviceBusinessLogic.updateForwardingPath(any(), any(), any(), anyBoolean()))
103 .then(invocationOnMock -> service);
104 when(toscaOperationFacade.getToscaFullElement(any())).thenReturn(Either.left(newNodeAC));
105 testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);
106 assertEquals(nodeACI.getName(), dataHolder.getOrigComponentInstId());
108 // Change internal ci, just like change version do
109 service.getComponentInstances().remove(nodeACI);
110 service.getComponentInstances().add(newNodeACI);
112 Component component = testInstance.mergeDataAfterCreate(user, dataHolder, service, newNodeA);
113 assertNotNull(component);
117 public void handleNullCapailities() {
118 nodeACI.setCapabilities(null);
119 testInstance.saveDataBeforeMerge(dataHolder, service, nodeACI, newNodeAC);