PhyConfigLoader { private List<PhysicalHost> buildHosts(JsonNode hostsNode) { List<PhysicalHost> physicalHosts = new ArrayList<PhysicalHost>(); JsonNode hosts = hostsNode.path(HOSTS); log.debug("Build hosts: {} .", hosts); for (int i = 0; i < hosts.size(); i++) { JsonNode host = hosts.get(i); PhysicalHost physicalHost = buildHost(host); if (physicalHost != null) { physicalHosts.add(physicalHost); } } return physicalHosts; } 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; }
@Test public void testBuildHosts()throws Exception{ Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("buildHosts", new Class[]{JsonNode.class}); method.setAccessible(true); JsonNode hostsNode = mock(JsonNode.class); JsonNode hosts = mock(JsonNode.class); JsonNode host = mock(JsonNode.class); JsonNode host_temp = mock(JsonNode.class); JsonNode host_temp1 = mock(JsonNode.class); JsonNode ipaddrs = mock(JsonNode.class); JsonNode ipaddr = mock(JsonNode.class); List<PhysicalHost> list; when(hostsNode.path(any(String.class))).thenReturn(hosts); when(hosts.size()).thenReturn(1); when(hosts.get(any(Integer.class))).thenReturn(host); when(host.get(any(String.class))).thenReturn(host_temp); when(host_temp.asText()) .thenReturn(new String("00001111-0000-0000-0000-000011112222")) .thenReturn(new String("hostName")) .thenReturn(new String("00:11:22:33:44:55")) .thenReturn(new String("nodeId")) .thenReturn(new String("connetionId")); when(host.path(any(String.class))).thenReturn(ipaddrs); when(ipaddrs.size()).thenReturn(1); when(ipaddrs.get(any(Integer.class))).thenReturn(ipaddr); when(ipaddr.get(any(String.class))).thenReturn(host_temp1); when(host_temp1.asText()).thenReturn(new String("192.168.1.1")); list = (List<PhysicalHost>) method.invoke(phyConfigLoader,hostsNode); Assert.assertTrue(list.size() == 1); }