@Test public void testBuildLinks()throws Exception{ List<PhysicalLink> list; JsonNode hostsNode = mock(JsonNode.class); JsonNode hosts = mock(JsonNode.class); JsonNode jsonNode = mock(JsonNode.class); JsonNode jsonNode1 = mock(JsonNode.class); PhysicalHost physicalHost; Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("buildLinks",new Class[]{JsonNode.class}); method.setAccessible(true); when(hostsNode.path(any(String.class))).thenReturn(hosts); when(hosts.size()).thenReturn(1); when(hosts.get(any(Integer.class))).thenReturn(jsonNode); when(jsonNode.get(any(String.class))) .thenReturn(jsonNode1) .thenReturn(jsonNode1); when(jsonNode1.asText()).thenReturn(new String("test")); when(jsonNode1.asLong()).thenReturn((long) 1); list = (List<PhysicalLink>)method.invoke(phyConfigLoader,hostsNode); Assert.assertTrue(list.size() == 1); }
private List<PhysicalLink> buildLinks(JsonNode linksRoot) { List<PhysicalLink> physicalLinks = new ArrayList<PhysicalLink>(); JsonNode links = linksRoot.path(LINKS); log.debug("Build links: {} .", links); for (int i = 0; i < links.size(); i++) { log.debug("build physical node execution body"); JsonNode link = links.get(i); PhysicalLink phyLink = buildLink(link); if (phyLink != null) { physicalLinks.add(phyLink); } } return physicalLinks; }
PhyConfigLoader { private List<PhysicalLink> buildLinks(JsonNode linksRoot) { List<PhysicalLink> physicalLinks = new ArrayList<PhysicalLink>(); JsonNode links = linksRoot.path(LINKS); log.debug("Build links: {} .", links); for (int i = 0; i < links.size(); i++) { log.debug("build physical node execution body"); JsonNode link = links.get(i); PhysicalLink phyLink = buildLink(link); if (phyLink != null) { physicalLinks.add(phyLink); } } return physicalLinks; } }
PhyConfigLoader { private List<PhysicalLink> buildLinks(JsonNode linksRoot) { List<PhysicalLink> physicalLinks = new ArrayList<PhysicalLink>(); JsonNode links = linksRoot.path(LINKS); log.debug("Build links: {} .", links); for (int i = 0; i < links.size(); i++) { log.debug("build physical node execution body"); JsonNode link = links.get(i); PhysicalLink phyLink = buildLink(link); if (phyLink != null) { physicalLinks.add(phyLink); } } return physicalLinks; } PhyConfigLoader(DataBroker dataBroker); }
PhyConfigLoader { private List<PhysicalLink> buildLinks(JsonNode linksRoot) { List<PhysicalLink> physicalLinks = new ArrayList<PhysicalLink>(); JsonNode links = linksRoot.path(LINKS); log.debug("Build links: {} .", links); for (int i = 0; i < links.size(); i++) { log.debug("build physical node execution body"); JsonNode link = links.get(i); PhysicalLink phyLink = buildLink(link); if (phyLink != null) { physicalLinks.add(phyLink); } } return physicalLinks; } PhyConfigLoader(DataBroker dataBroker); Table<PhysicalNodeId, PhysicalPortId, MacAddress> getExternalNetworkMac(); void close(); }
PhyConfigLoader { private List<PhysicalLink> buildLinks(JsonNode linksRoot) { List<PhysicalLink> physicalLinks = new ArrayList<PhysicalLink>(); JsonNode links = linksRoot.path(LINKS); log.debug("Build links: {} .", links); for (int i = 0; i < links.size(); i++) { log.debug("build physical node execution body"); JsonNode link = links.get(i); PhysicalLink phyLink = buildLink(link); if (phyLink != null) { physicalLinks.add(phyLink); } } return physicalLinks; } 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; }