@Test public void testBuildNodes() throws Exception{ Class<PhyConfigLoader>class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("buildNodes", new Class[]{JsonNode.class}); method.setAccessible(true); JsonNode nodesRoot = mock(JsonNode.class); JsonNode nodes = mock(JsonNode.class); JsonNode node = mock(JsonNode.class); JsonNode node_temp = mock(JsonNode.class); JsonNode port_temp = mock(JsonNode.class); JsonNode attribute_temp = mock(JsonNode.class); JsonNode attribute_temp_son = mock(JsonNode.class); JsonNode ports = mock(JsonNode.class); JsonNode attributes = mock(JsonNode.class); JsonNode portAttributes = mock(JsonNode.class); JsonNode portAttribute = mock(JsonNode.class); JsonNode attributes_son = mock(JsonNode.class); JsonNode port = mock(JsonNode.class); List<PhysicalNode> result; when(nodesRoot.path(any(String.class))).thenReturn(nodes); when(nodes.size()).thenReturn(1); when(nodes.get(any(Integer.class))).thenReturn(node); when(node.get(any(String.class))).thenReturn(node_temp); when(node_temp.asText()) .thenReturn(new String("")) .thenReturn(new String("test")) .thenReturn(new String("switch")); result = (List<PhysicalNode>) method.invoke(phyConfigLoader,nodesRoot); Assert.assertTrue(result.size() == 0); verify(node_temp).asText(); when(node.path(any(String.class))) .thenReturn(ports) .thenReturn(attributes); when(ports.size()).thenReturn(1); when(ports.get(any(Integer.class))).thenReturn(port); when(port.get(any(String.class))).thenReturn(port_temp); when(port_temp.asText()) .thenReturn(new String("test")) .thenReturn(new String("switch")); when(port.path(any(String.class))).thenReturn(portAttributes); when(portAttributes.size()).thenReturn(1); when(portAttributes.get(any(Integer.class))).thenReturn(attributes_son); when(attributes_son.path(any(String.class))).thenReturn(attribute_temp_son); when(attribute_temp_son.asText()) .thenReturn(new String("zm")) .thenReturn(new String("zm")); when(attributes.size()).thenReturn(1); when(attributes.get(any(Integer.class))).thenReturn(portAttribute); when(portAttribute.path(any(String.class))).thenReturn(attribute_temp); when(attribute_temp.asText()) .thenReturn(new String("test")) .thenReturn(new String("test")); result = (List<PhysicalNode>) method.invoke(phyConfigLoader,nodesRoot); Assert.assertTrue(result.size() == 1); }
private List<PhysicalNode> buildNodes(JsonNode nodesRoot) { List<PhysicalNode> physicalNodes = new ArrayList<PhysicalNode>(); JsonNode nodes = nodesRoot.path(NODES); log.debug("Build nodes: {} .", nodes); for (int i = 0; i < nodes.size(); i++) { log.debug("build physical node execution body"); JsonNode node = nodes.get(i); PhysicalNode phyNode = buildNode(node); if (phyNode != null) { physicalNodes.add(phyNode); } } return physicalNodes; }
PhyConfigLoader { private List<PhysicalNode> buildNodes(JsonNode nodesRoot) { List<PhysicalNode> physicalNodes = new ArrayList<PhysicalNode>(); JsonNode nodes = nodesRoot.path(NODES); log.debug("Build nodes: {} .", nodes); for (int i = 0; i < nodes.size(); i++) { log.debug("build physical node execution body"); JsonNode node = nodes.get(i); PhysicalNode phyNode = buildNode(node); if (phyNode != null) { physicalNodes.add(phyNode); } } return physicalNodes; } }
PhyConfigLoader { private List<PhysicalNode> buildNodes(JsonNode nodesRoot) { List<PhysicalNode> physicalNodes = new ArrayList<PhysicalNode>(); JsonNode nodes = nodesRoot.path(NODES); log.debug("Build nodes: {} .", nodes); for (int i = 0; i < nodes.size(); i++) { log.debug("build physical node execution body"); JsonNode node = nodes.get(i); PhysicalNode phyNode = buildNode(node); if (phyNode != null) { physicalNodes.add(phyNode); } } return physicalNodes; } PhyConfigLoader(DataBroker dataBroker); }
PhyConfigLoader { private List<PhysicalNode> buildNodes(JsonNode nodesRoot) { List<PhysicalNode> physicalNodes = new ArrayList<PhysicalNode>(); JsonNode nodes = nodesRoot.path(NODES); log.debug("Build nodes: {} .", nodes); for (int i = 0; i < nodes.size(); i++) { log.debug("build physical node execution body"); JsonNode node = nodes.get(i); PhysicalNode phyNode = buildNode(node); if (phyNode != null) { physicalNodes.add(phyNode); } } return physicalNodes; } PhyConfigLoader(DataBroker dataBroker); Table<PhysicalNodeId, PhysicalPortId, MacAddress> getExternalNetworkMac(); void close(); }
PhyConfigLoader { private List<PhysicalNode> buildNodes(JsonNode nodesRoot) { List<PhysicalNode> physicalNodes = new ArrayList<PhysicalNode>(); JsonNode nodes = nodesRoot.path(NODES); log.debug("Build nodes: {} .", nodes); for (int i = 0; i < nodes.size(); i++) { log.debug("build physical node execution body"); JsonNode node = nodes.get(i); PhysicalNode phyNode = buildNode(node); if (phyNode != null) { physicalNodes.add(phyNode); } } return physicalNodes; } PhyConfigLoader(DataBroker dataBroker); Table<PhysicalNodeId, PhysicalPortId, MacAddress> getExternalNetworkMac(); void close(); final static String NODE_PROPERTY; final static String LINK_PROPERTY; final static String EXTERNAL_NETWORK_MAC_PROPERTY; final static String HOST_PROPERTY; }