2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.appc.dg.common.impl;
24 import com.att.eelf.configuration.EELFLogger;
25 import com.att.eelf.configuration.EELFManager;
26 import org.openecomp.sdnc.sli.SvcLogicContext;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Matchers;
31 import org.openecomp.appc.dg.common.VnfExecutionFlow;
32 import org.openecomp.appc.dg.common.impl.Constants;
33 import org.openecomp.appc.dg.common.impl.VnfExecutionFlowImpl;
34 import org.openecomp.appc.dg.dependencymanager.DependencyManager;
35 import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
36 import org.openecomp.appc.dg.dependencymanager.impl.DependencyModelFactory;
37 import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
38 import org.openecomp.appc.dg.objects.DependencyTypes;
39 import org.openecomp.appc.dg.objects.Node;
40 import org.openecomp.appc.dg.objects.VnfcDependencyModel;
41 import org.openecomp.appc.domainmodel.Vnfc;
42 import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
43 import org.osgi.framework.FrameworkUtil;
44 import org.powermock.api.mockito.PowerMockito;
45 import org.powermock.core.classloader.annotations.PrepareForTest;
46 import org.powermock.modules.junit4.PowerMockRunner;
48 import java.util.HashMap;
49 import java.util.HashSet;
53 @RunWith(PowerMockRunner.class)
54 @PrepareForTest({TestVnfExecutionFlowImpl.class, FrameworkUtil.class,DependencyManager.class,DependencyModelFactory.class})
55 public class TestVnfExecutionFlowImpl {
57 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVnfExecutionFlowImpl.class);
61 logger.setLevel(EELFLogger.Level.DEBUG);
65 public void testPositiveFlow() throws DependencyModelNotFound {
66 Map<String, String> params = prepareParams();
67 SvcLogicContext context = prepareContext();
68 VnfcDependencyModel dependencyModel = readDependencyModel();
70 PowerMockito.mockStatic(DependencyModelFactory.class);
71 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
73 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
74 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
75 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
76 .thenReturn(dependencyModel);
78 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
79 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
83 public void testComplexFlow() throws DependencyModelNotFound {
84 Map<String, String> params = prepareParams();
85 SvcLogicContext context = prepareContextForComplexDependency();
86 VnfcDependencyModel dependencyModel = readComplexDependencyModel();
88 PowerMockito.mockStatic(DependencyModelFactory.class);
89 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
91 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
92 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
93 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
94 .thenReturn(dependencyModel);
96 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
97 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
100 @Test(expected = InvalidDependencyModel.class)
101 public void testCycleFlow() throws DependencyModelNotFound {
102 Map<String, String> params = prepareParams();
103 SvcLogicContext context = prepareContextForComplexDependency();
104 VnfcDependencyModel dependencyModel = readCyclicDependencyModel();
105 PowerMockito.mockStatic(DependencyModelFactory.class);
106 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
108 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
109 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
110 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
111 .thenReturn(dependencyModel);
113 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
114 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
117 private VnfcDependencyModel readCyclicDependencyModel() {
119 Vnfc a = new Vnfc("A","Active-Passive",null);
120 Vnfc b = new Vnfc("B","Active-Active",null);
121 Vnfc c = new Vnfc("C","Active-Active",null);
122 Vnfc d = new Vnfc("D","Active-Active",null);
123 Vnfc e = new Vnfc("E","Active-Active",null);
124 Vnfc f = new Vnfc("F","Active-Active",null);
125 Vnfc g = new Vnfc("G","Active-Active",null);
127 Node aNode = new Node(a);
128 Node bNode = new Node(b);
129 Node cNode = new Node(c);
130 Node dNode = new Node(d);
131 Node eNode = new Node(e);
132 Node fNode = new Node(f);
133 Node gNode = new Node(g);
142 Set<Node<Vnfc>> dependencies = new HashSet<>();
143 dependencies.add(aNode);
144 dependencies.add(bNode);
145 dependencies.add(cNode);
146 dependencies.add(dNode);
147 dependencies.add(eNode);
148 dependencies.add(fNode);
149 dependencies.add(gNode);
151 return new VnfcDependencyModel(dependencies);
155 private SvcLogicContext prepareContextForComplexDependency() {
156 SvcLogicContext context = new SvcLogicContext();
157 context.setAttribute("input.action-identifiers.vnf-id","1");
158 context.setAttribute("vnf.type","vSCP");
159 context.setAttribute("vnf.vnfcCount","7");
161 context.setAttribute("vnf.vnfc[0].name","A");
162 context.setAttribute("vnf.vnfc[0].type","A");
163 context.setAttribute("vnf.vnfc[0].vm_count","2");
164 context.setAttribute("vnf.vnfc[0].vm[0].url","A1");
165 context.setAttribute("vnf.vnfc[0].vm[1].url","A2");
167 context.setAttribute("vnf.vnfc[1].name","B");
168 context.setAttribute("vnf.vnfc[1].type","B");
169 context.setAttribute("vnf.vnfc[1].vm_count","5");
170 context.setAttribute("vnf.vnfc[1].vm[0].url","B1");
171 context.setAttribute("vnf.vnfc[1].vm[1].url","B2");
172 context.setAttribute("vnf.vnfc[1].vm[2].url","B3");
173 context.setAttribute("vnf.vnfc[1].vm[3].url","B4");
174 context.setAttribute("vnf.vnfc[1].vm[4].url","B5");
176 context.setAttribute("vnf.vnfc[2].name","C");
177 context.setAttribute("vnf.vnfc[2].type","C");
178 context.setAttribute("vnf.vnfc[2].vm_count","4");
179 context.setAttribute("vnf.vnfc[2].vm[0].url","C1");
180 context.setAttribute("vnf.vnfc[2].vm[1].url","C2");
181 context.setAttribute("vnf.vnfc[2].vm[2].url","C3");
182 context.setAttribute("vnf.vnfc[2].vm[3].url","C4");
184 context.setAttribute("vnf.vnfc[3].name","D");
185 context.setAttribute("vnf.vnfc[3].type","D");
186 context.setAttribute("vnf.vnfc[3].vm_count","3");
187 context.setAttribute("vnf.vnfc[3].vm[0].url","D1");
188 context.setAttribute("vnf.vnfc[3].vm[1].url","D2");
189 context.setAttribute("vnf.vnfc[3].vm[2].url","D3");
191 context.setAttribute("vnf.vnfc[4].name","E");
192 context.setAttribute("vnf.vnfc[4].type","E");
193 context.setAttribute("vnf.vnfc[4].vm_count","2");
194 context.setAttribute("vnf.vnfc[4].vm[0].url","E1");
195 context.setAttribute("vnf.vnfc[4].vm[1].url","E2");
197 context.setAttribute("vnf.vnfc[5].name","F");
198 context.setAttribute("vnf.vnfc[5].type","F");
199 context.setAttribute("vnf.vnfc[5].vm_count","1");
200 context.setAttribute("vnf.vnfc[5].vm[0].url","F1");
202 context.setAttribute("vnf.vnfc[6].name","G");
203 context.setAttribute("vnf.vnfc[6].type","G");
204 context.setAttribute("vnf.vnfc[6].vm_count","1");
205 context.setAttribute("vnf.vnfc[6].vm[0].url","G1");
211 private VnfcDependencyModel readComplexDependencyModel() {
212 Vnfc a = new Vnfc("A","Active-Passive",null);
213 Vnfc b = new Vnfc("B","Active-Active",null);
214 Vnfc c = new Vnfc("C","Active-Active",null);
215 Vnfc d = new Vnfc("D","Active-Active",null);
216 Vnfc e = new Vnfc("E","Active-Active",null);
217 Vnfc f = new Vnfc("F","Active-Active",null);
218 Vnfc g = new Vnfc("G","Active-Active",null);
221 Node aNode = new Node(a);
222 Node bNode = new Node(b);
223 Node cNode = new Node(c);
224 Node dNode = new Node(d);
225 Node eNode = new Node(e);
226 Node fNode = new Node(f);
227 Node gNode = new Node(g);
240 Set<Node<Vnfc>> dependencies = new HashSet<>();
241 dependencies.add(aNode);
242 dependencies.add(bNode);
243 dependencies.add(cNode);
244 dependencies.add(dNode);
245 dependencies.add(eNode);
246 dependencies.add(fNode);
247 dependencies.add(gNode);
249 return new VnfcDependencyModel(dependencies);
252 private VnfcDependencyModel readDependencyModel() {
254 Vnfc smp = new Vnfc("SMP","Active-Passive",null);
255 Vnfc be = new Vnfc("BE","Active-Active",null);
256 Vnfc fe = new Vnfc("FE","Active-Active",null);
259 Node smpNode = new Node(smp);
260 Node beNode = new Node(be);
261 Node feNode = new Node(fe);
263 beNode.addParent(smp);
264 feNode.addParent(be);
265 // smpNode.addParent(fe);
267 Set<Node<Vnfc>> dependencies = new HashSet<>();
268 dependencies.add(smpNode);
269 dependencies.add(feNode);
270 dependencies.add(beNode);
272 return new VnfcDependencyModel(dependencies);
275 private Map<String, String> prepareParams() {
276 Map<String,String> params = new HashMap<>();
277 params.put(Constants.DEPENDENCY_TYPE,"RESOURCE");
278 params.put(Constants.FLOW_STRATEGY,"FORWARD");
280 params.put(Constants.VNF_TYPE,"vSCP");
281 params.put(Constants.VNF_VERION,"1.00");
285 private SvcLogicContext prepareContext() {
286 SvcLogicContext context = new SvcLogicContext();
287 context.setAttribute("input.action-identifiers.vnf-id","1");
288 context.setAttribute("vnf.type","vSCP");
289 context.setAttribute("vnf.vnfcCount","3");
291 context.setAttribute("vnf.vnfc[0].name","SMPname");
292 context.setAttribute("vnf.vnfc[0].type","SMP");
293 context.setAttribute("vnf.vnfc[0].vm_count","2");
294 context.setAttribute("vnf.vnfc[0].vm[0].url","SMP_URL1");
295 context.setAttribute("vnf.vnfc[0].vm[1].url","SMP_URL2");
297 context.setAttribute("vnf.vnfc[1].name","BEname");
298 context.setAttribute("vnf.vnfc[1].type","BE");
299 context.setAttribute("vnf.vnfc[1].vm_count","5");
300 context.setAttribute("vnf.vnfc[1].vm[0].url","BE_URL1");
301 context.setAttribute("vnf.vnfc[1].vm[1].url","BE_URL2");
302 context.setAttribute("vnf.vnfc[1].vm[2].url","BE_URL3");
303 context.setAttribute("vnf.vnfc[1].vm[3].url","BE_URL4");
304 context.setAttribute("vnf.vnfc[1].vm[4].url","BE_URL5");
306 context.setAttribute("vnf.vnfc[2].name","FEname");
307 context.setAttribute("vnf.vnfc[2].type","FE");
308 context.setAttribute("vnf.vnfc[2].vm_count","2");
309 context.setAttribute("vnf.vnfc[2].vm[0].url","FE_URL1");
310 context.setAttribute("vnf.vnfc[2].vm[1].url","FE_URL2");
315 @Test(expected = RuntimeException.class)
316 public void testMissingVnfcTypeInDependencyModel() throws DependencyModelNotFound {
317 Map<String, String> params = prepareParams();
318 SvcLogicContext context = prepareContext();
319 context.setAttribute("vnf.vnfc[3].name","XEname");
320 context.setAttribute("vnf.vnfc[3].type","XE");
321 context.setAttribute("vnf.vnfc[3].vm_count","2");
322 context.setAttribute("vnf.vnfc[3].vm[0].url","XE_URL1");
323 context.setAttribute("vnf.vnfc[3].vm[1].url","XE_URL2");
324 context.setAttribute("vnf.vnfcCount","4");
326 VnfcDependencyModel dependencyModel = readDependencyModel();
328 PowerMockito.mockStatic(DependencyModelFactory.class);
329 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
331 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
332 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
333 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
334 .thenReturn(dependencyModel);
336 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
337 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
340 @Test(expected = RuntimeException.class)
341 public void testMissingMandatoryVnfcTypeInInventoryModel() throws DependencyModelNotFound {
342 Map<String, String> params = prepareParams();
343 SvcLogicContext context = prepareContext();
344 VnfcDependencyModel dependencyModel = readDependencyModel();
346 Vnfc xe = new Vnfc("XE","Active-Active",null, true);
347 Node xeNode = new Node(xe);
348 dependencyModel.getDependencies().add(xeNode);
350 PowerMockito.mockStatic(DependencyModelFactory.class);
351 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
353 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
354 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
355 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
356 .thenReturn(dependencyModel);
358 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
359 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
363 public void testMissingOptionalVnfcTypeInInventoryModel() throws DependencyModelNotFound {
364 Map<String, String> params = prepareParams();
365 SvcLogicContext context = prepareContext();
366 VnfcDependencyModel dependencyModel = readDependencyModel();
368 Vnfc xe = new Vnfc("XE","Active-Active",null, false);
369 Node xeNode = new Node(xe);
370 dependencyModel.getDependencies().add(xeNode);
372 PowerMockito.mockStatic(DependencyModelFactory.class);
373 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
375 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
376 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
377 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
378 .thenReturn(dependencyModel);
380 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
381 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
385 public void testMissingOptionalVnfcTypeInInventoryModelWithDependentChild() throws DependencyModelNotFound {
386 Map<String, String> params = prepareParams();
387 SvcLogicContext context = prepareContext();
388 context.setAttribute("vnf.vnfc[3].name","YEname");
389 context.setAttribute("vnf.vnfc[3].type","YE");
390 context.setAttribute("vnf.vnfc[3].vm_count","2");
391 context.setAttribute("vnf.vnfc[3].vm[0].url","YE_URL1");
392 context.setAttribute("vnf.vnfc[3].vm[1].url","YE_URL2");
393 context.setAttribute("vnf.vnfcCount","4");
395 VnfcDependencyModel dependencyModel = readDependencyModel();
397 Vnfc xe = new Vnfc("XE","Active-Active",null, false);
398 Vnfc ye = new Vnfc("YE","Active-Active",null, true);
399 Node xeNode = new Node(xe);
400 Node yeNode = new Node(ye);
401 yeNode.addParent(xe);
403 dependencyModel.getDependencies().add(yeNode);
404 dependencyModel.getDependencies().add(xeNode);
406 PowerMockito.mockStatic(DependencyModelFactory.class);
407 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
409 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
410 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
411 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
412 .thenReturn(dependencyModel);
414 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
415 vnfExecutionFlow.getVnfExecutionFlowData(params,context);