ConfigReader { public static BgpSpeakers getBgpSpeakers() { if (rootJsonNode == null) { return null; } JsonNode bgpSpeakersJsonNode = rootJsonNode.path("bgpSpeakers"); Iterator<JsonNode> bgpSpeakerNodeIterator = bgpSpeakersJsonNode.elements(); BgpSpeakersBuilder bgpSpeakersBuilder = new BgpSpeakersBuilder(); List<BgpSpeaker> bgpSpeakerList = new ArrayList<BgpSpeaker>(); while (bgpSpeakerNodeIterator.hasNext()) { BgpSpeakerBuilder bgpSpeakerBuilder = new BgpSpeakerBuilder(); JsonNode speakerElementNode = bgpSpeakerNodeIterator.next(); String speakerName = speakerElementNode.path("name").asText(); String ofAttachmentDpId = AtriumUtils .hexDpidStringToOpenFlowDpid(speakerElementNode.path("attachmentDpid").asText()); long attachmentPort = speakerElementNode.path("attachmentPort").asLong(); MacAddress macAddress = new MacAddress(speakerElementNode.path("macAddress").asText()); NodeId attachmentDpId = new NodeId(ofAttachmentDpId); List<InterfaceAddresses> interfaceAddressesList = new ArrayList<InterfaceAddresses>(); BgpSpeakerKey bgpSpeakerKey = new BgpSpeakerKey(macAddress); Iterator<JsonNode> interfaceAddressesIterator = speakerElementNode.path("interfaceAddresses").elements(); while (interfaceAddressesIterator.hasNext()) { InterfaceAddressesBuilder interfaceAddressesBuilder = new InterfaceAddressesBuilder(); JsonNode interfaceElementNode = interfaceAddressesIterator.next(); String ofNode = AtriumUtils .hexDpidStringToOpenFlowDpid(interfaceElementNode.path("interfaceDpid").asText()); String nodeConnectorString = ofNode + ":" + interfaceElementNode.path("interfacePort").asText(); IpAddress ipAddress = new IpAddress(new Ipv4Address(interfaceElementNode.path("ipAddress").asText())); NodeConnectorId of_port_id = new NodeConnectorId(nodeConnectorString); InterfaceAddressesKey addressesKey = new InterfaceAddressesKey(of_port_id); interfaceAddressesBuilder.setIpAddress(ipAddress); interfaceAddressesBuilder.setOfPortId(of_port_id); interfaceAddressesBuilder.setKey(addressesKey); interfaceAddressesList.add(interfaceAddressesBuilder.build()); } bgpSpeakerBuilder.setAttachmentPort(attachmentPort); bgpSpeakerBuilder.setMacAddress(macAddress); bgpSpeakerBuilder.setSpeakerName(speakerName); bgpSpeakerBuilder.setAttachmentDpId(attachmentDpId); bgpSpeakerBuilder.setInterfaceAddresses(interfaceAddressesList); bgpSpeakerBuilder.setKey(bgpSpeakerKey); bgpSpeakerList.add(bgpSpeakerBuilder.build()); } bgpSpeakersBuilder.setBgpSpeaker(bgpSpeakerList); return bgpSpeakersBuilder.build(); }  static boolean initialize(URL configFileUrl); static BgpSpeakers getBgpSpeakers(); static BgpPeers getBgpPeer();  }
@Test public void testGetBgpSpeakers() throws FileNotFoundException, IOException, ParseException { testInitialize(); BgpSpeakers actualBgpSpeakers = null; BgpSpeakers expectedBgpSpeakers = null; BgpSpeakerBuilder bgpSpeakerBuilder = new BgpSpeakerBuilder(); BgpSpeakersBuilder bgpSpeakersBuilder = new BgpSpeakersBuilder(); InterfaceAddressesBuilder intfAddressBuilder = new InterfaceAddressesBuilder(); List<InterfaceAddresses> intfAddressesList = new ArrayList<InterfaceAddresses>(); List<BgpSpeaker> bgpSpeakerList = new ArrayList<BgpSpeaker>(); JSONArray bgpSpeakers = (JSONArray) jsonObject.get("bgpSpeakers"); Iterator<JSONObject> bgpIterator = bgpSpeakers.iterator(); while (bgpIterator.hasNext()) { JSONObject bgp = (JSONObject) bgpIterator.next(); bgpSpeakerBuilder.setSpeakerName((String) bgp.get("name")); String attachmentDpid = AtriumUtils.hexDpidStringToOpenFlowDpid((String) bgp.get("attachmentDpid")); bgpSpeakerBuilder.setAttachmentDpId(NodeId.getDefaultInstance(attachmentDpid)); String attachmentPort = (String) bgp.get("attachmentPort"); bgpSpeakerBuilder.setAttachmentPort(Long.valueOf(attachmentPort)); String macAddress = (String) bgp.get("macAddress"); bgpSpeakerBuilder.setMacAddress(MacAddress.getDefaultInstance(macAddress)); JSONArray intfList = (JSONArray) bgp.get("interfaceAddresses"); Iterator<JSONObject> intfIterator = intfList.iterator(); while (intfIterator.hasNext()) { JSONObject intfAddress = (JSONObject) intfIterator.next(); String ipAddress = (String) intfAddress.get("ipAddress"); intfAddressBuilder.setIpAddress(new IpAddress(Ipv4Address.getDefaultInstance(ipAddress))); String interfaceDpid = AtriumUtils .hexDpidStringToOpenFlowDpid((String) intfAddress.get("interfaceDpid")); String interfacePort = (String) intfAddress.get("interfacePort"); NodeConnectorId ncId = NodeConnectorId.getDefaultInstance(interfaceDpid + ":" + interfacePort); intfAddressBuilder.setOfPortId(ncId); intfAddressBuilder.setKey(new InterfaceAddressesKey(ncId)); intfAddressesList.add(intfAddressBuilder.build()); } bgpSpeakerBuilder.setInterfaceAddresses(intfAddressesList); bgpSpeakerList.add(bgpSpeakerBuilder.build()); } bgpSpeakersBuilder.setBgpSpeaker(bgpSpeakerList); expectedBgpSpeakers = bgpSpeakersBuilder.build(); actualBgpSpeakers = ConfigReader.getBgpSpeakers(); assertEquals(expectedBgpSpeakers, actualBgpSpeakers); }