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.impl;
23 import mockit.Deencapsulation;
24 import org.javatuples.Pair;
25 import org.junit.Test;
26 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
27 import org.openecomp.sdc.be.components.merge.instance.DataForMergeHolder;
28 import org.openecomp.sdc.be.datamodel.NameIdPair;
29 import org.openecomp.sdc.be.datamodel.NameIdPairWrapper;
30 import org.openecomp.sdc.be.datamodel.ServiceRelations;
31 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
32 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition;
33 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
34 import org.openecomp.sdc.be.model.Component;
35 import org.openecomp.sdc.be.model.ComponentInstance;
36 import org.openecomp.sdc.be.model.Resource;
37 import org.openecomp.sdc.be.model.Service;
39 import java.util.HashMap;
40 import java.util.LinkedList;
41 import java.util.List;
45 public class ForwardingPathUtilsTest {
47 private ForwardingPathUtils createTestSubject() {
48 return new ForwardingPathUtils();
52 public void testConvertServiceToServiceRelations() throws Exception {
53 ForwardingPathUtils testSubject;
54 Service service = new Service();
55 ServiceRelations result;
58 testSubject = createTestSubject();
59 result = testSubject.convertServiceToServiceRelations(service);
60 List<ComponentInstance> resourceInstances = new LinkedList<>();
61 ComponentInstance e = new ComponentInstance();
62 e.setCapabilities(new HashMap<>());
63 resourceInstances.add(e);
64 service.setComponentInstances(resourceInstances);
66 result = testSubject.convertServiceToServiceRelations(service);
70 public void testCreateWrapper() throws Exception {
71 ForwardingPathUtils testSubject;
72 NameIdPair cpOption = new NameIdPair("mock", "mock");
73 NameIdPairWrapper result;
76 testSubject = createTestSubject();
77 result = Deencapsulation.invoke(testSubject, "createWrapper", cpOption);
81 public void testGetResponseFormatManager() throws Exception {
82 ForwardingPathUtils testSubject;
83 ResponseFormatManager result;
86 testSubject = createTestSubject();
87 result = Deencapsulation.invoke(testSubject, "getResponseFormatManager");
91 public void testFindForwardingPathNamesToDeleteOnComponentInstanceDeletion() throws Exception {
92 ForwardingPathUtils testSubject;
93 Service containerService = new Service();
94 containerService.setForwardingPaths(new HashMap<>());
95 String componentInstanceId = "";
99 testSubject = createTestSubject();
100 result = testSubject.findForwardingPathNamesToDeleteOnComponentInstanceDeletion(containerService,
101 componentInstanceId);
105 public void testFindForwardingPathToDeleteOnCIDeletion() throws Exception {
106 ForwardingPathUtils testSubject;
107 Service containerService = new Service();
108 containerService.setForwardingPaths(new HashMap<>());
109 String componentInstanceId = "";
110 Map<String, ForwardingPathDataDefinition> result;
113 testSubject = createTestSubject();
114 result = Deencapsulation.invoke(testSubject, "findForwardingPathToDeleteOnCIDeletion", containerService,
115 componentInstanceId);
119 public void testElementContainsCI_1() throws Exception {
120 ForwardingPathUtils testSubject;
121 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
122 elementDataDefinitions.setFromNode("mock");
123 String componentInstanceId = "mock";
127 testSubject = createTestSubject();
128 result = Deencapsulation.invoke(testSubject, "elementContainsCI", elementDataDefinitions, componentInstanceId);
132 public void testUpdateForwardingPathOnVersionChange() throws Exception {
133 ForwardingPathUtils testSubject;
134 Service containerService = new Service();
135 containerService.setForwardingPaths(new HashMap<>());
136 DataForMergeHolder dataHolder = new DataForMergeHolder();
137 Component updatedContainerComponent = new Service();
138 String newInstanceId = "";
139 Pair<Map<String, ForwardingPathDataDefinition>, Map<String, ForwardingPathDataDefinition>> result;
142 testSubject = createTestSubject();
143 result = testSubject.updateForwardingPathOnVersionChange(containerService, dataHolder,
144 updatedContainerComponent, newInstanceId);
148 public void testGetForwardingPathsToBeDeletedOnVersionChange() throws Exception {
149 ForwardingPathUtils testSubject;
150 Service containerService = new Service();
151 containerService.setForwardingPaths(new HashMap<>());
152 DataForMergeHolder dataHolder = new DataForMergeHolder();
153 Component updatedContainerComponent = new Service();
157 testSubject = createTestSubject();
158 result = testSubject.getForwardingPathsToBeDeletedOnVersionChange(containerService, dataHolder,
159 updatedContainerComponent);
163 public void testUpdateCI() throws Exception {
164 ForwardingPathUtils testSubject;
165 ForwardingPathDataDefinition inFP = new ForwardingPathDataDefinition();
166 inFP.setPathElements(new ListDataDefinition<>());
169 ForwardingPathDataDefinition result;
172 testSubject = createTestSubject();
173 result = Deencapsulation.invoke(testSubject, "updateCI", inFP, oldCI, newCI);
177 public void testUpdateElement() throws Exception {
178 ForwardingPathUtils testSubject;
179 ForwardingPathElementDataDefinition element = new ForwardingPathElementDataDefinition();
180 element.setFromNode("mock");
181 element.setToNode("mock");
182 element.setToCP("mock");
185 ForwardingPathElementDataDefinition result;
188 testSubject = createTestSubject();
189 result = Deencapsulation.invoke(testSubject, "updateElement", element, oldCI, newCI);
193 public void testElementContainsCIAndForwarder_1() throws Exception {
194 ForwardingPathUtils testSubject;
195 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
196 elementDataDefinitions.setFromNode("mock");
197 elementDataDefinitions.setToNode("mock");
198 elementDataDefinitions.setToCP("mock");
199 String oldCIId = "mock";
200 Component newCI = new Resource();
204 testSubject = createTestSubject();
205 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndForwarder", elementDataDefinitions, oldCIId,
210 public void testCiContainsForwarder() throws Exception {
211 ForwardingPathUtils testSubject;
212 Component newCI = new Resource();
213 String capabilityID = "mock";
217 testSubject = createTestSubject();
218 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
219 newCI.setCapabilities(new HashMap<>());
220 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
224 public void testElementContainsCIAndDoesNotContainForwarder() throws Exception {
225 ForwardingPathUtils testSubject;
226 ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition();
227 ListDataDefinition<ForwardingPathElementDataDefinition> pathElements = new ListDataDefinition<>();
228 forwardingPathDataDefinition.setPathElements(pathElements);
230 Component newCI = new Resource();
234 testSubject = createTestSubject();
235 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
236 forwardingPathDataDefinition, oldCIId, newCI);
240 public void testElementContainsCIAndDoesNotContainForwarder_1() throws Exception {
241 ForwardingPathUtils testSubject;
242 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
243 elementDataDefinitions.setFromNode("mock");
244 elementDataDefinitions.setToNode("mock");
245 elementDataDefinitions.setToCP("mock");
247 Component newCI = new Resource();
251 testSubject = createTestSubject();
252 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
253 elementDataDefinitions, oldCIId, newCI);