1 package org.openecomp.sdc.be.impl;
3 import mockit.Deencapsulation;
4 import org.javatuples.Pair;
6 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
7 import org.openecomp.sdc.be.components.merge.instance.DataForMergeHolder;
8 import org.openecomp.sdc.be.datamodel.NameIdPair;
9 import org.openecomp.sdc.be.datamodel.NameIdPairWrapper;
10 import org.openecomp.sdc.be.datamodel.ServiceRelations;
11 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
12 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition;
13 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
14 import org.openecomp.sdc.be.model.Component;
15 import org.openecomp.sdc.be.model.ComponentInstance;
16 import org.openecomp.sdc.be.model.Resource;
17 import org.openecomp.sdc.be.model.Service;
21 public class ForwardingPathUtilsTest {
23 private ForwardingPathUtils createTestSubject() {
24 return new ForwardingPathUtils();
28 public void testConvertServiceToServiceRelations() throws Exception {
29 ForwardingPathUtils testSubject;
30 Service service = new Service();
31 ServiceRelations result;
34 testSubject = createTestSubject();
35 result = testSubject.convertServiceToServiceRelations(service);
36 List<ComponentInstance> resourceInstances = new LinkedList<>();
37 ComponentInstance e = new ComponentInstance();
38 e.setCapabilities(new HashMap<>());
39 resourceInstances.add(e);
40 service.setComponentInstances(resourceInstances);
42 result = testSubject.convertServiceToServiceRelations(service);
46 public void testCreateWrapper() throws Exception {
47 ForwardingPathUtils testSubject;
48 NameIdPair cpOption = new NameIdPair("mock", "mock");
49 NameIdPairWrapper result;
52 testSubject = createTestSubject();
53 result = Deencapsulation.invoke(testSubject, "createWrapper", cpOption);
57 public void testGetResponseFormatManager() throws Exception {
58 ForwardingPathUtils testSubject;
59 ResponseFormatManager result;
62 testSubject = createTestSubject();
63 result = Deencapsulation.invoke(testSubject, "getResponseFormatManager");
67 public void testFindForwardingPathNamesToDeleteOnComponentInstanceDeletion() throws Exception {
68 ForwardingPathUtils testSubject;
69 Service containerService = new Service();
70 containerService.setForwardingPaths(new HashMap<>());
71 String componentInstanceId = "";
75 testSubject = createTestSubject();
76 result = testSubject.findForwardingPathNamesToDeleteOnComponentInstanceDeletion(containerService,
81 public void testFindForwardingPathToDeleteOnCIDeletion() throws Exception {
82 ForwardingPathUtils testSubject;
83 Service containerService = new Service();
84 containerService.setForwardingPaths(new HashMap<>());
85 String componentInstanceId = "";
86 Map<String, ForwardingPathDataDefinition> result;
89 testSubject = createTestSubject();
90 result = Deencapsulation.invoke(testSubject, "findForwardingPathToDeleteOnCIDeletion", containerService,
95 public void testElementContainsCI_1() throws Exception {
96 ForwardingPathUtils testSubject;
97 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
98 elementDataDefinitions.setFromNode("mock");
99 String componentInstanceId = "mock";
103 testSubject = createTestSubject();
104 result = Deencapsulation.invoke(testSubject, "elementContainsCI", elementDataDefinitions, componentInstanceId);
108 public void testUpdateForwardingPathOnVersionChange() throws Exception {
109 ForwardingPathUtils testSubject;
110 Service containerService = new Service();
111 containerService.setForwardingPaths(new HashMap<>());
112 DataForMergeHolder dataHolder = new DataForMergeHolder();
113 Component updatedContainerComponent = new Service();
114 String newInstanceId = "";
115 Pair<Map<String, ForwardingPathDataDefinition>, Map<String, ForwardingPathDataDefinition>> result;
118 testSubject = createTestSubject();
119 result = testSubject.updateForwardingPathOnVersionChange(containerService, dataHolder,
120 updatedContainerComponent, newInstanceId);
124 public void testGetForwardingPathsToBeDeletedOnVersionChange() throws Exception {
125 ForwardingPathUtils testSubject;
126 Service containerService = new Service();
127 containerService.setForwardingPaths(new HashMap<>());
128 DataForMergeHolder dataHolder = new DataForMergeHolder();
129 Component updatedContainerComponent = new Service();
133 testSubject = createTestSubject();
134 result = testSubject.getForwardingPathsToBeDeletedOnVersionChange(containerService, dataHolder,
135 updatedContainerComponent);
139 public void testUpdateCI() throws Exception {
140 ForwardingPathUtils testSubject;
141 ForwardingPathDataDefinition inFP = new ForwardingPathDataDefinition();
142 inFP.setPathElements(new ListDataDefinition<>());
145 ForwardingPathDataDefinition result;
148 testSubject = createTestSubject();
149 result = Deencapsulation.invoke(testSubject, "updateCI", inFP, oldCI, newCI);
153 public void testUpdateElement() throws Exception {
154 ForwardingPathUtils testSubject;
155 ForwardingPathElementDataDefinition element = new ForwardingPathElementDataDefinition();
156 element.setFromNode("mock");
157 element.setToNode("mock");
158 element.setToCP("mock");
161 ForwardingPathElementDataDefinition result;
164 testSubject = createTestSubject();
165 result = Deencapsulation.invoke(testSubject, "updateElement", element, oldCI, newCI);
169 public void testElementContainsCIAndForwarder_1() throws Exception {
170 ForwardingPathUtils testSubject;
171 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
172 elementDataDefinitions.setFromNode("mock");
173 elementDataDefinitions.setToNode("mock");
174 elementDataDefinitions.setToCP("mock");
175 String oldCIId = "mock";
176 Component newCI = new Resource();
180 testSubject = createTestSubject();
181 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndForwarder", elementDataDefinitions, oldCIId,
186 public void testCiContainsForwarder() throws Exception {
187 ForwardingPathUtils testSubject;
188 Component newCI = new Resource();
189 String capabilityID = "mock";
193 testSubject = createTestSubject();
194 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
195 newCI.setCapabilities(new HashMap<>());
196 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
200 public void testElementContainsCIAndDoesNotContainForwarder() throws Exception {
201 ForwardingPathUtils testSubject;
202 ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition();
203 ListDataDefinition<ForwardingPathElementDataDefinition> pathElements = new ListDataDefinition<>();
204 forwardingPathDataDefinition.setPathElements(pathElements);
206 Component newCI = new Resource();
210 testSubject = createTestSubject();
211 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
212 forwardingPathDataDefinition, oldCIId, newCI);
216 public void testElementContainsCIAndDoesNotContainForwarder_1() throws Exception {
217 ForwardingPathUtils testSubject;
218 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
219 elementDataDefinitions.setFromNode("mock");
220 elementDataDefinitions.setToNode("mock");
221 elementDataDefinitions.setToCP("mock");
223 Component newCI = new Resource();
227 testSubject = createTestSubject();
228 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
229 elementDataDefinitions, oldCIId, newCI);