@Test public void testBuildLinks()throws Exception{ List<PhysicalLink> list; Class<PhysicalResourceLoader> class1 = PhysicalResourceLoader.class; Method method = class1.getDeclaredMethod("buildLinks", new Class[]{JsonNode.class}); method.setAccessible(true); JsonNode linksRoot = mock(JsonNode.class); JsonNode links = mock(JsonNode.class); JsonNode link = mock(JsonNode.class); JsonNode link_temp_buildlink = mock(JsonNode.class); when(linksRoot.path(any(String.class))).thenReturn(links); when(links.size()).thenReturn(1); when(links.get(any(Integer.class))).thenReturn(link); when(link.get(any(String.class))).thenReturn(link_temp_buildlink); when(link_temp_buildlink.asText()) .thenReturn(new String("1")) .thenReturn(new String("2")) .thenReturn(new String("3")) .thenReturn(new String("4")) .thenReturn(new String("5")) .thenReturn(new String("")); when(link_temp_buildlink.asLong()).thenReturn((long) 1); list = (List<PhysicalLink>)method.invoke(physicalResourceLoader,linksRoot); Assert.assertTrue(list.size() == 1); verify(link_temp_buildlink,times(6)).asText(); }
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; }
PhysicalResourceLoader { 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; } }
PhysicalResourceLoader { 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; } PhysicalResourceLoader(DataBroker dataBroker); }
PhysicalResourceLoader { 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; } PhysicalResourceLoader(DataBroker dataBroker); void close(); }
PhysicalResourceLoader { 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; } PhysicalResourceLoader(DataBroker dataBroker); void close(); final static String NODE_PROPERTY; final static String LINK_PROPERTY; final static String EXTERNAL_NETWORK_PROPERTY; final static String HOST_PROPERTY; }