PhyConfigLoader { private void buildExternals(JsonNode externalRoot) { JsonNode exNetworkNodes = externalRoot.path(EXTERNAL_NETWORK_MAC); log.debug("Build external network mac : {} .", exNetworkNodes); for (int i = 0; i < exNetworkNodes.size(); i++) { log.debug("Build external network execution body"); JsonNode exNetworkNode = exNetworkNodes.get(i); buildExNetwork(exNetworkNode); } } 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 testBuildExternals() throws Exception{ JsonNode externalRoot = mock(JsonNode.class); JsonNode exNetworkNodes = mock(JsonNode.class); JsonNode exNetworkNode = mock(JsonNode.class); JsonNode jsonNode = mock(JsonNode.class); String nodeId = new String("1"); String portId = new String("2"); String peerMac = new String("00:11:22:33:44:55"); Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("buildExternals",new Class[]{JsonNode.class}); method.setAccessible(true); when(externalRoot.path(any(String.class))).thenReturn(exNetworkNodes); when(exNetworkNodes.size()).thenReturn(1); when(exNetworkNodes.get(any(Integer.class))).thenReturn(exNetworkNode); when(exNetworkNode.get(any(String.class))).thenReturn(jsonNode); when(jsonNode.asText()) .thenReturn(nodeId) .thenReturn(portId) .thenReturn(peerMac); method.invoke(phyConfigLoader, externalRoot); verify(externalRoot).path(any(String.class)); verify(exNetworkNodes,times(2)).size(); verify(exNetworkNodes).get(any(Integer.class)); verify(exNetworkNode,times(3)).get(any(String.class)); verify(jsonNode,times(3)).asText(); }