re base code
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / impl / ForwardingPathUtilsTest.java
1 package org.openecomp.sdc.be.impl;
2
3 import mockit.Deencapsulation;
4 import org.javatuples.Pair;
5 import org.junit.Test;
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;
18
19 import java.util.*;
20
21 public class ForwardingPathUtilsTest {
22
23         private ForwardingPathUtils createTestSubject() {
24                 return new ForwardingPathUtils();
25         }
26
27         @Test
28         public void testConvertServiceToServiceRelations() throws Exception {
29                 ForwardingPathUtils testSubject;
30                 Service service = new Service();
31                 ServiceRelations result;
32
33                 // default test
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);
41
42                 result = testSubject.convertServiceToServiceRelations(service);
43         }
44
45         @Test
46         public void testCreateWrapper() throws Exception {
47                 ForwardingPathUtils testSubject;
48                 NameIdPair cpOption = new NameIdPair("mock", "mock");
49                 NameIdPairWrapper result;
50
51                 // default test
52                 testSubject = createTestSubject();
53                 result = Deencapsulation.invoke(testSubject, "createWrapper", cpOption);
54         }
55
56         @Test
57         public void testGetResponseFormatManager() throws Exception {
58                 ForwardingPathUtils testSubject;
59                 ResponseFormatManager result;
60
61                 // default test
62                 testSubject = createTestSubject();
63                 result = Deencapsulation.invoke(testSubject, "getResponseFormatManager");
64         }
65
66         @Test
67         public void testFindForwardingPathNamesToDeleteOnComponentInstanceDeletion() throws Exception {
68                 ForwardingPathUtils testSubject;
69                 Service containerService = new Service();
70                 containerService.setForwardingPaths(new HashMap<>());
71                 String componentInstanceId = "";
72                 Set<String> result;
73
74                 // default test
75                 testSubject = createTestSubject();
76                 result = testSubject.findForwardingPathNamesToDeleteOnComponentInstanceDeletion(containerService,
77                                 componentInstanceId);
78         }
79
80         @Test
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;
87
88                 // default test
89                 testSubject = createTestSubject();
90                 result = Deencapsulation.invoke(testSubject, "findForwardingPathToDeleteOnCIDeletion", containerService,
91                                 componentInstanceId);
92         }
93
94         @Test
95         public void testElementContainsCI_1() throws Exception {
96                 ForwardingPathUtils testSubject;
97                 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
98                 elementDataDefinitions.setFromNode("mock");
99                 String componentInstanceId = "mock";
100                 boolean result;
101
102                 // default test
103                 testSubject = createTestSubject();
104                 result = Deencapsulation.invoke(testSubject, "elementContainsCI", elementDataDefinitions, componentInstanceId);
105         }
106
107         @Test
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;
116
117                 // default test
118                 testSubject = createTestSubject();
119                 result = testSubject.updateForwardingPathOnVersionChange(containerService, dataHolder,
120                                 updatedContainerComponent, newInstanceId);
121         }
122
123         @Test
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();
130                 Set<String> result;
131
132                 // default test
133                 testSubject = createTestSubject();
134                 result = testSubject.getForwardingPathsToBeDeletedOnVersionChange(containerService, dataHolder,
135                                 updatedContainerComponent);
136         }
137
138         @Test
139         public void testUpdateCI() throws Exception {
140                 ForwardingPathUtils testSubject;
141                 ForwardingPathDataDefinition inFP = new ForwardingPathDataDefinition();
142                 inFP.setPathElements(new ListDataDefinition<>());
143                 String oldCI = "";
144                 String newCI = "";
145                 ForwardingPathDataDefinition result;
146
147                 // default test
148                 testSubject = createTestSubject();
149                 result = Deencapsulation.invoke(testSubject, "updateCI", inFP, oldCI, newCI);
150         }
151
152         @Test
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");
159                 String oldCI = "";
160                 String newCI = "";
161                 ForwardingPathElementDataDefinition result;
162
163                 // default test
164                 testSubject = createTestSubject();
165                 result = Deencapsulation.invoke(testSubject, "updateElement", element, oldCI, newCI);
166         }
167
168         @Test
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();
177                 boolean result;
178
179                 // default test
180                 testSubject = createTestSubject();
181                 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndForwarder", elementDataDefinitions, oldCIId,
182                                 newCI);
183         }
184
185         @Test
186         public void testCiContainsForwarder() throws Exception {
187                 ForwardingPathUtils testSubject;
188                 Component newCI = new Resource();
189                 String capabilityID = "mock";
190                 boolean result;
191
192                 // default test
193                 testSubject = createTestSubject();
194                 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
195                 newCI.setCapabilities(new HashMap<>());
196                 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
197         }
198
199         @Test
200         public void testElementContainsCIAndDoesNotContainForwarder() throws Exception {
201                 ForwardingPathUtils testSubject;
202                 ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition();
203                 ListDataDefinition<ForwardingPathElementDataDefinition> pathElements = new ListDataDefinition<>();
204                 forwardingPathDataDefinition.setPathElements(pathElements);
205                 String oldCIId = "";
206                 Component newCI = new Resource();
207                 boolean result;
208
209                 // default test
210                 testSubject = createTestSubject();
211                 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
212                                 forwardingPathDataDefinition, oldCIId, newCI);
213         }
214
215         @Test
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");
222                 String oldCIId = "";
223                 Component newCI = new Resource();
224                 boolean result;
225
226                 // default test
227                 testSubject = createTestSubject();
228                 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
229                                 elementDataDefinitions, oldCIId, newCI);
230         }
231 }