Catalog alignment
[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.HashMap;
40 import java.util.LinkedList;
41 import java.util.List;
42 import java.util.Map;
43 import java.util.Set;
44
45 public class ForwardingPathUtilsTest {
46
47         private ForwardingPathUtils createTestSubject() {
48                 return new ForwardingPathUtils();
49         }
50
51         @Test
52         public void testConvertServiceToServiceRelations() throws Exception {
53                 ForwardingPathUtils testSubject;
54                 Service service = new Service();
55                 ServiceRelations result;
56
57                 // default test
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);
65
66                 result = testSubject.convertServiceToServiceRelations(service);
67         }
68
69         @Test
70         public void testCreateWrapper() throws Exception {
71                 ForwardingPathUtils testSubject;
72                 NameIdPair cpOption = new NameIdPair("mock", "mock");
73                 NameIdPairWrapper result;
74
75                 // default test
76                 testSubject = createTestSubject();
77                 result = Deencapsulation.invoke(testSubject, "createWrapper", cpOption);
78         }
79
80         @Test
81         public void testGetResponseFormatManager() throws Exception {
82                 ForwardingPathUtils testSubject;
83                 ResponseFormatManager result;
84
85                 // default test
86                 testSubject = createTestSubject();
87                 result = Deencapsulation.invoke(testSubject, "getResponseFormatManager");
88         }
89
90         @Test
91         public void testFindForwardingPathNamesToDeleteOnComponentInstanceDeletion() throws Exception {
92                 ForwardingPathUtils testSubject;
93                 Service containerService = new Service();
94                 containerService.setForwardingPaths(new HashMap<>());
95                 String componentInstanceId = "";
96                 Set<String> result;
97
98                 // default test
99                 testSubject = createTestSubject();
100                 result = testSubject.findForwardingPathNamesToDeleteOnComponentInstanceDeletion(containerService,
101                                 componentInstanceId);
102         }
103
104         @Test
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;
111
112                 // default test
113                 testSubject = createTestSubject();
114                 result = Deencapsulation.invoke(testSubject, "findForwardingPathToDeleteOnCIDeletion", containerService,
115                                 componentInstanceId);
116         }
117
118         @Test
119         public void testElementContainsCI_1() throws Exception {
120                 ForwardingPathUtils testSubject;
121                 ForwardingPathElementDataDefinition elementDataDefinitions = new ForwardingPathElementDataDefinition();
122                 elementDataDefinitions.setFromNode("mock");
123                 String componentInstanceId = "mock";
124                 boolean result;
125
126                 // default test
127                 testSubject = createTestSubject();
128                 result = Deencapsulation.invoke(testSubject, "elementContainsCI", elementDataDefinitions, componentInstanceId);
129         }
130
131         @Test
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;
140
141                 // default test
142                 testSubject = createTestSubject();
143                 result = testSubject.updateForwardingPathOnVersionChange(containerService, dataHolder,
144                                 updatedContainerComponent, newInstanceId);
145         }
146
147         @Test
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();
154                 Set<String> result;
155
156                 // default test
157                 testSubject = createTestSubject();
158                 result = testSubject.getForwardingPathsToBeDeletedOnVersionChange(containerService, dataHolder,
159                                 updatedContainerComponent);
160         }
161
162         @Test
163         public void testUpdateCI() throws Exception {
164                 ForwardingPathUtils testSubject;
165                 ForwardingPathDataDefinition inFP = new ForwardingPathDataDefinition();
166                 inFP.setPathElements(new ListDataDefinition<>());
167                 String oldCI = "";
168                 String newCI = "";
169                 ForwardingPathDataDefinition result;
170
171                 // default test
172                 testSubject = createTestSubject();
173                 result = Deencapsulation.invoke(testSubject, "updateCI", inFP, oldCI, newCI);
174         }
175
176         @Test
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");
183                 String oldCI = "";
184                 String newCI = "";
185                 ForwardingPathElementDataDefinition result;
186
187                 // default test
188                 testSubject = createTestSubject();
189                 result = Deencapsulation.invoke(testSubject, "updateElement", element, oldCI, newCI);
190         }
191
192         @Test
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();
201                 boolean result;
202
203                 // default test
204                 testSubject = createTestSubject();
205                 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndForwarder", elementDataDefinitions, oldCIId,
206                                 newCI);
207         }
208
209         @Test
210         public void testCiContainsForwarder() throws Exception {
211                 ForwardingPathUtils testSubject;
212                 Component newCI = new Resource();
213                 String capabilityID = "mock";
214                 boolean result;
215
216                 // default test
217                 testSubject = createTestSubject();
218                 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
219                 newCI.setCapabilities(new HashMap<>());
220                 result = Deencapsulation.invoke(testSubject, "ciContainsForwarder", newCI, capabilityID);
221         }
222
223         @Test
224         public void testElementContainsCIAndDoesNotContainForwarder() throws Exception {
225                 ForwardingPathUtils testSubject;
226                 ForwardingPathDataDefinition forwardingPathDataDefinition = new ForwardingPathDataDefinition();
227                 ListDataDefinition<ForwardingPathElementDataDefinition> pathElements = new ListDataDefinition<>();
228                 forwardingPathDataDefinition.setPathElements(pathElements);
229                 String oldCIId = "";
230                 Component newCI = new Resource();
231                 boolean result;
232
233                 // default test
234                 testSubject = createTestSubject();
235                 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
236                                 forwardingPathDataDefinition, oldCIId, newCI);
237         }
238
239         @Test
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");
246                 String oldCIId = "";
247                 Component newCI = new Resource();
248                 boolean result;
249
250                 // default test
251                 testSubject = createTestSubject();
252                 result = Deencapsulation.invoke(testSubject, "elementContainsCIAndDoesNotContainForwarder",
253                                 elementDataDefinitions, oldCIId, newCI);
254         }
255 }