ConfigReader { public static BgpPeers getBgpPeer() { if (rootJsonNode == null) { return null; } JsonNode bgpPeersJsonNode = rootJsonNode.path("bgpPeers"); Iterator<JsonNode> bgpPeerNodeIterator = bgpPeersJsonNode.elements(); BgpPeersBuilder bgpPeersBuilder = new BgpPeersBuilder(); List<BgpPeer> bgpPeerList = new ArrayList<BgpPeer>(); while (bgpPeerNodeIterator.hasNext()) { BgpPeerBuilder bgpPeerBuilder = new BgpPeerBuilder(); JsonNode peerElementNode = bgpPeerNodeIterator.next(); IpAddress peerAddr = new IpAddress(new Ipv4Address(peerElementNode.path("ipAddress").asText())); String ofDpId = AtriumUtils.hexDpidStringToOpenFlowDpid(peerElementNode.path("attachmentDpid").asText()); NodeId peerDpId = new NodeId(ofDpId); Long peerPort = peerElementNode.path("attachmentPort").asLong(); BgpPeerKey peerKey = new BgpPeerKey(peerAddr); bgpPeerBuilder.setPeerAddr(peerAddr); bgpPeerBuilder.setPeerDpId(peerDpId); bgpPeerBuilder.setPeerPort(peerPort); bgpPeerBuilder.setKey(peerKey); bgpPeerList.add(bgpPeerBuilder.build()); } bgpPeersBuilder.setBgpPeer(bgpPeerList); return bgpPeersBuilder.build(); }  static boolean initialize(URL configFileUrl); static BgpSpeakers getBgpSpeakers(); static BgpPeers getBgpPeer();  }
@Test public void testGetBgpPeers() throws FileNotFoundException, IOException, ParseException { testInitialize(); BgpPeers actualBgpPeers = null; BgpPeers expectedBgpPeers = null; List<BgpPeer> bgpPeerList = new ArrayList<BgpPeer>(); BgpPeerBuilder bgpPeerBuilder = new BgpPeerBuilder(); BgpPeersBuilder bgpPeersBuilder = new BgpPeersBuilder(); JSONArray bgpPeers = (JSONArray) jsonObject.get("bgpPeers"); Iterator<JSONObject> bgpIterator = bgpPeers.iterator(); while (bgpIterator.hasNext()) { JSONObject bgpPeer = (JSONObject) bgpIterator.next(); String dpId = AtriumUtils.hexDpidStringToOpenFlowDpid((String) bgpPeer.get("attachmentDpid")); bgpPeerBuilder.setPeerDpId(NodeId.getDefaultInstance(dpId)); String attachmentPort = (String) bgpPeer.get("attachmentPort"); bgpPeerBuilder.setPeerPort(Long.valueOf(attachmentPort)); String ipAddress = (String) bgpPeer.get("ipAddress"); IpAddress ip = new IpAddress(Ipv4Address.getDefaultInstance(ipAddress)); bgpPeerBuilder.setPeerAddr(ip); bgpPeerBuilder.setKey(new BgpPeerKey(ip)); bgpPeerList.add(bgpPeerBuilder.build()); } bgpPeersBuilder.setBgpPeer(bgpPeerList); expectedBgpPeers = bgpPeersBuilder.build(); actualBgpPeers = ConfigReader.getBgpPeer(); assertEquals(expectedBgpPeers, actualBgpPeers); }