From 13b9505921e2cbbd4b155a78bfdaa5caa3375ec0 Mon Sep 17 00:00:00 2001 From: Ramya Balaji Date: Tue, 2 Jan 2018 21:58:59 -0500 Subject: Updated SDC listener and dependent bundles Changes related to SDC adapter.Also includes sequence generator changes and changes to appc-dg-shared. Issue-ID: APPC-355 Change-Id: Ib8a0b1d304199db6d2595291539b266885842d63 Signed-off-by: Ramya Balaji --- .../onap/appc/dg/common/impl/JsonDgUtilImpl.java | 4 +- .../appc/dg/common/impl/VnfExecutionFlowImpl.java | 137 ++++--- .../dg/common/impl/DCAEReporterPluginImplTest.java | 5 +- .../dg/common/impl/TestVnfExecutionFlowImpl.java | 420 -------------------- .../dg/common/impl/VnfExecutionFlowImplTest.java | 421 +++++++++++++++++++++ 5 files changed, 512 insertions(+), 475 deletions(-) delete mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java create mode 100644 appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImplTest.java (limited to 'appc-dg/appc-dg-shared/appc-dg-common/src') diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java index fff43cbf5..caad8b809 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/JsonDgUtilImpl.java @@ -29,7 +29,7 @@ import java.text.SimpleDateFormat; import java.util.Map; import java.util.Set; -import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.onap.appc.dg.common.JsonDgUtil; import org.onap.appc.exceptions.APPCException; @@ -63,7 +63,7 @@ public class JsonDgUtilImpl implements JsonDgUtil { try { String paramName = Constants.PAYLOAD; String payload = params.get(paramName); - if (payload == "") + if (payload == null || payload.isEmpty()) payload = ctx.getAttribute("input.payload"); if (!StringUtils.isEmpty(payload)) { Map flatMap = JsonUtil.convertJsonStringToFlatMap(payload); diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java index 65b364f62..8129e2e02 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/main/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImpl.java @@ -28,6 +28,7 @@ import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import com.att.eelf.i18n.EELFResourceManager; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.appc.exceptions.APPCException; import java.util.*; @@ -36,7 +37,7 @@ import org.onap.appc.dg.dependencymanager.DependencyManager; import org.onap.appc.dg.dependencymanager.exception.DependencyModelNotFound; import org.onap.appc.dg.dependencymanager.impl.DependencyModelFactory; import org.onap.appc.dg.flowbuilder.FlowBuilder; -import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModel; +import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModelException; import org.onap.appc.dg.flowbuilder.impl.FlowBuilderFactory; import org.onap.appc.dg.objects.*; import org.onap.appc.domainmodel.Vnf; @@ -47,10 +48,15 @@ import org.onap.appc.metadata.objects.DependencyModelIdentifier; public class VnfExecutionFlowImpl implements VnfExecutionFlow { - private static final EELFLogger logger = EELFManager.getInstance().getLogger(VnfExecutionFlowImpl.class); - + private final EELFLogger logger = EELFManager.getInstance().getLogger(VnfExecutionFlowImpl.class); + private static final String VNFC_FLOW="vnfcFlow["; + private static final String VNF_VNFC="vnf.vnfc["; + /** + * Constructor + *

Used through blueprint + */ public VnfExecutionFlowImpl(){ - + // do nothing } @Override @@ -58,7 +64,7 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { String dependencyType = params.get(Constants.DEPENDENCY_TYPE); String flowStrategy = params.get(Constants.FLOW_STRATEGY); DependencyModelIdentifier modelIdentifier = readDependencyModelIdentifier(params); - VnfcDependencyModel dependencyModel = null; + VnfcDependencyModel dependencyModel; try { validateInput(dependencyType, flowStrategy, params); @@ -69,8 +75,6 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { } DependencyManager dependencyManager = DependencyModelFactory.createDependencyManager(); - - dependencyModel = dependencyManager.getVnfcDependencyModel( modelIdentifier, DependencyTypes.findByString(dependencyType)); } catch (DependencyModelNotFound e) { @@ -79,12 +83,17 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg); context.setAttribute("dependencyModelFound","false"); return; - } catch (InvalidDependencyModel e){ + } catch (InvalidDependencyModelException e){ String msg = EELFResourceManager.format(Msg.INVALID_DEPENDENCY_MODEL,params.get(Constants.VNF_TYPE), e.getMessage()); logger.error(msg); context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg); - throw e; - }catch (RuntimeException e){ + throw new RuntimeException(e.getMessage(),e); + } catch (APPCException e){ + logger.error(e.getMessage()); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); + throw new RuntimeException(e.getMessage(),e); + } + catch (RuntimeException e){ logger.error(e.getMessage()); context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); throw e; @@ -96,7 +105,14 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { logger.debug("Dependency Model = " +dependencyModel); } logger.info("Building Inventory Model from DG context"); - InventoryModel inventoryModel = readInventoryModel(context); + InventoryModel inventoryModel = null; + try { + inventoryModel = readInventoryModel(context); + } catch (APPCException e) { + logger.error(e.getMessage()); + context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); + throw new RuntimeException(e.getMessage(),e); + } if(logger.isDebugEnabled()){ logger.debug("Inventory Model = " +inventoryModel); } @@ -106,25 +122,26 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { } try { validateInventoryModelWithDependencyModel(dependencyModel, inventoryModel); - }catch (RuntimeException e){ + } + catch (APPCException e){ logger.error(e.getMessage()); context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,e.getMessage()); - throw e; + throw new RuntimeException(e.getMessage(),e); } logger.info("Creating flow builder"); FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder( FlowStrategies.findByString(flowStrategy)); logger.info("Building Vnf flow model"); - VnfcFlowModel flowModel = null; + VnfcFlowModel flowModel; try{ flowModel = flowBuilder.buildFlowModel(dependencyModel,inventoryModel); } - catch (InvalidDependencyModel e){ + catch (InvalidDependencyModelException e){ String msg = EELFResourceManager.format(Msg.INVALID_DEPENDENCY_MODEL,params.get(Constants.VNF_TYPE), e.getMessage()); logger.error(msg); context.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg); - throw e; + throw new RuntimeException(e.getMessage(),e); } // remove VNFCs from the flow model where vserver list is empty @@ -137,22 +154,22 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { context.setAttribute(org.onap.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg); } - private void validateInput(String dependencyType, String flowStrategy, Map params) { + private void validateInput(String dependencyType, String flowStrategy, Map params) throws APPCException { DependencyTypes dependencyTypes = DependencyTypes.findByString(dependencyType); if(dependencyTypes == null){ - throw new RuntimeException("Dependency type from the input : " + dependencyType +" is invalid."); + throw new APPCException("Dependency type from the input : " + dependencyType +" is invalid."); } FlowStrategies flowStrategies = FlowStrategies.findByString(flowStrategy); if(flowStrategies == null){ - throw new RuntimeException("Flow Strategy from the input : " + flowStrategy +" is invalid."); + throw new APPCException("Flow Strategy from the input : " + flowStrategy +" is invalid."); } String vnfType = params.get(Constants.VNF_TYPE); if(vnfType ==null || vnfType.length() ==0){ - throw new RuntimeException("Vnf Type is not passed in the input"); + throw new APPCException("Vnf Type is not passed in the input"); } String vnfVersion = params.get(Constants.VNF_VERION); if(vnfVersion == null || vnfVersion.length() ==0){ - throw new RuntimeException("Vnf Version not found"); + throw new APPCException("Vnf Version not found"); } } @@ -167,13 +184,13 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { Iterator> iterator = flowModel.getModelIterator(); while (iterator.hasNext()){ for(Vnfc vnfc:iterator.next()){ - context.setAttribute("vnfcFlow["+flowIndex+"].vnfcName",vnfc.getVnfcName()); - context.setAttribute("vnfcFlow["+flowIndex+"].vnfcType",vnfc.getVnfcType()); - context.setAttribute("vnfcFlow["+flowIndex+"].resilienceType",vnfc.getResilienceType()); - context.setAttribute("vnfcFlow["+flowIndex+"].vmCount",Integer.toString(vnfc.getVserverList().size())); + context.setAttribute(VNFC_FLOW+flowIndex+"].vnfcName",vnfc.getVnfcName()); + context.setAttribute(VNFC_FLOW+flowIndex+"].vnfcType",vnfc.getVnfcType()); + context.setAttribute(VNFC_FLOW+flowIndex+"].resilienceType",vnfc.getResilienceType()); + context.setAttribute(VNFC_FLOW+flowIndex+"].vmCount",Integer.toString(vnfc.getVserverList().size())); int vmIndex =0; for(Vserver vm :vnfc.getVserverList()){ - context.setAttribute("vnfcFlow["+flowIndex+"].vm["+vmIndex+"].url",vm.getUrl()); + context.setAttribute(VNFC_FLOW+flowIndex+"].vm["+vmIndex+"].url",vm.getUrl()); vmIndex++; } flowIndex++; @@ -182,73 +199,88 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { context.setAttribute("vnfcFlowCount",Integer.toString(flowIndex)); } - private InventoryModel readInventoryModel(SvcLogicContext context) { + private InventoryModel readInventoryModel(SvcLogicContext context) throws APPCException { String vnfId = context.getAttribute("input.action-identifiers.vnf-id"); String vnfType = context.getAttribute("vnf.type"); String vnfVersion = context.getAttribute("vnf.version"); String vnfcCountStr = context.getAttribute("vnf.vnfcCount"); Integer vnfcCount = Integer.parseInt(vnfcCountStr); - - Vnf vnf = new Vnf(vnfId,vnfType,vnfVersion); - + Vnf vnf = createVnf(vnfId, vnfType, vnfVersion); for(Integer i=0;i params) { String vnfType = params.get(Constants.VNF_TYPE); String catalogVersion = params.get(Constants.VNF_VERION); return new DependencyModelIdentifier(vnfType,catalogVersion); } - private void validateInventoryModelWithDependencyModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) { - Set dependencyModelVnfcSet = new HashSet(); - Set dependencyModelMandatoryVnfcSet = new HashSet(); - Set inventoryModelVnfcsSet = new HashSet(); - + private void validateInventoryModelWithDependencyModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) throws APPCException { + Set dependencyModelVnfcSet = new HashSet<>(); + Set dependencyModelMandatoryVnfcSet = new HashSet<>(); + Set inventoryModelVnfcsSet = new HashSet<>(); for (Node node : dependencyModel.getDependencies()) { dependencyModelVnfcSet.add(node.getChild().getVnfcType().toLowerCase()); if (node.getChild().isMandatory()) { dependencyModelMandatoryVnfcSet.add(node.getChild().getVnfcType().toLowerCase()); } } - for (Vnfc vnfc : inventoryModel.getVnf().getVnfcs()) { inventoryModelVnfcsSet.add(vnfc.getVnfcType().toLowerCase()); } - // if dependency model and inventory model contains same set of VNFCs, validation succeed and hence return if (dependencyModelVnfcSet.equals(inventoryModelVnfcsSet)) { return; } - if (inventoryModelVnfcsSet.size() >= dependencyModelVnfcSet.size()) { - Set difference = new HashSet(inventoryModelVnfcsSet); + Set difference = new HashSet<>(inventoryModelVnfcsSet); difference.removeAll(dependencyModelVnfcSet); logger.error("Dependency model is missing following vnfc type(s): " + difference); - throw new RuntimeException("Dependency model is missing following vnfc type(s): " + difference); + throw new APPCException("Dependency model is missing following vnfc type(s): " + difference); } else { - Set difference = new HashSet(dependencyModelVnfcSet); + Set difference = new HashSet<>(dependencyModelMandatoryVnfcSet); difference.removeAll(inventoryModelVnfcsSet); - difference.retainAll(dependencyModelMandatoryVnfcSet); if (difference.size() > 0) { logger.error("Inventory model is missing following mandatory vnfc type(s): " + difference); - throw new RuntimeException("Inventory model is missing following mandatory vnfc type(s): " + difference); + throw new APPCException("Inventory model is missing following mandatory vnfc type(s): " + difference); } } } @@ -268,4 +300,5 @@ public class VnfExecutionFlowImpl implements VnfExecutionFlow { } } } + } diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java index 7c36360f8..42f7a6bc6 100644 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/DCAEReporterPluginImplTest.java @@ -28,7 +28,10 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.*; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.mockito.Spy; import org.onap.appc.adapter.message.EventSender; import org.onap.appc.adapter.message.MessageDestination; import org.onap.appc.adapter.message.event.EventMessage; diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java deleted file mode 100644 index bad862030..000000000 --- a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/TestVnfExecutionFlowImpl.java +++ /dev/null @@ -1,420 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.dg.common.impl; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.onap.appc.dg.common.VnfExecutionFlow; -import org.onap.appc.dg.common.impl.Constants; -import org.onap.appc.dg.common.impl.VnfExecutionFlowImpl; -import org.onap.appc.dg.dependencymanager.DependencyManager; -import org.onap.appc.dg.dependencymanager.exception.DependencyModelNotFound; -import org.onap.appc.dg.dependencymanager.impl.DependencyModelFactory; -import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModel; -import org.onap.appc.dg.objects.DependencyTypes; -import org.onap.appc.dg.objects.Node; -import org.onap.appc.dg.objects.VnfcDependencyModel; -import org.onap.appc.domainmodel.Vnfc; -import org.onap.appc.metadata.objects.DependencyModelIdentifier; -import org.osgi.framework.FrameworkUtil; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({TestVnfExecutionFlowImpl.class, FrameworkUtil.class,DependencyManager.class,DependencyModelFactory.class}) -public class TestVnfExecutionFlowImpl { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(TestVnfExecutionFlowImpl.class); - - @Before - public void setUp() { - logger.setLevel(EELFLogger.Level.DEBUG); - } - - @Test - public void testPositiveFlow() throws DependencyModelNotFound { - Map params = prepareParams(); - SvcLogicContext context = prepareContext(); - VnfcDependencyModel dependencyModel = readDependencyModel(); - - PowerMockito.mockStatic(DependencyModelFactory.class); - DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); - - PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); - PowerMockito.when(dependencyManager.getVnfcDependencyModel(( - DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) - .thenReturn(dependencyModel); - - VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); - vnfExecutionFlow.getVnfExecutionFlowData(params,context); - } - - @Test - public void testComplexFlow() throws DependencyModelNotFound { - Map params = prepareParams(); - SvcLogicContext context = prepareContextForComplexDependency(); - VnfcDependencyModel dependencyModel = readComplexDependencyModel(); - - PowerMockito.mockStatic(DependencyModelFactory.class); - DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); - - PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); - PowerMockito.when(dependencyManager.getVnfcDependencyModel(( - DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) - .thenReturn(dependencyModel); - - VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); - vnfExecutionFlow.getVnfExecutionFlowData(params,context); - } - - @Test(expected = InvalidDependencyModel.class) - public void testCycleFlow() throws DependencyModelNotFound { - Map params = prepareParams(); - SvcLogicContext context = prepareContextForComplexDependency(); - VnfcDependencyModel dependencyModel = readCyclicDependencyModel(); - PowerMockito.mockStatic(DependencyModelFactory.class); - DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); - - PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); - PowerMockito.when(dependencyManager.getVnfcDependencyModel(( - DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) - .thenReturn(dependencyModel); - - VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); - vnfExecutionFlow.getVnfExecutionFlowData(params,context); - } - - private VnfcDependencyModel readCyclicDependencyModel() { - - Vnfc a = new Vnfc("A","Active-Passive",null); - Vnfc b = new Vnfc("B","Active-Active",null); - Vnfc c = new Vnfc("C","Active-Active",null); - Vnfc d = new Vnfc("D","Active-Active",null); - Vnfc e = new Vnfc("E","Active-Active",null); - Vnfc f = new Vnfc("F","Active-Active",null); - Vnfc g = new Vnfc("G","Active-Active",null); - - Node aNode = new Node(a); - Node bNode = new Node(b); - Node cNode = new Node(c); - Node dNode = new Node(d); - Node eNode = new Node(e); - Node fNode = new Node(f); - Node gNode = new Node(g); - - bNode.addParent(a); - cNode.addParent(a); - cNode.addParent(b); - - bNode.addParent(d); - dNode.addParent(c); - - Set> dependencies = new HashSet<>(); - dependencies.add(aNode); - dependencies.add(bNode); - dependencies.add(cNode); - dependencies.add(dNode); - dependencies.add(eNode); - dependencies.add(fNode); - dependencies.add(gNode); - - return new VnfcDependencyModel(dependencies); - - } - - private SvcLogicContext prepareContextForComplexDependency() { - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("input.action-identifiers.vnf-id","1"); - context.setAttribute("vnf.type","vSCP"); - context.setAttribute("vnf.vnfcCount","7"); - - context.setAttribute("vnf.vnfc[0].name","A"); - context.setAttribute("vnf.vnfc[0].type","A"); - context.setAttribute("vnf.vnfc[0].vm_count","2"); - context.setAttribute("vnf.vnfc[0].vm[0].url","A1"); - context.setAttribute("vnf.vnfc[0].vm[1].url","A2"); - - context.setAttribute("vnf.vnfc[1].name","B"); - context.setAttribute("vnf.vnfc[1].type","B"); - context.setAttribute("vnf.vnfc[1].vm_count","5"); - context.setAttribute("vnf.vnfc[1].vm[0].url","B1"); - context.setAttribute("vnf.vnfc[1].vm[1].url","B2"); - context.setAttribute("vnf.vnfc[1].vm[2].url","B3"); - context.setAttribute("vnf.vnfc[1].vm[3].url","B4"); - context.setAttribute("vnf.vnfc[1].vm[4].url","B5"); - - context.setAttribute("vnf.vnfc[2].name","C"); - context.setAttribute("vnf.vnfc[2].type","C"); - context.setAttribute("vnf.vnfc[2].vm_count","4"); - context.setAttribute("vnf.vnfc[2].vm[0].url","C1"); - context.setAttribute("vnf.vnfc[2].vm[1].url","C2"); - context.setAttribute("vnf.vnfc[2].vm[2].url","C3"); - context.setAttribute("vnf.vnfc[2].vm[3].url","C4"); - - context.setAttribute("vnf.vnfc[3].name","D"); - context.setAttribute("vnf.vnfc[3].type","D"); - context.setAttribute("vnf.vnfc[3].vm_count","3"); - context.setAttribute("vnf.vnfc[3].vm[0].url","D1"); - context.setAttribute("vnf.vnfc[3].vm[1].url","D2"); - context.setAttribute("vnf.vnfc[3].vm[2].url","D3"); - - context.setAttribute("vnf.vnfc[4].name","E"); - context.setAttribute("vnf.vnfc[4].type","E"); - context.setAttribute("vnf.vnfc[4].vm_count","2"); - context.setAttribute("vnf.vnfc[4].vm[0].url","E1"); - context.setAttribute("vnf.vnfc[4].vm[1].url","E2"); - - context.setAttribute("vnf.vnfc[5].name","F"); - context.setAttribute("vnf.vnfc[5].type","F"); - context.setAttribute("vnf.vnfc[5].vm_count","1"); - context.setAttribute("vnf.vnfc[5].vm[0].url","F1"); - - context.setAttribute("vnf.vnfc[6].name","G"); - context.setAttribute("vnf.vnfc[6].type","G"); - context.setAttribute("vnf.vnfc[6].vm_count","1"); - context.setAttribute("vnf.vnfc[6].vm[0].url","G1"); - - - return context; - } - - private VnfcDependencyModel readComplexDependencyModel() { - Vnfc a = new Vnfc("A","Active-Passive",null); - Vnfc b = new Vnfc("B","Active-Active",null); - Vnfc c = new Vnfc("C","Active-Active",null); - Vnfc d = new Vnfc("D","Active-Active",null); - Vnfc e = new Vnfc("E","Active-Active",null); - Vnfc f = new Vnfc("F","Active-Active",null); - Vnfc g = new Vnfc("G","Active-Active",null); - - - Node aNode = new Node(a); - Node bNode = new Node(b); - Node cNode = new Node(c); - Node dNode = new Node(d); - Node eNode = new Node(e); - Node fNode = new Node(f); - Node gNode = new Node(g); - - bNode.addParent(a); - cNode.addParent(a); - - dNode.addParent(b); - eNode.addParent(b); - gNode.addParent(b); - - fNode.addParent(c); - - gNode.addParent(f); - - Set> dependencies = new HashSet<>(); - dependencies.add(aNode); - dependencies.add(bNode); - dependencies.add(cNode); - dependencies.add(dNode); - dependencies.add(eNode); - dependencies.add(fNode); - dependencies.add(gNode); - - return new VnfcDependencyModel(dependencies); - } - - private VnfcDependencyModel readDependencyModel() { - - Vnfc smp = new Vnfc("SMP","Active-Passive",null); - Vnfc be = new Vnfc("BE","Active-Active",null); - Vnfc fe = new Vnfc("FE","Active-Active",null); - - - Node smpNode = new Node(smp); - Node beNode = new Node(be); - Node feNode = new Node(fe); - - beNode.addParent(smp); - feNode.addParent(be); -// smpNode.addParent(fe); - - Set> dependencies = new HashSet<>(); - dependencies.add(smpNode); - dependencies.add(feNode); - dependencies.add(beNode); - - return new VnfcDependencyModel(dependencies); - } - - private Map prepareParams() { - Map params = new HashMap<>(); - params.put(Constants.DEPENDENCY_TYPE,"RESOURCE"); - params.put(Constants.FLOW_STRATEGY,"FORWARD"); - - params.put(Constants.VNF_TYPE,"vSCP"); - params.put(Constants.VNF_VERION,"1.00"); - return params; - } - - private SvcLogicContext prepareContext() { - SvcLogicContext context = new SvcLogicContext(); - context.setAttribute("input.action-identifiers.vnf-id","1"); - context.setAttribute("vnf.type","vSCP"); - context.setAttribute("vnf.vnfcCount","3"); - - context.setAttribute("vnf.vnfc[0].name","SMPname"); - context.setAttribute("vnf.vnfc[0].type","SMP"); - context.setAttribute("vnf.vnfc[0].vm_count","2"); - context.setAttribute("vnf.vnfc[0].vm[0].url","SMP_URL1"); - context.setAttribute("vnf.vnfc[0].vm[1].url","SMP_URL2"); - - context.setAttribute("vnf.vnfc[1].name","BEname"); - context.setAttribute("vnf.vnfc[1].type","BE"); - context.setAttribute("vnf.vnfc[1].vm_count","5"); - context.setAttribute("vnf.vnfc[1].vm[0].url","BE_URL1"); - context.setAttribute("vnf.vnfc[1].vm[1].url","BE_URL2"); - context.setAttribute("vnf.vnfc[1].vm[2].url","BE_URL3"); - context.setAttribute("vnf.vnfc[1].vm[3].url","BE_URL4"); - context.setAttribute("vnf.vnfc[1].vm[4].url","BE_URL5"); - - context.setAttribute("vnf.vnfc[2].name","FEname"); - context.setAttribute("vnf.vnfc[2].type","FE"); - context.setAttribute("vnf.vnfc[2].vm_count","2"); - context.setAttribute("vnf.vnfc[2].vm[0].url","FE_URL1"); - context.setAttribute("vnf.vnfc[2].vm[1].url","FE_URL2"); - - return context; - } - - @Test(expected = RuntimeException.class) - public void testMissingVnfcTypeInDependencyModel() throws DependencyModelNotFound { - Map params = prepareParams(); - SvcLogicContext context = prepareContext(); - context.setAttribute("vnf.vnfc[3].name","XEname"); - context.setAttribute("vnf.vnfc[3].type","XE"); - context.setAttribute("vnf.vnfc[3].vm_count","2"); - context.setAttribute("vnf.vnfc[3].vm[0].url","XE_URL1"); - context.setAttribute("vnf.vnfc[3].vm[1].url","XE_URL2"); - context.setAttribute("vnf.vnfcCount","4"); - - VnfcDependencyModel dependencyModel = readDependencyModel(); - - PowerMockito.mockStatic(DependencyModelFactory.class); - DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); - - PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); - PowerMockito.when(dependencyManager.getVnfcDependencyModel(( - DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) - .thenReturn(dependencyModel); - - VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); - vnfExecutionFlow.getVnfExecutionFlowData(params,context); - } - - @Test(expected = RuntimeException.class) - public void testMissingMandatoryVnfcTypeInInventoryModel() throws DependencyModelNotFound { - Map params = prepareParams(); - SvcLogicContext context = prepareContext(); - VnfcDependencyModel dependencyModel = readDependencyModel(); - - Vnfc xe = new Vnfc("XE","Active-Active",null, true); - Node xeNode = new Node(xe); - dependencyModel.getDependencies().add(xeNode); - - PowerMockito.mockStatic(DependencyModelFactory.class); - DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); - - PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); - PowerMockito.when(dependencyManager.getVnfcDependencyModel(( - DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) - .thenReturn(dependencyModel); - - VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); - vnfExecutionFlow.getVnfExecutionFlowData(params,context); - } - - @Test - public void testMissingOptionalVnfcTypeInInventoryModel() throws DependencyModelNotFound { - Map params = prepareParams(); - SvcLogicContext context = prepareContext(); - VnfcDependencyModel dependencyModel = readDependencyModel(); - - Vnfc xe = new Vnfc("XE","Active-Active",null, false); - Node xeNode = new Node(xe); - dependencyModel.getDependencies().add(xeNode); - - PowerMockito.mockStatic(DependencyModelFactory.class); - DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); - - PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); - PowerMockito.when(dependencyManager.getVnfcDependencyModel(( - DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) - .thenReturn(dependencyModel); - - VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); - vnfExecutionFlow.getVnfExecutionFlowData(params,context); - } - - @Test - public void testMissingOptionalVnfcTypeInInventoryModelWithDependentChild() throws DependencyModelNotFound { - Map params = prepareParams(); - SvcLogicContext context = prepareContext(); - context.setAttribute("vnf.vnfc[3].name","YEname"); - context.setAttribute("vnf.vnfc[3].type","YE"); - context.setAttribute("vnf.vnfc[3].vm_count","2"); - context.setAttribute("vnf.vnfc[3].vm[0].url","YE_URL1"); - context.setAttribute("vnf.vnfc[3].vm[1].url","YE_URL2"); - context.setAttribute("vnf.vnfcCount","4"); - - VnfcDependencyModel dependencyModel = readDependencyModel(); - - Vnfc xe = new Vnfc("XE","Active-Active",null, false); - Vnfc ye = new Vnfc("YE","Active-Active",null, true); - Node xeNode = new Node(xe); - Node yeNode = new Node(ye); - yeNode.addParent(xe); - - dependencyModel.getDependencies().add(yeNode); - dependencyModel.getDependencies().add(xeNode); - - PowerMockito.mockStatic(DependencyModelFactory.class); - DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); - - PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); - PowerMockito.when(dependencyManager.getVnfcDependencyModel(( - DependencyModelIdentifier) Matchers.any(),(DependencyTypes) Matchers.any())) - .thenReturn(dependencyModel); - - VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); - vnfExecutionFlow.getVnfExecutionFlowData(params,context); - } -} diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImplTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImplTest.java new file mode 100644 index 000000000..558a463ac --- /dev/null +++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/impl/VnfExecutionFlowImplTest.java @@ -0,0 +1,421 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.dg.common.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.onap.appc.dg.common.VnfExecutionFlow; +import org.onap.appc.dg.dependencymanager.DependencyManager; +import org.onap.appc.dg.dependencymanager.exception.DependencyModelNotFound; +import org.onap.appc.dg.dependencymanager.impl.DependencyModelFactory; +import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModelException; +import org.onap.appc.dg.objects.Node; +import org.onap.appc.dg.objects.VnfcDependencyModel; +import org.onap.appc.domainmodel.Vnfc; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.osgi.framework.FrameworkUtil; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({VnfExecutionFlowImplTest.class, FrameworkUtil.class,DependencyManager.class,DependencyModelFactory.class}) +@SuppressWarnings("unchecked") +public class VnfExecutionFlowImplTest { + + private final EELFLogger logger = EELFManager.getInstance().getLogger(VnfExecutionFlowImplTest.class); + + @Before + public void setUp() { + logger.setLevel(EELFLogger.Level.DEBUG); + } + + @Test + public void testPositiveFlow() throws DependencyModelNotFound, InvalidDependencyModelException { + Map params = prepareParams(); + SvcLogicContext context = prepareContext(); + VnfcDependencyModel dependencyModel = readDependencyModel(); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(Matchers.any(), Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + @Test + public void testComplexFlow() throws DependencyModelNotFound, InvalidDependencyModelException { + Map params = prepareParams(); + SvcLogicContext context = prepareContextForComplexDependency(); + VnfcDependencyModel dependencyModel = readComplexDependencyModel(); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(Matchers.any(), Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + @Test(expected = RuntimeException.class) + public void testCycleFlow() throws DependencyModelNotFound, InvalidDependencyModelException { + Map params = prepareParams(); + SvcLogicContext context = prepareContextForComplexDependency(); + VnfcDependencyModel dependencyModel = readCyclicDependencyModel(); + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(Matchers.any(), Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + private VnfcDependencyModel readCyclicDependencyModel() { + + Vnfc a = createVnfc("A","Active-Passive",null,false); + Vnfc b = createVnfc("B","Active-Active",null,false); + Vnfc c = createVnfc("C","Active-Active",null,false); + Vnfc d = createVnfc("D","Active-Active",null,false); + Vnfc e = createVnfc("E","Active-Active",null,false); + Vnfc f = createVnfc("F","Active-Active",null,false); + Vnfc g = createVnfc("G","Active-Active",null,false); + + Node aNode = new Node(a); + Node bNode = new Node(b); + Node cNode = new Node(c); + Node dNode = new Node(d); + Node eNode = new Node(e); + Node fNode = new Node(f); + Node gNode = new Node(g); + + bNode.addParent(a); + cNode.addParent(a); + cNode.addParent(b); + + bNode.addParent(d); + dNode.addParent(c); + + Set> dependencies = new HashSet<>(); + dependencies.add(aNode); + dependencies.add(bNode); + dependencies.add(cNode); + dependencies.add(dNode); + dependencies.add(eNode); + dependencies.add(fNode); + dependencies.add(gNode); + + return new VnfcDependencyModel(dependencies); + + } + + private Vnfc createVnfc(String vnfcType,String resilienceType,String vnfcName,boolean mandatory) { + Vnfc vnfc = new Vnfc(); + vnfc.setVnfcType(vnfcType); + vnfc.setResilienceType(resilienceType); + vnfc.setVnfcName(vnfcName); + vnfc.setMandatory(mandatory); + return vnfc; + } + + private SvcLogicContext prepareContextForComplexDependency() { + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("input.action-identifiers.vnf-id","1"); + context.setAttribute("vnf.type","vSCP"); + context.setAttribute("vnf.vnfcCount","7"); + + context.setAttribute("vnf.vnfc[0].name","A"); + context.setAttribute("vnf.vnfc[0].type","A"); + context.setAttribute("vnf.vnfc[0].vm_count","2"); + context.setAttribute("vnf.vnfc[0].vm[0].url","A1"); + context.setAttribute("vnf.vnfc[0].vm[1].url","A2"); + + context.setAttribute("vnf.vnfc[1].name","B"); + context.setAttribute("vnf.vnfc[1].type","B"); + context.setAttribute("vnf.vnfc[1].vm_count","5"); + context.setAttribute("vnf.vnfc[1].vm[0].url","B1"); + context.setAttribute("vnf.vnfc[1].vm[1].url","B2"); + context.setAttribute("vnf.vnfc[1].vm[2].url","B3"); + context.setAttribute("vnf.vnfc[1].vm[3].url","B4"); + context.setAttribute("vnf.vnfc[1].vm[4].url","B5"); + + context.setAttribute("vnf.vnfc[2].name","C"); + context.setAttribute("vnf.vnfc[2].type","C"); + context.setAttribute("vnf.vnfc[2].vm_count","4"); + context.setAttribute("vnf.vnfc[2].vm[0].url","C1"); + context.setAttribute("vnf.vnfc[2].vm[1].url","C2"); + context.setAttribute("vnf.vnfc[2].vm[2].url","C3"); + context.setAttribute("vnf.vnfc[2].vm[3].url","C4"); + + context.setAttribute("vnf.vnfc[3].name","D"); + context.setAttribute("vnf.vnfc[3].type","D"); + context.setAttribute("vnf.vnfc[3].vm_count","3"); + context.setAttribute("vnf.vnfc[3].vm[0].url","D1"); + context.setAttribute("vnf.vnfc[3].vm[1].url","D2"); + context.setAttribute("vnf.vnfc[3].vm[2].url","D3"); + + context.setAttribute("vnf.vnfc[4].name","E"); + context.setAttribute("vnf.vnfc[4].type","E"); + context.setAttribute("vnf.vnfc[4].vm_count","2"); + context.setAttribute("vnf.vnfc[4].vm[0].url","E1"); + context.setAttribute("vnf.vnfc[4].vm[1].url","E2"); + + context.setAttribute("vnf.vnfc[5].name","F"); + context.setAttribute("vnf.vnfc[5].type","F"); + context.setAttribute("vnf.vnfc[5].vm_count","1"); + context.setAttribute("vnf.vnfc[5].vm[0].url","F1"); + + context.setAttribute("vnf.vnfc[6].name","G"); + context.setAttribute("vnf.vnfc[6].type","G"); + context.setAttribute("vnf.vnfc[6].vm_count","1"); + context.setAttribute("vnf.vnfc[6].vm[0].url","G1"); + + + return context; + } + + private VnfcDependencyModel readComplexDependencyModel() { + Vnfc a = createVnfc("A","Active-Passive",null,false); + Vnfc b = createVnfc("B","Active-Active",null,false); + Vnfc c = createVnfc("C","Active-Active",null,false); + Vnfc d = createVnfc("D","Active-Active",null,false); + Vnfc e = createVnfc("E","Active-Active",null,false); + Vnfc f = createVnfc("F","Active-Active",null,false); + Vnfc g = createVnfc("G","Active-Active",null,false); + + + Node aNode = new Node(a); + Node bNode = new Node(b); + Node cNode = new Node(c); + Node dNode = new Node(d); + Node eNode = new Node(e); + Node fNode = new Node(f); + Node gNode = new Node(g); + + bNode.addParent(a); + cNode.addParent(a); + + dNode.addParent(b); + eNode.addParent(b); + gNode.addParent(b); + + fNode.addParent(c); + + gNode.addParent(f); + + Set> dependencies = new HashSet<>(); + dependencies.add(aNode); + dependencies.add(bNode); + dependencies.add(cNode); + dependencies.add(dNode); + dependencies.add(eNode); + dependencies.add(fNode); + dependencies.add(gNode); + + return new VnfcDependencyModel(dependencies); + } + + private VnfcDependencyModel readDependencyModel() { + + Vnfc smp = createVnfc("SMP","Active-Passive",null,false); + Vnfc be = createVnfc("BE","Active-Active",null,false); + Vnfc fe = createVnfc("FE","Active-Active",null,false); + + + Node smpNode = new Node(smp); + Node beNode = new Node(be); + Node feNode = new Node(fe); + + beNode.addParent(smp); + feNode.addParent(be); +// smpNode.addParent(fe); + + Set> dependencies = new HashSet<>(); + dependencies.add(smpNode); + dependencies.add(feNode); + dependencies.add(beNode); + + return new VnfcDependencyModel(dependencies); + } + + private Map prepareParams() { + Map params = new HashMap<>(); + params.put(Constants.DEPENDENCY_TYPE,"RESOURCE"); + params.put(Constants.FLOW_STRATEGY,"FORWARD"); + + params.put(Constants.VNF_TYPE,"vSCP"); + params.put(Constants.VNF_VERION,"1.00"); + return params; + } + + private SvcLogicContext prepareContext() { + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("input.action-identifiers.vnf-id","1"); + context.setAttribute("vnf.type","vSCP"); + context.setAttribute("vnf.vnfcCount","3"); + + context.setAttribute("vnf.vnfc[0].name","SMPname"); + context.setAttribute("vnf.vnfc[0].type","SMP"); + context.setAttribute("vnf.vnfc[0].vm_count","2"); + context.setAttribute("vnf.vnfc[0].vm[0].url","SMP_URL1"); + context.setAttribute("vnf.vnfc[0].vm[1].url","SMP_URL2"); + + context.setAttribute("vnf.vnfc[1].name","BEname"); + context.setAttribute("vnf.vnfc[1].type","BE"); + context.setAttribute("vnf.vnfc[1].vm_count","5"); + context.setAttribute("vnf.vnfc[1].vm[0].url","BE_URL1"); + context.setAttribute("vnf.vnfc[1].vm[1].url","BE_URL2"); + context.setAttribute("vnf.vnfc[1].vm[2].url","BE_URL3"); + context.setAttribute("vnf.vnfc[1].vm[3].url","BE_URL4"); + context.setAttribute("vnf.vnfc[1].vm[4].url","BE_URL5"); + + context.setAttribute("vnf.vnfc[2].name","FEname"); + context.setAttribute("vnf.vnfc[2].type","FE"); + context.setAttribute("vnf.vnfc[2].vm_count","2"); + context.setAttribute("vnf.vnfc[2].vm[0].url","FE_URL1"); + context.setAttribute("vnf.vnfc[2].vm[1].url","FE_URL2"); + + return context; + } + + @Test(expected = RuntimeException.class) + public void testMissingVnfcTypeInDependencyModel() throws DependencyModelNotFound, InvalidDependencyModelException { + Map params = prepareParams(); + SvcLogicContext context = prepareContext(); + context.setAttribute("vnf.vnfc[3].name","XEname"); + context.setAttribute("vnf.vnfc[3].type","XE"); + context.setAttribute("vnf.vnfc[3].vm_count","2"); + context.setAttribute("vnf.vnfc[3].vm[0].url","XE_URL1"); + context.setAttribute("vnf.vnfc[3].vm[1].url","XE_URL2"); + context.setAttribute("vnf.vnfcCount","4"); + + VnfcDependencyModel dependencyModel = readDependencyModel(); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(Matchers.any(), Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + @Test(expected = RuntimeException.class) + public void testMissingMandatoryVnfcTypeInInventoryModel() throws DependencyModelNotFound, InvalidDependencyModelException { + Map params = prepareParams(); + SvcLogicContext context = prepareContext(); + VnfcDependencyModel dependencyModel = readDependencyModel(); + + Vnfc xe = createVnfc("XE","Active-Active",null, true); + Node xeNode = new Node(xe); + dependencyModel.getDependencies().add(xeNode); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(Matchers.any(), Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + @Test + public void testMissingOptionalVnfcTypeInInventoryModel() throws DependencyModelNotFound, InvalidDependencyModelException { + Map params = prepareParams(); + SvcLogicContext context = prepareContext(); + VnfcDependencyModel dependencyModel = readDependencyModel(); + + Vnfc xe = createVnfc("XE","Active-Active",null, false); + Node xeNode = new Node(xe); + dependencyModel.getDependencies().add(xeNode); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(Matchers.any(), Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + @Test + public void testMissingOptionalVnfcTypeInInventoryModelWithDependentChild() throws DependencyModelNotFound, InvalidDependencyModelException { + Map params = prepareParams(); + SvcLogicContext context = prepareContext(); + context.setAttribute("vnf.vnfc[3].name","YEname"); + context.setAttribute("vnf.vnfc[3].type","YE"); + context.setAttribute("vnf.vnfc[3].vm_count","2"); + context.setAttribute("vnf.vnfc[3].vm[0].url","YE_URL1"); + context.setAttribute("vnf.vnfc[3].vm[1].url","YE_URL2"); + context.setAttribute("vnf.vnfcCount","4"); + + VnfcDependencyModel dependencyModel = readDependencyModel(); + + Vnfc xe = createVnfc("XE","Active-Active",null, false); + Vnfc ye = createVnfc("YE","Active-Active",null, true); + Node xeNode = new Node(xe); + Node yeNode = new Node(ye); + yeNode.addParent(xe); + + dependencyModel.getDependencies().add(yeNode); + dependencyModel.getDependencies().add(xeNode); + + PowerMockito.mockStatic(DependencyModelFactory.class); + DependencyManager dependencyManager = PowerMockito.mock(DependencyManager.class); + + PowerMockito.when(DependencyModelFactory.createDependencyManager()).thenReturn(dependencyManager); + PowerMockito.when(dependencyManager.getVnfcDependencyModel(Matchers.any(), Matchers.any())) + .thenReturn(dependencyModel); + + VnfExecutionFlow vnfExecutionFlow = new VnfExecutionFlowImpl(); + vnfExecutionFlow.getVnfExecutionFlowData(params,context); + } + + +} -- cgit 1.2.3-korg