Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / impl / ForwardingPathUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.impl;
22
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;
38
39 import java.util.*;
40
41 public class ForwardingPathUtilsTest {
42
43         private ForwardingPathUtils createTestSubject() {
44                 return new ForwardingPathUtils();
45         }
46
47         @Test
48         public void testConvertServiceToServiceRelations() throws Exception {
49                 ForwardingPathUtils testSubject;
50                 Service service = new Service();
51                 ServiceRelations result;
52
53                 // default test
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);
61
62                 result = testSubject.convertServiceToServiceRelations(service);
63         }
64
65         @Test
66         public void testCreateWrapper() throws Exception {
67                 ForwardingPathUtils testSubject;
68                 NameIdPair cpOption = new NameIdPair("mock", "mock");
69                 NameIdPairWrapper result;
70
71                 // default test
72                 testSubject = createTestSubject();
73                 result = Deencapsulation.invoke(testSubject, "createWrapper", cpOption);
74         }
75
76         @Test
77         public void testGetResponseFormatManager() throws Exception {
78                 ForwardingPathUtils testSubject;
79                 ResponseFormatManager result;
80
81                 // default test
82                 testSubject = createTestSubject();
83                 result = Deencapsulation.invoke(testSubject, "getResponseFormatManager");
84         }
85
86         @Test
87         public void testFindForwardingPathNamesToDeleteOnComponentInstanceDeletion() throws Exception {
88                 ForwardingPathUtils testSubject;
89                 Service containerService = new Service();
90                 containerService.setForwardingPaths(new HashMap<>());
91                 String componentInstanceId = "";
92                 Set<String> result;
93
94                 // default test
95                 testSubject = createTestSubject();
96                 result = testSubject.findForwardingPathNamesToDeleteOnComponentInstanceDeletion(containerService,
97                                 componentInstanceId);
98         }
99
100         @Test
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;
107
108                 // default test
109                 testSubject = createTestSubject();
110                 result = Deencapsulation.invoke(testSubject, "findForwardingPathToDeleteOnCIDeletion", containerService,
111                                 componentInstanceId);
112         }
113
114         @Test
115         public void testElementContainsCI_1() throws Exception {
116                 ForwardingPathUtils testSubject;
117                 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
118                 elementDataDefinitions.setFromNode("mock");
119                 String componentInstanceId = "mock";
120                 boolean result;
121
122                 // default test
123                 testSubject = createTestSubject();
124                 result = Deencapsulation.invoke(testSubject, "elementContainsCI", elementDataDefinitions, componentInstanceId);
125         }
126
127         @Test
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;
136
137                 // default test
138                 testSubject = createTestSubject();
139                 result = testSubject.updateForwardingPathOnVersionChange(containerService, dataHolder,
140                                 updatedContainerComponent, newInstanceId);
141         }
142
143         @Test
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();
150                 Set<String> result;
151
152                 // default test
153                 testSubject = createTestSubject();
154                 result = testSubject.getForwardingPathsToBeDeletedOnVersionChange(containerService, dataHolder,
155                                 updatedContainerComponent);
156         }
157
158         @Test
159         public void testUpdateCI() throws Exception {
160                 ForwardingPathUtils testSubject;
161                 ForwardingPathDataDefinition inFP = new ForwardingPathDataDefinition();
162                 inFP.setPathElements(new ListDataDefinition<>());
163                 String oldCI = "";
164                 String newCI = "";
165                 ForwardingPathDataDefinition result;
166
167                 // default test
168                 testSubject = createTestSubject();
169                 result = Deencapsulation.invoke(testSubject, "updateCI", inFP, oldCI, newCI);
170         }
171
172         @Test
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");
179                 String oldCI = "";
180                 String newCI = "";
181                 ForwardingPathElementDataDefinition result;
182
183                 // default test
184                 testSubject = createTestSubject();
185                 result = Deencapsulation.invoke(testSubject, "updateElement", element, oldCI, newCI);
186         }
187
188         @Test
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();
197                 boolean result;
198
199                 // default test
200                 testSubject = createTestSubject();
201                 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndForwarder", elementDataDefinitions, oldCIId,
202                                 newCI);
203         }
204
205         @Test
206         public void testCiContainsForwarder() throws Exception {
207                 ForwardingPathUtils testSubject;
208                 Component newCI = new Resource();
209                 String capabilityID = "mock";
210                 boolean result;
211
212                 // default test
213                 testSubject = createTestSubject();
214                 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
215                 newCI.setCapabilities(new HashMap<>());
216                 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
217         }
218
219         @Test
220         public void testElementContainsCIAndDoesNotContainForwarder() throws Exception {
221                 ForwardingPathUtils testSubject;
222                 ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition();
223                 ListDataDefinition<ForwardingPathElementDataDefinition> pathElements = new ListDataDefinition<>();
224                 forwardingPathDataDefinition.setPathElements(pathElements);
225                 String oldCIId = "";
226                 Component newCI = new Resource();
227                 boolean result;
228
229                 // default test
230                 testSubject = createTestSubject();
231                 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
232                                 forwardingPathDataDefinition, oldCIId, newCI);
233         }
234
235         @Test
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");
242                 String oldCIId = "";
243                 Component newCI = new Resource();
244                 boolean result;
245
246                 // default test
247                 testSubject = createTestSubject();
248                 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
249                                 elementDataDefinitions, oldCIId, newCI);
250         }
251 }