@Test public void testResolveNode() throws Exception { User user = mock(User.class); Node node = mock(Node.class); VirtualNetwork virtualNetwork = mock(VirtualNetwork.class); UserIntentVnMapping userIntentVnMapping = mock(UserIntentVnMapping.class); NodeType nodeType = mock(NodeType.class); when(node.getNodeType()) .thenReturn(new NodeType("host")); VirtualNodes virtualNodes = mock(VirtualNodes.class); VirtualNode virtualNode = mock(VirtualNode.class); IpAddress ipAddress = mock(IpAddress.class); IpAddresses ipAddresses = mock(IpAddresses.class); MacAddress macAddress = mock(MacAddress.class); PhysicalPortId physicalPortId = mock(PhysicalPortId.class); ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class); PhysicalNodeId physicalNodeId = mock(PhysicalNodeId.class); PhysicalHost physicalHost = mock(PhysicalHost.class); IntentVnMappingResult intentVnMappingResult = mock(IntentVnMappingResult.class); PhysicalHosts physicalHosts_resolveHost = mock(PhysicalHosts.class); VirtualArps virtualArps = mock(VirtualArps.class); NodeId nodeId = mock(NodeId.class); Optional<PhysicalHosts> result_resolveHost = Optional.of(physicalHosts_resolveHost); CheckedFuture checkedFuture = mock(CheckedFuture.class); List<PhysicalHost> physicalHostList_resolveHost = new ArrayList<PhysicalHost>(); List<VirtualNode> virtualNodeList_resolveHost = new ArrayList<VirtualNode>(); List<IpAddress> ipAddressList = new ArrayList<IpAddress>(); List<IntentVnMappingResult> intentVnMappingResultList = new ArrayList<IntentVnMappingResult>(); ipAddressList.add(ipAddress); when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction); when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture); when(checkedFuture.get()).thenReturn(result_resolveHost); when(physicalHosts_resolveHost.getPhysicalHost()).thenReturn(physicalHostList_resolveHost); PowerMockito.mockStatic(IntentResolverUtils.class); PowerMockito.when(IntentResolverUtils.getPhysicalHost(physicalHostList_resolveHost, node)).thenReturn(physicalHost); Assert.assertTrue(physicalHost != null); when(physicalHost.getNodeId()).thenReturn(physicalNodeId); when(physicalNodeId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222")); when(virtualNetwork.getVirtualNodes()).thenReturn(virtualNodes); when(virtualNodes.getVirtualNode()).thenReturn(virtualNodeList_resolveHost); when(virtualNetwork.getVirtualArps()).thenReturn(virtualArps); when(virtualArps.getVirtualArp()).thenReturn(new ArrayList<VirtualArp>()); when(physicalHost.getMacAddress()).thenReturn(macAddress); when(physicalHost.getPortId()).thenReturn(physicalPortId); when(physicalPortId.getValue()).thenReturn(new String("portid")); when(physicalHost.getIpAddresses()).thenReturn(ipAddresses); when(ipAddresses.getIpAddress()).thenReturn(ipAddressList); when(userIntentVnMapping.getIntentVnMappingResult()).thenReturn(intentVnMappingResultList); when(node.getNodeId()).thenReturn(nodeId); when(nodeId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222")); nodeMapper.resolveNode(user, node, virtualNetwork, userIntentVnMapping); verify(nodeId).getValue(); }
protected void resolveNode(User user, Node node, VirtualNetwork virtualNetwork, UserIntentVnMapping userIntentVnMapping) throws IntentResolutionException { NodeType nodeType = node.getNodeType(); if ( nodeType.equals(new NodeType("host")) ) { resolveHost(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType(("l2-group"))) ) { resolveLayer2Group(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("l3-group")) ) { resolveLayer3Group(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("ext-group")) ) { if ( IntentResolverUtils.checkExternalLayer3Group(node) ) { resolveExternalLayer3Group(user, node, virtualNetwork, userIntentVnMapping); } return; } if ( nodeType.equals(new NodeType("chain-group")) ) { resolveServiceChainGroup(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("fw")) || nodeType.equals(new NodeType("lb")) || nodeType.equals(new NodeType("cache")) ) { resolveServiceFunction(user, node, virtualNetwork, userIntentVnMapping); return; } throw new IntentResolutionException("Unknown node type."); }
NodeMapper { protected void resolveNode(User user, Node node, VirtualNetwork virtualNetwork, UserIntentVnMapping userIntentVnMapping) throws IntentResolutionException { NodeType nodeType = node.getNodeType(); if ( nodeType.equals(new NodeType("host")) ) { resolveHost(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType(("l2-group"))) ) { resolveLayer2Group(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("l3-group")) ) { resolveLayer3Group(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("ext-group")) ) { if ( IntentResolverUtils.checkExternalLayer3Group(node) ) { resolveExternalLayer3Group(user, node, virtualNetwork, userIntentVnMapping); } return; } if ( nodeType.equals(new NodeType("chain-group")) ) { resolveServiceChainGroup(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("fw")) || nodeType.equals(new NodeType("lb")) || nodeType.equals(new NodeType("cache")) ) { resolveServiceFunction(user, node, virtualNetwork, userIntentVnMapping); return; } throw new IntentResolutionException("Unknown node type."); } }
NodeMapper { protected void resolveNode(User user, Node node, VirtualNetwork virtualNetwork, UserIntentVnMapping userIntentVnMapping) throws IntentResolutionException { NodeType nodeType = node.getNodeType(); if ( nodeType.equals(new NodeType("host")) ) { resolveHost(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType(("l2-group"))) ) { resolveLayer2Group(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("l3-group")) ) { resolveLayer3Group(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("ext-group")) ) { if ( IntentResolverUtils.checkExternalLayer3Group(node) ) { resolveExternalLayer3Group(user, node, virtualNetwork, userIntentVnMapping); } return; } if ( nodeType.equals(new NodeType("chain-group")) ) { resolveServiceChainGroup(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("fw")) || nodeType.equals(new NodeType("lb")) || nodeType.equals(new NodeType("cache")) ) { resolveServiceFunction(user, node, virtualNetwork, userIntentVnMapping); return; } throw new IntentResolutionException("Unknown node type."); } NodeMapper(DataBroker dataBroker); }
NodeMapper { protected void resolveNode(User user, Node node, VirtualNetwork virtualNetwork, UserIntentVnMapping userIntentVnMapping) throws IntentResolutionException { NodeType nodeType = node.getNodeType(); if ( nodeType.equals(new NodeType("host")) ) { resolveHost(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType(("l2-group"))) ) { resolveLayer2Group(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("l3-group")) ) { resolveLayer3Group(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("ext-group")) ) { if ( IntentResolverUtils.checkExternalLayer3Group(node) ) { resolveExternalLayer3Group(user, node, virtualNetwork, userIntentVnMapping); } return; } if ( nodeType.equals(new NodeType("chain-group")) ) { resolveServiceChainGroup(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("fw")) || nodeType.equals(new NodeType("lb")) || nodeType.equals(new NodeType("cache")) ) { resolveServiceFunction(user, node, virtualNetwork, userIntentVnMapping); return; } throw new IntentResolutionException("Unknown node type."); } NodeMapper(DataBroker dataBroker);  }
NodeMapper { protected void resolveNode(User user, Node node, VirtualNetwork virtualNetwork, UserIntentVnMapping userIntentVnMapping) throws IntentResolutionException { NodeType nodeType = node.getNodeType(); if ( nodeType.equals(new NodeType("host")) ) { resolveHost(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType(("l2-group"))) ) { resolveLayer2Group(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("l3-group")) ) { resolveLayer3Group(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("ext-group")) ) { if ( IntentResolverUtils.checkExternalLayer3Group(node) ) { resolveExternalLayer3Group(user, node, virtualNetwork, userIntentVnMapping); } return; } if ( nodeType.equals(new NodeType("chain-group")) ) { resolveServiceChainGroup(user, node, virtualNetwork, userIntentVnMapping); return; } if ( nodeType.equals(new NodeType("fw")) || nodeType.equals(new NodeType("lb")) || nodeType.equals(new NodeType("cache")) ) { resolveServiceFunction(user, node, virtualNetwork, userIntentVnMapping); return; } throw new IntentResolutionException("Unknown node type."); } NodeMapper(DataBroker dataBroker);   }