2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.dg.common.impl;
25 import com.att.eelf.configuration.EELFLogger;
26 import com.att.eelf.configuration.EELFManager;
27 import org.openecomp.sdnc.sli.SvcLogicContext;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.Matchers;
32 import org.openecomp.appc.dg.common.VnfExecutionFlow;
33 import org.openecomp.appc.dg.common.impl.Constants;
34 import org.openecomp.appc.dg.common.impl.VnfExecutionFlowImpl;
35 import org.openecomp.appc.dg.dependencymanager.DependencyManager;
36 import org.openecomp.appc.dg.dependencymanager.exception.DependencyModelNotFound;
37 import org.openecomp.appc.dg.dependencymanager.impl.DependencyModelFactory;
38 import org.openecomp.appc.dg.flowbuilder.exception.InvalidDependencyModel;
39 import org.openecomp.appc.dg.objects.DependencyTypes;
40 import org.openecomp.appc.dg.objects.Node;
41 import org.openecomp.appc.dg.objects.VnfcDependencyModel;
42 import org.openecomp.appc.domainmodel.Vnfc;
43 import org.openecomp.appc.metadata.objects.DependencyModelIdentifier;
44 import org.osgi.framework.FrameworkUtil;
45 import org.powermock.api.mockito.PowerMockito;
46 import org.powermock.core.classloader.annotations.PrepareForTest;
47 import org.powermock.modules.junit4.PowerMockRunner;
49 import java.util.HashMap;
50 import java.util.HashSet;
54 @RunWith(PowerMockRunner.class)
55 @PrepareForTest({TestVnfExecutionFlowImpl.class, FrameworkUtil.class,DependencyManager.class,DependencyModelFactory.class})
56 public class TestVnfExecutionFlowImpl {
58 private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVnfExecutionFlowImpl.class);
62 logger.setLevel(EELFLogger.Level.DEBUG);
66 public void testPositiveFlow() throws DependencyModelNotFound {
67 Map<String, String> params = prepareParams();
68 SvcLogicContext context = prepareContext();
69 VnfcDependencyModel dependencyModel = readDependencyModel();
71 PowerMockito.mockStatic(DependencyModelFactory.class);
72 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
74 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
75 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
76 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
77 .thenReturn(dependencyModel);
79 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
80 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
84 public void testComplexFlow() throws DependencyModelNotFound {
85 Map<String, String> params = prepareParams();
86 SvcLogicContext context = prepareContextForComplexDependency();
87 VnfcDependencyModel dependencyModel = readComplexDependencyModel();
89 PowerMockito.mockStatic(DependencyModelFactory.class);
90 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
92 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
93 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
94 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
95 .thenReturn(dependencyModel);
97 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
98 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
101 @Test(expected = InvalidDependencyModel.class)
102 public void testCycleFlow() throws DependencyModelNotFound {
103 Map<String, String> params = prepareParams();
104 SvcLogicContext context = prepareContextForComplexDependency();
105 VnfcDependencyModel dependencyModel = readCyclicDependencyModel();
106 PowerMockito.mockStatic(DependencyModelFactory.class);
107 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
109 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
110 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
111 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
112 .thenReturn(dependencyModel);
114 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
115 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
118 private VnfcDependencyModel readCyclicDependencyModel() {
120 Vnfc a = new Vnfc("A","Active-Passive",null);
121 Vnfc b = new Vnfc("B","Active-Active",null);
122 Vnfc c = new Vnfc("C","Active-Active",null);
123 Vnfc d = new Vnfc("D","Active-Active",null);
124 Vnfc e = new Vnfc("E","Active-Active",null);
125 Vnfc f = new Vnfc("F","Active-Active",null);
126 Vnfc g = new Vnfc("G","Active-Active",null);
128 Node aNode = new Node(a);
129 Node bNode = new Node(b);
130 Node cNode = new Node(c);
131 Node dNode = new Node(d);
132 Node eNode = new Node(e);
133 Node fNode = new Node(f);
134 Node gNode = new Node(g);
143 Set<Node<Vnfc>> dependencies = new HashSet<>();
144 dependencies.add(aNode);
145 dependencies.add(bNode);
146 dependencies.add(cNode);
147 dependencies.add(dNode);
148 dependencies.add(eNode);
149 dependencies.add(fNode);
150 dependencies.add(gNode);
152 return new VnfcDependencyModel(dependencies);
156 private SvcLogicContext prepareContextForComplexDependency() {
157 SvcLogicContext context = new SvcLogicContext();
158 context.setAttribute("input.action-identifiers.vnf-id","1");
159 context.setAttribute("vnf.type","vSCP");
160 context.setAttribute("vnf.vnfcCount","7");
162 context.setAttribute("vnf.vnfc[0].name","A");
163 context.setAttribute("vnf.vnfc[0].type","A");
164 context.setAttribute("vnf.vnfc[0].vm_count","2");
165 context.setAttribute("vnf.vnfc[0].vm[0].url","A1");
166 context.setAttribute("vnf.vnfc[0].vm[1].url","A2");
168 context.setAttribute("vnf.vnfc[1].name","B");
169 context.setAttribute("vnf.vnfc[1].type","B");
170 context.setAttribute("vnf.vnfc[1].vm_count","5");
171 context.setAttribute("vnf.vnfc[1].vm[0].url","B1");
172 context.setAttribute("vnf.vnfc[1].vm[1].url","B2");
173 context.setAttribute("vnf.vnfc[1].vm[2].url","B3");
174 context.setAttribute("vnf.vnfc[1].vm[3].url","B4");
175 context.setAttribute("vnf.vnfc[1].vm[4].url","B5");
177 context.setAttribute("vnf.vnfc[2].name","C");
178 context.setAttribute("vnf.vnfc[2].type","C");
179 context.setAttribute("vnf.vnfc[2].vm_count","4");
180 context.setAttribute("vnf.vnfc[2].vm[0].url","C1");
181 context.setAttribute("vnf.vnfc[2].vm[1].url","C2");
182 context.setAttribute("vnf.vnfc[2].vm[2].url","C3");
183 context.setAttribute("vnf.vnfc[2].vm[3].url","C4");
185 context.setAttribute("vnf.vnfc[3].name","D");
186 context.setAttribute("vnf.vnfc[3].type","D");
187 context.setAttribute("vnf.vnfc[3].vm_count","3");
188 context.setAttribute("vnf.vnfc[3].vm[0].url","D1");
189 context.setAttribute("vnf.vnfc[3].vm[1].url","D2");
190 context.setAttribute("vnf.vnfc[3].vm[2].url","D3");
192 context.setAttribute("vnf.vnfc[4].name","E");
193 context.setAttribute("vnf.vnfc[4].type","E");
194 context.setAttribute("vnf.vnfc[4].vm_count","2");
195 context.setAttribute("vnf.vnfc[4].vm[0].url","E1");
196 context.setAttribute("vnf.vnfc[4].vm[1].url","E2");
198 context.setAttribute("vnf.vnfc[5].name","F");
199 context.setAttribute("vnf.vnfc[5].type","F");
200 context.setAttribute("vnf.vnfc[5].vm_count","1");
201 context.setAttribute("vnf.vnfc[5].vm[0].url","F1");
203 context.setAttribute("vnf.vnfc[6].name","G");
204 context.setAttribute("vnf.vnfc[6].type","G");
205 context.setAttribute("vnf.vnfc[6].vm_count","1");
206 context.setAttribute("vnf.vnfc[6].vm[0].url","G1");
212 private VnfcDependencyModel readComplexDependencyModel() {
213 Vnfc a = new Vnfc("A","Active-Passive",null);
214 Vnfc b = new Vnfc("B","Active-Active",null);
215 Vnfc c = new Vnfc("C","Active-Active",null);
216 Vnfc d = new Vnfc("D","Active-Active",null);
217 Vnfc e = new Vnfc("E","Active-Active",null);
218 Vnfc f = new Vnfc("F","Active-Active",null);
219 Vnfc g = new Vnfc("G","Active-Active",null);
222 Node aNode = new Node(a);
223 Node bNode = new Node(b);
224 Node cNode = new Node(c);
225 Node dNode = new Node(d);
226 Node eNode = new Node(e);
227 Node fNode = new Node(f);
228 Node gNode = new Node(g);
241 Set<Node<Vnfc>> dependencies = new HashSet<>();
242 dependencies.add(aNode);
243 dependencies.add(bNode);
244 dependencies.add(cNode);
245 dependencies.add(dNode);
246 dependencies.add(eNode);
247 dependencies.add(fNode);
248 dependencies.add(gNode);
250 return new VnfcDependencyModel(dependencies);
253 private VnfcDependencyModel readDependencyModel() {
255 Vnfc smp = new Vnfc("SMP","Active-Passive",null);
256 Vnfc be = new Vnfc("BE","Active-Active",null);
257 Vnfc fe = new Vnfc("FE","Active-Active",null);
260 Node smpNode = new Node(smp);
261 Node beNode = new Node(be);
262 Node feNode = new Node(fe);
264 beNode.addParent(smp);
265 feNode.addParent(be);
266 // smpNode.addParent(fe);
268 Set<Node<Vnfc>> dependencies = new HashSet<>();
269 dependencies.add(smpNode);
270 dependencies.add(feNode);
271 dependencies.add(beNode);
273 return new VnfcDependencyModel(dependencies);
276 private Map<String, String> prepareParams() {
277 Map<String,String> params = new HashMap<>();
278 params.put(Constants.DEPENDENCY_TYPE,"RESOURCE");
279 params.put(Constants.FLOW_STRATEGY,"FORWARD");
281 params.put(Constants.VNF_TYPE,"vSCP");
282 params.put(Constants.VNF_VERION,"1.00");
286 private SvcLogicContext prepareContext() {
287 SvcLogicContext context = new SvcLogicContext();
288 context.setAttribute("input.action-identifiers.vnf-id","1");
289 context.setAttribute("vnf.type","vSCP");
290 context.setAttribute("vnf.vnfcCount","3");
292 context.setAttribute("vnf.vnfc[0].name","SMPname");
293 context.setAttribute("vnf.vnfc[0].type","SMP");
294 context.setAttribute("vnf.vnfc[0].vm_count","2");
295 context.setAttribute("vnf.vnfc[0].vm[0].url","SMP_URL1");
296 context.setAttribute("vnf.vnfc[0].vm[1].url","SMP_URL2");
298 context.setAttribute("vnf.vnfc[1].name","BEname");
299 context.setAttribute("vnf.vnfc[1].type","BE");
300 context.setAttribute("vnf.vnfc[1].vm_count","5");
301 context.setAttribute("vnf.vnfc[1].vm[0].url","BE_URL1");
302 context.setAttribute("vnf.vnfc[1].vm[1].url","BE_URL2");
303 context.setAttribute("vnf.vnfc[1].vm[2].url","BE_URL3");
304 context.setAttribute("vnf.vnfc[1].vm[3].url","BE_URL4");
305 context.setAttribute("vnf.vnfc[1].vm[4].url","BE_URL5");
307 context.setAttribute("vnf.vnfc[2].name","FEname");
308 context.setAttribute("vnf.vnfc[2].type","FE");
309 context.setAttribute("vnf.vnfc[2].vm_count","2");
310 context.setAttribute("vnf.vnfc[2].vm[0].url","FE_URL1");
311 context.setAttribute("vnf.vnfc[2].vm[1].url","FE_URL2");
316 @Test(expected = RuntimeException.class)
317 public void testMissingVnfcTypeInDependencyModel() throws DependencyModelNotFound {
318 Map<String, String> params = prepareParams();
319 SvcLogicContext context = prepareContext();
320 context.setAttribute("vnf.vnfc[3].name","XEname");
321 context.setAttribute("vnf.vnfc[3].type","XE");
322 context.setAttribute("vnf.vnfc[3].vm_count","2");
323 context.setAttribute("vnf.vnfc[3].vm[0].url","XE_URL1");
324 context.setAttribute("vnf.vnfc[3].vm[1].url","XE_URL2");
325 context.setAttribute("vnf.vnfcCount","4");
327 VnfcDependencyModel dependencyModel = readDependencyModel();
329 PowerMockito.mockStatic(DependencyModelFactory.class);
330 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
332 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
333 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
334 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
335 .thenReturn(dependencyModel);
337 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
338 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
341 @Test(expected = RuntimeException.class)
342 public void testMissingMandatoryVnfcTypeInInventoryModel() throws DependencyModelNotFound {
343 Map<String, String> params = prepareParams();
344 SvcLogicContext context = prepareContext();
345 VnfcDependencyModel dependencyModel = readDependencyModel();
347 Vnfc xe = new Vnfc("XE","Active-Active",null, true);
348 Node xeNode = new Node(xe);
349 dependencyModel.getDependencies().add(xeNode);
351 PowerMockito.mockStatic(DependencyModelFactory.class);
352 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
354 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
355 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
356 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
357 .thenReturn(dependencyModel);
359 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
360 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
364 public void testMissingOptionalVnfcTypeInInventoryModel() throws DependencyModelNotFound {
365 Map<String, String> params = prepareParams();
366 SvcLogicContext context = prepareContext();
367 VnfcDependencyModel dependencyModel = readDependencyModel();
369 Vnfc xe = new Vnfc("XE","Active-Active",null, false);
370 Node xeNode = new Node(xe);
371 dependencyModel.getDependencies().add(xeNode);
373 PowerMockito.mockStatic(DependencyModelFactory.class);
374 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
376 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
377 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
378 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
379 .thenReturn(dependencyModel);
381 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
382 vnfExecutionFlow.getVnfExecutionFlowData(params,context);
386 public void testMissingOptionalVnfcTypeInInventoryModelWithDependentChild() throws DependencyModelNotFound {
387 Map<String, String> params = prepareParams();
388 SvcLogicContext context = prepareContext();
389 context.setAttribute("vnf.vnfc[3].name","YEname");
390 context.setAttribute("vnf.vnfc[3].type","YE");
391 context.setAttribute("vnf.vnfc[3].vm_count","2");
392 context.setAttribute("vnf.vnfc[3].vm[0].url","YE_URL1");
393 context.setAttribute("vnf.vnfc[3].vm[1].url","YE_URL2");
394 context.setAttribute("vnf.vnfcCount","4");
396 VnfcDependencyModel dependencyModel = readDependencyModel();
398 Vnfc xe = new Vnfc("XE","Active-Active",null, false);
399 Vnfc ye = new Vnfc("YE","Active-Active",null, true);
400 Node xeNode = new Node(xe);
401 Node yeNode = new Node(ye);
402 yeNode.addParent(xe);
404 dependencyModel.getDependencies().add(yeNode);
405 dependencyModel.getDependencies().add(xeNode);
407 PowerMockito.mockStatic(DependencyModelFactory.class);
408 DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class);
410 PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager);
411 PowerMockito.when(dependencyManager.getVnfcDependencyModel((
412 DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any()))
413 .thenReturn(dependencyModel);
415 VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl();
416 vnfExecutionFlow.getVnfExecutionFlowData(params,context);