VNMappingUnit implements AutoCloseable { private PhysicalNode virtualNodeMapping(VirtualNetworkId virtualNetworkId, VirtualNode virtualNode, List<PhysicalNode> physicalNodes) throws VNMappingException { List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.node.instance.PhysicalResourceRequirement> physicalResourceRequirements = virtualNode.getPhysicalResourceRequirement(); List<PhysicalNode> candidates = new LinkedList<PhysicalNode>(); switch ( virtualNode.getNodeType() ) { case Vswitch: for ( PhysicalNode physicalNode : physicalNodes ) { if ( PhysicalNode.NodeType.Switch == physicalNode.getNodeType() ) { if ( checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements) ) { candidates.add(physicalNode); } } } break; case Vrouter: for ( PhysicalNode physicalNode : physicalNodes ) { if ( PhysicalNode.NodeType.Router == physicalNode.getNodeType() ) { if ( checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements) ) { candidates.add(physicalNode); } } } break; case Vfirewall: for ( PhysicalNode physicalNode : physicalNodes ) { if ( PhysicalNode.NodeType.Firewall == physicalNode.getNodeType() ) { if ( checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements) ) { candidates.add(physicalNode); } } } break; case Vloadbalancer: for ( PhysicalNode physicalNode : physicalNodes ) { if ( PhysicalNode.NodeType.Loadbalancer == physicalNode.getNodeType() ) { if ( checkPhysicalNodeSatisfied(physicalNode, physicalResourceRequirements) ) { candidates.add(physicalNode); } } } break; default: throw new VNMappingException("Unsupported virtual node type " + virtualNode.getNodeType() + "."); } if ( candidates.isEmpty() ) { return null; } return candidates.get(0); } VNMappingUnit(DataBroker dataBroker,
                         PNComputationUnit pnComputationUnit,
                         PNResourcesTracker pnResourcesTracker); void virtualNetworkMapping(VirtualNetwork virtualNetwork, UserVnPnMapping userVnPnMapping,
                                      List<PhysicalPath> physicalPaths); void virtualNetworkMapping(VirtualNetwork virtualNetwork, List<VirtualLink> unmappedVirtualLinks,
                                      UserVnPnMapping userVnPnMapping, List<PhysicalPath> physicalPaths); @Override void close();  }
@Test public void testVirtualNodeMapping() throws Exception{ method = class1.getDeclaredMethod("virtualNodeMapping",new Class[]{ VirtualNetworkId.class, VirtualNode.class, List.class }); method.setAccessible(true); VirtualNetworkId virtualNetworkId = mock(VirtualNetworkId.class); VirtualNode virtualNode = mock(VirtualNode.class); PhysicalNode.NodeType NodeType_Switch = PhysicalNode.NodeType.Switch; PhysicalNode.NodeType NodeType_Router = PhysicalNode.NodeType.Router; PhysicalNode.NodeType NodeType_Firewall = PhysicalNode.NodeType.Firewall; PhysicalNode.NodeType NodeType_Loadbalancer = PhysicalNode.NodeType.Loadbalancer; NodeType nodeType_Vswitch = NodeType.Vswitch; NodeType nodeType_Vrouter = NodeType.Vrouter; NodeType nodeType_Vfirewall = NodeType.Vrouter; NodeType nodeType_Vloadbalancer = NodeType.Vrouter; PhysicalNode physicalNode = mock(PhysicalNode.class); org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.node.instance.PhysicalResourceRequirement physicalResourceRequirement = mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.node.instance.PhysicalResourceRequirement.class); List<PhysicalNode> physicalNodes = new ArrayList<PhysicalNode>(); List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.node.instance.PhysicalResourceRequirement> physicalResourceRequirements = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.node.instance.PhysicalResourceRequirement>(); physicalResourceRequirements.add(physicalResourceRequirement); when(virtualNode.getPhysicalResourceRequirement()).thenReturn(physicalResourceRequirements); when(virtualNode.getNodeType()) .thenReturn(nodeType_Vswitch) .thenReturn(nodeType_Vswitch) .thenReturn(nodeType_Vswitch) .thenReturn(nodeType_Vrouter) .thenReturn(nodeType_Vrouter) .thenReturn(nodeType_Vfirewall) .thenReturn(nodeType_Vfirewall) .thenReturn(nodeType_Vloadbalancer) .thenReturn(nodeType_Vloadbalancer); Assert.assertTrue(method.invoke(vnMappingUnit, virtualNetworkId, virtualNode, physicalNodes) == null); physicalNodes.add(physicalNode); when(physicalNode.getNodeType()) .thenReturn(null) .thenReturn(NodeType_Switch) .thenReturn(null) .thenReturn(NodeType_Router) .thenReturn(null) .thenReturn(NodeType_Firewall) .thenReturn(null) .thenReturn(NodeType_Loadbalancer); Assert.assertTrue(method.invoke(vnMappingUnit, virtualNetworkId, virtualNode, physicalNodes) == null); Assert.assertTrue(method.invoke(vnMappingUnit, virtualNetworkId, virtualNode, physicalNodes) == null); Assert.assertTrue(method.invoke(vnMappingUnit, virtualNetworkId, virtualNode, physicalNodes) == null); Assert.assertTrue(method.invoke(vnMappingUnit, virtualNetworkId, virtualNode, physicalNodes) == null); Assert.assertTrue(method.invoke(vnMappingUnit, virtualNetworkId, virtualNode, physicalNodes) == null); Assert.assertTrue(method.invoke(vnMappingUnit, virtualNetworkId, virtualNode, physicalNodes) == null); Assert.assertTrue(method.invoke(vnMappingUnit, virtualNetworkId, virtualNode, physicalNodes) == null); Assert.assertTrue(method.invoke(vnMappingUnit, virtualNetworkId, virtualNode, physicalNodes) == null); }