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;
41 public class ForwardingPathUtilsTest {
43 private ForwardingPathUtils createTestSubject() {
44 return new ForwardingPathUtils();
48 public void testConvertServiceToServiceRelations() throws Exception {
49 ForwardingPathUtils testSubject;
50 Service service = new Service();
51 ServiceRelations result;
54 testSubject = createTestSubject();
55 result = testSubject.convertServiceToServiceRelations(service);
56 List<ComponentInstance> resourceInstances = new LinkedList<>();
57 ComponentInstance e = new ComponentInstance();
58 e.setCapabilities(new HashMap<>());
59 resourceInstances.add(e);
60 service.setComponentInstances(resourceInstances);
62 result = testSubject.convertServiceToServiceRelations(service);
66 public void testCreateWrapper() throws Exception {
67 ForwardingPathUtils testSubject;
68 NameIdPair cpOption = new NameIdPair("mock", "mock");
69 NameIdPairWrapper result;
72 testSubject = createTestSubject();
73 result = Deencapsulation.invoke(testSubject, "createWrapper", cpOption);
77 public void testGetResponseFormatManager() throws Exception {
78 ForwardingPathUtils testSubject;
79 ResponseFormatManager result;
82 testSubject = createTestSubject();
83 result = Deencapsulation.invoke(testSubject, "getResponseFormatManager");
87 public void testFindForwardingPathNamesToDeleteOnComponentInstanceDeletion() throws Exception {
88 ForwardingPathUtils testSubject;
89 Service containerService = new Service();
90 containerService.setForwardingPaths(new HashMap<>());
91 String componentInstanceId = "";
95 testSubject = createTestSubject();
96 result = testSubject.findForwardingPathNamesToDeleteOnComponentInstanceDeletion(containerService,
101 public void testFindForwardingPathToDeleteOnCIDeletion() throws Exception {
102 ForwardingPathUtils testSubject;
103 Service containerService = new Service();
104 containerService.setForwardingPaths(new HashMap<>());
105 String componentInstanceId = "";
106 Map<String, ForwardingPathDataDefinition> result;
109 testSubject = createTestSubject();
110 result = Deencapsulation.invoke(testSubject, "findForwardingPathToDeleteOnCIDeletion", containerService,
111 componentInstanceId);
115 public void testElementContainsCI_1() throws Exception {
116 ForwardingPathUtils testSubject;
117 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
118 elementDataDefinitions.setFromNode("mock");
119 String componentInstanceId = "mock";
123 testSubject = createTestSubject();
124 result = Deencapsulation.invoke(testSubject, "elementContainsCI", elementDataDefinitions, componentInstanceId);
128 public void testUpdateForwardingPathOnVersionChange() throws Exception {
129 ForwardingPathUtils testSubject;
130 Service containerService = new Service();
131 containerService.setForwardingPaths(new HashMap<>());
132 DataForMergeHolder dataHolder = new DataForMergeHolder();
133 Component updatedContainerComponent = new Service();
134 String newInstanceId = "";
135 Pair<Map<String, ForwardingPathDataDefinition>, Map<String, ForwardingPathDataDefinition>> result;
138 testSubject = createTestSubject();
139 result = testSubject.updateForwardingPathOnVersionChange(containerService, dataHolder,
140 updatedContainerComponent, newInstanceId);
144 public void testGetForwardingPathsToBeDeletedOnVersionChange() throws Exception {
145 ForwardingPathUtils testSubject;
146 Service containerService = new Service();
147 containerService.setForwardingPaths(new HashMap<>());
148 DataForMergeHolder dataHolder = new DataForMergeHolder();
149 Component updatedContainerComponent = new Service();
153 testSubject = createTestSubject();
154 result = testSubject.getForwardingPathsToBeDeletedOnVersionChange(containerService, dataHolder,
155 updatedContainerComponent);
159 public void testUpdateCI() throws Exception {
160 ForwardingPathUtils testSubject;
161 ForwardingPathDataDefinition inFP = new ForwardingPathDataDefinition();
162 inFP.setPathElements(new ListDataDefinition<>());
165 ForwardingPathDataDefinition result;
168 testSubject = createTestSubject();
169 result = Deencapsulation.invoke(testSubject, "updateCI", inFP, oldCI, newCI);
173 public void testUpdateElement() throws Exception {
174 ForwardingPathUtils testSubject;
175 ForwardingPathElementDataDefinition element = new ForwardingPathElementDataDefinition();
176 element.setFromNode("mock");
177 element.setToNode("mock");
178 element.setToCP("mock");
181 ForwardingPathElementDataDefinition result;
184 testSubject = createTestSubject();
185 result = Deencapsulation.invoke(testSubject, "updateElement", element, oldCI, newCI);
189 public void testElementContainsCIAndForwarder_1() throws Exception {
190 ForwardingPathUtils testSubject;
191 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
192 elementDataDefinitions.setFromNode("mock");
193 elementDataDefinitions.setToNode("mock");
194 elementDataDefinitions.setToCP("mock");
195 String oldCIId = "mock";
196 Component newCI = new Resource();
200 testSubject = createTestSubject();
201 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndForwarder", elementDataDefinitions, oldCIId,
206 public void testCiContainsForwarder() throws Exception {
207 ForwardingPathUtils testSubject;
208 Component newCI = new Resource();
209 String capabilityID = "mock";
213 testSubject = createTestSubject();
214 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
215 newCI.setCapabilities(new HashMap<>());
216 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
220 public void testElementContainsCIAndDoesNotContainForwarder() throws Exception {
221 ForwardingPathUtils testSubject;
222 ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition();
223 ListDataDefinition<ForwardingPathElementDataDefinition> pathElements = new ListDataDefinition<>();
224 forwardingPathDataDefinition.setPathElements(pathElements);
226 Component newCI = new Resource();
230 testSubject = createTestSubject();
231 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
232 forwardingPathDataDefinition, oldCIId, newCI);
236 public void testElementContainsCIAndDoesNotContainForwarder_1() throws Exception {
237 ForwardingPathUtils testSubject;
238 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
239 elementDataDefinitions.setFromNode("mock");
240 elementDataDefinitions.setToNode("mock");
241 elementDataDefinitions.setToCP("mock");
243 Component newCI = new Resource();
247 testSubject = createTestSubject();
248 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
249 elementDataDefinitions, oldCIId, newCI);