@Test public PhysicalLink testBuildLink(JsonNode arg)throws Exception{ if(arg == null)return null; PhysicalLink physicalLink = mock(PhysicalLink.class); JsonNode jsonNode = mock(JsonNode.class); JsonNode jsonNode1 = mock(JsonNode.class); Class<PhyConfigLoader> class1 = PhyConfigLoader.class; Method method = class1.getDeclaredMethod("buildLink",new Class[]{JsonNode.class}); method.setAccessible(true); when(jsonNode.get(any(String.class))) .thenReturn(jsonNode1) .thenReturn(jsonNode1); when(jsonNode1.asText()).thenReturn(new String("test")); when(jsonNode1.asLong()).thenReturn((long) 1); physicalLink = (PhysicalLink)method.invoke(phyConfigLoader,jsonNode); Assert.assertTrue(physicalLink != null); Assert.assertTrue(physicalLink != mock(PhysicalLink.class)); return physicalLink; }
private PhysicalLink buildLink(JsonNode linkNode) { PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); String strLinkId = linkNode.get(LINK_ID).asText(); long metric = linkNode.get(METRIC).asLong(); linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); linkBuilder.setMetric(metric); linkBuilder.setBandwidth(DEFAULT_LINK_BANDWIDTH); linkBuilder.setDelay(DEFAULT_LINK_DELAY); linkBuilder.setLossRate(DEFAULT_LINK_LOSS_RATE); return linkBuilder.build(); }
PhyConfigLoader { private PhysicalLink buildLink(JsonNode linkNode) { PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); String strLinkId = linkNode.get(LINK_ID).asText(); long metric = linkNode.get(METRIC).asLong(); linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); linkBuilder.setMetric(metric); linkBuilder.setBandwidth(DEFAULT_LINK_BANDWIDTH); linkBuilder.setDelay(DEFAULT_LINK_DELAY); linkBuilder.setLossRate(DEFAULT_LINK_LOSS_RATE); return linkBuilder.build(); } }
PhyConfigLoader { private PhysicalLink buildLink(JsonNode linkNode) { PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); String strLinkId = linkNode.get(LINK_ID).asText(); long metric = linkNode.get(METRIC).asLong(); linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); linkBuilder.setMetric(metric); linkBuilder.setBandwidth(DEFAULT_LINK_BANDWIDTH); linkBuilder.setDelay(DEFAULT_LINK_DELAY); linkBuilder.setLossRate(DEFAULT_LINK_LOSS_RATE); return linkBuilder.build(); } PhyConfigLoader(DataBroker dataBroker); }
PhyConfigLoader { private PhysicalLink buildLink(JsonNode linkNode) { PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); String strLinkId = linkNode.get(LINK_ID).asText(); long metric = linkNode.get(METRIC).asLong(); linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); linkBuilder.setMetric(metric); linkBuilder.setBandwidth(DEFAULT_LINK_BANDWIDTH); linkBuilder.setDelay(DEFAULT_LINK_DELAY); linkBuilder.setLossRate(DEFAULT_LINK_LOSS_RATE); return linkBuilder.build(); } PhyConfigLoader(DataBroker dataBroker); Table<PhysicalNodeId, PhysicalPortId, MacAddress> getExternalNetworkMac(); void close(); }
PhyConfigLoader { private PhysicalLink buildLink(JsonNode linkNode) { PhysicalLinkBuilder linkBuilder = new PhysicalLinkBuilder(); String strLinkId = linkNode.get(LINK_ID).asText(); long metric = linkNode.get(METRIC).asLong(); linkBuilder.setLinkId(new PhysicalLinkId(strLinkId)); linkBuilder.setMetric(metric); linkBuilder.setBandwidth(DEFAULT_LINK_BANDWIDTH); linkBuilder.setDelay(DEFAULT_LINK_DELAY); linkBuilder.setLossRate(DEFAULT_LINK_LOSS_RATE); return linkBuilder.build(); } 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; }