Skip to content

Commit

Permalink
Add findTopology method to the API
Browse files Browse the repository at this point in the history
  • Loading branch information
khalidzahra committed Sep 29, 2021
1 parent 9bf33ef commit 9a5a445
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/github/khalidzahra/TopologyAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ public List<Topology> queryTopologies() {
return topologyRegistry.getTopologyList();
}

/**
* Finds topology with specified topology ID
* @param topologyID String variable containing the topology ID
* @return Returns Topology object with specified topology ID
*/
public Topology findTopology(String topologyID) {
return topologyRegistry.getTopologyList()
.stream()
.filter(topology -> topology.getId().equals(topologyID))
.findAny()
.orElse(null);
}

/**
* Deletes the specified topology from memory
*
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/com/github/khalidzahra/TopologyAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,20 @@ public void testQueryDevicesWithNetlistNode() {
assertEquals(topologyAPI.queryDevicesWithNetlistNode("top2", "vss").get(0).getDeviceType(), DeviceType.PMOS);

}

public void testFindTopology() {
TopologyAPI topologyAPI = new TopologyAPI();
topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology1.json");
assertNotNull(topologyAPI.findTopology("top1"));
assertEquals(topologyAPI.findTopology("top1").getId(), "top1");
topologyAPI.readJSON(resourceDirectory.toAbsolutePath() + "/topology2.json");
assertNotNull(topologyAPI.findTopology("top2"));
assertEquals(topologyAPI.findTopology("top2").getId(), "top2");
assertNull(topologyAPI.findTopology("top3"));
assertNull(topologyAPI.findTopology("top4"));
topologyAPI.deleteTopology("top1");
assertNull(topologyAPI.findTopology("top1"));
topologyAPI.deleteTopology("top2");
assertNull(topologyAPI.findTopology("top2"));
}
}

0 comments on commit 9a5a445

Please sign in to comment.